0% found this document useful (0 votes)
27 views50 pages

26 Maximum Flow

1) A network flow problem models the flow of material through a network of conduits represented by a graph. Each edge has a capacity limiting the maximum flow rate. 2) The maximum flow problem aims to find the maximum rate of flow that can be sent from a source node to a sink node, respecting the capacity constraints of each edge. 3) Flow is defined on the graph using a net flow function satisfying properties like capacity, skew symmetry, and flow conservation. Maximum flow can be computed using various algorithms that exploit properties of minimum cuts in the graph.

Uploaded by

twzfpdwg6k
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views50 pages

26 Maximum Flow

1) A network flow problem models the flow of material through a network of conduits represented by a graph. Each edge has a capacity limiting the maximum flow rate. 2) The maximum flow problem aims to find the maximum rate of flow that can be sent from a source node to a sink node, respecting the capacity constraints of each edge. 3) Flow is defined on the graph using a net flow function satisfying properties like capacity, skew symmetry, and flow conservation. Maximum flow can be computed using various algorithms that exploit properties of minimum cuts in the graph.

Uploaded by

twzfpdwg6k
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 50

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 ) 
vV

p ( u, v )
vV
flow into u flow out of u

Equivalently,  p ( u, v )   p ( v , u )  0
vV vV
2/2
w x 2 /3
1/ 3

s 0/ 1 1/3 1/1 2/3 1/2 t


2 /2
 y 2/3
z 1 /2

• Note that all positive flow are  capacities.


• Verify flow conservation by adding up flow at a couple of vertices
• Note that all positive flow = 0 is legitimate
Cancellation with positive flows

• 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
vV
Another way to think of flow conservation:

 f ( v , u )   f ( u, v )
vV : f ( v ,u ) 0 vV : f ( u ,v ) 0
total positive total positive
flow entering u flow leaving u

“flow in =flow out”


The differences between positive flow p and net flow f
– p ( u, v )  0
– f satisfies skew symmetry
Equivalence of positive flow and net flow definitions

Define net flow in terms of positive flow:


• Define f( u , v) = p( u ,v) - p( v ,u)
• Argue, given definition of p ,that this definition of f satisfies capacity const
raint and flow conservation
Capacity constraint:
p(u, v )  c(u, v ) and p( v, u )  0  p(u, v )  p( v, u )  c(u, v )
Flow conservation:
 f (u, v )   ( p(u, v )  p(v, u))
vV vV

  p ( u, v )   p ( v , u )
vV vV

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:

