1 / 40

Algorithm Design and Analysis

L ECTURES 18-19 Network Flows Flows, cuts Ford-Fulkerson Min-cut/max- flow theorem. Algorithm Design and Analysis. CSE 565. Adam Smith. Detecting Negative Cycles. Theorem. Can find negative cost cycle in O(mn ) time. Add new node t and connect all nodes to t with 0-cost edge.

cady
Download Presentation

Algorithm Design and Analysis

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. LECTURES18-19 • Network Flows • Flows, cuts • Ford-Fulkerson • Min-cut/max-flow theorem Algorithm Design and Analysis CSE 565 Adam Smith A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne

  2. Detecting Negative Cycles • Theorem. Can find negative cost cycle in O(mn) time. • Add new node t and connect all nodes to t with 0-cost edge. • Check if OPT(n, v) = OPT(n-1, v) for all nodes v. • if yes, then no negative cycles • if no, then extract cycle from shortest path from v to t • Last lecture we proved: if OPT(n, v) < OPT(n-1, v) then we can find a neg.-cost cycle on a path from v to t • Questions to think about: • Prove that if there is a negative-cost cycle,then OPT(n, v) < OPT(n-1, v) for some v • (Hint: what would happen ifwe kept running Bellman-Ford for many iterations?) • Why do we bother with the extra node t? t 0 0 0 0 0 18 2 6 -23 5 -11 v -15

  3. Network Flow and Linear Programming A. Smith; based on slides by S. Raskhodnikova and K. Wayne

  4. Soviet Rail Network, 1955 Reference: On the history of the transportation and maximum flow problems.Alexander Schrijver in Math Programming, 91: 3, 2002.

  5. Max flow and min cut. Two very rich algorithmic problems. Cornerstone problems in combinatorial optimization. Beautiful mathematical duality. Nontrivial applications / reductions. Data mining. Open-pit mining. Project selection. Airline scheduling. Bipartite matching. Image segmentation. Clustering Network connectivity. Network reliability. Distributed computing. Egalitarian stable matching. Network intrusion detection. Multi-camera scene reconstruction. Data privacy. Many many more … Maximum Flow and Minimum Cut

  6. Minimum Cut Problem • Flow network. • Abstraction for material flowing through the edges. • G = (V, E) = directed graph, no parallel edges. • Two distinguished nodes: s = source, t = sink. • c(e) = capacity of edge e. 2 5 9 10 15 15 10 4 source sink 5 s 3 6 t 8 10 15 4 6 10 15 capacity 4 7 30

  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: we don’t count edges into A 2 5 9 10 15 15 10 4 5 s 3 6 t 8 10 A 15 4 6 10 15 Capacity = 10 + 5 + 15 = 30 4 7 30

  8. 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: 2 5 9 10 15 15 10 4 5 s 3 6 t 8 10 A 15 4 6 10 15 Capacity = 9 + 15 + 8 + 30 = 62 4 7 30

  9. Minimum Cut Problem • Min s-t cut problem. Find an s-t cut of minimum capacity. 2 5 9 10 15 15 10 4 5 s 3 6 t 8 10 15 4 6 10 A 15 Capacity = 10 + 8 + 10 = 28 4 7 30

  10. 2 5 9 10 15 15 10 4 5 s 3 6 t 8 10 15 4 6 10 15 4 7 30 Flows • Def. An s-t flow is a function f from E to real numbers that satisfies: • For each e E: [capacity] • For each v V – {s, t}: [conservation] water flowing from source to sink 0 4 0 0 0 4 0 4 4 0 0 0 0 capacity flow 0 0

  11. 2 5 9 10 15 15 10 4 5 s 3 6 t 8 10 15 4 6 10 15 4 7 30 Flows • Def. An s-t flow is a function f from E to real numbers that satisfies: • For each e  E: [capacity] • For each v  V – {s, t}: [conservation] • Def. The value of a flow f is: water flowing from source to sink 0 4 0 0 0 4 0 4 4 0 0 0 0 capacity flow 0 0 Value = 4

  12. 2 5 9 10 15 15 10 4 5 s 3 6 t 8 10 15 4 6 10 15 4 7 30 Flows • Def. An s-t flow is a function f from E to real numbers that satisfies: • For each e  E: [capacity] • For each v  V – {s, t}: [conservation] • Def. The value of a flow f is: water flowing from source to sink 6 10 6 0 0 4 3 8 8 1 10 0 0 capacity flow 11 11 Value = 24

  13. 2 5 9 10 15 15 10 4 5 s 3 6 t 8 10 15 4 6 10 15 4 7 30 Maximum Flow Problem • Max flow problem. Find s-t flow of maximum value. 9 10 9 1 0 0 4 9 8 4 10 0 0 capacity flow 14 14 Value = 28

  14. Flows and Cuts • Flow value lemma. Let f be any flow, and let (A, B) be any s-t cut. Then, the net flow across the cut is equal to the amount leaving s. 6 2 5 9 10 6 0 10 15 15 0 10 4 4 3 8 8 5 s 3 6 t 8 10 A 1 10 15 0 0 4 6 10 15 11 11 Value = 24 4 7 30

  15. Flows and Cuts • Flow value lemma. Let f be any flow, and let (A, B) be any s-t cut. Then, the net flow across the cut is equal to the amount leaving s. 6 2 5 9 10 6 0 10 15 15 0 10 4 4 3 8 8 5 s 3 6 t 8 10 A 1 10 15 0 0 4 6 10 15 11 Value = 6 + 0 + 8 - 1 + 11= 24 11 4 7 30

  16. Flows and Cuts • Flow value lemma. Let f be any flow, and let (A, B) be any s-t cut. Then, the net flow across the cut is equal to the amount leaving s. 6 2 5 9 10 6 0 10 15 15 0 10 4 4 3 8 8 5 s 3 6 t 8 10 A 1 10 15 0 0 4 6 10 15 11 Value = 10 - 4 + 8 - 0 + 10= 24 11 4 7 30

  17. Flows and Cuts • Flow value lemma. Let f be any flow, and let (A, B) be any s-t cut. Then • Proof. by flow conservation, all termsexcept v = s are 0

  18. Question • Two problems • min cut • max flow • How do they relate?

  19. 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. Big Optimization Idea #1: Look for structural constraints, e.g. max flow min-cut Cut capacity = 30  Flow value  30 2 5 9 10 15 15 10 4 5 s 3 6 t 8 10 A 15 4 6 10 15 Capacity = 30 4 7 30

  20. Flows and Cuts • Weak duality. Let f be any flow. Then v(f) cap(A, B), for any s-t cut (A, B). • Pf. • ▪ A B 4 8 t s 7 6

  21. Certificate of Optimality • Corollary. Let f be any flow, and let (A, B) be any s-t cut.If v(f) =cap(A, B), then f is a max flow and (A, B) is a min s-t cut. Value of flow = 28Cut capacity = 28  Flow value  28 9 2 5 9 10 9 1 10 15 15 0 10 0 4 4 9 8 5 s 3 6 t 8 10 4 10 15 0 A 0 4 6 10 15 14 14 4 7 30

  22. 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

  23. 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 20 0 0 X 20 10 20 30 0 t X s 10 20 Flow value = 20 20 0 0 X 2

  24. How can we get from greedy to opt here? What if we push water back across middle edge? 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 30 20 30 10 t t s s 10 20 10 20 0 20 10 20 2 2 greedy = 20 opt = 30

  25. Residual Graph • Original edge: e = (u, v)  E. • Flowf(e), capacity c(e). • Residual edge. • e= (u, v) and eR = (v, u). • Residual capacity: • If e in E: • unused capacity • If eR in E: • ability of sent less water, or “undo“ flow • Residual graph: Gf = (V, Ef). • Residual edges with positive residual capacity. • Ef = {e : f(e) < c(e)} {eR : c(e) > 0}. capacity u v 17 6 flow residual capacity u v 11 6 residual capacity

  26. Ford-Fulkerson Algorithm 2 4 4 capacity G: 6 8 10 10 2 10 s 3 5 t 10 9

  27. Ford-Fulkerson Algorithm 0 flow 2 4 4 capacity G: 0 0 0 6 0 8 10 10 2 0 0 0 0 10 s 3 5 t 10 9 Flow value = 0

  28. 8 X 8 X 8 X Ford-Fulkerson Algorithm 0 flow 2 4 4 capacity G: 0 0 0 6 0 8 10 10 2 0 0 0 0 10 s 3 5 t 10 9 Flow value = 0 2 4 4 residual capacity Gf: 6 8 10 10 2 10 s 3 5 t 10 9

  29. 10 X X 2 10 X 2 X Ford-Fulkerson Algorithm 0 2 4 4 G: 0 8 8 6 0 8 10 10 2 0 0 8 0 10 s 3 5 t 10 9 Flow value = 8 2 4 4 Gf: 8 6 8 10 2 2 10 s 3 5 t 2 9 8

  30. 6 X X 6 6 X 8 X Ford-Fulkerson Algorithm 0 2 4 4 G: 0 10 8 6 0 8 10 10 2 2 0 10 2 10 s 3 5 t 10 9 Flow value = 10 2 4 4 Gf: 6 8 10 10 2 10 s 3 5 t 10 7 2

  31. 2 X 8 X X 0 8 X Ford-Fulkerson Algorithm 0 2 4 4 G: 6 10 8 6 6 8 10 10 2 2 6 10 8 10 s 3 5 t 10 9 Flow value = 16 2 4 4 Gf: 6 6 8 4 10 2 4 s 3 5 t 10 1 6 8

  32. 3 X 9 X 7 X 9 X 9 X Ford-Fulkerson Algorithm 2 2 4 4 G: 8 10 8 6 6 8 10 10 2 0 8 10 8 10 s 3 5 t 10 9 Flow value = 18 2 2 4 2 Gf: 8 6 8 2 10 2 2 s 3 5 t 10 1 8 8

  33. Ford-Fulkerson Algorithm 3 2 4 4 G: 9 10 7 6 6 8 10 10 2 0 9 10 9 10 s 3 5 t 10 9 Flow value = 19 3 2 4 1 Gf: 9 1 6 7 1 10 2 1 s 3 5 t 10 9 9

  34. Ford-Fulkerson Algorithm 3 2 4 4 G: 9 10 7 6 6 8 10 10 2 0 9 10 9 10 s 3 5 t 10 9 Cut capacity = 19 Flow value = 19 3 2 4 1 Gf: 9 1 6 7 1 10 2 1 s 3 5 t 10 9 9

  35. Augmenting Path Algorithm Ford-Fulkerson(G, s, t, c) { foreach e  E f(e)  0 Gf residual graph while (there is an s-t path P in Gf) { f  Augment(f, c, P) update Gf } return f } Augment(f, c, P) { b  bottleneck(P) foreach e  P { if (e  E) f(e)  f(e) + b else f(e)  f(e) - b } return f } Min residual capacity of an edge in P forward edge reverse edge

  36. Ford-Fulkerson: Summary so far • Ford-Fulkerson: • While you can, • Greedily push flow • Update residual graph • Lemma 1: This outputs a valid flow. • Proof: (Check conservation conditions… see book.) • Still to do: • Running time (in particular, termination!) • How good a flow?

  37. Running Time • Assumption. All capacities are integers between 1 and C. • Invariant. Every flow value f(e) and every residual capacity cf(e) remains an integer throughout the algorithm. • Proof: exercise. • Theorem. The algorithm terminates in at most v(f*) nC iterations. • Pf. Each augmentation increase value by at least 1. ▪ • Running time of Ford-Fulkerson: O(mnC). Space: O(m+n). • Corollary. If C = 1, Ford-Fulkerson runs in O(mn) time.

  38. 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. [Elias-Feinstein-Shannon 1956, Ford-Fulkerson 1956]The value of the max flow is equal to the value of the min s-t cut. • Pf. We prove both simultaneously by showing (i) -- (iii) are equivalent. (i) There exists an s-t cut (A, B) such that v(f) = cap(A, B). (ii) Flow f is a max flow, and (A,B) is min s-t cut. (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.

  39. 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. • Observation: No edges of the residual graph go from A to B. • Claim 1: If e goes from A to B, then f(e) =c(e).Proof: Otherwise there would be residual capacity, and the residual graph would have an edge A to B. • Claim 2: If e goes from B to A, then f(e)=0.Proof: Otherwise residual edge would go from A to B. original network A B t s

  40. Summary • Assumption. All capacities are integers between 1 and C. • Running time: The FF algorithm terminates in at most v(f*) nC iterations. Running time = O(mnC). Space: O(m+n). • Important special case: 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.

More Related