CSE 521 Algorithms 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? 4
Soviet Rail Network, 1955 Reference: On the history of the transportation and maximum flow problems . 5 Alexander Schrijver in Math Programming, 91: 3, 2002.
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 ∈ ∈ 6
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 ∈ 7
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 8
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 9
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 . 10
A Brief History of Flow # Year Discoverer(s) Bound n = # of vertices 2 mC) 1 1951 Dantzig O(n m= # of edges 2 1955 Ford & Fulkerson O(nmC) C = Max capacity 2 ) 3 1970 Dinitz; Edmonds & Karp O(nm 2 m) 4 1970 Dinitz O(n 2 log C) 5 1972 Edmonds & Karp; Dinitz O(m Source: Goldberg & Rao, FOCS ‘97 6 1973 Dinitz;Gabow O(nm log C) 3 ) 7 1974 Karzanov O(n 2 sqrt(m)) 8 1977 Cherkassky O(n 2 n) 9 1980 Galil & Naamad O(nm log 10 1983 Sleator & Tarjan O(nm log n) 2 /m)) 11 1986 Goldberg &Tarjan O(nm log (n 2 log C) 12 1987 Ahuja & Orlin O(nm + n 13 1987 Ahuja et al. O(nm log(n sqrt(log C)/(m+2)) 2 log 2 n) 14 1989 Cheriyan & Hagerup E(nm + n 3 /log n) 15 1990 Cheriyan et al. O(n 8/3 log n) 16 1990 Alon O(nm + n 2+ ε ) 17 1992 King et al. O(nm + n 2+ ε n) 18 1993 Phillips & Westbrook O(nm(log m/n n + log 19 1994 King et al. O(nm(log m/(n log n) n) 3/2 log(n 2 /m) log C) ; O(n 2/3 m log(n 2 /m) logC) 20 1997 Goldberg & Rao O(m … … … … 12
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
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
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
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
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
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
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
Augmenting A Flow 3 /4 3 /4 a x a x 3 /3 3 /3 5 /5 5 /5 2 /3 2 /3 7 1/7 7 4 7 4 s b y t s b y t ? ? 6 1 /6 2 /6 1 2 /4 1 1/ 4 5 1 /5 c z c z 1+1 /6 3 1 a x new green, 3 2 3 same blue; 1 2 what is result? 7 7 4 s b y t 6 2 1 2 4 5 c z 2 20
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 21
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: Residual Capacity: 0 < c p ≤ c f (u,v) = f ’(u,v) = f(u,v) + c p c(u,v) - f(u,v) ≤ f(u,v) + c f (u,v) Cap Constraints: = f(u,v) + c(u,v) - f(u,v) -c(v,u) ≤ f(u,v) ≤ c(u,v) = c(u,v) f ’ (v,u) = f(v,u) - c p < f(v,u) ≤ c(v,u) QED 22
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’ 23
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’ 24
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 [E.g., c p = 8, f(u,v) = -5] u v u’ v’ 25
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 f(v,u)/c(v,u) c p > f(v,u) > 0: u v u’ v’ Both: 0/c(u,v) cancel/redirect reverse flow G after 0/c(v,u) and u v add forward flow u’ v’ c p -f(v,u) /c(u,v) 26
Ford-Fulkerson Method While G f has an augmenting path, augment Questions: » Does it halt? » Does it find a maximum flow? » How fast? 27
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 28
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 29
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 30
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 31
(3) ⇒ (1) S T s t (no aug) ⇒ (cut) u v S = { u | ∃ an augmenting path wrt f from s to u } T = V - S; s ∈ S, t ∈ T Idea: where’s the bottleneck 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 32 ∈ ∈ ∈ ∈ ∈ ∈
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 33
Recommend
More recommend