410 likes | 445 Views
Chapter 26: Max Flow. A Flow Network and Flow:. Three Properties: Capacity Constraint: u,vV: f(u,v) c(u,v) Skew Symmetry: u,vV: f(u,v) = f(v,u) Flow Conservation: uV {s,t}: v V f(u,v) = 0. 12. v 3. v 1. 20. 16. s. t. 4. 10. 7. 9. 4. 13. v 4. v 2. 14. 12/12.
E N D
Chapter 26: Max Flow A Flow Network and Flow: Three Properties: Capacity Constraint: u,vV: f(u,v) c(u,v) Skew Symmetry: u,vV: f(u,v) = f(v,u) Flow Conservation: uV {s,t}:v V f(u,v) = 0 12 v3 v1 20 16 s t 4 10 7 9 4 13 v4 v2 14 12/12 v3 v1 15/20 11/16 s t 1/4 10 7/7 4/9 4/4 8/13 v4 v2 11/14 Comp 750, Fall 2009
Capacities must be nonnegative. Flows can be positive or negative. • No flow is going along the edge of capacity 10 from v1 to v2 but one unit of flow is going from v2 to v1 along the edge of capacity 4. Comp 750, Fall 2009
Max-Flow Problem • Definition:Value of flow f: |f | = v V f(s,v) |f | = 19 in example • Max-Flow Problem: Given G, s, and t, find a flow f of maximum value from s to t. • Applications: • flow of liquid through pipes, • parts through an assembly line, • current through electrical networks, • information through communication networks, • scheduling problems (!!). Comp 750, Fall 2009
Cancellation of Flow v1 v1 = 5/10 8/10 0/4 3/4 v2 v2 Comp 750, Fall 2009
Multiple Sources/Sinks s1 s2 t1 t s3 t2 s s4 t3 s5 capacities omitted here due to laziness Comp 750, Fall 2009
Implicit Summation Notation For X,Y V: f(X,Y) = x X y Y f(x,y) Lemma 26.1: f(X,X) = 0 f(X,Y) = f(Y,X) if XY = then f(XY,Z) = f(X,Z) + f(Y,Z) f(Z, XY) = f(Z,X) + f(Z,Y) Comp 750, Fall 2009
Example of using Implicit Summations Proof that |f | = f(V,t): Comp 750, Fall 2009
f(V,V – s – t) = 0 because f(V,V – s – t) = – f(V – s – t, V) and f(V – s – t, V) = 0 by flow conservation. Comp 750, Fall 2009
Ford-Fulkerson Method F-F-Method(G,s,t) initialize flow f to 0 while there exists an augmenting path p do augment flow f along p od; return f Details to be filled in … Comp 750, Fall 2009
Example 12/12 12 v3 v3 v1 v1 15/20 5 5 11/16 4 11 15 s t s t 1/4 10 7/7 7 11 3 4/9 5 5 3 4 4/4 8/13 v4 v2 v4 v2 8 11/14 11 12/12 12 v3 v1 v3 v1 19/20 5 1 11/16 11 s 19 t s t 1/4 10 7/7 7 11 3 9 9 1 3 4 4/4 12/13 v4 v2 v4 v2 12 11/14 11 Comp 750, Fall 2009
On the preceding slide, all the flows in the augmenting path have been increased by 4 units of flow. Comp 750, Fall 2009
Residual Networks Given flow f, the residual capacity of (u,v), where u,v V, is cf(u,v) = c(u,v) f(u,v). Residual network of G induced by f is Gf = (V,Ef), where Ef = {(u,v) VV: cf(u,v) > 0}. Note: Gf can have edges not in G. (See example.) Let cf(p) = min{cf(u,v): (u,v) is on p}. (p goes from s to t.) cf(p) if (u,v) is on p Let fp(u,v) = – cf(p) if (v,u) is on p 0 otherwise Corollary 26.4:Let f = f + fp. Then, f is a flow in G with value |f | = |f | + |fp| > |f |. See example. (Follows formally from two lemmas not stated here.) Comp 750, Fall 2009
Cuts A cut (S,T) of a flow network G = (V,E) is a partition of V into S and T = V S such that s S and t T. f(S,T) = net flow across cut (using implicit summation notation) c(S,T) = capacity of cut (using implicit summation notation) 12/12 Example: v3 v1 15/20 11/16 s t 1/4 10 7/7 4/9 4/4 8/13 v4 v2 11/14 S T Comp 750, Fall 2009
Lemma 26.5 Lemma 26.5: f(S,T) = |f |. Proof: Comp 750, Fall 2009
f(S – s, V) = 0 by flow conservation, because t V. Comp 750, Fall 2009
Corollary 26.6 Corollary 26.6: |f | capacity of any cut. Proof: Comp 750, Fall 2009
Max-Flow/Min-Cut Theorem Theorem 26.7 (Max-Flow/Min-Cut Theorem): The following are equivalent: 1. f is a maximum flow in G. 2. Gf contains no augmenting paths. 3. |f | = c(S,T) for some cut (S,T) of G. Proof: (1) (2): If Gf has an augmenting path p, then by Corollary 26.4, f + fp is a flow in G. (2) (3): Suppose (2) holds. Define S = {vV: path from s to v in Gf}, and T = V – S. (S,T) is a cut. For u S, v T, f(u,v) = c(u,v). (Why?) Thus, by Lemma 26.5, |f | = f(S,T) = c(S,T). (3) (1): By Corollary 26.6, |f | = c(S,T) implies f is a maximum flow. Comp 750, Fall 2009
Basic Ford-Fulkerson Method F-F(G,s,t) for each (u,v) E[G] do f[u,v] := 0; f[v,u] := 0 od; while there exist path p from s to t in Gfdo cf(p) := min{cf(u,v): (u,v) is in p}; for each (u,v) in p do f[u,v] := f[u,v] + cf(p); f[v,u] := –f[u,v] od od Comp 750, Fall 2009
Performance • If capacities are integers, then O(E|f*|), where f* is the maximum flow. • With irrational capacities, might never terminate. • Counterexample is kind of bizarre (see handout). • What about rational capacities? • Edmonds-Karp algorithm: Always augment along breadth-first shortest path in Gf. • Performance improves to O(VE2). • Simply pick augmenting path using BFS algorithm. Comp 750, Fall 2009
Example: Basic F-F Flows Residual Networks 4/12 12 v3 v3 v1 v1 20 20 4/16 16 s s t t 4 4 10 7 10 7 4/9 9 4/4 4 13 13 v4 v4 v2 v2 4/14 14 8 4/12 v3 v1 v3 v1 7/20 20 11/16 12 4 4 4 s t s t 4 7/10 7/7 4 10 7 4/9 5 10 4/4 4 13 v4 v2 13 v4 v2 11/14 4 Comp 750, Fall 2009
8 12/12 v3 v1 v3 v1 15/20 5 13 11/16 4 4 11 7 s t s t 1/4 10 7/7 7 3 11 4/9 5 13 3 4 4/4 8/13 v4 v2 v4 v2 11/14 11 12/12 12 v3 v1 v3 v1 19/20 5 5 11/16 4 11 15 s t s t 1/4 10 7/7 7 11 3 9 5 5 3 4 4/4 12/13 v4 v2 v4 v2 8 11/14 11 12 v3 v1 5 1 11 19 s t No augmenting path 7 11 3 9 1 3 4 v4 v2 12 11 Comp 750, Fall 2009
Example: E-K Flows Residual Networks 12/12 12 v3 v3 v1 v1 12/20 20 12/16 16 s s t t 4 4 10 7 10 7 9 9 4 4 13 13 v4 v4 v2 v2 14 14 f(s,v3) = 2 12/12 v3 v3 v1 v1 12/20 4 12 12/16 8 12 12 s s t t 4 10 7 7 10 4 9 9 4/4 4 14 4/13 13 v4 v4 v2 v2 4/14 f(s,v3) = 3 Comp 750, Fall 2009
12/12 v3 v3 v1 v1 19/20 4 12 12/16 8 12 12 s s t t 4 10 7 7 10 4 9 9 9 10 4/4 4 4 11/13 v4 v4 v2 v2 11/14 4 f(s,v3) = 3 12 v3 v1 4 1 12 19 s t No augmenting path 7 10 4 9 2 3 4 11 v4 v2 11 f(s,v3) = Comp 750, Fall 2009
Lemma 26.8 Lemma 26.8: Let (v) = f(s,v) = B-F distance from s to v in Gf. Then, (v) increases monotonically. (See E-K Example.) Proof: Suppose f is a flow, and augmentation produces f . Let (v) = f(s,v). Want to prove: (v) (v). Suppose (for contradiction) that (v) < (v) for some v. Comp 750, Fall 2009
Proof (Continued) (**) W.o.l.o.g., let (v) be minimal over all vertices for which (v) < (v). Consider shortest path s u v in Gf (could have u = s). Because it’s a shortest path, (v) = (u) + 1. (**) implies that (u) (u). Consider edge (u,v) in Ef. Is (u,v) in Ef??? Comp 750, Fall 2009
Proof (Continued) Case 1: (u,v) is in Ef. Implies the following. Contradiction! Comp 750, Fall 2009
Proof (Continued) Case 2: (u,v) is not in Ef. Thus, (u,v) is not in Ef but is in Ef. Must have: Gf (before) Gf (after) Augmenting path p must have (v,u) p, and p is a B-F path. Gf: Contradiction! v u v u u v t s Comp 750, Fall 2009
Computing the Time Bound Theorem 26.9: Number of flow augmentations in E-K is O(VE). Proof: Suppose p is augmenting path, (u,v) p, and cf(p) = cf(u,v). Then (u,v) is critical, and disappears from the residual network after augmentation. Before edge can become critical again, must send flow back the other way. Since augmenting on S.P.’s must be shortest in one direction, then other, etc. Comp 750, Fall 2009
Proof (Continued) First time (u,v) is critical: (v) = (u) + 1 since p is a shortest path. Must wait until (v,u) is on new augmenting path before (u,v) can become critical again. Let be the distance function when (v,u) is on augmenting path. We have: Thus,(u,v) is critical O(V) times, since (u) increases by at least 2 between occurrences. ((u) starts nonnegative, never decreases, and is less than |V| while u is reachable.) Comp 750, Fall 2009
Proof (Continued) Each edge is critical O(V) times. Because there are |E| edges, number of flow augmentations is O(VE). BFS costs O(E). Thus, E-K runs in O(VE2) time. Sections 26.4 and 26.5 give O(V2E) and O(V3) algorithms. They are much more complicated. (We skip these sections.) Comp 750, Fall 2009
Irrational Flows (Handout) Non-convergence and sub-optimality of F-F are possible in this case. We prove this by example. In the example, the initial flow augmentation introduces a flow of a0. Flow is then augmented step by step. Each step consists of two augmentations of value an+1 and an+2 satisfying an+2 = an – an+1 with a0 = 1 and a1 = (5 – 1)/2 < 1. By induction, it follows that ai = i. Total flow approaches the limit a0 + (a2 + a3) + (a3 + a4) + … = a0 + a1 + a2 + … = 1/(1 – ) S. Comp 750, Fall 2009
Pathological Flow Graph Maximum flow is 4S (even though F-F converges to S). A1 y1 x1 A2 y2 x2 t s A3 y3 x3 A4 y4 x4 A1 has capacity a0, A2has capacity a1, and A3and A4 have capacity a2. All other arcs have capacity S. Comp 750, Fall 2009
Step 0 Augmenting path = (s, x1, y1, t). Flow is a0. New residual capacities of A1, A2, A3, A4 are 0, a1, a2, a2. A1 y1 x1 A2 y2 x2 t s A3 y3 x3 A4 y4 x4 A1 has capacity a0, A2has capacity a1, and A3and A4 have capacity a2. All other arcs have capacity S. Comp 750, Fall 2009
Step n 1 y1 x1 Assume A1, A2, A3, A4 is some ordering of A1, A2, A3, A4 such that residual capacities are 0, an, an+1, an+1 (see Step 0 and Step n(b)). Order x’s and y’s accordingly. y2 x2 t s y3 x3 y4 x4 Comp 750, Fall 2009
Step n(a) Augmenting path = (s, x2, y2, x3, y3, t). Flow is an+1. New residual capacities of A1, A2, A3, A4 are 0, an+2, 0, an+1. y1 x1 y2 x2 t s y3 x3 y4 x4 Comp 750, Fall 2009
Step n(b) Augmenting path = (s, x2, y2, y1, x1, y3, x3, y4, t). Flow is an+2. New residual capacities of A1, A2, A3, A4 are an+2, 0, an+2, an+1. y1 x1 y2 x2 t s y3 x3 y4 x4 Comp 750, Fall 2009
Application: Maximum Bipartite Matching L R L R s t L R Comp 750, Fall 2009