p(u,v )  {0 f (u,v ) if f (u, v )  0,


if f (u, v )  0.
• Argue, given definition of f , that this definition of p satisfies capacity
constraint and flow conservation.
Capacity constraint:
If f (u, v )  0 :
f ( u, v )  c ( u, v )  0  p ( u, v )  c ( u, v )
If f (u, v )  0 :
0  p (u, v )  c(u, v ).
Flow conservation :
 p (u, v )   p ( v , u )
vV vV
(  p (u, v )   p (u, v ))
vV : f ( u ,v ) 0 vV : f ( u ,v ) 0
 (  p ( v, u )   p ( v, u ))
vV : f ( u ,v ) 0 vV : f ( u ,v ) 0
  p (u, v )   p (u, v )
vV : f ( u ,v ) 0 vV : f ( u ,v ) 0
  p( v, u )   p( v, u )
vV : f ( v ,u )0 vV : f ( v ,u ) 0
  p (u, v )  0  0   p ( v , u )
vV : f ( u ,v ) 0 vV : f ( v ,u ) 0
  f ( u, v )   f ( v , u )
vV : f ( u ,v ) 0 vV : f ( v ,u ) 0
  f (u, v )   (  f (u, v ))
vV : f ( u ,v ) 0 vV : f ( u ,v ) 0

  f ( u, v )
vV

0
Value of flow f  f   f ( s, v )  total flow out of source
vV

Consider the example blow. [The cancellation possible in the previous


example has been made here. Also, showing only flows that are positive.]
2/2
w x 2 /3
1 /3

s 0/1 1/3 1/1 2/3 1/2 t


2 /2
y 2/3
z 1 /2

Value of flow f  f  3
Cancellation with flow

If we have edges (u , v) and (v , u) ,skew symmetry makes it so that at most \


one of these edges has positive flow.
Say f (u ,v) = 5 .If we “ship” 2 units v → u. we lower f (u ,v) to 3.The 2 units
v → u cancel 2 of the u → v units.
Due to cancellation, a flow only gives us this “net” effect. We cannot
reconstruct actual shipments from a flow
5 units u  v 8 units u  v
same as
0 units v  u 3 units v  u
We could add another 3 units of flow u → v and another 3 units
v → u ,maintaining flow conservation.
The flow from u to v would remain f (u ,v) = 5 ,and f (v ,u) = -5.
Maximum-flow problem: Given G,s,t and c, find a flow whose value is
maximum.

Implicit summation notation


We work with function, like f ,that take pairs of vertices as arguments. Extend
to take sets of vertices, with interpretation of summing over all vertices in the
set.
Example: If X and Y are sets of vertices,
f ( X , Y )   f ( x, y )
xX yY

Therefore, can express flow conservation as f (u,V )  0, for all u V  s, t


Notation: Omit braces in sets with implicit summations.
Example: f ( s,V  s )  f ( s,V ). Here, f ( s,V  s ) means f ( s,V  {s})
Lemma
For any flow f in G  (V , E )
1.For all X  V , f ( X , X )  0,
2.For all X , Y  V , f ( X , Y )   f (Y , X ),
3.For all X , Y , Z  V such that X  Y   ,
f ( X  Y , Z )  f ( X , Z )  f (Y , Z ) and
f ( Z , X  Y )  f ( Z , X )  f (Z ,Y )
Proof

2. f ( X , Y )   f ( x, y )
xX yY
   f ( y , x ) (skew symmetry)
xX yY
   f ( y , x )
xX yY
  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 zZ
   
    f ( v, z )      f ( v, z )  ( X  Y )  
vX  zZ  vY  zZ 
 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

A cut (S,T) of flow network G = (V,E) is a partition of V into S and T=V-S


such that s  S , t  T
• Similar to cut used in minimum spanning trees, except that here the graph
is directed, and we require s  S , t  T
For flow f, the net flow across cut (S , T) is f (S , T).
Capacity of cut (S , T) is c (S , T).
A minimum cut of G is a cut whose capacity is minimum over all cuts of G.
For our example: 2/2
w x 2/3
1/ 3

s 1 1/3 1/1 1/3 2 t


2/ 2
y 2/3
z 1/2

Consider the cut S  s, w, t, T  x, z, t


f ( S , T )  f ( w, x )  f ( y , x )  f ( y , z )
 2  ( 1)  2
3
c( S , T )  c( w, x )  c( y , z )
23
5

Same flow as previous cut, higher capacity.


Note the difference between capacity and flow.
• Flow obeys skew symmetry, so f (y , x) = -f (x , y) = -1.
• Capacity does not: c (y , x) = 0 ,but c (x , y) = 1.
So include flows going both ways across the cut, but capacity going only S to
T.
Now consider the cut
f ( S , T )  f ( x, z )  f ( x, t )  f ( y , z )
 ( 1)  2  2
3
c( S , T )  c( x, z )  c( x, t )  c( y , z )
 2  3 3
8
Lemma
For any cut (S,T), f ( S , T )  f
Proof First, show that f ( S  s,V )  0
S  s V  s, t
Therefore,
f ( S  s ,V )   f (u,V )
uS  s
 0 (flow conservation and S - s V  s, t)
uS  s
0
So
f ( S , T )  f ( S ,V )  f ( S , S ) (lemma, part(3), and
S  T  V, S  T   )
 f ( S ,V ) (lemma, part(1))
 f ( s,V )  f ( S  s,V ) (lemma, part(3))
 f ( s ,V ) ( f ( S  s , V )  0)

 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 )
uS vT
  c(u, v ) (capacity constraints)
uS vT
 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

Each edge of the residual network can admit a positive flow.


For our example:
2
2
w x 1

2
1
s 1 2 1 2 3 t
1
1
3
y z 1
2

Every edge (u , v)  Ef corresponds to an edge (u , v) E or (u , v) E (or both)


Therefore, Ef  2 E
Given flows f1 + f2 ,the flow sum f1 + f2 is defined by
( f1 + f2 ) (u , v) = f1 (u , v) + f2 (u , v)
For all u , v  V
Lemma
Given a flow network G, a flow f in G, and the residual network Gf ,let f’ be
any flow in Gf .Then the flow sum f + f’ is a flow in G with value
f  f'  f  f'

[See book for proof]


Augmenting path
A path s t in Gf .
• Admits more flow along each edge
• Like a sequence of pipes through which we can squirt more flow from s to
t
How
cf ( pmuch
)  mincf (flow
more u, v )can
: (uwe
, v )push p s to t along augmenting path p?
is onfrom
For our example, consider the augmenting path p  s, w, y , z, x, t
Minimum residual capacity is 1.
After we push 1 additional unit along p:

2/2
w
2/2
x 2/3
w x 3/3
1/3 2/3

s 1 1/3 1/1 1/3 2 t s 1 3 1/1 2/3 2 t


2/2 2/2
y 2/3
z 1/2
y 3/3
z 1/2
Observe that Gf now has no augmenting path. Why? No edges cross the cut

({ s , w },{ x , y , z , t }) in the forward direction in Gf .So no path can get fro


m
s to t. Claim that the flow shown in G is a maximum flow.
2
1
w x 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)

