1 / 24

CSE 202 Network flow II

CSE 202 Network flow II. Fan Chung Graham UC San Diego. Flow Network: Oil Through Pipelines. A. D. How much oil can be shipped from S to T ?. 2. 5. 3. 2. 2. T. S. B. 1. 10. 1. 4. 6. C. E. Directed graph G = (V,E) Identified source S and sink T

eyal
Download Presentation

CSE 202 Network flow II

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. CSE 202 Network flow II Fan Chung Graham UC San Diego

  2. Flow Network: Oil Through Pipelines A D How much oil can be shipped from S to T ? 2 5 3 2 2 T S B 1 10 1 4 6 C E • Directed graph G = (V,E) • Identified sourceS and sinkT • Edge capacitiesce

  3. A Feasible Flow in the Network A D How much oil can be shipped from S to T ? 2/2 4/5 2/3 0/2 T 2/2 S B 0/1 2/10 1/1 5 units of flow – is this the maximum possible? 1/4 1/6 C E • Directed graph G = (V,E) • Identified sourceS and sinkT • Edge capacitiesce • The flow along an edge is ≤capacity

  4. Formal Definition of Flow Flow never exceeds capacity Conservation of flow at all nodes except source, sink • A flow on a graph G is a function f : E   such that: • 0 ≤ f(e) ≤ ce for all edges e  E • Flow into a node = flow out of that node For all u  s, t : (u,w)  E f(u,w) = (z,u)  E f(z,u) • Size of flow: size(f) = (s,u)  E f(s,u) Amount of flow leaving the source 2 units of s-t flow A D 2/2 4/5 2/3 0/2 T 2/2 2 units of s-t flow S B 0/1 2/10 1/1 1 unit of s-t flow 1/4 1/6 C E

  5. Flows and Cuts • The size of a flow can be measured across any cut • A cut (L,R) satisfies: • V = L  R, with L R =  disjoint partition of V • S  L, T  R source is in L, sink is in R • Flow across an (L,R) cut:  f(u,w) – f(w,z) u L, w R (u,w)  E w R, z L (w,z)  E From R to L From L to R A D 2/2 4/5 2/3 0/2 T 2/2 S B 0/1 2/10 1/1 1/4 1/6 C E

  6. Observations • The flow across an (L,R) cut cannot exceed the capacity of the cut capacity(L,R) =  c(u,w) •  For any flow f and any cut C, size(f) ≤ capacity(C) “maximum flow ≤ minimum cut” • Previous example had size(f) = 5 and capacity(C) = 5 • The cut is a certificate of optimality (maximality) of the flow • The flow is a certificate optimality (minimality) of the cut u L, w R

  7. Ford-Fulkerson Algorithm – Basic Idea • Start with zero flow • REPEAT: • Find a path from S to T along which flow can be increased • Increase the flow along this path

  8. Residual Graph • We have some flow, and want to improve it • Two ways to “push” or “advance” flow in G • Find some unused capacity on an edge • Find some cancelable flow on an edge •  residual graph Gf= “what’s unused or cancelable” Flow f Residual Graph Gf A T A T 1 1 1 1 1 1 1 S B S B 1 REPEAT: Find an S-T path in Gf ; Increase f along this path as much as possible

  9. Recipe for Constructing Gf reversed edges • Gf = (V, Ef) • Ef  E  ER • For any (u,w) in E or ER capacity cf(u,w) = c(u,w) – f(u,w) + f(w,u) • Note 1: Can ignore edges with cf( , ) = 0 • Note 2: If (u,w)  E, write c(u,w) = 0, f(u,w) = 0 remaining capacity cancelable flow REPEAT: Find an S-T path in Gf ; Increase f along this path as much as possible

  10. A D 2 2 2 T S Worked Example A D 5 2 3 2 2 T S B 1 10 1 • Initial Gf • Augment flow along a path New Gf 4 6 C E 2 A D 2 2 1 3 2 2 T S B 1 10 1 4 6 C E

  11. Worked Example 2 A D 2 2 1 3 2 2 T S B 1 10 1 4 6 C E T S 1 D 1 1 C E 2 2 T S B 4 A D 2 2 2 1 1 2 2 T 2 S B 1 Final Gf 8 1 1 What is the significance of this cut? 3 5 C E 1

  12. Ford-Fulkerson Algorithm – Summary • Initialize f = 0 • REPEAT: • Construct the residual graph Gf • Find a path P from s to t in Gf • If there is no such path, HALT • cp = minimum cf-capacity edge on path P • Increase f by cp units along path P • Flow always increases  the algorithm terminates • But, if capacities are bounded by f*, can take up to |E|  f* iterations in worst case. running time is |E|2 f* 106 A T 106 1 106 S B 106

  13. The Max-Flow Min-Cut Theorem • Ford-Fulkerson constructively proves that the maximum flow equals the minimum cut • Define an (L,R) cut as follows: • L = nodes reachable from s in final residual graph Gf • R = rest of nodes = V – L Note that t cannot be in L  T must be in R • Consider edges between L and R in G • Edges e going from L  R : must have flow = capacity (by def. of L, R) • Edges e’ going from R  L : must have flow = 0 (by def. of L, R)  The flow across this cut = LR edges e c(e) = the capacity of the cut  Since any flow is ≤ any cut, we have max flow = min cut e L R S T e’

  14. Integrality theorem: If all capacities in the flow network are integers, then there is a maximum flow for which all flow values are integers. Proof: Can choose augumenting paths with integer value flows. The flow network can be maintained to be integer valued.

  15. Ford-Fulkerson Algorithm – Summary • Initialize f = 0 • REPEAT: • Construct the residual graph Gf • Find a path P from s to t in Gf • If there is no such path, HALT • cp = minimum cf-capacity edge on path P • Increase f by cp units along path P • Flow always increases  the algorithm terminates • But, if capacities are bounded by f*, can take up to |E|  f* iterations in worst case. The running time is |E|2 f* 106 A T 106 1 106 S B 106

  16. Improving Ford-Fulkerson Algorithm • Find better augumenting paths 106 A T 106 1 106 S B 106

  17. Edmond Karp Algorithm– an improvement of Ford-Fulkerson Algorithm • Initialize f = 0 • REPEAT: • Construct the residual graph Gf • Find a shortest saturating path P using BFS from s to t in Gf • If there is no such path, HALT • cp = minimum cf-capacity edge on path P • Increase f by cp units along path P • Flow always increases  the algorithm terminates • Can take up to |V| |E| iterations in worst case. The running time is |V| |E|2 106 A T 106 1 106 S B 106

  18. Edmond Karp Algorithm– an improvement of Ford-Fulkerson Algorithm Analysis: Observation 1: The length of shortest paths in residual graph can not decrease. Observation 2: Choose the augumenting path so that it contains at least one saturated edge. Can take up to |V| |E| iterations in worst case. The running time is |V| |E|2 saturated T S A B augumenting T S A B Length increased by 2.

More Related