flow networks
play

Flow Networks Flow Network: - digraph - weights, called - PDF document

M AXIMUM F LOW How to do it... Why you want it... Where you find it... The Tao of Flow: Let your body go with the flow. -Madonna, Vogue Maximum flow...because youre worth it. -Loreal Go with the flow, Joe.


  1. M AXIMUM F LOW • How to do it... • Why you want it... • Where you find it... The Tao of Flow: “Let your body go with the flow.” -Madonna, Vogue “Maximum flow...because you’re worth it.” -L’oreal “Go with the flow, Joe.” -Paul Simon, 50 ways to leave your lover “Life is flow; flow is life.” -Ford & Fulkerson, Ford & Fulkerson Algorithm “Use the flow, Luke!” -Obi-wan Kenobi, Star Wars “Learn flow, or flunk the course” -CS16 Despot, as played by Roberto Tamassia Maximum Flow 1

  2. Flow Networks • Flow Network: - digraph - weights, called capacities on edges - two distinguishes vertices, namely - Source, “s”: Vertex with no incoming edges. - Sink, “t”: Vertex with no outgoing edges. Source s 2 3 1 2 2 1 2 2 4 2 2 1 t Sink Maximum Flow 2

  3. Capacity and Flow • Edge Capacities: Nonnegative weights on network edges • Flow: - Function on network edges: 0 ≤ flow ≤ capacity flow into vertex = flow out of vertex value : combined flow into the sink Source s 2 3 2 1 1 1 2 2 0 2 2 0 1 1 2 4 2 2 0 1 2 1 t 1 1 Sink Maximum Flow 3

  4. The Logic of Flow • Flow: flow(u,v) ∀ edge(u,v) -Capacity rule: ∀ edge (u,v) 0 ≤ flow(u,v) ≤ capacity (u,v) -Conservation rule: ∀ vertex v ≠ s, t Σ flow(u,v) = Σ flow(v,w) u ∈ in(v) wŒout(v) -Value of flow: |f| = Σ flow(s,w) = Σ flow(u,t) w ∈ out(s) u ∈ in(t) • Note: - ∀ means “for all” - in(v) is the set of vertices u such that there is and edge from u to v - out(v) is the set of vertices w such that there is an edge from v to w Maximum Flow 4

  5. Maximum Flow Problem • “Given a network N, find a flow f of maximum value.” • Applications: - Traffic movement - Hydraulic systems - Electrical circuits - Layout Source s 2 3 2 2 1 1 2 2 1 1 1 1 2 1 2 4 2 2 0 1 2 1 t 2 1 Sink Example of Maximum Flow Maximum Flow 5

  6. Augmenting Flow s 2 2 2 1 A network with a flow 1 of value 3 1 2 2 1 2 t s 2 2 Augmenting 1 path 0 2 2 t s 2 2 2 2 1 0 2 2 2 2 t • Voila! We have increased the flow value to 4! But wait! What’s an augmenting path?!? Maximum Flow 6

  7. Augmenting Path • Forward Edges flow(u,v) < capacity (u,v) flow can be increased! v u • Backward Edges flow(u,v) > 0 flow can be decreased! v u Maximum Flow 7

  8. Maximum Flow Theorem A flow has maximum value if and only if it has no augmenting path. Proof: Flow is maximum ⇒ No augmenting path (The only-if part is easy to prove.) No augmenting path ⇒ Flow is maximum (Proving the if part is more difficult.) Maximum Flow 8

  9. Ford & Fulkerson Algorithm • One day, Ford phoned his buddy Fulkerson and said, “Hey Fulk! Let’s formulate an algorithm to determine maximum flow.” Fulk responded in kind by saying, “Great idea, Ford! Let’s just do it!” And so, after several days of abstract computation, they came up with the Ford Fulkerson Algorithm, affectionately known as the “Ford & Fulkerson Algorithm.” initialize network with null flow; Method FindFlow if augmenting paths exist then find augmenting path; increase flow; recursive call to FindFlow; • And now, for some algorithmic animation... Maximum Flow 9

  10. Finding the Maximum Flow s 2 2 Initialize the network with 0 0 a null flow. Note the 1 capacities above the 0 edges , and the flow 2 2 below the edges. 0 0 t s Send one unit of flow 2 2 through the network. 1 0 Note the path of the 1 flow unit traced in red. 1 2 2 The incremented flow values are in blue. 0 1 t s 2 2 2 0 Send another unit of flow 1 through the network. 1 2 2 1 1 t Maximum Flow 10

  11. Finding the Maximum Flow Send another unit of flow s 2 2 through the network. 2 1 Note that there still ex- 1 ists an augmenting 1 path, that can proceed 2 2 backward against the 1 2 t directed central edge. s Send one unit of flow 2 2 through the augment- 2 2 ing path. Note that 1 there are no more aug- 0 2 2 menting paths. That means... 2 2 t With the help of both Ford s 2 2 & Fulkerson, we have 2 2 achieved this net- 1 work’s maximum 0 flow . 2 2 2 2 t Is this power, or what?!? Maximum Flow 11

  12. Residual Network • Residual Network N f = (V, Ef, cf, s, t) N N f c f (u,v) = c(u,v) − f(u,v) v v f(u,v) c(u,v) u u c f (v,u) = f(u,v) • In the residual network N f , all edges (w,z) with capacity cf(w,z) = 0 are removed. Augmenting path in Directed path in the network N residual network N f s s 1 2 2 1 2 2 1 1 1 1 2 2 1 2 1 2 t t 1 Augmenting paths can be found performing a depth-first search on the residual network N f Maximum Flow 12

  13. Maximum Flow Algorithm Part I: Setup Start with null flow: f(u,v) = 0 ∀ (u,v) ∈ E; Initialize residual network: N f = N; Part II: Loop repeat search for directed path p in N f from s to t if (path p found) Df = min {c f (u,v), (u,v) ∈ p}; for (each (u,v) ∈ p) do if (forward (u,v)) f(u,v) = f(u,v) + Df; if (backward (u,v)) f(u,v) = f(u,v) - Df; update N f ; until (no augmenting path); Maximum Flow 13

  14. Maximum Flow: Time Complexity • And now, the moment you’ve all been waiting for...the time complexity of Ford & Fulkerson’s Maximum Flow algorithm. Drum roll, please! [Pause for dramatic drum roll music] O( F (n + m) ) where F is the maximum flow value, n is the number of vertices, and m is the number of edges • The problem with this algorithm, however, is that it is strongly dependent on the maximum flow value F. For example, if F=2 n the algorithm may take exponential time. • Then, along came Edmonds & Karp... Maximum Flow 14

  15. Maximum Flow: Improvement • Theorem: [Edmonds & Karp, 1972] By using BFS, Breadth First Search, a maximum flow can be computed in time... O((n + m) n m) = O(n 5 ) • Note: - Edmonds & Karp algorithm runs in time O(n 5 ) regardless of the maximum flow value. - The worst case usually does not happen in practice. Maximum Flow 15

  16. CUTS • What is a cut ? a)a skin-piercing laceration b)sharp lateral movement c)opposite of paste d)getting dropped from the team e)frontsies on the lunch line f)common CS16 attendence phenomenon g)line of muscular definition h) C omputer U ndergraduate T orture (e.g., CS16, Roberto Tamassia, dbx, etc.) i)a partition of the vertices X=(V s ,V t ), with s ∈ V s and t ∈ V t • The answer is: j)all of the above...but for the educational purposes, we’ll use choice i) Maximum Flow 16

  17. What Is A Cut? Source V s s 2 3 6 4 2 X 1 6 4 2 1 8 7 V t t Sink • Capacity of a cut X = (V s ,V t ): - c(X) = Σ capacity(v,w) = (1+2+1+3) = 7 v ∈ V s w ∈ V t • The cut partition (X in this case) must pass through the entire network, and can not pass through a vertex. Maximum Flow 17

  18. Maximum Flow vs. Minimum Cut (value of maximum flow) = (capacity of minimum cut) Source V s s 2 2 3 3 1 6 2 4 2 0 X 1 1 6 3 4 0 2 2 1 1 3 8 7 3 V t t Sink • Value of maximum flow: 7 flow units • Capacity of minimum cut: 7 flow units Maximum Flow 18

  19. Finding a Minimum Cut • Let V s be the set of vertices reached by augmenting paths from the source s, V t the set of remaining vertices, and place the cut partition X accordingly. Source V s s 2 2 3 3 1 6 2 4 2 0 X 1 1 6 3 4 0 2 2 1 1 3 8 7 3 V t t Sink • Hence, a minor modification of the Ford & Fulkerson algorithm gives a minimum cut • Value of maximum flow: 7 flow units • Capacity of minimum cut: 7 flow units Maximum Flow 19

  20. Why is that a Minimum Cut? • Let f be a flow of value |f| and X a cut ofcapacity |X|. Then, |f| <=|X|. s t X • Hence, if we find a flow f* of value |f*| and a cut X* of capacity |X*|=|f*|, then f* must be the maximum flow and X* must be the minimum cut. • We have seen that from the flow obtained by the Ford and Fulkerson algorithm we can construct a cut with capacity equal to the flow value. Therefore, - we have given an alternative proof that the Ford and Fulkerson algorithm yields a maximum flow - we have shown how to construct a minimum cut Maximum Flow 20

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend