1 / 39

CS473-Algorithms I

CS473-Algorithms I. Lecture ? Network Flows Flow Networks & Flows. FLOW NETWORKS & FLOWS. • A flow network: a directed graph G = ( V , E ) Two distinguished vertices : a source s and a sink t Each edge has a nonegative capacity c( u , v )  0

oprah-cline
Download Presentation

CS473-Algorithms I

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS473-Algorithms I Lecture ? Network Flows Flow Networks & Flows Lecture ?

  2. FLOW NETWORKS & FLOWS •A flow network: a directed graph G = ( V , E ) • Two distinguished vertices : a source s and a sink t • Each edge has a nonegative capacity c(u,v)  0 (if (u,v)  E then c(u,v) = 0) • for convenience :  v V – { s,t }, sv t, i.e., every vertex v lies on some path from s to t. Lecture ?

  3. FLOW NETWORKS & FLOWS •A positive flow p on G: a fn p:VxV  R0 satisfying • capacity constraint: 0  p(u,v)  c(u,v),  u,v V • i.e., flow from one vertex to another cannot exceed the capacity • note : p(u,v)> 0  (u,v)  E with c(u,v) > 0 • flow conservation: Kirschoff’s current law • total positive flow leaving a vertex = total positive flow entering the vertex  u  V- { s,t } Lecture ?

  4. FLOW NETWORKS & FLOWS • value of a positive flow: • a sample flow network G and a positive flow p on G: p/c for every edge note: flow  capacity at every edge 2/2 v1 v3 1/3 2/3 note: flow conservation holds at every vertex (except s and t) 1/1 1/3 s t 2/3 1/2 0/1 2/2 1/2 v2 v4 2/3 Lecture ?

  5. FLOW NETWORKS & FLOWS 2/2 v1 v3 1/3 2/3 1/1 1/3 s t 2/3 1/2 0/1 2/2 1/2 v2 v4 2/3 Lecture ?

  6. FLOW NETWORKS & FLOWS • cancellation : can say positive flow either goes from u to v or from v to u, but not both • if not true, can transform by cancellation to be true • e.g.,  3 units of net positive flow from u to v •  • can be obtained by canceling 2 units of flow in each direction • capacity constraint still satisfied : flows only decrease • flow conservation still satisfied : flow-in & flow-out both reduced by the same amount 5/6 u v 2/4 3/6 u v 0/4 Lecture ?

  7. NET FLOW VERSUS POSITIVE FLOW DEFINITIONS • positive flowis more intuitive • net flow brings mathematical simplification: half as many summations to write • A net flow f on G: a fn f:VxV  Rsatisfying • capacity constraint:  u,v V f(u,v)  c(u,v) • skew symmetry:  u,v V f(u,v)= - f(v,u) • thus, f(u,u)= - f(u,u)  f(u,u)=0  net flow from a vertex toitself is 0 • flow conservation:  u V- {s,t}, • total net flow into a vertex is 0 • Nonzero net flow from u to v(u,v)  E, or (v,u)  E, or both. • value of a net flow : |f|= net flow out of the source Lecture ?

  8. NET FLOW VERSUS POSITIVE FLOW DEFINITIONS • equivalence of net flow and positive flow definitions: • define net flow in terms of positive flow: • f(u,v)= p(u,v) - p(v,u) • Given definition of p, this def. of f satisfies (1)capacity constraint, (2)skew symmetry, and (3)flow constraint. Lecture ?

  9. NET FLOW VERSUS POSITIVE FLOW DEFINITIONS • define positive flow in terms of net flow: f(u,v), if f(u,v) > 0 0, if f(u,v)  0 • Given definition of f, this def. of p satisfies (1)capacity constraint, (2)flow constraint. p(u,v)= Lecture ?

  10. NET FLOW VERSUS POSITIVE FLOW DEFINITIONS split summation because of skew symmetry • proof of (2)  flow conservation in net flow model means that •  positive net flow leaving a vertex = positive net flow entering the vertex Lecture ?

  11. FLOW NETWORKS & MAXIMUM FLOW PROBLEM • maximum flow problem : given a flow network G with source s and sink t • find a flow of maximum value from s to t • flow network with multiple sources and sinks : • a flow network G with m sources {s1, s2,..., sm}= Sm and n sinks {t1, t2,..., tn}= Tn • Max flow problem : find a flow of max value from m sources to n sinks • Can reduce to an ordinary max-flow problem witha single source & a single sink Lecture ?

  12. FLOW NETWORKS & MAXIMUM FLOW PROBLEM • add a supersources and a supersinkt such that • Add a directed edge (s,si) with capacity c(s,si)= for i=1,2,...,m • Add a directed edge (t,ti) with capacity c(t,ti)= for i=1,2,...,n • i.e., V = V  {s,t}; E = E {(s,si) with c(s,si)=:si}{(t,ti) with c(t,ti)=:ti} Lecture ?

  13. FLOW NETWORKS & MAXIMUM FLOW PROBLEM Example: A flow network with multiple sources and sinks 10 10 s1 s1 14  14 6 v1 6 v1 s2 s1   4 6 t1 4 6 t1 s v1 v1 7 7 t  4 4 s3 s1 t1 t1 5 5   v1 7 v1 7 s4 s1 3 3 Lecture ?

  14. NET FLOW VERSUS POSITIVE FLOW DEFINITIONS • Claim : any flow in a multiple-source multiple-sink flow network G = (v, t) • Corresponds to a flow of identical value in G = ( v, t ) • Proof : define f for G interms of G Lecture ?

  15. IMPLICIT SUMMATION NOTATION • functions over sets imply summation; because will write lots of summations. where X,Y  V Example: value of a flow f = Example: flow conservation : Lecture ?

  16. IMPLICIT SUMMATION NOTATION • L1 : let G=(V,E) be a flow network, and let f be a flow on G, then: • (a) For X  V; f(X,X) = 0 • Because each f(u,v) canceled by f(v,u)= – f(u,v) due to skew symmetry. • (b) for X,Y  V; f(X,Y) = – f(Y,X) • Generalization of f(X,X)=0, same reasoning • (c) for X,Y,Z  V, with XY= • f(X Y,Z) = f(X,Z)+f(Y,Z) & f(Z,X Y) = f(Z,X)+f(Z,Y) • Split summation into sum of two summations, one over X, one over Y Lecture ?

  17. IMPLICIT SUMMATION NOTATION f(x,y) X X Y f(y,x) f(X,X) = 0 f(X,Y) = – f(Y,X) XY X f(x,z) Z Y f(y,z) f(XY,Z) = f(X,Z) + f(Y,Z) Lecture ?

  18. IMPLICIT SUMMATION NOTATION • (d) For any X  V – {s,t}; f(X,V) = 0  f(V,X) = – f(X,V) = 0 due to flow conservation • L2: |f| = f(V,t) Lecture ?

  19. CUTS OF FLOW NETWORKS & UPPER BOUND ON MAX FLOW • def: A cut(S, T) of a flow network is a partition of V into S and T = V-S such that s S and t  T • Similar to the cut definition given for MST • Differences: G is a directed graph here & we insist that s S and t  T • def: f(S, T) is the net flow across the cut (S, T) of G for a flow f on G • Add all edges S T and negative of all edges T  S due to skew symmetry • def: c(S, T) is the capacity across the cut (S, T) of G • not like flow because no skew symmetry; just add edges S T (no neg. values) Lecture ?

  20. CUTS OF FLOW NETWORKS & UPPER BOUND ON MAX FLOW Example: (S1, T1) = ({s, a, b}, {c, d, t}) • f(S1, T1) = f(a, c) + f(b, c) + f(b, d) = 12 + (-4) + 11 = 19 • c(S1, T1) = c(a, c) + c(b, d) = 12 + 14 = 26 (S2, T2) = ({s, a}, {b, c, d, t}) • f(S2, T2) = f(s, b) + f(a, b) + f(a, c) = 8 + (-1) + 12 = 19 • c(S2, T2) = c(s, b) + c(a, b) + c(a, c) = 13 + 10 + 12 = 35 12/12 a c 11/16 15/20 1/4 s 0/10 4/9 7/7 t 8/13 4/4 b d 11/14 S2 T2 S1 T1 T1 Lecture ?

  21. WHY WE NEED NEGATIVE FLOWS • Reasons behind negative flow across a cut : ?/10 5/10 a c a c ?/10 ?/5 5/10 5/5 s s ?/5 t 0/5 t ?/5 5/5 b d ?/10 b d 5/10 ?/10 5/10 S T S T f(S,T) = f(a,c) – f(c,b) + f(b,d) = 5 – 0 + 5 = 10 = |f| no neg. Flow across the cut Lecture ?

  22. WHY WE NEED NEGATIVE FLOWS • Exploit capacity c(c,b) = 5 to induce negative flow across (S,T) • i.e., sacrifice negative flow of 5 for a better utilization of c(a,c) = 10 & c(b,d) = 10 10/10 a c f '(S,T) = f(a,c) – f(c,b) + f(b,d) = (5+5) – (5) + (5+5) = 10 – 5 – 10 = 15 = | f | 10/10 5/5 s 5/5 t 5/5 b d 10/10 10/10 S T Lecture ?

  23. CUTS OF FLOW NETWORKS & UPPER BOUND ON MAX FLOW • L3: For any flow f on G, the net flow across any cut (S, T) of G = |f| • f(S, T) = f(S, V-S) = f(S, V) – f(S, S) by L1(c)= f(S, V) + 0 = f(S, V) by L1(a)= f(s  (S – s), V) = f(s, V) + f(S – s, V) by L1(c)= f(s, V) + 0 = f(s, V) = |f| by L1(d)since S-s  V – {s, t} Lecture ?

  24. CUTS OF FLOW NETWORKS & UPPER BOUND ON MAX FLOW • C1: the value of any flow f in G is bounded above by the capacity of any cut of G • Let (S, T) be any cut of G • |f| = f(S, T) = Lecture ?

  25. RESIDUAL NETWORKS • intuitively: the residual network Gfof a flow network G with a flow f • Consists of edges that can admit more flow • def:given a flow network G = (V, E) with a flow f • residual capacity of (u, v): cf (u, v) = c(u, v) – f(u, v) • cf (u, v): additional flow we can push from u to v without exceeding c(u, v) • residual network of G induced by f is the graph Gf = (V, Ef) with • Strictly positive residual capacities: Ef = {(u, v)VxV: cf (u, v) > 0} Lecture ?

  26. RESIDUAL NETWORKS • recall: if both (u, v) E and (v, u) E then • Transform such that either f(u, v) = 0 or f(v, u) = 0 by cancellation • examples: (1)both (u, v)  E and (v, u)  E cf (u, v) = c(u, v) – f(u, v) = 5 – 3 = 2 > 0 cf (v, u) = c(v, u) – f(v, u) = 1 –(–3) = 4 > 0 3/5 2 u v u v 0/1 4 Lecture ?

  27. RESIDUAL NETWORKS (2)(u, v) E but (v, u)  E and f(u, v) ≥ 0: (v, u) becomes an edge of Ef • |Ef| ≤ 2|E|, since (u,v)Efonly if at least one of (u,v) and (v,u) is in E • note: cf (u, v) + cf (v, u) = c(u, v) + c(v, u) • cf (u, v) = 5 – 5 = 0 ≤ 0× • cf (v, u) = 0 – (– 5) = 5 > 0 √ 5/5 5 u v u v 2 • cf (u, v) = 5 – 3 = 2 > 0 √ • cf (v, u) = 0 – (– 3) = 3 > 0 √ 3/5 u v u v 3 Lecture ?

  28. FLOW SUMS • def:let f1and f2be flows on G flow sumf1+f2: VxV  R  (f1+f2)(u,v) = f1(u,v)+f2(u,v) • L4:flow sum f1+ f2 satisfies (2) skew symmetry & (3) flow conservation • (2)(f1+ f2)(u, v) = f1(u, v) + f2(u, v) = – f1(v, u) – f2(v, u) = – (f1(v, u) + f2(v, u)) = – (f1+ f2)(u, v) • (3) • note:flow sum may violate(1) capacity constraint • f1(u,v), f2(u,v) ≤ c(u,v) may not mean that f1(u,v)+f2(u,v) ≤ c(u,v) Lecture ?

  29. FLOW SUMS • How a flow on Gf relates to a flow on the original network G? • L5: let f be a flow on G and let f' be a flow on Gf then, flow sumf+f' is a flow on G with value |f+f'| = |f|+|f'| • First verify that f+f'is a flow on G • ie, show that f+f'satisfies (1) capacity constraint, (2) skew symmetry, (3) flow constraint • note that f' is also a flow on G • so, by L4, f+f'already satisfies (2) and (3) on G • thus it remains to show that f+f'satisfies (1) on G • (f+f')(u, v) = f(u, v)+f'(u, v)≤ f(u, v)+cf(u, v) = f(u, v)+(c(u, v) – f(u, v)) = c(u, v) Lecture ?

  30. FLOW SUMS • Second show that |f+f'| = |f|+|f'| • |f+f'| = = = |f|+|f'| Lecture ?

  31. AUGMENTING PATHS • For a flow f on G • augmenting path p is a simple path from s to t in Gf • cf(p): residual capacity of a path p = • i.e., cf(p) = max. amount of the flow we can ship along edges of p on Gf Lecture ?

  32. AUGMENTING PATHS • L6: let f be a flow on G, and let p be an augmenting path in Gf. Let fp be a flow on Gfwith value |fp| = cf (p) > 0 defined as cf(p) if (u,v)  p in Gf fp(u,v) = 0 otherwise then, f’ = f+fpis a flow on G with value |f’| = |f| + |fp| > |f| Lecture ?

  33. AUGMENTING PATHS 3/5 2/6 5/5 2/3 2/4 • example: a single path p on G • can easily say that it is not all of G since flow is not conserved on p • define flow fp on Gfwith cf (p) = min{2, 4, 5, 2, 2, 2} = 2 p on G with f: s t 2 4 2 2 5 p on Gf : s t 3 2 1 2 2/2 2/4 2/2 2/2 2/5 fp on Gf : s t Lecture ?

  34. AUGMENTING PATHS 3/5 2/6 5/5 2/3 2/4 p on G with f: s t • example (cont.): a single path p on G • flow on p in G that results from augmenting along path p: 2/2 2/4 2/2 2/2 2/5 fp on Gf : s t 5/5 4/6 3/5 0/3 4/4 f + fp on p of G: s t +2 +2 -2 -2 +2 Lecture ?

  35. MAX-FLOW MIN-CUT THEOREM • Thm (max-flow min-cut): the following are equivalent for a flow f on G • (1)f is a maximum flow • (2)Gfcontains no augmenting paths • (3) |f| = c(S, T) for some cut (S, T) of G Lecture ?

  36. MAX-FLOW MIN-CUT THEOREM • proof (1) (2): f is a max flow on G • for contradiction, assume that G contains an augmenting path p with cf(p) > 0 • then, by L6 flow sum f+fp is a flow on Gf with value > |f|, contradiction Lecture ?

  37. MAX-FLOW MIN-CUT THEOREM • proof (2) (3): Gfcontains no augmenting path, i.e., Gfcontains no path from s to t • define S = s  {u:  a path from s to u in Gf} • define T = V – S • (S, T) is a cut: s  S & t  S  t  T because  no path from s to t in Gf Lecture ?

  38. MAX-FLOW MIN-CUT THEOREM • proof (2) (3) (cont.): • for each u  S and v  T, we have f(u, v) = c(u, v) • Otherwise cf(u,v) = c(u,v) – f(u,v) > 0  v  S, contradiction u v v u so, by L3, | f | = f(S, T) =c(S,T) s …. …. u v S V-S Lecture ?

  39. MAX-FLOW MIN-CUT THEOREM • proof (3) (1): |f| = c(S,T) for some cut (S,T) of G • already proved by C1 that | f | ≤ c(S, T) for all cuts (S, T) • so, | f | = c(S, T) implies that f is a max flow Lecture ?

More Related