Network Flow
Analysis of Algorithms
Network Flow
flow network is a directed graph in whicheach directed edge (u,v) has a positivecapacity c(u,v) > 0
 Capacity is the maximum rate of flow that anyedge cacarry
Two special nodes: source, s, and target, t
Network Flow
Flow ithe rate at which material moves fromthe source to the target
For example, liquid through pipes, electricalcurrent through circuit, data through network,or many other types of information
The value of flow idefined to be the totalflow leaving the source vertex
Cabe positive, negative, or zero
f is also the value of the in-flow at the target
Network Flow
A flonetwork is directed graph with sourcevertex s, target vertex t, and every edge labeledwith a positive capacity, c
Initial network with capacities on the edges. No flow yet.
Network Flow
flow ithen induced at the source
Aevery vertex except s and t, the inflow mustbe equal to the outflow athat vertex
Network Flow
Every flow mussatisfy the following 3 properties:
Capacity constraint: for allu, 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},
vV  f(u,v) = 0
The maxflow problem: given a directed graph(network) with a capacity on each edge, find a flowof maximum value
Ford-Fulkerson Algorithm
Ford-Fulkerson is a greedy, iterative methodfor solving the maxfloproblem:
Initially, flow = 0 for alu,v  V
At eacstage, an augmenting path is found
An augmenting path is path from s to t for which wecan push more flow
Repeat until no more augmenting paths can befound
Ford-Fulkerson Algorithm
The residual network
Consider a flow network (G,c) together with a flow f
Define new flow network (Gf,cf), where G has the samenode set as G, ancf(u,v) = c(u,v) - f(u,v)
 The capacities of Gf  are the  unused capacities of G
G icalled the residual network, c icalled the residualcapacity
If we can finan additional flow f(u,v) iGf, thenwe can define f*(u,v) to be the current total flowithe network G, where f*(u,v) = f(u,v) + f(u,v)
Ford-Fulkerson Algorithm
The leftover capacity ithe original networkwith flow f creates an augmenting pathavailable for more flow (the residual network)
When the capacity of anedge is used up, we canreverse the direction of theedge to allow datto flowin the opposite direction.
Ford-Fulkerson Algorithm
The residual capacity cf = the capacity that islefover after a flow has “run along an edge
The bottleneck capacity b = the minimumresidual capacity of the edges along theaugmenting path
b = min { cf(u,v): (u,v) is on path p }
Ford-Fulkerson Algorithm
Initialize: Start with a flow of 0 on each edge
Repeat: Push more flow along an augmentingpath until a maximum flow has been found
Ford-Fulkerson Algorithm
An augmenting path is any undirected pathfrom s to such that either:
Flow can be increased along forward edge (an edge withcapacity that is not full) or
Flow can bdecreased along backward edge (a reversededge with flothat is not zero)
Send 10 units offlow from s to t.
Ford-Fulkerson Algorithm
Send 10 units offlow from s to t.
Send 5 units offlow from s to t.
Ford-Fulkerson Algorithm
Send 3 units offlow from s to t.
Terminate when allpaths fros tt areblocked by either afulforward edge oran empty backwardedge
Ford-Fulkerson Algorithm
t
s
4
2
10/10
6/10
10/10
6/10
8/8
6/6
8/9
2/2
Question: In the flow network shown below, how many differentaugmenting paths are there with respect to the given flof ?
1  0/43
Ford-Fulkerson Algorithm
When the capacities are integers, Ford-Fulkerson runs in timeproportional to the number of edgein the graph times themaximum flow in the graph.
AnalysioFord-Fulkerson
How do you choose an augmenting path?
Will any sequence of paths do just as well?
Consider the following flow network:
v
1,000,000
s
1,000,000
t
1,000,000
1,000,000
1
s
v
uu
t
999,999
999,999
999,999
v
u
t
999,999
s
1,000,000
999,999
1,000,000
1
11
11
999,999
1
1
1
Two augmenting paths with bottleneck capacities of 1and resultingresidual network. Running time is proportional to  f, where f is thevalue of the maximum flow; for this example, f 2,000,000.
Improvements to Ford-Fulkerson
Edmunds and Karp suggested two heuristicsfor improving performance by selecting betteraugmenting paths
Always augment by path of maximumbottleneck capacity (the fattest path) or
Always augment by path with the fewestnumber of edges (the shortest path)
Is Ford-Fulkerson Optimal?
Since Ford-Fulkerson is a greedy methodhowdo we know if we have founthe optimal(maximum) flow?
Consider:
A flow is maximum if and only if its residual networkcontains no augmenting paths
There will be no more augmenting paths when allthe bottleneck capacities have been used up
The bottleneck capacities are found from theminimum cut of the network
Network Cuts
Definition: A cuis a partition of the verticesinto two disjoint sets, and B
An st-cut is a cut where the source s is in A
and the sint iin B
A
B
s
t
Network Cuts
The capacity of a cuithe sum of thecapacities of the edges from A to B
In the example below, A = {s} and = {all othervertices}
Network Cuts
In this example, = {the dark-colored vertices}and B = {the light-colored vertices}
 Only include the edges from A to B whendetermining the capacity across the cut; do notinclude the edges from B to A or from A to A
