CS 4102: AlgorithmsLecture 22: Network Flow
David WuFall 2019
Review: All-Pairs Shortest Path
2
Thus far: single-source shortest path algorithms (Dijkstra, Bellman-Ford)
All-pairs shortest-paths: find shortest path between every pair of nodes
10
2
11
95
8
3
7
3
1
8
12
9
Review: All-Pairs Shortest Path
Naรฏvely: Run single-source shortest paths algorithm for each node ๐ (to compute shortest path from ๐ to every other node in the graph)
โข If edge weights are all non-negative, can use Dijkstra (running time ๐ ๐ ๐ธ log ๐
โข If edge weights can be negative, can use Bellman-Ford (running time ๐ ๐ ( ๐ธ
When ๐ธ = ฮฉ ๐ ( , both of these algorithms are ๐ ๐ + log ๐ or ๐ ๐ ,
3
Floyd-Warshall All-Pairs Shortest Paths
4
Finds all-pairs shortest paths in ฮ( ๐ +) using dynamic programmingAlso works if graph has negative-weight edges
Same observation as before: Every subpath of a shortest path is itself a shortest path (optimal substructure)โข Namely if shortest path from ๐ to ๐ goes through ๐, then the ๐ โ ๐ and ๐ โ ๐ subpaths must themselves be a shortest path
Two possibilities for node ๐:
Shortest path from ๐ to ๐ includes ๐
Shortest path from ๐ to ๐ excludes ๐OR
Short(๐, ๐, ๐ โ 1)
Short(๐, ๐, ๐ โ 1) + Short(๐, ๐, ๐ โ 1)
๐๐
๐
๐
๐๐
Short ๐, ๐, ๐ = weight of shortest path from ๐ โ ๐ using nodes 1,โฆ , ๐ as intermediate hops
Floyd-Warshall All-Pairs Shortest Paths
5
Finds all-pairs shortest paths in ฮ( ๐ +) using dynamic programmingAlso works if graph has negative-weight edges
Same observation as before: Every subpath of a shortest path is itself a shortest path (optimal substructure)โข Namely if shortest path from ๐ to ๐ goes through ๐, then the ๐ โ ๐ and ๐ โ ๐ subpaths must themselves be a shortest path
Short(๐, ๐, ๐ โ 1)Short(๐, ๐, ๐ โ 1) + Short(๐, ๐, ๐ โ 1)Short ๐, ๐, ๐ = min
Short ๐, ๐, ๐ = weight of shortest path from ๐ โ ๐ using nodes 1,โฆ , ๐ as intermediate hops
Floyd-Warshall All-Pairs Shortest Paths
6
allocate short[n][n][n] (initialized to โ)for (i, j) in E:
short[i][j][0] = w[i][j]
for i = 1,...,n:
short[i][i][0] = 0
for k = 1,...,n:
for i = 1,...,n:
for j = 1,...,n:
short[i][j][k] = min(short[i][k][k-1] + short[k][j][k-1], short[i][j][k-1])
๐ = ๐: shortest path cannot use any intermediate nodes (must be direct path)
๐ = ๐: shortest path from node to itself is always 0
Short(๐, ๐, ๐ โ 1)Short(๐, ๐, ๐ โ 1) + Short(๐, ๐, ๐ โ 1)Short ๐, ๐, ๐ = min
Floyd-Warshall All-Pairs Shortest Paths
7
allocate short[n][n] (initialized to โ)for (i, j) in E:
short[i][j] = w[i][j]
for i = 1,...,n:
short[i][i] = 0
for k = 1,...,n:
for i = 1,...,n:
for j = 1,...,n:
short[i][j] = min(short[i][k] + short[k][j], short[i][j])
๐ = ๐: shortest path cannot use any intermediate nodes (must be direct path)
๐ = ๐: shortest path from node to itself is always 0
Observation: short[i][j][k] only depends on values for short[][][k โ 1], so we can just use a single two-dimensional array
Short(๐, ๐, ๐ โ 1)Short(๐, ๐, ๐ โ 1) + Short(๐, ๐, ๐ โ 1)Short ๐, ๐, ๐ = min
In this case, the initialization step is constructing the adjacency matrix of the graph
(this step is not needed if graph already represented in this form!)
Floyd-Warshall All-Pairs Shortest Paths
8
allocate short[n][n] (initialized to โ)for (i, j) in E:
short[i][j] = w[i][j]
for i = 1,...,n:
short[i][i] = 0
for k = 1,...,n:
for i = 1,...,n:
for j = 1,...,n:
short[i][j] = min(short[i][k] + short[k][j], short[i][j])
๐ = ๐: shortest path cannot use any intermediate nodes (must be direct path)
๐ = ๐: shortest path from node to itself is always 0
Very simple implementation!
Running time: ๐ ๐+ = ๐ ๐ +
Short(๐, ๐, ๐ โ 1)Short(๐, ๐, ๐ โ 1) + Short(๐, ๐, ๐ โ 1)Short ๐, ๐, ๐ = min
Todayโs Keywords
GraphsNetwork flowFord-FulkersonEdmonds-KarpMax-Flow Min-Cut Theorem
9
CLRS Readings: Chapter 25, 26
Homework
HW7 due today, 11pmโข Graph algorithmsโข Written (use LaTeX!) โ Submit both zip and pdf (two separate attachments)!
HW10B due today, 11pmโข No late submissions allowed (no exceptions)
HW8 out today, due Thursday, November 21, 11pmโข Programming assignment (Python or Java)โข Graph algorithms
10
Network Flow
11Railway map of Western USSR, 1955
Question: What is the maximum throughput of the
railroad network?
Flow Networks
Graph ๐บ = (๐, ๐ธ)Source node ๐ โ ๐Sink node ๐ก โ ๐Edge capacities ๐ ๐ โ โK
Max flow intuition: If ๐ is a faucet, ๐ก is a drain, and ๐ connects to ๐ก through a network of pipes ๐ธ with capacities ๐(๐), what is the maximum amount of water which can flow from the faucet to the drain?
12
3
3
3
2
๐ ๐ก
1
2
1 3 2
2
3
Assignment of values ๐ ๐ to edgesโข โAmount of water going through that pipeโ
Capacity constraintโข ๐ ๐ โค ๐(๐)โข โFlow cannot exceed capacityโ
Flow constraintโข โ๐ฃ โ ๐ โ {๐ , ๐ก}, inRlow ๐ฃ = outRlow(๐ฃ)โข inRlow ๐ฃ = โVโW ๐(๐ฅ, ๐ฃ)โข outRlow ๐ฃ = โVโW ๐(๐ฃ, ๐ฅ)โข Water going in must match water coming out
Flow of ๐บ: |๐| = outRlow ๐ โ inRlow(๐ )โข Net outflow of ๐
13
flow / capacity
3 in this example
Network Flow
1/3
1/3
2/3
2/2
๐ ๐ก
0/1
2/2
1/1
2/31/2
1/2
2/3
Maximum Flow Problem
Of all valid flows through the graph, find the one that maximizes:
๐ = outRlow ๐ โ inRlow(๐ )
14
3
3
3
2
๐ ๐ก
1
2
1
32
2
30/3
2/3
2/3
2/2
๐ ๐ก
0/1
2/2
0/1
0/30/2
2/2
2/3
Greedy Approach
15
30
20
๐ ๐ก
10 20
10
Greedy choice: saturate highest capacity path first
Greedy Approach
16
30
20
๐ ๐ก
10 20
10
Greedy choice: saturate highest capacity path first
Greedy Approach
17
20/30
20/20
๐ ๐ก
10 20/20
10
Greedy choice: saturate highest capacity path first
Flow: 20
Greedy Approach
18
10/30
20/20
๐ ๐ก
10/10 20/20
10/10
Greedy choice: saturate highest capacity path first
Maximum Flow: 30
Observe: highest capacity path is not saturated in optimal solution
Residual Graphs
19
1/3
1/3
2/3
2/2
๐ ๐ก
0/1
2/2
1/1
2/31/2
1/2
2/3
Flow ๐ in ๐บ
Given a flow ๐ in graph ๐บ, the residual graph ๐บZ models additional flow that is possibleโข Forward edge for each edge in ๐บ with weight set to remaining capacity ๐ ๐ โ ๐(๐)
โข Models additional flow that can be sent along the edge
Residual graph ๐บZ
๐ ๐ก
21
1
112
11
Residual Graphs
20
1/3
1/3
2/3
2/2
๐ ๐ก
0/1
2/2
1/1
2/31/2
1/2
2/3
Flow ๐ in ๐บ Residual graph ๐บZ
๐ ๐ก
21
1
112
11
1
21
2
1
2
212
1
Given a flow ๐ in graph ๐บ, the residual graph ๐บZ models additional flow that is possibleโข Forward edge for each edge in ๐บ with weight set to remaining capacity ๐ ๐ โ ๐(๐)
โข Models additional flow that can be sent along the edgeโข Backward edge by flipping each edge ๐ in ๐บ with weight set to flow ๐(๐)
โข Models amount of flow that can be removed from the edge
Residual Graphs
21
1/3
1/3
2/3
2/2
๐ ๐ก
0/1
2/2
1/1
2/31/2
1/2
2/3
Flow ๐ in ๐บ
Consider a path from ๐ โ ๐ก in ๐บZ using only edges with positive (non-zero) weightConsider the minimum-weight edge ๐ along the path: we can increase the flow by ๐ค(๐)โข Send ๐ค(๐) flow along all forward edges (these have at least ๐ค(๐) capacity)
Residual graph ๐บZ
๐ ๐ก
21
1
112
11
1
21
2
1
2
212
1
Residual Graphs
22
1/3
1/3
2/3
2/2
๐ ๐ก
0/1
2/2
1/1
2/31/2
1/2
2/3
Flow ๐ in ๐บ
Consider a path from ๐ โ ๐ก in ๐บZ using only edges with positive (non-zero) weightConsider the minimum-weight edge ๐ along the path: we can increase the flow by ๐ค(๐)โข Send ๐ค(๐)flow along all forward edges (these have at least ๐ค(๐) capacity)โข Remove ๐ค(๐)flow along all backward edges (these contain at least ๐ค(๐) units of flow)
Residual graph ๐บZ
๐ ๐ก
21
1
112
11
1
21
2
1
2
212
1
Residual Graphs
23
0/3
2/3
2/3
2/2
๐ ๐ก
0/1
2/2
0/1
2/31/2
1/2
3/3
Flow ๐ in ๐บ Residual graph ๐บZ
๐ ๐ก
21
1
112
11
1
21
2
1
2
212
1
Observe: Flow has increased by ๐ค(๐)
Consider a path from ๐ โ ๐ก in ๐บZ using only edges with positive (non-zero) weightConsider the minimum-weight edge ๐ along the path: we can increase the flow by ๐ค(๐)โข Send ๐ค(๐)flow along all forward edges (these have at least ๐ค(๐) capacity)โข Remove ๐ค(๐)flow along all backward edges (these contain at least ๐ค(๐) units of flow)
Residual Graphs
24
Consider a path from ๐ โ ๐ก in ๐บZ using only edges with positive (non-zero) weightConsider the minimum-weight edge ๐ along the path: we can increase the flow by ๐ค(๐)โข Send ๐ค(๐) flow along all forward edges (these have at least ๐ค(๐) capacity)โข Remove ๐ค(๐) flow along all backward edges (these contain at least ๐ค(๐) units of flow)
Residual graph ๐บZ
๐ ๐ก
21
1
112
11
1
21
2
1
2
212
1
Observe: Flow has increased by ๐ค(๐)
Why does this respect flow constraints?โข Incoming edge to a node always
corresponds to increased flow to the node (more incoming flow from forward edge or less outgoing flow from backward edge)
โข Outgoing edge to a node always corresponds to decreased flow to the node
Residual Graphs
25
Consider a path from ๐ โ ๐ก in ๐บZ using only edges with positive (non-zero) weightConsider the minimum-weight edge ๐ along the path: we can increase the flow by ๐ค(๐)โข Send ๐ค(๐) flow along all forward edges (these have at least ๐ค(๐) capacity)โข Remove ๐ค(๐) flow along all backward edges (these contain at least ๐ค(๐) units of flow)
Residual graph ๐บZ
๐ ๐ก
21
1
112
11
1
21
2
1
2
212
1
Observe: Flow has increased by ๐ค(๐)
Why does this respect flow constraints?โข Incoming edge to a node always
corresponds to increased flow to the node (more incoming flow from forward edge or less outgoing flow from backward edge)
โข Outgoing edge to a node always corresponds to decreased flow to the node
Capacity constraints satisfied by construction of the residual network
Ford-Fulkerson Algorithm
Define an augmenting path to be an ๐ โ ๐ก path in the residual graph ๐บZ (using edges of non-zero weight)
Ford-Fulkerson max-flow algorithm:โข Initialize ๐ ๐ = 0 for all ๐ โ ๐ธโข Construct the residual network ๐บZโข While there is an augmenting path ๐ in ๐บZ:
โข Let ๐ = min]โ^
๐Z(๐) (๐Z(๐) is the weight of edge ๐ in the residual network ๐บZ)โข Add ๐ units of flow to ๐บ based on the augmenting path ๐โข Update the residual network ๐บZ for the updated flow
26
Ford-Fulkerson approach: take any augmenting path(will revisit this later)
Ford-Fulkerson Example
27
0/3
0/3
0/3
0/2
๐ ๐ก
0/1
0/2
0/1
0/30/2
0/2
0/3
Initially: ๐ ๐ = 0 for all ๐ โ ๐ธ
3
3
3
๐ ๐ก
1
2
1
32
2
Residual graph ๐บZ
3
2
Ford-Fulkerson Example
28
0/3
0/3
0/3
0/2
๐ ๐ก
0/1
0/2
0/1
0/30/2
0/2
0/33
3
๐ ๐ก
1
2
1
32
2
Residual graph ๐บZ
Increase flow by 1 unit
33
2
Ford-Fulkerson Example
29
0/3
1/3
1/3
0/2
๐ ๐ก
0/1
1/2
1/1
0/30/2
1/2
0/33
3
๐ ๐ก
1
2
1
32
2
Residual graph ๐บZ
Increase flow by 1 unit
33
2
Ford-Fulkerson Example
30
0/3
1/3
1/3
0/2
๐ ๐ก
0/1
1/2
1/1
0/30/2
1/2
0/32
2
๐ ๐ก
1
1
32
1
11
1
1
1
Residual graph ๐บZ
33
2
Ford-Fulkerson Example
31
0/3
1/3
1/3
0/2
๐ ๐ก
0/1
1/2
1/1
0/30/2
1/2
0/32
2
๐ ๐ก
1
1
32
1
11
1
1
1
Residual graph ๐บZ
Increase flow by 1 unit
33
2
Ford-Fulkerson Example
32
0/3
2/3
1/3
0/2
๐ ๐ก
0/1
2/2
1/1
0/30/2
1/2
1/32
2
๐ ๐ก
1
1
32
1
11
1
1
1
Residual graph ๐บZ
Increase flow by 1 unit
33
2
Ford-Fulkerson Example
33
0/3
2/3
1/3
0/2
๐ ๐ก
0/1
2/2
1/1
0/30/2
1/2
1/31
2
๐ ๐ก
1
32
1
221
1
1
2 1
Residual graph ๐บZ
Increase flow by 1 unit
3
2
Ford-Fulkerson Example
34
0/3
2/3
1/3
0/2
๐ ๐ก
0/1
2/2
1/1
0/30/2
1/2
1/3
Residual graph ๐บZ
1
2
๐ ๐ก
1
32
1
221
1
1
2 13
2
Ford-Fulkerson Example
35
0/3
2/3
1/3
1/2
๐ ๐ก
0/1
2/2
0/1
0/30/2
1/2
2/3
Residual graph ๐บZ
1
2
๐ ๐ก
1
32
1
221
1
1
2 1
Increase flow by 1 unit
3
2
Ford-Fulkerson Example
36
0/3
2/3
1/3
1/2
๐ ๐ก
0/1
2/2
0/1
0/30/2
1/2
2/3
Residual graph ๐บZ
1
2
๐ ๐ก
1
32
1
121
1
1
2 2
Increase flow by 1 unit
3
11
Ford-Fulkerson Example
37
0/3
2/3
1/3
1/2
๐ ๐ก
0/1
2/2
0/1
0/30/2
1/2
2/3
Residual graph ๐บZ
1
2
๐ ๐ก
1
32
1
121
1
1
2 23
11
Ford-Fulkerson Example
38
0/3
2/3
2/3
2/2
๐ ๐ก
0/1
2/2
0/1
0/30/2
2/2
2/3
Residual graph ๐บZ
1
2
๐ ๐ก
1
32
1
121
1
1
2 2
Increase flow by 1 unit
3
11
Ford-Fulkerson Example
39
0/3
2/3
2/3
2/2
๐ ๐ก
0/1
2/2
0/1
0/30/2
2/2
2/3
Residual graph ๐บZ
No more augmenting paths
1
1
๐ ๐ก
1
3212
1
2
2
2 23
2
Maximum flow: 4
Ford-Fulkerson Running Time
Define an augmenting path to be an ๐ โ ๐ก path in the residual graph ๐บZ (using edges of non-zero weight)
Ford-Fulkerson max-flow algorithm:โข Initialize ๐ ๐ = 0 for all ๐ โ ๐ธโข Construct the residual network ๐บZโข While there is an augmenting path ๐ in ๐บZ:
โข Let ๐ = min]โ^
๐Z(๐) (๐Z(๐) is the weight of edge ๐ in the residual network ๐บZ)โข Add ๐ units of flow to ๐บ based on the augmenting path ๐โข Update the residual network ๐บZ for the updated flow
40
Initialization: ๐ ๐ธ
Ford-Fulkerson Running Time
Define an augmenting path to be an ๐ โ ๐ก path in the residual graph ๐บZ (using edges of non-zero weight)
Ford-Fulkerson max-flow algorithm:โข Initialize ๐ ๐ = 0 for all ๐ โ ๐ธโข Construct the residual network ๐บZโข While there is an augmenting path ๐ in ๐บZ:
โข Let ๐ = min]โ^
๐Z(๐) (๐Z(๐) is the weight of edge ๐ in the residual network ๐บZ)โข Add ๐ units of flow to ๐บ based on the augmenting path ๐โข Update the residual network ๐บZ for the updated flow
41
Initialization: ๐ ๐ธConstruct residual network: ๐ ๐ธ
Ford-Fulkerson Running Time
Define an augmenting path to be an ๐ โ ๐ก path in the residual graph ๐บZ (using edges of non-zero weight)
Ford-Fulkerson max-flow algorithm:โข Initialize ๐ ๐ = 0 for all ๐ โ ๐ธโข Construct the residual network ๐บZโข While there is an augmenting path ๐ in ๐บZ:
โข Let ๐ = min]โ^
๐Z(๐) (๐Z(๐) is the weight of edge ๐ in the residual network ๐บZ)โข Add ๐ units of flow to ๐บ based on the augmenting path ๐โข Update the residual network ๐บZ for the updated flow
42
Initialization: ๐ ๐ธConstruct residual network: ๐ ๐ธFinding augmenting path in residual network: ๐ ๐ธ using BFS/DFS
We only care about nodes reachable from the source ๐ (so the number of nodes
that are โrelevantโ is at most ๐ธ )
Ford-Fulkerson Running Time
Define an augmenting path to be an ๐ โ ๐ก path in the residual graph ๐บZ (using edges of non-zero weight)
Ford-Fulkerson max-flow algorithm:โข Initialize ๐ ๐ = 0 for all ๐ โ ๐ธโข Construct the residual network ๐บZโข While there is an augmenting path ๐ in ๐บZ:
โข Let ๐ = min]โ^
๐Z(๐) (๐Z(๐) is the weight of edge ๐ in the residual network ๐บZ)โข Add ๐ units of flow to ๐บ based on the augmenting path ๐โข Update the residual network ๐บZ for the updated flow
43
Initialization: ๐ ๐ธConstruct residual network: ๐ ๐ธFinding augmenting path in residual network: ๐ ๐ธ using BFS/DFS
How many iterations are needed?โข For integer-valued capacities, min-weight of each augmenting path is 1, so
number of iterations is bounded by ๐โ , where ๐โ is max-flow in ๐บโข For rational-valued capacities, can scale to make capacities integerโข For irrational-valued capacities, algorithm may never terminate!
โข Extra credit: Construct a graph where this happens
Ford-Fulkerson Running Time
Define an augmenting path to be an ๐ โ ๐ก path in the residual graph ๐บZ (using edges of non-zero weight)
Ford-Fulkerson max-flow algorithm:โข Initialize ๐ ๐ = 0 for all ๐ โ ๐ธโข Construct the residual network ๐บZโข While there is an augmenting path ๐ in ๐บZ:
โข Let ๐ = min]โ^
๐Z(๐) (๐Z(๐) is the weight of edge ๐ in the residual network ๐บZ)โข Add ๐ units of flow to ๐บ based on the augmenting path ๐โข Update the residual network ๐บZ for the updated flow
44
Initialization: ๐ ๐ธConstruct residual network: ๐ ๐ธFinding augmenting path in residual network: ๐ ๐ธ using BFS/DFS
For graphs with integer capacities, running time of Ford-Fulkerson is
๐ ๐โ โ ๐ธHighly undesirable if ๐โ โซ |๐ธ| (e.g., graph is small, but capacities are โ 2+()
As described, algorithm is not polynomial-time!
Worst-Case Ford-Fulkerson
45
0/1
0/100
๐ ๐ก
0/100 0/100
0/100
1
100
๐ ๐ก
100 100
100
Worst-Case Ford-Fulkerson
46
0/1
0/100
๐ ๐ก
0/100 0/100
0/100
1
100
๐ ๐ก
100 100
100
Increase flow by 1 unit
Worst-Case Ford-Fulkerson
47
1/1
1/100
๐ ๐ก
0/100 1/100
0/100
1
100
๐ ๐ก
100 100
100
Increase flow by 1 unit
Worst-Case Ford-Fulkerson
48
1/1
1/100
๐ ๐ก
0/100 1/100
0/100
1
99
๐ ๐ก
100 99
100
11
Worst-Case Ford-Fulkerson
49
1/1
1/100
๐ ๐ก
0/100 1/100
0/100
1
99
๐ ๐ก
100 99
100
11
Increase flow by 1 unit
Worst-Case Ford-Fulkerson
50
0/1
1/100
๐ ๐ก
1/100 1/100
1/100
1
99
๐ ๐ก
100 99
100
11
Increase flow by 1 unit
Worst-Case Ford-Fulkerson
51
0/1
1/100
๐ ๐ก
1/100 1/100
1/100
1
99
๐ ๐ก
99 99
99
11
1
1
Worst-Case Ford-Fulkerson
52
0/1
1/100
๐ ๐ก
1/100 1/100
1/100
1
99
๐ ๐ก
99 99
99
11
1
1
Observation: each iteration increases flow by 1 unitTotal number of iterations: ๐โ = 200
Can We Avoid this?
Edmonds-Karp Algorithm: choose augmenting path with fewest hopsRunning time: ฮ min ๐ธ ๐โ , ๐ ๐ธ ( = ๐ ๐ ๐ธ (
53
Ford-Fulkerson max-flow algorithm:โข Initialize ๐ ๐ = 0 for all ๐ โ ๐ธโข Construct the residual network ๐บZโข While there is an augmenting path in ๐บZ, let ๐ be the path with fewest hops:โข Let ๐ = min
]โ^๐Z(๐) (๐Z(๐) is the weight of edge ๐ in the residual network ๐บZ)
โข Add ๐ units of flow to ๐บ based on the augmenting path ๐โข Update the residual network ๐บZ for the updated flow
How to find this? Use breadth-first search (BFS)!
Edmonds-Karp = Ford-Fulkerson using BFS to find augmenting path
Proof: See CLRS (Chapter 26.2)
Correctness of Ford-Fulkerson
Consider cuts which separate ๐ and ๐กโข Let ๐ โ ๐, ๐ก โ ๐, such that ๐ = ๐ โช ๐
Cost ๐, ๐ of cut ๐, ๐ : sum of the capacities of edges from ๐ to ๐
54
3
3
3
2
๐ ๐ก
1
2
1
32
2
3
๐ ๐๐, ๐ = 5
Max-Flow / Min-CutClaim: Maximum flow in a flow network ๐บ always upper-bounded by the cost any cut that separates ๐ and ๐กProof: โConservation of flowโ
โข All flow from ๐ must eventually get to ๐กโข To get from ๐ to ๐ก, all flow must cross the cut somewhere
Conclusion: Max-flow in ๐บ is at most the cost of the min-cut in ๐บโข max
Z๐ โค min
j,k๐, ๐
55
3
3
3
2
๐ ๐ก
1
2
1
32
2
3
๐ ๐
Max-Flow Min-Cut Theorem
Let ๐ be a flow in a graph ๐บ
56
๐ is a maximum flow in ๐บ
there are no augmenting paths in the
residual graph ๐บZ
there exists a cut (๐, ๐) of ๐บ where
๐ = โ๐, ๐โ
Statements are equivalent!
Implications:โข Correctness of Ford-Fulkerson: Ford-Fulkerson terminates when there are no more
augmenting paths in the residual graph ๐บZ, which means that ๐ is a maximum flowโข Max-flow min-cut duality: the maximum flow in a network coincides with the minimum cut
of the graph (maxZ
๐ = minj,k
๐, ๐ )
โข Finding either the minimum cut or the maximum flow yields solution to the otherโข Special case of more general principle (duality in linear programming)
Max-Flow Min-Cut Duality Example
57
0/3
2/3
2/3
2/2
๐ ๐ก
0/1
2/2
0/1
0/30/2
2/2
2/31
1
๐ ๐ก
1
3212
1
2
2
2 23
2
Flow graph Residual graph
no more augmenting paths
Max flow: 4
๐
๐
Max-Flow Min-Cut Duality Example
58
0/3
2/3
2/3
2/2
๐ ๐ก
0/1
2/2
0/1
0/30/2
2/2
2/31
1
๐ ๐ก
1
3212
1
2
2
2 23
2
Flow graph Residual graph
no more augmenting paths๐
๐
Max flow: 4Min cut: 4
When there are no more augmenting paths in the graph, there is a cut whose cost matches the flow
Max-Flow Min-Cut Theorem Proof
Let ๐ be a flow in a graph ๐บ
59
๐ is a maximum flow in ๐บ
there are no augmenting paths in the
residual graph ๐บZ
there exists a cut (๐, ๐) of ๐บ where
๐ = โ๐, ๐โ
Proof:โข Suppose ๐ is a max flow in ๐บ and there is an augmenting path in ๐บZโข If there is an augmenting path in ๐บZ, then we can send additional units of flow though
the network along the augmenting pathโข This contradicts optimality of ๐
Max-Flow Min-Cut Theorem Proof
Let ๐ be a flow in a graph ๐บ
60
๐ is a maximum flow in ๐บ
there are no augmenting paths in the
residual graph ๐บZ
there exists a cut (๐, ๐) of ๐บ where
๐ = โ๐, ๐โ
Proof:โข Take any flow ๐mโข Consider the cut ๐, ๐ of ๐บ; then, ๐m โค ๐, ๐ = ๐โข Thus, ๐m โค ๐ , so ๐ must be a maximum flow
Max-Flow Min-Cut Theorem Proof
Let ๐ be a flow in a graph ๐บ
61
๐ is a maximum flow in ๐บ
there are no augmenting paths in the
residual graph ๐บZ
there exists a cut (๐, ๐) of ๐บ where
๐ = โ๐, ๐โ
Max-Flow Min-Cut Theorem Proof
62
0/3
2/3
2/3
2/2
๐ ๐ก
0/1
2/2
0/1
0/30/2
2/2
2/31
1
๐ ๐ก
1
3212
1
2
2
2 23
2
no more augmenting paths๐
๐Flow graph Residual graph
No augmenting paths means there is no path from ๐ to ๐ก in ๐บZโข Let ๐ be set of nodes reachable from ๐ in ๐บZโข Let ๐ = ๐ โ ๐
Max-Flow Min-Cut Theorem Proof
63
0/3
2/3
2/3
2/2
๐ ๐ก
0/1
2/2
0/1
0/30/2
2/2
2/31
1
๐ ๐ก
1
3212
1
2
2
2 23
2
no more augmenting paths๐
๐Claim: ๐, ๐ = ๐โข Total flow ๐ is amount of outgoing flow from ๐ to ๐ minus the amount of incoming flow from ๐ to ๐
Max-Flow Min-Cut Theorem Proof
64
0/3
2/3
2/3
2/2
๐
๐ข๐ฃ
๐ก
0/1
2/2
0/1
0/30/2
2/2
2/31
1
๐
๐ข๐ฃ
๐ก
1
3212
1
2
2
2 23
2
no more augmenting paths๐
๐Claim: ๐, ๐ = ๐โข Total flow ๐ is amount of outgoing flow from ๐ to ๐ minus the amount of incoming flow from ๐ to ๐โข Outgoing flow: Consider edge ๐ข, ๐ฃ where ๐ข โ ๐ and ๐ฃ โ ๐
โข Then, ๐ ๐ข, ๐ฃ = ๐ ๐ข, ๐ฃ . Otherwise, there is a forward edge ๐ข, ๐ฃ with positive weight in ๐บZ and ๐ฃ โ ๐
Max-Flow Min-Cut Theorem Proof
65
0/3
2/3
2/3
2/2
๐
๐ฅ
๐ฆ
๐ก
0/1
2/2
0/1
0/30/2
2/2
2/31
1
๐
๐ฅ
๐ฆ
๐ก
1
3212
1
2
2
2 23
2
no more augmenting paths๐
๐Claim: ๐, ๐ = ๐โข Total flow ๐ is amount of outgoing flow from ๐ to ๐ minus the amount of incoming flow from ๐ to ๐โข Outgoing flow: Consider edge ๐ข, ๐ฃ where ๐ข โ ๐ and ๐ฃ โ ๐
โข Then, ๐ ๐ข, ๐ฃ = ๐ ๐ข, ๐ฃ . Otherwise, there is a forward edge ๐ข, ๐ฃ with positive weight in ๐บZ and ๐ฃ โ ๐โข Incoming flow: Consider edge ๐ฆ, ๐ฅ where ๐ฆ โ ๐ and ๐ฅ โ ๐
โข Then, ๐ ๐ฆ, ๐ฅ = 0. Otherwise, there is a backward edge ๐ฅ, ๐ฆ with positive weight in ๐บZ and ๐ฆ โ ๐
Max-Flow Min-Cut Theorem Proof
66
0/3
2/3
2/3
2/2
๐ ๐ก
0/1
2/2
0/1
0/30/2
2/2
2/3๐
๐Claim: ๐, ๐ = ๐โข Total flow ๐ is amount of outgoing flow from ๐ to ๐ minus the amount of incoming flow from ๐ to ๐โข Outgoing flow: Consider edge ๐ข, ๐ฃ where ๐ข โ ๐ and ๐ฃ โ ๐
โข Then, ๐ ๐ข, ๐ฃ = ๐ ๐ข, ๐ฃ . Otherwise, there is a forward edge ๐ข, ๐ฃ with positive weight in ๐บZ and ๐ฃ โ ๐โข Incoming flow: Consider edge ๐ฆ, ๐ฅ where ๐ฆ โ ๐ and ๐ฅ โ ๐
โข Then, ๐ ๐ฆ, ๐ฅ = 0. Otherwise, there is a backward edge ๐ฅ, ๐ฆ with positive weight in ๐บZ and ๐ฆ โ ๐
๐ = pqโj,rโk
๐ ๐ข, ๐ฃ โ psโk,Vโj
๐ ๐ฆ, ๐ฅ
= ๐, ๐
= pqโj,rโk
๐ ๐ข, ๐ฃ
Max-Flow Min-Cut Theorem
Let ๐ be a flow in a graph ๐บ
67
๐ is a maximum flow in ๐บ
there are no augmenting paths in the
residual graph ๐บZ
there exists a cut (๐, ๐) of ๐บ where
๐ = โ๐, ๐โ
Statements are equivalent!
Implications:โข Correctness of Ford-Fulkerson: Ford-Fulkerson terminates when there are no more
augmenting paths in the residual graph ๐บZ, which means that ๐ is a maximum flowโข Max-flow min-cut duality: the maximum flow in a network coincides with the minimum cut
of the graph (maxZ
๐ = minj,k
๐, ๐ )
Other Max Flow Algorithms
Ford-Fulkersonโข ฮ ๐ธ ๐โ
Edmonds-Karp (Ford-Fulkerson using BFS to choose augmenting path)โข ฮ( ๐ธ ( ๐ )
Push-Relabel (Tarjan)โข ฮ( ๐ธ ๐ ()
Faster Push-Relabel (also Tarjan)โข ฮ( ๐ +)
68
Minimum-Cost Maximum-Flow Problem
Not all paths are created equal!
69
3
3
3
2
๐ ๐ก
1
2
1
32
2
3
2 5
211
3 4
7
1 2
1
A cost is associated with each unit of flow sent along an edgeGoal: Maximize flow while minimizing cost
Much harder problem!Can solve using linear programming