maximum flow problem - github pagesmaximum flow problem what is the greatest amount of ow that can...

35
Maximum flow problem CE 367R

Upload: others

Post on 07-Dec-2020

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Maximum flow problem - GitHub PagesMaximum Flow Problem What is the greatest amount of ow that can be shipped between a given source and sink without exceeding link capacities? MaximumNetwork

Maximum flow problem

CE 367R

Page 2: Maximum flow problem - GitHub PagesMaximum Flow Problem What is the greatest amount of ow that can be shipped between a given source and sink without exceeding link capacities? MaximumNetwork

MAXIMUM FLOWPROBLEM

Page 3: Maximum flow problem - GitHub PagesMaximum Flow Problem What is the greatest amount of ow that can be shipped between a given source and sink without exceeding link capacities? MaximumNetwork

Maximum Flow Problem

What is the greatest amount of flow that can be shipped between a givensource and sink without exceeding link capacities?

Maximum flow problem Maximum flow problem

Page 4: Maximum flow problem - GitHub PagesMaximum Flow Problem What is the greatest amount of ow that can be shipped between a given source and sink without exceeding link capacities? MaximumNetwork

Applications

Determining the capacity of a network

Identifying critical links in a network

Rounding a matrix

Maximum flow problem Maximum flow problem

Page 5: Maximum flow problem - GitHub PagesMaximum Flow Problem What is the greatest amount of ow that can be shipped between a given source and sink without exceeding link capacities? MaximumNetwork

Network capacity

Assume we are trying to transport something from one point to another(fluid in pipes, people to evacuate, etc.)

Network links represent the physical system and its capacities; set theorigin as source and destination as sink.

The solution gives the way to transport goods from the source to sink atthe fastest possible rate.

Maximum flow problem Maximum flow problem

Page 6: Maximum flow problem - GitHub PagesMaximum Flow Problem What is the greatest amount of ow that can be shipped between a given source and sink without exceeding link capacities? MaximumNetwork

Bottleneck analysis

By examining the solution to the network capacity problem, you canidentify the “critical links” where any capacity reduction will affect theoverall rate of flow from source to sink.

You can also identify “noncritical links,” where the capacity can bereduced slightly without affecting the overall flow rate.

Maximum flow problem Maximum flow problem

Page 7: Maximum flow problem - GitHub PagesMaximum Flow Problem What is the greatest amount of ow that can be shipped between a given source and sink without exceeding link capacities? MaximumNetwork

Matrix rounding problem

Assume we are given a matrix, and want to round its entries to integers.The row and column sums should also be rounded, and give the correctvalues for the rounded entries.

3.1 6.8 7.3 17.29.6 2.4 0.7 12.73.6 1.2 6.5 11.3

16.3 10.4 14.5

If we can round any entry up or down to the nearest integer, we can solvethis as a max flow problem.

Maximum flow problem Maximum flow problem

Page 8: Maximum flow problem - GitHub PagesMaximum Flow Problem What is the greatest amount of ow that can be shipped between a given source and sink without exceeding link capacities? MaximumNetwork

Create a column of nodes for each row, and a column of nodes for eachcolumn. Also create two artificial nodes, the source and the sink.

Links have lower and upper flow bounds representing the range ofrounding possibilities. Any feasible integer flow in this network (includingthe maximum) is a valid rounding.

Maximum flow problem Maximum flow problem

Page 9: Maximum flow problem - GitHub PagesMaximum Flow Problem What is the greatest amount of ow that can be shipped between a given source and sink without exceeding link capacities? MaximumNetwork

FORMULATION

Page 10: Maximum flow problem - GitHub PagesMaximum Flow Problem What is the greatest amount of ow that can be shipped between a given source and sink without exceeding link capacities? MaximumNetwork

In the maximum flow problem, we are given...

A directed network G = (N,A) with a specified “source” node s and“sink” node t.

Each link (i , j) has a capacity uij . (Costs are irrelevant in the maximumflow problem.)

The objective is to ship the maximum amount of flow from s to t whilerespecting the link capacities.

