CS 401 Max Flow Xiaorui Sun 1
Stuff Homework 3 due today Homework 4 will be out soon
Flow network Flow network. G = (V, E) = directed graph, no parallel edges. Two distinguished nodes: s = source, t = sink. c(e) = capacity of edge e. 9 2 5 10 15 15 10 4 source 5 sink 8 s 3 6 10 t 15 4 6 10 15 capacity 30 4 7
Cuts Def. An s-t cut is a partition (A, B) of V with s Î A and t Î B. Def. The capacity of a cut (A, B) is: 9 2 5 10 15 15 10 4 5 8 s 3 6 10 t A 15 4 6 10 15 Capacity = 10 + 5 + 15 = 30 30 4 7
Minimum Cut Problem Min s-t cut problem. Find an s-t cut of minimum capacity. 9 2 5 10 15 15 10 4 5 8 s 3 6 10 t 15 4 6 10 A 15 Capacity = 10 + 8 + 10 = 28 30 5 4 7
Flows Def. An s-t flow is a function that satisfies: For each e Î E: (capacity) For each v Î V – {s, t}: (conservation) Def. The value of a flow f is: the total flow sends out from vertex s 0 9 2 5 4 0 0 10 15 15 0 10 4 4 0 4 4 5 8 s 3 6 10 t 0 0 0 15 0 4 6 10 capacity 15 flow 0 0 Value = 4 30 6 4 7
Maximum Flow Problem Max flow problem. Find s-t flow of maximum value. 9 9 2 5 10 9 1 10 15 15 0 10 4 0 4 9 8 5 8 s 3 6 10 t 4 10 0 15 0 4 6 10 capacity 15 flow 14 14 Value = 28 30 7 4 7
Flows and Cuts Flow value lemma. Let f be any flow, and let (A, B) be any s-t cut. Then, the net flow sent across the cut is equal to the amount leaving s. 6 9 2 5 10 6 0 10 15 15 0 10 4 4 3 8 8 5 8 s 3 6 10 t A 1 10 0 15 0 4 6 10 15 11 11 Value = 6 + 0 + 8 - 1 + 11 = 24 30 8 4 7
Flows and Cuts Weak duality. Let f be any flow, and let (A, B) be any s-t cut. Then the value of the flow is at most the capacity of the cut. Þ Flow value £ 28 Cut capacity = 28 9 9 2 5 10 9 1 10 15 15 0 10 4 0 4 9 8 5 8 s 3 6 10 t 4 10 A 0 15 0 4 6 10 15 14 14 30 4 7
Towards a Max Flow Algorithm Greedy algorithm. Start with f(e) = 0 for all edge e Î E. Find an s-t path P where each edge has f(e) < c(e). Augment flow along path P. Repeat until you get stuck. 1 0 0 20 10 30 0 t s 10 20 Flow value = 0 0 0 2
Towards a Max Flow Algorithm Greedy algorithm. Start with f(e) = 0 for all edge e Î E. Find an s-t path P where each edge has f(e) < c(e). Augment flow along path P. Repeat until you get stuck. 1 X 20 0 0 20 10 X 30 0 20 t s 10 20 Flow value = 20 X 0 0 20 2
Towards a Max Flow Algorithm Greedy algorithm. Start with f(e) = 0 for all edge e Î E. Find an s-t path P where each edge has f(e) < c(e). Augment flow along path P. Repeat until you get stuck. locally optimality Þ global optimality 1 1 20 0 20 10 20 10 20 10 s t s t 30 20 30 10 10 20 10 20 0 20 10 20 2 2 greedy = 20 opt = 30 12
Residual Graph Original edge: e = (u, v) Î E. capacity u v Flow f(e), capacity c(e). 17 6 flow Residual edge. "Undo" flow sent. e = (u, v) and e R = (v, u). residual capacity Residual capacity: u v 11 6 residual capacity Residual graph: G f = (V, E f ). Residual edges with positive residual capacity. E f = {e : f(e) < c(e)} È {e R : c(e) > 0}.
Residual Graph 1 1 0 20 20 0 20 10 0 10 20 s t s t 30 20 10 0 0 10 20 10 20 0 20 2 2 Original graph Residual graph 14
Residual Graph 1 1 0 20 20 0 20 10 0 10 20 s t s t 30 20 10 0 0 10 20 10 20 0 20 2 2 Original graph Residual graph 15
Residual Graph 1 1 0 20 20 10 20 10 0 10 20 s t s t 30 10 10 0 0 10 20 10 20 10 20 2 2 Original graph Residual graph 16
Ford-Fulkerson Algorithm 0 flow 4 2 4 capacity G: 0 0 0 6 0 8 10 10 2 0 0 0 0 10 s 3 5 10 t 9 Flow value = 0 17
Ford-Fulkerson Algorithm 0 flow 4 2 4 capacity G: 0 8 X 0 0 8 X 6 0 8 10 10 2 0 0 8 X 0 0 10 s 3 5 10 t 9 Flow value = 0 2 4 4 residual capacity G f : 8 6 10 10 2 10 s 3 5 t 9 10 18
Ford-Fulkerson Algorithm 0 4 2 4 G: 0 10 X 8 8 6 0 8 10 10 2 0 X 2 0 10 X 8 0 2 X 10 s 3 5 10 t 9 Flow value = 8 2 4 4 G f : 8 8 6 10 2 2 10 s 3 5 t 9 2 8 19
Ford-Fulkerson Algorithm 0 4 2 4 G: X 0 6 10 8 6 0 8 X 10 10 2 2 6 0 6 X 10 2 8 X 10 s 3 5 10 t 9 Flow value = 10 2 4 4 G f : 8 6 10 10 2 10 s 3 5 t 7 10 2 20
Ford-Fulkerson Algorithm 0 2 X 4 2 4 G: X 6 8 10 8 6 6 8 10 10 2 2 X 0 6 8 X 10 8 10 s 3 5 10 t 9 Flow value = 16 2 4 4 G f : 6 8 6 10 4 2 4 s 3 5 t 1 10 6 8 21
Ford-Fulkerson Algorithm 2 X 3 4 2 4 G: X 8 9 10 8 7 X 6 6 8 10 10 2 0 8 9 X 10 8 9 X 10 s 3 5 10 t 9 Flow value = 18 2 2 2 4 G f : 8 8 6 10 2 2 2 s 3 5 t 1 10 8 8 22
Ford-Fulkerson Algorithm 3 4 2 4 G: 9 10 7 6 6 8 10 10 2 0 9 10 9 10 s 3 5 10 t 9 Flow value = 19 3 2 1 4 G f : 9 1 7 6 10 1 2 1 s 3 5 t 9 10 9 23
Ford-Fulkerson Algorithm 3 4 2 4 G: 9 10 7 6 6 8 10 10 2 0 9 10 9 10 s 3 5 10 t 9 Cut capacity = 19 Flow value = 19 3 2 1 4 G f : 9 1 7 6 10 1 2 1 s 3 5 t 9 10 9 24
Augmenting Path Algorithm Augment(f, c, P) { b ¬ bottleneck(P) foreach e Î P { if (e Î E) f(e) ¬ f(e) + b forward edge f(e R ) ¬ f(e) - b else reverse edge } return f } Ford-Fulkerson(G, s, t, c) { foreach e Î E f(e) ¬ 0 G f ¬ residual graph while (there exists augmenting path P) { f ¬ Augment(f, c, P) update G f } return f }
Max-Flow Min-Cut Theorem Augmenting path theorem. Flow f is a max flow iff there are no augmenting paths. Max-flow min-cut theorem. [Ford-Fulkerson 1956] The value of the max flow is equal to the value of the min cut. Proof strategy. We prove both simultaneously by showing the the following are equivalent: (i) There exists a cut (A, B) such that v(f) = cap(A, B). (ii) Flow f is a max flow. (iii) There is no augmenting path relative to f. (i) Þ (ii) This was the corollary to weak duality lemma. (ii) Þ (iii) We show contrapositive. Let f be a flow. If there exists an augmenting path, then we can improve f by sending flow along path.
Proof of Max-Flow Min-Cut Theorem (iii) Þ (i) Let f be a flow with no augmenting paths. Let A be set of vertices reachable from s in residual graph. By definition of A, s Î A. By definition of f, t Ï A. A B t s original network
Running Time Assumption. All capacities are integers between 1 and C. Invariant. Every flow value f(e) and every residual capacities c f (e) remains an integer throughout the algorithm. Theorem. The algorithm terminates in at most v(f*) £ nC iterations. Pf. Each augmentation increase value by at least 1. ▪ Corollary. If C = 1, Ford-Fulkerson runs in O(mn) time. Integrality theorem. If all capacities are integers, then there exists a max flow f for which every flow value f(e) is an integer. Pf. Since algorithm terminates, theorem follows from invariant. ▪
7.3 Choosing Good Augmenting Paths
Ford-Fulkerson: Exponential Number of Augmentations Q. Is generic Ford-Fulkerson algorithm polynomial in input size? m, n, and log C A. No. If max capacity is C, then algorithm can take C iterations. 1 1 X X 1 X 0 0 0 0 1 1 C C C C X 1 X s X t s t 1 0 1 0 0 1 C C C C X X X 1 0 0 1 0 0 1 2 2
Choosing Good Augmenting Paths Use care when selecting augmenting paths. Some choices lead to exponential algorithms. Clever choices lead to polynomial algorithms. If capacities are irrational, algorithm not guaranteed to terminate! Goal: choose augmenting paths so that: Can find augmenting paths efficiently. Few iterations. Choose augmenting paths with: [Edmonds-Karp 1972, Dinitz 1970] Sufficiently large bottleneck capacity. Fewest number of edges.
Capacity Scaling Intuition. Choosing path with highest bottleneck capacity increases flow by max possible amount. How to find exact highest bottleneck path? Homework 4 Maintain scaling parameter D . Let G f ( D ) be the subgraph of the residual graph consisting of only arcs with capacity at least D . 4 4 110 102 110 102 1 s s t t 122 170 122 170 2 2 G f G f (100)
Capacity Scaling Scaling-Max-Flow(G, s, t, c) { foreach e Î E f(e) ¬ 0 D ¬ smallest power of 2 greater than or equal to C G f ¬ residual graph while ( D ³ 1) { G f ( D ) ¬ D -residual graph while (there exists augmenting path P in G f ( D )) { f ¬ augment(f, c, P) update G f ( D ) } D ¬ D / 2 } return f }
Capacity Scaling: Correctness Assumption. All edge capacities are integers between 1 and C. Integrality invariant. All flow and residual capacity values are integral. Correctness. If the algorithm terminates, then f is a max flow. Pf. By integrality invariant, when D = 1 Þ G f ( D ) = G f . Upon termination of D = 1 phase, there are no augmenting paths. ▪
Recommend
More recommend