cse 421 introduction to algorithms winter 2012
play

CSE 421 Introduction to Algorithms Winter 2012 The Network Flow - PowerPoint PPT Presentation

CSE 421 Introduction to Algorithms Winter 2012 The Network Flow Problem 2 The Network Flow Problem 4 a x 3 5 3 7 7 4 s b y t 6 6 1 4 5 c z How much stuff can flow from s to t? 3 Soviet Rail Network, 1955 Reference: On the


  1. CSE 421 Introduction to Algorithms Winter 2012 The Network Flow Problem 2

  2. The Network Flow Problem 4 a x 3 5 3 7 7 4 s b y t 6 6 1 4 5 c z How much stuff can flow from s to t? 3

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

  4. Net Flow: Formal Definition Find: Given: A flow function f: V x V → R s.t., A digraph G = (V,E) for all u,v: Two vertices s,t in V – f(u,v) ≤ c(u,v) [Capacity Constraint] (source & sink) – f(u,v) = -f(v,u) [Skew Symmetry] A capacity c(u,v) ≥ 0 – if u ≠ s,t, f(u,V) = 0 [Flow Conservation] for each (u,v) ∈ E (and c(u,v) = 0 for all non- Maximizing total flow |f| = f(s,V) edges (u,v)) Notation: f ( X , Y ) f ( x , y ) ! ! = x X y Y " " 5

  5. Example: A Flow Function flow/capacity, not 0.66... 2/3 2/2 s u t f(s,u) = f(u,t) = 2 f(u,s) = f(t,u) = -2 (Why?) f(s,t) = -f(t,s) = 0 (In every flow function for this G. Why?) f ( u , V ) f ( u , v ) f ( u , s ) f ( u , t ) 2 2 0 = = + = ! + = " v V # 6

  6. Example: A Flow Function 3 /4 a x 3 /3 4 /5 1 /3 7 7 4 s b y t 6 1 /6 1 1 /4 5 c z Not shown: f(u,v) if ≤ 0 Note: max flow ≥ 4 since f is a flow, |f| = 4 7

  7. Max Flow via 2 a 1 a Greedy Alg? s 3 t 1 2 b While there is an 2 a 1 s 3 t s → t path in G 1 b Pick such a path, p Find c p , the min capacity a 1 1 of any edge in p s t 2 Subtract c p from all b capacities on p a Delete edges of s 2 t capacity 0 b 8

  8. Max Flow via a Greedy Alg? This does NOT always find a max flow: If you pick s → b → a → t first, 2 a 1 s t 3 1 a b 2 1 s 1 t 1 b Flow stuck at 2. But flow 3 possible . 9

  9. A Brief History of Flow n = # of vertices # Year Discoverer(s) Bound m= # of edges 1 1951 Dantzig O(n 2 mU) U = Max capacity 2 1955 Ford & Fulkerson O(nmU) 3 1970 Dinitz; Edmonds & Karp O(nm 2 ) 4 1970 Dinitz O(n 2 m) 5 1972 Edmonds & Karp; Dinitz O(m 2 logU) Source: Goldberg & Rao, FOCS ‘97 6 1973 Dinitz;Gabow O(nm logU) 7 1974 Karzanov O(n 3 ) 8 1977 Cherkassky O(n 2 sqrt(m)) 9 1980 Galil & Naamad O(nm log 2 n) 10 1983 Sleator & Tarjan O(nm log n) 11 1986 Goldberg &Tarjan O(nm log (n 2 /m)) 12 1987 Ahuja & Orlin O(nm + n 2 log U) 13 1987 Ahuja et al. O(nm log(n sqrt(log U)/(m+2)) 14 1989 Cheriyan & Hagerup E(nm + n 2 log 2 n) 15 1990 Cheriyan et al. O(n 3 /log n) 16 1990 Alon O(nm + n 8/3 log n) 17 1992 King et al. O(nm + n 2+ ε ) 18 1993 Phillips & Westbrook O(nm(log m/n n + log 2+ ε n) 19 1994 King et al. O(nm(log m/(n log n) n) 20 1997 Goldberg & Rao O(m 3/2 log(n 2 /m) log U) ; O(n 2/3 m log(n 2 /m) logU) … … … … 12

  10. Greed Revisited a a 2 /2 1+1 /2 1 1/1 s t s t 2 /3 1 /3 1 1/1 b b 2 /2 2 /2 a a 2 2 1 1 s t s t 2 1 2 1 2 2 1 1 b b 13

  11. Residual Capacity The residual capacity (w.r.t. f) of (u,v) is c f (u,v) = c(u,v) - f(u,v) 3 /4 E.g.: a x 3 /3 4 /5 1 /3 c f (s,b) = 7; 7 7 4 s b y t c f (a,x) = 1; 6 1 /6 1 1 /4 5 c f (x,a) = 3; c z c f (x,t) = 0 (a saturated edge) 14

  12. Residual Networks & Augmenting Paths The residual network (w.r.t. f) is the graph G f = (V,E f ), where E f = { (u,v) | c f (u,v) > 0 } An augmenting path (w.r.t. f) is a simple s → t path in G f . 15

  13. A Residual Network 3 /4 residual network : the graph a x 3 /3 4 /5 G f = (V,E f ), where 1 /3 E f = { (u,v) | c f (u,v) > 0 } 7 7 4 s b y t 6 1 /6 1 1 /4 3 5 c z 1 a x 3 1 4 2 1 7 7 4 s b y t 6 1 1 3 5 5 c z 1 16

  14. An Augmenting Path 3 /4 augmenting path: a x 3 /3 a simple s → t path in G f . 4 /5 1 /3 7 7 4 s b y t 6 1 /6 1 1 /4 3 5 c z 1 a x 3 1 4 2 1 7 7 4 s b y t 6 1 1 3 5 5 c z 1 17

  15. Lemma 1 If f admits an augmenting path p, then f is not maximal. Proof: “obvious” -- augment along p by c p , the min residual capacity of p’s edges. 18

  16. Augmenting A Flow 3 /4 3 /4 a x a x 3 /3 3 /3 4 /5 4 /5 1 /3 1 /3 7 1/7 7 4 7 4 s b y t s b y t 6 1 /6 1 /6 1 /6 1 1 /4 1 4 5 1 /5 c z c z 3 1 a x 3 1 4 2 1 7 7 4 s b y t 6 1 1 3 5 5 c z 1 19

  17. Lemma 1 ’ : Augmented Flows are Flows If f is a flow & p an augmenting path of capacity c p , then f ’ is also a valid flow, where f ( u , v ) c , if ( u , v ) in path p + $ p ! f ' ( u , v ) f ( u , v ) c , if ( v , u ) in path p = % # p ! f ( u , v ), otherwise " Proof: a) Flow conservation – easy b) Skew symmetry – easy c) Capacity constraints – pretty easy 20

  18. Lma 1 ’ : Augmented f ( u , v ) c , if ( u , v ) in path p + $ p ! f ' ( u , v ) f ( u , v ) c , if ( v , u ) in path p = % # Flows are Flows p ! f ( u , v ), otherwise " f a flow & p an aug path of cap c p , then f ’ also a valid flow. Proof (Capacity constraints): (u,v), (v,u) not on path: no change (u,v) on path: f ’(u,v) = f(u,v) + c p f ’ (v,u) = f(v,u) - c p < f(v,u) ≤ f(u,v) + c f (u,v) ≤ c(v,u) = f(u,v) + c(u,v) - f(u,v) = c(u,v) Residual Capacity: 0 < c p ≤ c f (u,v) = c(u,v) - f(u,v) Cap Constraints: -c(v,u) ≤ f(u,v) ≤ c(u,v) 21

  19. Lemma 1 ’ Example—Case 1 G f c p c p Let (u,v) be any edge in c p u v u’ v’ augmenting path. Note c f (u,v) = c(u,v) – f(u,v) ≥ c p > 0 G before Case 1: f(u,v) ≥ 0: f(u,v)/c(u,v) u v u’ v’ Add forward flow G after f(u,v)+c p /c(u,v) u v u’ v’ 22

  20. Lemma 1 ’ Example—Case 2 G f c p Let (u,v) be any edge in c p c p u v u’ v’ augmenting path. Note c f (u,v) = c(u,v) – f(u,v) ≥ c p > 0 Case 2: f(u,v) ≤ -c p : G before f(v,u)/c(v,u) f(v,u) = -f(u,v) ≥ c p u v u’ v’ Cancel/redirect G after f(v,u)-c p /c(v,u) reverse flow u v u’ v’ 23

  21. Lemma 1 ’ Example—Case 3 G f c p Let (u,v) be any edge in c p c p u v u’ v’ augmenting path. Note c f (u,v) = c(u,v) – f(u,v) ≥ c p > 0 Case 3: -c p < f(u,v) < 0: G before u v u’ v’ ??? G after u v u’ v’ 24

  22. Lemma 1 ’ Example—Case 3 G f c p Let (u,v) be any edge in c p c p u v u’ augmenting path. Note v’ c f (u,v) = c(u,v) – f(u,v) ≥ c p > 0 Case 3: -c p < f(u,v) < 0 c p > f(v,u) > 0: G before f(v,u)/c(v,u) u v Both: u’ v’ cancel/redirect 0/c(u,v) reverse flow G after and 0/c(v,u) add forward flow u v u’ v’ c p -f(v,u) /c(u,v) 25

  23. Ford-Fulkerson Method While G f has an augmenting path, augment Questions: » Does it halt? » Does it find a maximum flow? » How fast? 26

  24. Cuts A partition S,T of V is a cut if s ∈ S, t ∈ T. Capacity of cut S,T is c ( S , T ) c ( u , v ) ! = u S " sum of caps 4 v T " a x of edges 3 5 from S to T 3 7 7 4 s b y t a x 6 6 3 1 4 5 7 s b y t 5 c z 6 {t} c z {s} c=16 {s,x} {s,b,c} c=18 c=21 c=15 27

  25. Lemma 2 For any flow f and any cut S,T, the net flow across the cut equals the total flow, i.e., |f| = f(S,T), and the net flow across the cut cannot exceed the capacity of the cut, i.e. f(S,T) ≤ c(S,T) Corollary: 1 Cut Cap = 3 s Max flow ≤ Min cut Net Flow = 1 1 1 Cut Cap = 2 1 Net Flow = 1 1 t 28

  26. Lemma 2 For any flow f and any cut S,T, net flow across cut = total flow ≤ cut capacity Proof: Track a flow unit. Starts at s, ends at t. crosses cut an odd # of times; net = 1. Last crossing uses a 1 Cut Cap = 3 s Net Flow = 1 forward edge totaled 1 in C(S,T) 1 Cut Cap = 2 1 Net Flow = 1 1 t 29

  27. Max Flow / Min Cut Theorem For any flow f, the following are equivalent (1) |f| = c(S,T) for some cut S,T (a min cut) (2) f is a maximum flow (3) f admits no augmenting path Proof: (1) ⇒ (2): corollary to lemma 2 (2) ⇒ (3): contrapositive of lemma 1 30

  28. (3) ⇒ (1) S T s t (no aug) ⇒ (cut) u v S = { u | ∃ an augmenting path wrt f from s to u } Idea: where’s bottleneck T = V - S; s ∈ S, t ∈ T For any (u,v) in S × T, ∃ an augmenting path from s to u, but not to v. ∴ (u,v) has 0 residual capacity: (u,v) ∈ E ⇒ saturated f(u,v) = c(u,v) (v,u) ∈ E ⇒ no flow f(u,v) = 0 = -f(v,u) This is true for every edge crossing the cut, i.e. | f | f ( S , T ) f ( u , v ) ! ! = = = u S v T " " = ! f ( u , v ) c ( u , v ) c ( S , T ) ! = u S , v T , ( u , v ) E u S , v T , ( u , v ) E 31 " " " " " "

  29. Corollaries & Facts If Ford-Fulkerson terminates, then it’s found a max flow. It will terminate if c(e) integer or rational (but may not if they’re irrational). However, may take exponential time, even with integer capacities: c a c c = 10 99 , say s t 1 c b c 32

  30. How to Make it Faster Many ways. Three important ones: “Scaling” – do big edges first; see text. if C = max capacity, T = O(m 2 log C) Preflow-Push – see text. T = O(n 3 ) Edmonds-Karp (next) T = O(nm 2 ) 33

  31. Edmonds-Karp Algorithm Use a shortest augmenting path (via Breadth First Search in residual graph) Time: O(n m 2 ) 34

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