Maximum flow problem Formulation

Page 11: Maximum flow problem - GitHub PagesMaximum Flow Problem What is the greatest amount of ow that can be shipped between a given source and sink without exceeding link capacities? MaximumNetwork

What do we mean by amount of flow?

Think about shipping one unit of flow from s to t along a particular path.

Because links have capacities, you can probably send more flow if you usemultiple paths (keeping in mind where they intersect.)

The xij values show the total amount of flow on link (i , j), which is notallowed to exceed the capacity uij .

Maximum flow problem Formulation

Page 12: Maximum flow problem - GitHub PagesMaximum Flow Problem What is the greatest amount of ow that can be shipped between a given source and sink without exceeding link capacities? MaximumNetwork

A feasible flow satisfies conservation: except for the source and the sink,the flow entering a link must be the same as the flow leaving.

We can express this as ∑(i ,j)∈A(i)

xij −∑

(h,i)∈B(i)

xhi = 0

for all nodes i except for s and t.

Furthermore the net flow leaving the source should be the same amountentering the sink:∑

(s,j)∈A(s)

xsj −∑

(h,s)∈B(s)

xhs =∑

(h,t)∈B(t)

xht −∑

(t,j)∈A(t)

xtj

and this is what we are trying to maximize. We can call this b forconvenience.

Maximum flow problem Formulation

Page 13: Maximum flow problem - GitHub PagesMaximum Flow Problem What is the greatest amount of ow that can be shipped between a given source and sink without exceeding link capacities? MaximumNetwork

Formulation

maxb,x

b

s.t.∑

(h,i)∈A

xhi −∑

(i ,j)∈A

xij =

−b i = s

+b i = t

0 otherwise

0 ≤ xij ≤ uij ∀(i , j) ∈ A

A feasible solution x to this problem is called a flow. The amount of flowshipped is given by b.

Maximum flow problem Formulation

Page 14: Maximum flow problem - GitHub PagesMaximum Flow Problem What is the greatest amount of ow that can be shipped between a given source and sink without exceeding link capacities? MaximumNetwork

AUGMENTING PATHALGORITHM

Page 15: Maximum flow problem - GitHub PagesMaximum Flow Problem What is the greatest amount of ow that can be shipped between a given source and sink without exceeding link capacities? MaximumNetwork

An augmenting path is an undirected path from the source to the sink,satisfying the following properties:

1 Every link in the forward direction has flow less than capacity,xij < uij .

2 Every link in the reverse direction has flow greater than zero, xij > 0.

The residual capacity of this path is the smallest gap between the left andright hand sides of the above inequality (that is, find the smallest value of

uij − xij for forward links, the smallest value of xij for reverse link; the residual

capacity is the smaller of those two numbers.)

The idea: we will increase flow on forward links and decrease flow onreverse links. This maintains flow conservation.

Maximum flow problem Augmenting path algorithm

Page 16: Maximum flow problem - GitHub PagesMaximum Flow Problem What is the greatest amount of ow that can be shipped between a given source and sink without exceeding link capacities? MaximumNetwork

Example

1

3

4

23 2

2 2

1

CapacityMaximum flow problem Augmenting path algorithm

Page 17: Maximum flow problem - GitHub PagesMaximum Flow Problem What is the greatest amount of ow that can be shipped between a given source and sink without exceeding link capacities? MaximumNetwork

Algorithm

1 Initialize the flow with x = 0, b ← 0.

2 Identify an undirected path π connecting s and t with positiveresidual capacity. (Terminate if no such path exists.)

3 Find the residual capacity u∗ of π.

4 For each forward arc (i , j) in π, set xij = xij + u∗. For each reverse arc(j , i) in π, set xij = xij − u∗.

5 Increase b by u∗, and return to step 2.

If you were writing code to do this, how would you implement step 2?

Maximum flow problem Augmenting path algorithm

Page 18: Maximum flow problem - GitHub PagesMaximum Flow Problem What is the greatest amount of ow that can be shipped between a given source and sink without exceeding link capacities? MaximumNetwork