Subtle different between f [u , v] and f (u , v):


• f (u , v) is a function, defined on all u ,v V
• f [u , v] is a value computed by algorithm.

– f [u , v] = f (u , v) where (u , v) E or (v , u) E

– f [u , v] is undefined if neither (u , v) E nor (v , u)  E
Analysis: If capacities are all integer, then each augmenting path raises f by  1
If max flow is f* , then need  |f*| iterations  time is O  E f 
*

 
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

Do FORD-FULKERSON, but compute paths by BFS of Gf , Augmenting


paths are shortest path s t in Gf . With all edge weights = 1.
Edmonds-Karp runs in O(V E2) time.
To prove, need to look at distance to vertices in Gf.
Let δf (u , v) = shortest path distance u to v in Gf , with unit edge weights.
Lemma
For all v V  s, t, f s, v  increases monotonically with each flow
augmentation.
Proof
Suppose there exists v V  s, t such that there is a flow augmentation that
cause δf (s , v) to decrease. Will derive a contradiction.
Let f be the flow before the first augmentation that causes a shortest-path
distance to decrease, f’ be the flow afterward.
Let v be a vertex with minimum δf’ (s , v) whose distance was decreased by
the augmentation, so δf’ (s , v) < δf (s , v) .

Let a shortest path s to v in Gf’ be s u → v, so (u , v) Ef ’ and
δf ‘(s , v) =δf ’ (s , u) + 1. (Or δf’ (s , u) = δf’ (s , v) - 1 .)
Since δf ‘ (s, u) < δf ‘ (s , v) and how we chose v, we have
δf ‘ (s , u) δf (s , v) .
Claim (u, v )  Ef
Proof If (u, v )  Ef ,then
f ( s, v )  f ( s, u )  1 ( triangle inequality)
 f ' ( s , u )  1
 f ' ( s , v )
contradicting f ' ( s, v )  f ( s, v )

How can (u, v )  Ef and (u, v )  Ef ' ?


The augmentation must increase flow v to u. Since Edmonds-Karp augment
s
along shortest paths, the shortest path s to u in Gf has v → u as its last edge.
Therefore,
f ( s , v )  f ( s , u )  1
 f ' ( s , u )  1
 f ' ( s , v )  2
contradict ing f ' ( s, v )  f ( s, v )

Therefore, v cannot exist.


Theorem
Edmond-Karp performs O(V E) augmentations.
Proof Suppose p is an augmenting path and cf (u , v) = cf (p). Then call (u , v) a
critical edge in Gf , And it disappears from the residual network after an
augmentation along p .
 1 edge on any augmenting path is critical.
Will show that each of the |E| edges can become critical  |V|/2 – 1 times.
Consider u,v V such that either (u , v) E or (v , u) E or both. Since
augmenting paths are shortest paths, when (u , v) becomes critical first time,
δf (s , v) = δf (s , u) + 1
Augment flow, so that (u , v) disappears from the residual network. The edge
cannot reappear in the residual network until flow from u to v decreases,
which happens only if (v , u) is on an augmenting path in
Gf ‘ :δf ‘ (s , u) = δf ‘ (s , v) +1 ( f ‘ is flow when this occurs)
By Lemma, f ( s, v )  f ' ( s, v ) 
f ' ( s , u )  f ' ( s , v )  1
 f ( s , v )  1
 f ( s , u )  2
Therefore, from the time (u , v) becomes critical to the next time, distance of
u from s increases by  2.Initially, distance to u is  0, and augmenting path
can’t have s, u, and t as intermediate vertices.
Therefore, until u becomes unreachable from source, its distance is  V  2  u
can become critical  V  2 / 2  V / 2  1 times
Since O(E ) pairs of vertices can have an edge between then in residual graph,
total # of critical edges is O(V E). Since each augmenting path has  critical
1
edge, have O(V E) augmentations.
Use BFS to find each augmenting path in O(E ) time  O(V E2) time.
Can get better bounds.
Push-relabel algorithms in Sections 26.4-26.5 give O(V3).
Can do even better.
Maximum bipartite matching

Example of a problem that can be solved by turning it into a flow problem.


G = (V , E) (undirected) is bipartite if we can partition V = L ∪ R such that all
edges in E go between L and R.

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).

Maximum matching: a matching of maximum cardinality. (M is a maximum


matching if |M|  |M’| for all the matchings M’.)
Problem:
Given a bipartite graph (with the partition), find a maximum matching.
Application:
Matching planes to routes.
• L = set of planes.
• R = set pf routes.
• (u , v) E if plane u can fly route v .
• Want maximum # of routes to be served by planes.
Given G, define flow network G’ = (V’ , E’)
• V’ = V ∪ {s , t}
• E '  s, u  : u  L
 u, v  : u  L, v  R, u, v  E 
 u, t  : v  R

• c(u, v )  1 for all (u, v )  E

You might also like