26 Maximum Flow
26 Maximum Flow
Overview
• Network flow
– Use a graph to model material that flows through conduits
– Each edge represents one conduit, and has a capacity ,which is an uppe
r bound on the flow rate = units /time
– Can think of edges as pipes of different sizes. But flows don’t have to b
e of liquids. Book has an example where a flow is how many trucks per
day can ship hockey pucks between cities.
– Want to compute max rate that we can ship material from a designated
source to a designated sink
Flow networks
G = (V , E) directed.
Each edge (u , v) has a capacity c(u,v) 0
If (u , v) E ,then c (u , v) = 0.
Source vertex s, sink vertex t, assume s v t for all v V
Example: [Edge are labeled with capacities.]
2
3
w x 3
s 1 3 1 3 2 t
2
y 3
z 2
• Positive flow :A function p : V × V → R satisfying
– Capacity constraint: For all u, v V ,0 p (u, v ) c(u, v )
– Flow conservation: For all u V {s, t},
p( v, u )
vV
p ( u, v )
vV
flow into u flow out of u
Equivalently, p ( u, v ) p ( v , u ) 0
vV vV
2/2
w x 2 /3
1/ 3
• Without loss of generality, can say positive flow goes either from u to v or
from v to u ,but not both.( Because if not true, can transform by cancellatio
n to be true.)
• In the above example, we can “cancel” 1 unit of flow in each direction bet
ween x and z
1 unit x z 0 unit x z
2units z x 1 unit z x
• In both case, ”net flow” is 1 unit z → x
• Capacity constraint is still satisfied (because flow only decrease)
• Flow conservation is still satisfied (flow in and flow out are both reduced b
y the same amount)
Here’s a concept similar to positive flow:
Netflow: A function f : V × V → R satisfying
• Capacity constraint: For all u, v V , f (u, v ) c(u, v )
• Skew symmetry: For all u, v V , f (u, v ) f ( v, u )
• Flow conservation: For all u V {s, t}, f ( u, v ) 0
vV
Another way to think of flow conservation:
f ( v , u ) f ( u, v )
vV : f ( v ,u ) 0 vV : f ( u ,v ) 0
total positive total positive
flow entering u flow leaving u
p ( u, v ) p ( v , u )
vV vV
0
• Skew symmetry is trivially satisfied by the definition of
f ( u, v ) p ( u, v ) p ( v , u )
( p( v, u ) p(u, v ))
f ( v, u )
Define positive flow in terms of net flow:
f ( u, v )
vV
0
Value of flow f f f ( s, v ) total flow out of source
vV
Value of flow f f 3
Cancellation with flow
2. f ( X , Y ) f ( x, y )
xX yY
f ( y , x ) (skew symmetry)
xX yY
f ( y , x )
xX yY
f (Y , X )
Proof
1. f ( X , X ) f ( X , X ) (part(2))
f (X , X ) 0
3. f ( X Y , Z ) f ( v, z )
v X Y zZ
f ( v, z ) f ( v, z ) ( X Y )
vX zZ vY zZ
f ( X , Z ) f (Y , Z )
Lemma f f (V , t )
Proof First, show that f (V ,V s t ) 0
f (u,V ) 0 for all u V {s, t}
f (V s t ,V ) 0 (add up f (u,V ) for all u V {s, t})
f (V ,V s t ) 0 (by lemma, part (2)).
Thus, f f ( s ,V ) (definition of f )
f (V ,V ) f (V s,V ) (lemma, part(3))
f (V s,V ) (lemma, part(1))
f (V ,V s ) (lemma, part(2))
f (V , t ) f (V ,V s t ) (lemma, part(3))
f (V , t ) (from above)
Cuts
f
Corollary
The value of any flow capacity of any cut.
Proof Let (S,T) be any cut, f be any flow.
f f (S,T ) (lemma)
f (u, v )
uS vT
c(u, v ) (capacity constraints)
uS vT
c(S,T)
Therefore, maximum flow capacity of minimum cut. Will see a little later
that this is in fact an equality.
The Ford-Fulkerson Method
Residual network
Given a flow f in network G = (V , E)
Consider a pair of vertices u , v V.
How much additional flow can we push directly from u to v ?
That’s the residual capacity.
cf ( u , v ) c ( u , v ) f ( u , v )
0 (since f (u, v ) c(u, v ))
Residual network: Gf (V , Ef )
Ef (u, v ) V V : cf (u, v ) 0
2
1
s 1 2 1 2 3 t
1
1
3
y z 1
2
2/2
w
2/2
x 2/3
w x 3/3
1/3 2/3
s 3 1 1 4 t
1
3 1
y 3
z
Lemma
Given flow network G, flow f in G, residual network Gf. Let p be an
augmenting path in Gf . Define fp : V × V → R:
cf ( p ) if (u, v ) is on p,
fp (u, v ) cf ( p ) if ( v, u ) is on p,
0 otherwise.
fp cf ( p ) 0
Then fp is a flow in Gf with value
Corollary
Given flow network G, flow f in G, and a augmenting path p in Gf ,define fp as
in lemma, and defin f’ : V × V → R by f’ = f + fp. Then f’ is a flow in G with
Value f ' f cf ( p ) f
Theorem (Max-flow min-cut theorem)
The following are equivalent:
1. f is a maximum flow.
2. f admits no augmenting path
3. |f| = c (S , T) for some cut (S , T)
Proof
(1) ( 2)
If f admits an augmenting path p ,then (by above corollary) would get a flow
with value |f| + cf(p) > |f| , so f wasn’t a max flow to start with.
( 2) (3)
Suppose f admits no augmenting path. Define
S v V : there exists a path s v in Gf
T V S
Must have t T ;otherwise there is an augmenting path.
Therefore, ( S , T ) is a cut.
For each u S and v T , must have f ( u , v) = c (u , v) , since otherwise
(u , v) Ef and the v S
By lemma (f ( S , T ) = |f| ), |f| = f ( S , T ) = c ( S , T ).
(3) (1)
By corollary, f c( S , T )
f c( S , T ) f is a max flow
Ford-Fulkerson algorithm
FORD-FULKERSON (V , E , s , t)
for all (u , v) E
do f [u , v] ← f [v , u] ← 0
while there is an augmenting path p in Gf
do augment f by cf (p)
Now that this running time is not polynomial in input size. It depends on
|f*| ,which is not a function of |V| and |E|.
If capacities are rational, can scale them to integers.
If irrational, FORD-FULKERSON might never terminate.
Edmonds-Karp algorithm
L R L R
matching maximum matching
A matching is a subset of edges M E such that for all v V , 1 edge of M
is incident on v .(Vertex v is matched of an edge M is incident on it, otherwise
unmatched).