Network Cuts
Question: In the flow network shown here,what is the capacity of the cut with
A = {s,2,4} and B = {1,3,t}?
Mincut problem: For all possible ways to cut a graph with s  A
and t  B, find the cut of minimum capacity.
1
t
s
4
2
3
10
10
10
10
8
6
9
2
 4
Flows and Cuts
The net flow across a cut (A, B) is the sum of the flows on itsedges from A (gray vertices) to B (white vertices) minus thesum of the flows on its edges from B to A
Flow-value lemma: Let f be any floand let (A, B) be any cut.Then, the net flow across (A, B) equals the value of f.
In other words, every cut must have the same net flow!
Maxflow-Mincut Theorem
According to the flow-value lemma, the netflow ithe same acrosall s-t cuts, includingthe minimum s-t cut
 If you send as much floas you possibly ca(themaximum flow), then the capacities of theminimum cut will be saturated and you cannotsend more flow
Therefore, the maximum flow = minimum cut
Maxflow-Mincut Theorem
Proof:
Suppose (A, B) is a cut such that vertex u  A
We can move u to B without altering the flow because ofthe conservation of flow (flow in floout), thus f(AB) =f(A - {u}, + {u})
Therefore, every flo(even the maximum flow) is thesame regardless of where you cut (even the minimum cut)
=
A
B
s
w
4
u
w3
w2
w1
t
w
5
B+{u}
A-{u}
s
w
4
u
w1
w3
w2
t
w
5
Flow Equivalence Conditions
The following three conditions are equivalentfor any flow f:
1.There exists a cut whose capacity equals the valueof the flow f
2.Flow f is a maxflow
3.There is no augmenting path with respect tf
Flow Equivalence Conditions
1.There exists a cut whose capacity equals the valuof theflof
2.Flow f is maxflow
1 implies 2:
Suppose that (A, B) is a cut with capacity equal to thevalue of
Then, the value of another flow f '  capacity of
cut(A, B) value of (by assumption on 1 above)
Thus, f is a maxflow
Flow Equivalence Conditions
2.Flow f is maxflow
3.There is no augmenting path with respect to f
2 implies 3 using the contrapositive (3 implies 2):
Suppose that there is another augmenting path withrespect to the current flow f
We could send morflow along this path
Thus, the current flow f is not a maxflow
Flow Equivalence Conditions
3.There is no augmenting path with respect to f
1.There exists a cut whose capacity equals the value ofthe flof
implies 1:
If there is no augmenting path with respect to f(i.e., if there is no path from to t where we couldsend more flow), then this creates a cut
The capacity of this cut defines the bottleneck,and has flowith value f (from the flow-valuelemma)
Applications of Network Flow
Data mining
Open-pit mining
Bipartite matching
Network reliability
Baseball elimination
Image segmentation
Network connectivity
Distributed computing
Security ostatistical data
Egalitarian stable matching
Multi-camera scene reconstruction
Sensor placement for homeland security
Manymanymore
Edge-Disjoint Paths
A set of paths is edge-disjoinif their edge setsare disjoint, i.e., no two paths share an edge
 Multiple paths may go through some of the nodes