MAX-FLOW/MIN-CUTDUALITY

Page 19: Maximum flow problem - GitHub PagesMaximum Flow Problem What is the greatest amount of ow that can be shipped between a given source and sink without exceeding link capacities? MaximumNetwork

To prove correctness of the augmenting path algorithm, we’ll take a shortdetour.

1

3

4

23 2

2 2

1

Capacity u(S,T) = 7

7

8

63 2

2 2

1

52 3

In a network, a cut is a partitioning of the nodes into two sets S and T ,where the source is in S and the sink is in T .A cut link is a link whose tail is in S and whose head is in T .

Maximum flow problem Max-flow/min-cut duality

Page 20: Maximum flow problem - GitHub PagesMaximum Flow Problem What is the greatest amount of ow that can be shipped between a given source and sink without exceeding link capacities? MaximumNetwork

The capacity of a cut u(R, S) is the sum of the capacities in the cut links.

1

3

4

23 2

2 2

1

Capacity u(S,T) = 7

7

8

63 2

2 2

1

52 3

Maximum flow problem Max-flow/min-cut duality

Page 21: Maximum flow problem - GitHub PagesMaximum Flow Problem What is the greatest amount of ow that can be shipped between a given source and sink without exceeding link capacities? MaximumNetwork

1

3

4

23 2

2 2

1

Capacity u(S,T) = 5

7

8

63 2

2 2

1

52 3

Maximum flow problem Max-flow/min-cut duality

Page 22: Maximum flow problem - GitHub PagesMaximum Flow Problem What is the greatest amount of ow that can be shipped between a given source and sink without exceeding link capacities? MaximumNetwork

1

3

4

23 2

2 2

1

Capacity u(S,T) = 10

7

8

63 2

2 2

1

52 3

Maximum flow problem Max-flow/min-cut duality

Page 23: Maximum flow problem - GitHub PagesMaximum Flow Problem What is the greatest amount of ow that can be shipped between a given source and sink without exceeding link capacities? MaximumNetwork

Weak max-flow/min-cut theorem

.

If (b, x) is a feasible solution to the max flow problem, and if (S ,T ) is acut, then b ≤ u(S ,T )

Proof sketch: Any unit of flow shipped from s to t must cross one ofthe cut links. So, the total amount of flow moving from s to t cannotexceed the sum of the capacities in the cut links.

Maximum flow problem Max-flow/min-cut duality

Page 24: Maximum flow problem - GitHub PagesMaximum Flow Problem What is the greatest amount of ow that can be shipped between a given source and sink without exceeding link capacities? MaximumNetwork

Strong max-flow/min-cut theorem

.

If (b∗, x∗) is an optimal solution to the max flow problem, and if u∗ =min{u(S ,T )} among all possible cuts, then b∗ = u∗

This is a “duality” result: finding the maximum flow in a network isequivalent to finding the cut with minimum capacity.

We will prove this theorem in conjunction with the correctness of theaugmenting path algorithm.

Maximum flow problem Max-flow/min-cut duality

Page 25: Maximum flow problem - GitHub PagesMaximum Flow Problem What is the greatest amount of ow that can be shipped between a given source and sink without exceeding link capacities? MaximumNetwork

Assume for now that the augmenting path algorithm terminates with someflow x. When it does so, there is no undirected path from s to t withpositive residual capacity.

Let S be the set of nodes for which undirected paths with positive residualcapacity do exist (including s itself), and let T be all other nodes.

Maximum flow problem Max-flow/min-cut duality

Page 26: Maximum flow problem - GitHub PagesMaximum Flow Problem What is the greatest amount of ow that can be shipped between a given source and sink without exceeding link capacities? MaximumNetwork

Since s ∈ S and t ∈ T , (S ,T ) is a valid cut. Furthermore, by definitionevery cut link has zero residual capacity.

Therefore, the capacity of the cut is exactly equal to the sum of the flowon the cut arcs, so b = u(S ,T ).

By the weak max-flow/min-cut theorem, this means b must be maximaland u(S ,T ) must be minimal. (Strong theorem has been proved.)

