CS 410/584, Algorithm Design & Analysis, Lecture Notes 5
1© 1994, 2003, 2003, 2006, 2008,
2009, 2010 David Maier
Algorithm Design & Analysis
Ford-Fulkerson Method
Flow maximization in a network (graph) with capacities
Basic idea:• Find a path from source to target that still
has flow capacity (augmenting path) • Add the maximum flow allowed along this
path
David Maier 1Lecture Notes 5
p• Repeat until
Algorithm Design & Analysis
Issues
1. How do we account for flow by
2. Does adding an augmenting path lead to a legal flow?
3. Will this process converge?
David Maier 2Lecture Notes 5
4. If so, will it lead to
CS 410/584, Algorithm Design & Analysis, Lecture Notes 5
2© 1994, 2003, 2003, 2006, 2008,
2009, 2010 David Maier
Algorithm Design & Analysis
Problem Formulation
Directed graph G = (N, E)Two special nodes: s tAssume for any node v N there are pathsAssume for any node v N, there are paths
Capacity c(v,w) ≥ 0If (v, w) not an edge, then
Flow f(v, w) can be
David Maier 3Lecture Notes 5
Flow ( , ) can be
wv
f:c
wv
6
Algorithm Design & Analysis
Detail
Assume no “useless” flows between nodesP iti fl i l di tiPositive flow in only one direction
wv
12:20
wv
:20
David Maier 4Lecture Notes 5
wv wv
5:10 :10
CS 410/584, Algorithm Design & Analysis, Lecture Notes 5
3© 1994, 2003, 2003, 2006, 2008,
2009, 2010 David Maier
Algorithm Design & Analysis
Legal Flow f
1.f(v, w) ≤ c(v, w)
2.f(v, w) = -f(w, v)
3.For any v ≠ s, t
Σ
David Maier 5Lecture Notes 5
Σf(v, w) = 0
Algorithm Design & Analysis
Inputs = Outputs
Consider node 6f(6,16) + f(6,12) + f(6,8) + f(6,3)
3
8
6
4:8 16
12
3:3
1:2 2:5
David Maier 6Lecture Notes 5
3
8
6
7:8 16
12
3:3
2:2 5:5
CS 410/584, Algorithm Design & Analysis, Lecture Notes 5
4© 1994, 2003, 2003, 2006, 2008,
2009, 2010 David Maier
Algorithm Design & Analysis
Value of Flow fTotal flow out of source
|f| Σf( )|f| = Σf(s, w) 3
s 8
2:18
3:10
David Maier 7Lecture Notes 5
s 8
94:4
Algorithm Design & Analysis
Residual Capacity for a Flow
Residual Capacity between nodes v and w:
r(u,v) = c(u,v) – f(u,v)
r(3,7) = c(3,7) – f(3,7)3 7
6:10
David Maier 8Lecture Notes 5
r(7,3) = c(7,3) – f(7,3)
CS 410/584, Algorithm Design & Analysis, Lecture Notes 5
5© 1994, 2003, 2003, 2006, 2008,
2009, 2010 David Maier
Algorithm Design & Analysis
Residual Graph for Flow f
R = (N, E’)E’ = {(v,w) | r(v,w) }
C i i id l i i f Capacities are residual capacities for f
David Maier 9Lecture Notes 5
Algorithm Design & Analysis
Examples1
s
2:25
s20:20
0:9s4
2:12
0:15
7:7 0:70:10
s62:4
6:6s7
0:6
t
8:20
4:15
s310:25
7:10 s5
s8
4:101:2
3:3
s1
s4
s6
David Maier 10Lecture Notes 5
s s2
s3
s4
s5
s7
s8
t
CS 410/584, Algorithm Design & Analysis, Lecture Notes 5
6© 1994, 2003, 2003, 2006, 2008,
2009, 2010 David Maier
Algorithm Design & Analysis
Capacity of a Path
Minimum capacity edgeAdd a flow of along the path
s1
s
2:25
s20:20
0:9s4
2:12
0:150:10
s62:4
6:6s7
0:6
t
8:20
David Maier 11Lecture Notes 5
s s2
s310:25
7:10 s57:7 0:7 s7
s8
4:101:2
3:3
t4:15
Algorithm Design & Analysis
Is the Result a Legal Flow?
• Capacity?
• Skew symmetry?
• Conservation?
s6
David Maier 12Lecture Notes 5
s2
s40:15
s62:4
CS 410/584, Algorithm Design & Analysis, Lecture Notes 5
7© 1994, 2003, 2003, 2006, 2008,
2009, 2010 David Maier
Algorithm Design & Analysis
Example 2s1
s
2:25
s22:20
0:9s4
2:12
2:15
7:7 0:70:10
s64:4
6:6s7
0:6
t
10:20
4:15
s310:25
7:10 s5
s8
4:101:2
3:3
s1
s4
s623
2210
69
David Maier 13Lecture Notes 5
s s2
s3
s4
s5
s7
s8
t
2
1510
107
7
6
6 4
3
6
4
11
11
3 7
9
Algorithm Design & Analysis
Example 3s1
s
2:25
s22:20
0:9s4
2:12
2:15
7:7 0:70:10
s64:4
6:6s7
0:6
t
10:20
4:15
s310:25
7:10 s5
s8
4:101:2
3:3
s1
s4
s623
2210
6
4
1029
David Maier 14Lecture Notes 5
s s2
s3
s4
s5
s7
s8
t
2
1510
7
7
6
3
6 2
3 7
9
CS 410/584, Algorithm Design & Analysis, Lecture Notes 5
8© 1994, 2003, 2003, 2006, 2008,
2009, 2010 David Maier
Algorithm Design & Analysis
Is it a Maximum Flow?
Would seem so:Have a group of edges that divides s from t
and
s12:25
3:20
0:9s4
2:12
3:150
s64:4
6:6
0:6 10:20
and
David Maier 15Lecture Notes 5
s s2
s310:25
7:10 s57:7 0:7
1:10 s7
s8
5:102:2
3:3
t5:15
Algorithm Design & Analysis
Cut of a Graph
Divide nodes of N into two groups S, Ts1 2:12 s64:4
s
2:25
s23:20
0:9
s310:25
7:10
s4
s5
3:15
7:7 0:71:10
6:6s7
0:6
s8
5:102:2
3:3
t
10:20
5:15
David Maier 16Lecture Notes 5
Net flow across cut Σf(v, w)Capacity across cut Σc(v, w)
CS 410/584, Algorithm Design & Analysis, Lecture Notes 5
9© 1994, 2003, 2003, 2006, 2008,
2009, 2010 David Maier
Algorithm Design & Analysis
Results
• Net flow across any cut• |f| is bounded above by|f| is bounded above by• Max-flow/min-cut theorem
1. f is maximum flow2. residual graph has no3. |f| is capacity of
David Maier 17Lecture Notes 5
Algorithm Design & Analysis
2 3Consider residual graph R with no
augmenting pathS = {v| } T = N - SMust have
Claim that for (v,w) with v S, t T, must haveSuppose not. Then r(v,w) > 0. Then R has
David Maier 18Lecture Notes 5
s v w t
CS 410/584, Algorithm Design & Analysis, Lecture Notes 5
10© 1994, 2003, 2003, 2006, 2008,
2009, 2010 David Maier
Algorithm Design & Analysis
Basic Implementation
Start with 0 flowRepeatp
Add flow along an augmenting path
Does it always converge?Yes, if capacities are integers. Flow grows by
at leastHow long does it take?
David Maier 19Lecture Notes 5
How long does it take?If you pick augmenting paths arbitrarilyO(|E||f*|)
Algorithm Design & Analysis
Edmonds-Karp Algorithm
Start with 0 flowRepeat
Add fl l ti th ithAdd flow along an augmenting path with
Time complexity no longer depends on value of maximum flowO(|N||E|2) timeIntuition: Length of shortest path to a node
i id l h
David Maier 20Lecture Notes 5
g pv in residual graph• Each addition of flow increases distance
to one node• Distance to a node v can be increased at
most
CS 410/584, Algorithm Design & Analysis, Lecture Notes 5
11© 1994, 2003, 2003, 2006, 2008,
2009, 2010 David Maier
Algorithm Design & Analysis
Edmonds-Karp Example
s1
s
25
s220
9
2510
s4
s5
12
15
7 710
s64
6s7
6
102
t
20
15
David Maier 21Lecture Notes 5
s3 s83