The Edge-Disjoint Paths Problem is to finthemaximum number of edge-disjoint s-t paths iG
The maximum number of edge-disjoint s-t pathsis equal to the minimum number of edgeswhose removal separates s from t
Edge-Disjoint Paths
The Ford-Fulkerson algorithm cabe used to find amaximum set of edge-disjoint s-t paths in runtimeproportional to VE
Given a graph G = (V,E) with source s and sink t,create a flow network with a capacity of 1 on eachedge
Maximum number of edge-disjoint paths = 3
s
t
Maximum Bipartite Matching
The assignment/matching/marriage problem
Goal: Find a maximum bipartite match
Example: match L machines with R tasks to beperformed
Example: match L applicants tjob offers
Edge (x,y) represents applicant wants job y andcompany y wants applicant x
The goal is to make the maximum number ofmatches of student to jobs
Multiple acceptance is forbidden!
Maximum Bipartite Matching
XY
XY
A bipartite graph. On the left is match with cardinality 2,and on the right is a match with cardinality 3. The match onthe right is optimal because 3 2.
Maximum Bipartite Matching
To find a maximum bipartite matching:construct a flow network, where a flowcorrespond to a match
1.Construct a flow network G’
2.Set all weights to 1 (initial capacities)
3.Run Ford-Fulkerson
4.Maximum bipartite matching = maximum flow
Runtime iproportional to VE
Maximum Bipartite Matching
s
t
XYXY
The corresponding flow network G with maximum flow shown.Each edge in G has capacity of 1. Shaded edges have a floof 1,and all other edges carry no flow.The shaded edges from X to Ycorrespond to those in maximum matching of the bipartite graph.
G
G
Baseball Elimination
Four baseball teams are trying to finish in first place. Currently,each team has the following number of wins:
New York: 92Baltimore: 91Toronto: 91Boston: 90
There are five games left in the season; these consist of all possiblepairings of the fouteams, except for New York and Boston.
Can Boston finish in first place, or at least tie for first?
Baseball Elimination
New York: 92     Baltimore: 91     Toronto: 91     Boston: 90
Bosto can finis with  a mos 92 wins. Cumulatively,  the otherthree  team have  274  win currently,  an their  three  gamesagains eac other  wil produce  exactly  three  more  wins,  for  afinal  total  o 277 Bu 277  win divide b three  teams  meansthat one of them must end up with more than 92 wins.
Therefore,  Bosto canno en u in  firs place,  o even  tie  forfirst.
Baseball Elimination
Suppose each team has the following number of wins:
New York: 90     Baltimore: 88     Toronto: 87     Boston: 79
The  remaining  games  are  as  follows:  Bosto still  has  four  gamesagains eac o the  other  three  teams Baltimore  has  one  moregame against each of NeYork and Toronto. NeYork and Torontostill have six games left to play against each other.
Is Boston eliminated?
Baseball Elimination
New York: 90     Baltimore: 88     Toronto: 87     Boston: 79
Bosto ca en with  a mos 91  wins Together,  New  York  andToronto  already  have  177  wins;  their  six  remaining  games  willresult in a total of 183, and since 183/2 > 91, one of them mustend up with more than 91 wins. Therefore, Boston is eliminated.
Interestingly,  in  this  instance,  we  canno prove  tha Bosto iseliminated by averaging all three teamsThe three teams ahead ofBoston together have a total of 265 wins with 8 games left amongthem This  i  total  o 273,  an 273/3   91 Averaging  over  allthree teams does not prove that Boston could not tie for first. Youmust bcareful to choose the correct set!
Baseball Elimination
In general, suppose we have a set S of teams, and for each x  S,its current number of wins is wx. Also, for two teams x, y  S, theystill  have  t play  gxy   games  agains eac other We  als have  aspecific  team  z,  for  which  we  wan t know  the  bes outcome.Lets suppose that z requires m wins total to end up in first place.
Let  S    –  {z},  an let  g*   the  total  number  o games  leftbetween all pairs of teams in S. Now construct a flow network Gto determine whether z has been eliminated: include nodes s andt,   vertex  uxy for  eac pair  o teams  x,     S  with   non-zeronumber of games left to play against each other, and a node vx foreach team x  S.
Baseball Elimination
Includthe following edges:
(s, uxy) with capacity gxy
(uxy, vx) and (uxy, vy) with capacities gxy
(vx, t) with capacity m - wx
If there is a flow of value at least g*, then it is possible for theoutcomes of all remaining games to yield a situation where noteam  has  more  than   wins Hence,  if  team   win all  itsremaining games, it can still achieve at least tie for first place.
Team z has been eliminated if and only if the maximum flow in
has value strictly less than g*.
Baseball Elimination
The maximum flow has value 7, whereas g* 6 1 1 8(g* is the total number of games left between teams in S).
Since max flow < g*Boston cannot at least tie for first place.
wNewYork
= 90
wBaltimore  = 88
wTorontowBoston
87
79
gNY-Tor  6gNY-Bal  1gBal-Tor 1
Boston has 12 gamesleft, so m 91
s
NY-Balt
Balt-Tor
NY
Balt
NY-Tor
1
1
6
91 - 88 = 3
Tor
  91 - 87 = 4    t
91 - 90 = 1
 6
6
1
1
1
1
Baseball Elimination
QUESTION: How many vertices and edges, respectively,are  there  in  a  flow  network  that  is  constructed  todetermine    whether    one    team    is    mathematicallyeliminated from a baseball league containing N teams?Assume the worst case (when there is a game remainingbetween everpair of teams in the league).
a)N and N2
b)N2  and N2
c)N2  and N3
d)N2  and N4
Network Flow Holy Grail
Worst-case analysis igenerally not useful forpredicting or comparing maxflow algorithmperformance in practice
Currenbesin practice: Push-relabel methodwith gap relabeling runs itime proportional to
E3/2
Network Flow Holy Grail
Year
Method
Worst Case
Discovered By
1951
Simplex
E C
Dantzig
1955
Augmenting path
E C*
Ford-Fulkerson
1970
Shortest augmenting path
E3
Dinitz andEdmonds-Karp
1970
Fattest augmenting path
E log E log(E C)
Dinitz andEdmonds-Karp
1977
Blocking flow
E5/2
Cherkasky
1978
Blocking flow
E7/3
Galil
1983
Dynamic trees
E log E
Sleator and Tarjan
1985
Capacity scaling
E log C
Gabow
1997
Length function
E1/ log E log C
Goldberg and Rao
2012
Compact network
E / log E
Orlin
?
?
E
?