network flow ii
play

Network Flow II 2 Every edge e has a capacity c(e) 0. Flow: 1 - PowerPoint PPT Presentation

Network Flow 1 Network flow: 2 graph G=(V,E). 2 2 s 1 t Special vertices s (source) and t (sink). 2 2 Network Flow II 2 Every edge e has a capacity c(e) 0. Flow: 1 Inge Li Grtz capacity constraint: every


  1. Network Flow 1 • Network flow: 2 • graph G=(V,E). 2 2 s 1 t • Special vertices s (source) and t (sink). 2 2 Network Flow II 2 • Every edge e has a capacity c(e) ≥ 0. • Flow: 1 Inge Li Gørtz • capacity constraint: every edge e has a flow 0 ≤ f(e) ≤ c(e). • flow conservation: for all u ≠ s, t: flow into u equals flow out of u. X X f ( v, u ) = f ( u, v ) u v :( v,u ) ∈ E v :( u,v ) ∈ E • Value of flow f is the sum of flows out of s minus sum of flows into s: ∑ ∑ f ( e ) = f out ( s ) − f in ( s ) v ( f ) = f ( e ) − v :( s , v ) ∈ E v :( v , s ) ∈ E KT 7.3, 7.5, 7.6 • Maximum flow problem: find s-t flow of maximum value 1 2 Ford-Fulkerson Today • Find (any) augmenting path and use it. • Augmenting path (definition di ff erent than in CLRS): s-t path where • Applications • forward edges have leftover capacity • Finding good augmenting paths. Edmonds-Karp and scaling algorithm. • backwards edges have positive flow + δ - δ + δ + δ - δ - δ s t f 1 < c 1 f 2 > 0 f 3 < c 3 f 4 < c 4 f 5 > 0 f 6 > 0 • Can add extra flow: min(c 1 - f 1 , f 2 , c 3 - f 3 , c 4 - f 4 , f 5 , f 6 ) = δ • To find augmenting path use DFS or BFS: 4 4 4 4 4 9 3 t s 5 6 2 8 6 3 4

  2. Ford-Fulkerson Edmonds-Karp • Integral capacities: • Find shortest augmenting path and use it. • Each augmenting path increases flow with at least 1. • Augmenting path (definition di ff erent than in CLRS): s-t path where • At most v(f) iterations • forward edges have leftover capacity • Find augmenting path via DFS/BFS: O(m) • backwards edges have positive flow • Total running time: O(v(f) m) • Lemma. If all the capacities are integers, then there is a maximum flow where the - δ + δ + δ + δ - δ - δ flow on every edge is an integer. s t f 1 < c 1 f 2 > 0 f 3 < c 3 f 4 < c 4 f 5 > 0 f 6 > 0 • Can add extra flow: min(c 1 - f 1 , f 2 , c 3 - f 3 , c 4 - f 4 , f 5 , f 6 ) = δ • Bad example for Ford-Fulkerson: 2/ 1/ 1.000.000 2/ 1/ 1.000.000 • To find augmenting path use BFS : s 1/ 0/ 0/ 1/ 1 4 4 4 4 1/ 2/ 1.000.000 2/ 1/ 1.000.000 4 3/ 9 3/ 3 t s 5 6 2 8 6 5 6 Edmonds-Karp Edmonds-Karp • Find shortest augmenting path and use it. • Find shortest augmenting path and use it. • Augmenting path (definition di ff erent than in CLRS): s-t path where • Augmenting path (definition di ff erent than in CLRS): s-t path where • forward edges have leftover capacity • forward edges have leftover capacity • backwards edges have positive flow • backwards edges have positive flow + δ - δ + δ + δ - δ + δ - δ + δ + δ - δ - δ - δ s s t t f 1 < c 1 f 2 > 0 f 3 < c 3 f 4 < c 4 f 5 > 0 f 6 > 0 f 1 < c 1 f 2 > 0 f 3 < c 3 f 4 < c 4 f 5 > 0 f 6 > 0 • Can add extra flow: min(c 1 - f 1 , f 2 , c 3 - f 3 , c 4 - f 4 , f 5 , f 6 ) = δ • Can add extra flow: min(c 1 - f 1 , f 2 , c 3 - f 3 , c 4 - f 4 , f 5 , f 6 ) = δ • To find augmenting path use BFS : • To find augmenting path use BFS : 4 4 4 4 4/4 4 4 4 4 4/4 3/9 3/3 7/9 3/3 s s 5 6 5 6 2 8 2 8 6 6 7 8

  3. Edmonds-Karp Edmonds-Karp • Find shortest augmenting path and use it. • Find shortest augmenting path and use it. • Augmenting path (definition di ff erent than in CLRS): s-t path where • Augmenting path (definition di ff erent than in CLRS): s-t path where • forward edges have leftover capacity • forward edges have leftover capacity • backwards edges have positive flow • backwards edges have positive flow - δ + δ - δ + δ + δ + δ - δ - δ + δ + δ - δ - δ s s t t f 1 < c 1 f 2 > 0 f 3 < c 3 f 4 < c 4 f 5 > 0 f 6 > 0 f 1 < c 1 f 2 > 0 f 3 < c 3 f 4 < c 4 f 5 > 0 f 6 > 0 • Can add extra flow: min(c 1 - f 1 , f 2 , c 3 - f 3 , c 4 - f 4 , f 5 , f 6 ) = δ • Can add extra flow: min(c 1 - f 1 , f 2 , c 3 - f 3 , c 4 - f 4 , f 5 , f 6 ) = δ • To find augmenting path use BFS : • To find augmenting path use BFS : 4 4 3/4 3/4 4/4 4/4 4 3/4 4/4 1/4 9/9 3/3 9/9 3/3 s s 2/5 6 5/5 6 2 2 2/8 5/8 2/6 5/6 9 10 Find a minimum cut Scaling algorithm • When there are no more augmenting s-t paths: • Scaling parameter Δ • Find all augmenting paths from s. • Only consider edges with capacity at least Δ in residual graph G f ( Δ ). • The nodes S that can be reached by these augmenting paths form the left side of a • Example: Δ = 4 minimum cut. 1 1 • edges out of S have c e = f e . G f 3 3 • edges into S have f e = 0. 1 3 4 3 1 4 • Capacity of the cut equals the flow. 3 t s 5 6 2 4 2 4 2 4 4 1 1 3 3 3/4 3/4 1 3 4 4/4 3/4 3 1 1/4 4 9/9 3/3 3 t G f (4) s 5 s 6 5/5 6 2 4 2 5/8 2 4 2 4 5/6 11 12 4

  4. Scaling algorithm Scaling algorithm • Scaling parameter Δ • Scaling parameter Δ • Only consider edges with capacity at least Δ in residual graph G f ( Δ ). • Only consider edges with capacity at least Δ in residual graph G f ( Δ ). • Start with Δ = “highest power of 2 ≤ largest capacity out of s” • Start with Δ = “highest power of 2 ≤ largest capacity out of s” Δ = 8 Δ = 8 9 9 6 6 10 10 13 3 13 3 s t s t 2 2 8 8 1 1 5 5 4 4 13 14 Scaling algorithm Scaling algorithm • Scaling parameter Δ • Scaling parameter Δ • Only consider edges with capacity at least Δ in residual graph G f ( Δ ). • Only consider edges with capacity at least Δ in residual graph G f ( Δ ). • Start with Δ = “highest power of 2 ≤ largest capacity out of s” • Start with Δ = “highest power of 2 ≤ largest capacity out of s” Δ = 8 Δ = 8 9/ 9 9 6 6 1 9 9/ 10 4 9/ 13 3 3 s t s t 9 2 2 8 8 1 5 1 5 4 4 15 16

  5. Scaling algorithm Scaling algorithm • Scaling parameter Δ • Scaling parameter Δ • Only consider edges with capacity at least Δ in residual graph G f ( Δ ). • Only consider edges with capacity at least Δ in residual graph G f ( Δ ). • Start with Δ = “highest power of 2 ≤ largest capacity out of s” • Start with Δ = “highest power of 2 ≤ largest capacity out of s” • When no more augmenting paths in G f ( Δ ): Δ = Δ /2 (new phase). • When no more augmenting paths in G f ( Δ ): Δ = Δ /2 (new phase). Δ = 8 Δ = 4 9 9 6 6 1 9 1 9 4 4 3 3 s t s t 9 9 2 2 8 8 1 1 5 5 4 4 17 18 Scaling algorithm Scaling algorithm • Scaling parameter Δ • Scaling parameter Δ • Only consider edges with capacity at least Δ in residual graph G f ( Δ ). • Only consider edges with capacity at least Δ in residual graph G f ( Δ ). • Start with Δ = “highest power of 2 ≤ largest capacity out of s” • Start with Δ = “highest power of 2 ≤ largest capacity out of s” • When no more augmenting paths in G f ( Δ ): Δ = Δ /2 (new phase). • When no more augmenting paths in G f ( Δ ): Δ = Δ /2 (new phase). 4 Δ = 4 Δ = 4 9 9 4/ 6 2 1 4/ 9 5 5 4 4 3 3 s t s t 9 9 2 2 4/ 8 4 1 4/ 5 1 4 4 1 4/ 4 4 19 20

  6. Scaling algorithm Scaling algorithm • Scaling parameter Δ • Scaling parameter Δ • Only consider edges with capacity at least Δ in residual graph G f ( Δ ). • Only consider edges with capacity at least Δ in residual graph G f ( Δ ). • Start with Δ = “highest power of 2 ≤ largest capacity out of s” • Start with Δ = “highest power of 2 ≤ largest capacity out of s” • When no more augmenting paths in G f ( Δ ): Δ = Δ /2 (new phase). • When no more augmenting paths in G f ( Δ ): Δ = Δ /2 (new phase). 4 4 Δ = 4 Δ = 2 9 9 2 2 5 5 5 5 4 4 3 3 s t s t 9 9 2 2 4 4 1 4 1 4 4 4 1 1 4 4 21 22 Scaling algorithm Scaling algorithm • Scaling parameter Δ • Scaling parameter Δ • Only consider edges with capacity at least Δ in residual graph G f ( Δ ). • Only consider edges with capacity at least Δ in residual graph G f ( Δ ). • Start with Δ = “highest power of 2 ≤ largest capacity out of s” • Start with Δ = “highest power of 2 ≤ largest capacity out of s” • When no more augmenting paths in G f ( Δ ): Δ = Δ /2 (new phase). • When no more augmenting paths in G f ( Δ ): Δ = Δ /2 (new phase). 4 6 Δ = 2 Δ = 2 9 9 2/ 2 5 2/ 5 7 3 4 4 1 2/ 3 s t s t 2 9 9 2 2 4 4 1 4 4 1 4 4 1 1 4 4 23 24

Recommend


More recommend