network flow
play

Network Flow Truck company: Wants to send as many trucks as possible - PowerPoint PPT Presentation

Network Flow Truck company: Wants to send as many trucks as possible from s to t. Limit 1 of number of trucks on each road. 2 2 2 s 1 t Network Flows 2 2 2 Inge Li Grtz 1 CLRS Chapter 26.0-26.2 Network Flow Network Flow 1


  1. Network Flow • Truck company: Wants to send as many trucks as possible from s to t. Limit 1 of number of trucks on each road. 2 2 2 s 1 t Network Flows 2 2 2 Inge Li Gørtz 1 CLRS Chapter 26.0-26.2 Network Flow Network Flow 1 • Network flow: • Truck company: Wants to send as many trucks as possible from s to t. Limit 1 1 2 of number of trucks on each road. • graph G=(V,E). 2 2 2 1 2 2 2 2 2 • Special vertices s (source) and t (sink). s 1 t 2 2 1 s 1 t • Example 1: • s has no edges in and t has no edges out. 2 2 2 2 2 2 1 2 • Every edge (e) has a (integer) capacity c(e) ≥ 0. • Solution 1: 4 trucks 1 • Flow: • Solution 2: 5 trucks 1 1 • 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. • Example 2: 2 2 2 0 X X 1 2 f ( v, u ) = f ( u, v ) u 3 • 5 trucks (need to cross river). 2 2 5 3 v :( v,u ) ∈ E v :( u,v ) ∈ E s 1 t • Value of flow f is the sum of flows out of s: 2 2 2 ∑ f ( e ) = f out ( s ) v ( f ) = 2 v :( s , v ) ∈ E • Maximum flow problem: find s-t flow of maximum value

  2. Algorithm Algorithm • Find path where we can send more flow. • Find path where we can send more flow. • Send flow back (cancel flow). 1 1 2 2 2 2 2 2 2 2 2 2 2 2 s 1 t s 1 t 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 s 1 t 2 2 2 2 1 2 1 1 Augmenting Paths Augmenting Paths • Augmenting path (definition di ff erent than in CLRS): s-t path where • Augmenting path: s-t path P 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 ) = δ = bottleneck ℗ . • Can add extra flow: min(c 1 - f 1 , f 2 , c 3 - f 3 , c 4 - f 4 , f 5 , f 6 ) = δ = bottleneck(P). • Ford-Fulkerson: 1/ 1 • Find augmenting path, use it 1/ 2/ 2 2/ 2 2/ 2 • Find augmenting path, use it 1/ s 1 t 1/ 2/ 2/ 1/ 2 2 1/ 2 • Find augmenting path, use it • …………………. 1/ 1

  3. Ford Fulkerson Analysis of Ford-Fulkerson • Augmenting path: s-t path P where • Integral capacities implies theres is a maximum flow where all flow values f(e) are integers. • forward edges have leftover capacity • backwards edges have positive flow • Number of iterations: + δ - δ + δ + δ - δ - δ s t • Always increment flow by at least 1: #iterations ≤ max flow value f* f 1 < c 1 f 2 > 0 f 3 < c 3 f 4 < c 4 f 5 > 0 f 6 > 0 • Time for one iteration: 3/ 5/ 3/ 8 3 2/ 2 • Can find augmenting path in linear time: One iteration takes O(m) time. 2 5/ 6 5/ 3/ 8 5/ 5 s t • Total running time = O(|f*| m). 2/ 2 2 4/ 4 6/ 4/ 9 Residual networks Residual networks 1 1 2 2/ 2 2 2 2/ 2/ 2 2 s 1 t s 1 t 2 2 2 2 2 2 1 1 0 0 1 1 2 2 2 2 2 2 0 0 0 0 s 0 t s 0 t 1 1 0 0 0 0 2 2 2 2 2 2 0 0 0 0 1 1 0 0

  4. Residual networks Residual networks 1 1 2/ 2 2/ 2 2 2 2/ 2/ 2/ 2/ 2 2 s 1 t s 1 t 2 2 2 2 2 2 1 1 0 0 1 1 0 0 0 0 0 0 2 2 2 2 s 2 t s 2 t 1 1 0 0 0 0 2 2 2 2 2 2 0 0 0 0 1 1 0 0 Residual networks Residual networks 1/ 1 1/ 1 1/ 2 1/ 2/ 2 2 2 2/ 2/ 2/ 2/ 2 2 1/ 1/ s 1 t s 1 t 1/ 2 1/ 2 2 2 2 2 1 1 0 1 1 0 0 1 0 0 0 0 2 1 2 2 s 2 t s 2 t 1 0 0 0 1 1 2 2 2 2 2 1 0 0 0 0 1 1 0 0

  5. Residual networks s-t Cuts • Cut: Partition of vertices into S and T, such that s ∈ S and t ∈ T. 1/ 1 S T 1/ 2 2 2/ 2/ 2 1/ t s 1 t s 1/ 2 2 2 1 1 • Capacity of cut: total capacity of edges going from S to T. 0 1 0 0 1 2 2 s 2 t 0 1 1 c(S,T) = 5 2 2 2 1 2 2 0 0 s 1 t c(S,T) = 8 2 1 2 0 2 2 s-t Cuts s-t Cuts • Cut: Partition of vertices into S and T, such that s ∈ S and t ∈ T. • Cut: Partition of vertices into S and T, such that s ∈ S and t ∈ T. S T S T t t s s • Flow across cut: = flow from S to T minus flow from T to S. • Flow across cut: = flow from S to T minus flow from T to S. 1/ 2 1/ 2 c(S,T) = 9 f(S,T) = 5 1/ 2 1/ 2 2/ 2 2/ 2/ 2 2/ 2 2 1/ 1/ s 1 t s 1 t 2/ 2/ 2 2/ 2/ 2 2 2 1/ 2 1/ 2 1/ 2 1/ 2

  6. s-t Cuts s-t Cuts • Cut: Partition of vertices into S and T, such that s ∈ S and t ∈ T. • Cut: Partition of vertices into S and T, such that s ∈ S and t ∈ T. S T S T t t s s • Flow across cut: = flow from S to T minus flow from T to S. • Flow across cut: = flow from S to T minus flow from T to S. 1/ 2 1/ 2 c(S,T) = 8 c(S,T) = 5 f(S,T) = 5 1/ 2 1/ 2 2/ 2 2/ 2/ 2 2/ 2 2 f(S,T) = 6 - 1 = 5 1/ 1/ s 1 t s 1 t 2/ 2/ 2 2/ 2/ 2 2 2 1/ 2 1/ 2 1/ 2 1/ 2 s-t Cuts s-t Cuts • Cut: Partition of vertices into S and T, such that s ∈ S and t ∈ T. • Cut: Partition of vertices into S and T, such that s ∈ S and t ∈ T. S T S T t t s s • Capacity of cut: total capacity of edges going from S to T. • Flow across cut = flow from S to T minus flow from T to S. • Capacity of cut: total capacity of edges going from S to T. • Flow across cut: f 4 + f 5 - f 6 = ? f 4 • Flow across cut = flow from S to T minus flow from T to S. f 1 • f 2 + f 4 + f 5 - f 1 = 0 • Net flow across cut is |f| for all cuts => net flow out of s = net flow into t. f 2 f 5 s • f 3 - f 2 - f 6 = 0 f 3 f 6 • |f| ≤ c(S,T): f 4 • f 1 - f 3 = |f| f 1 • |f| = f 4 + f 5 - f 6 ≤ f 4 + f 5 ≤ c 4 + c 5 = c(S,T) • (f 2 + f 4 - f 1 + f 5 ) + (f 3 - f 2 - f 6 ) + (f 1 - f 3 ) = |f| x x x x x x f 2 f 5 s f 3 • f 4 + f 5 - f 6 = |f| f 6 • Net flow across cut is |f| for all cuts => net flow out of s = net flow into t.

  7. s-t Cuts Finding minimum cuts • Cut: Partition of vertices into S and T, such that s ∈ S and t ∈ T. • Use Ford-Fulkerson to find a max-flow (finding augmenting paths). S T • When no augmenting s-t path: t s • Let S be all vertices to which there exists an augmenting path from s. • Capacity of cut: total capacity of edges going from S to T. • Flow across cut = flow from S to T minus flow from T to S. • |f| ≤ c(S,T). 1/ 2 • Suppose we have found flow f and cut (S,T) such that |f| = c(S,T). Then f is a 1/ 2/ 2 maximum flow and (S,T) is a minimum cut. 2/ 2 2/ 2 1/ s 1 t • Let f* be the maximum flow and the (S*,T*) minimum cut: 1/ 2/ 2 1/ 2/ 2 1/ 2 • |f| ≤ |f*| ≤ c(S*,T*) ≤ c(S,T). • Since |f| = c(S,T) this implies |f| = |f*| and c(S,T) = c(S*,T*). 1/ 2 Use of Max-flow min-cut theorem Finding minimum cuts • There is no augmenting path <=> f is a maximum flow. • Use Ford-Fulkerson to find a max-flow (finding augmenting paths). • f maximum flow => no augmenting path: • When no augmenting s-t path: • Show that exists augmenting path => f not maximum flow. • Let S be all vertices to which there exists an augmenting path from s. • no augmenting path => f maximum flow • Remember: • no augmenting path => exists cut (S,T) where |f| = c(S,T): • Let S be all vertices to which there exists an augmenting path from s. • All forward edges in the minimum cut are “full” (flow = capacity) • t not in S (since there is no augmenting s-t path). • All backwards edges in minimum cut have 0 flow. • Edges from S to T: f 1 = c 1 and f 2 = c 2 . • Edges from T to S: f 3 = 0. 3/ 5/ 8 3 • => |f| = f 1 + f 2 - f 3 = f 1 + f 2 = c 1 + c 2 = c(S,T). 2/ 2 2 • => f a maximum flow and (S,T) a minimum cut. 5/ 6 3/ 8 5/ 5 s t f 1 t 2/ 2 s f 2 2 4/ 4 6/ 9 f 3

  8. Removing assumptions Network Flow • Edges into s and out of t: • Multiple sources and sinks: v ( f ) = f out ( s ) − f in ( s ) • Capacities not integers.

Recommend


More recommend