Therefore, the augmenting path algorithm terminates with the correctanswer.

Maximum flow problem Max-flow/min-cut duality

Page 27: Maximum flow problem - GitHub PagesMaximum Flow Problem What is the greatest amount of ow that can be shipped between a given source and sink without exceeding link capacities? MaximumNetwork

COMPLEXITY

Page 28: Maximum flow problem - GitHub PagesMaximum Flow Problem What is the greatest amount of ow that can be shipped between a given source and sink without exceeding link capacities? MaximumNetwork

The other issue is proving that the augmenting path algorithm mustterminate.

This is easy to do if we assume that the capacities are integers.

(If they are fractional, multiply by a sufficiently large number.)

Each iteration adds at least 1 to b, so b will reach its maximum value b∗

in a finite number of iterations.

Maximum flow problem Complexity

Page 29: Maximum flow problem - GitHub PagesMaximum Flow Problem What is the greatest amount of ow that can be shipped between a given source and sink without exceeding link capacities? MaximumNetwork

If U is the largest capacity on any link, then the capacity of the min cut isbounded by nU. (Look at a cut where S is just the source.)

So, the augmenting path algorithm requires O(nU) iterations.

The basic search algorithm for finding a path also has O(n2) steps.

So, the augmenting path algorithm in all requires O(n3U) steps.

Maximum flow problem Complexity

Page 30: Maximum flow problem - GitHub PagesMaximum Flow Problem What is the greatest amount of ow that can be shipped between a given source and sink without exceeding link capacities? MaximumNetwork

CAPACITY SCALINGALGORITHM

Page 31: Maximum flow problem - GitHub PagesMaximum Flow Problem What is the greatest amount of ow that can be shipped between a given source and sink without exceeding link capacities? MaximumNetwork

The augmenting path algorithm can take a long time if U is large, and ifthe path is chosen poorly.

Can we do better?

Maximum flow problem Capacity Scaling Algorithm

Page 32: Maximum flow problem - GitHub PagesMaximum Flow Problem What is the greatest amount of ow that can be shipped between a given source and sink without exceeding link capacities? MaximumNetwork

The capacity scaling algorithm overcomes this drawback, by finding anaugmenting path with sufficiently large capacity.

One option is to find the augmenting path with maximum availablecapacity.

This works, but involves more computation at each iteration. There is afaster approach...

Maximum flow problem Capacity Scaling Algorithm

Page 33: Maximum flow problem - GitHub PagesMaximum Flow Problem What is the greatest amount of ow that can be shipped between a given source and sink without exceeding link capacities? MaximumNetwork

For a given value of ∆, we will only search for undirected paths whoseresidual capacity is at least ∆.

The idea: start with a large ∆, augment flows along paths with residualcapacity at least ∆ until no more exist. Reduce ∆ and continue.

Let bxc mean rounding x down to the nearest integer.

Maximum flow problem Capacity Scaling Algorithm

Page 34: Maximum flow problem - GitHub PagesMaximum Flow Problem What is the greatest amount of ow that can be shipped between a given source and sink without exceeding link capacities? MaximumNetwork

Capacity scaling algorithm

1 Initialize x = 0, b = 0, and ∆ = 2blog2 Uc.

2 If ∆ < 1 then terminate.

3 Try to find an augmenting path π from s to t with residual capacityat least ∆.

4 If no such path exists, set ∆ = ∆/2 and return to step 2.

5 Augment flow along that path as in the augmenting flow algorithm,and return to step 3.

Maximum flow problem Capacity Scaling Algorithm

Page 35: Maximum flow problem - GitHub PagesMaximum Flow Problem What is the greatest amount of ow that can be shipped between a given source and sink without exceeding link capacities? MaximumNetwork

We can show that the capacity scaling algorithm also terminates with thecorrect solution, and requires O(n4 logU) steps; a slightly moresophisticated version of capacity scaling can reduce this to O(n3 logU).

If capacity is large, this is much better than O(n3U).

Maximum flow problem Capacity Scaling Algorithm