cs 4102: algorithmsjh2jf/courses/fall2019/cs...review: all-pairs shortest path 2 thus...
TRANSCRIPT
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