CS 473 Algorithms I Lecture Network Flows Flow







































- Slides: 39
CS 473 -Algorithms I Lecture ? Network Flows Flow Networks & Flows 1
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 }, s v t, i. e. , every vertex v lies on some path from s to t. CS 473 Lecture ? 2
FLOW NETWORKS & FLOWS • A positive flow p on G: a fn p: Vx. V 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 u V- { s, t } • total positive flow leaving a vertex = total positive flow entering the vertex CS 473 Lecture ? 3
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 v 1 1/3 s 2/2 CS 473 0/1 1/3 v 2 2/2 v 3 1/1 2/3 note: flow capacity at every edge 2/3 1/2 v 4 t note: flow conservation holds at every vertex (except s and t) 1/2 Lecture ? 4
FLOW NETWORKS & FLOWS v 1 1/3 s 2/2 CS 473 0/1 1/3 v 2 2/2 1/1 2/3 v 3 2/3 1/2 v 4 Lecture ? t 1/2 5
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 5/6 u v 3 units of net positive flow from u to v – e. g. , 2/4 3/6 u v – 0/4 • 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 CS 473 Lecture ? 6
NET FLOW VERSUS POSITIVE FLOW DEFINITIONS • positive flow is more intuitive • net flow brings mathematical simplification: half as many summations to write • A net flow f on G: a fn f: Vx. V R satisfying – 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)=0 net flow from a vertex to itself 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|= CS 473 net flow out of the source Lecture ? 7
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. CS 473 Lecture ? 8
NET FLOW VERSUS POSITIVE FLOW DEFINITIONS • define positive flow in terms of net flow: p(u, v)= 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. CS 473 Lecture ? 9
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 CS 473 Lecture ? 10
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 {s 1, s 2, . . . , sm}= Sm and n sinks {t 1, t 2, . . . , 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 CS 473 Lecture ? 11
FLOW NETWORKS & MAXIMUM FLOW PROBLEM • add a supersource s and a supersink t 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} CS 473 Lecture ? 12
FLOW NETWORKS & MAXIMUM FLOW PROBLEM Example: A flow network with multiple sources and sinks s 1 10 6 s 2 4 7 s 3 5 s 4 3 CS 473 v 1 14 6 v 1 4 v 1 7 t 1 s s 1 10 6 s 1 4 7 s 1 5 s 1 3 Lecture ? v 1 14 6 v 1 4 v 1 7 t 1 t t 1 13
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 CS 473 Lecture ? 14
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 : CS 473 Lecture ? 15
IMPLICIT SUMMATION NOTATION • L 1 : 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 CS 473 Lecture ? 16
IMPLICIT SUMMATION NOTATION f(x, y) X X Y f(y, x) f(X, X) = 0 X Y f(X, Y) = – f(Y, X) X f(x, z) Z Y f(y, z) f(X Y, Z) = f(X, Z) + f(Y, Z) CS 473 Lecture ? 17
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 • L 2: |f| = f(V, t) CS 473 Lecture ? 18
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) CS 473 Lecture ? 19
CUTS OF FLOW NETWORKS & UPPER BOUND ON MAX FLOW (S 1, T 1) = ({s, a, b}, {c, d, t}) Example: • f(S 1, T 1) = f(a, c) + f(b, d) 11/16 1/4 s 8/13 S 2 a 12/12 c 0/10 4/9 b 11/14 15/20 d 4/4 = 12 + 14 = 26 • f(S 2, T 2) = f(s, b) + f(a, c) 8 + (-1) + 12 = 19 • c(S 2, T 2) = c(s, b) + c(a, c) = CS 473 11 = 19 (S 2, T 2) = ({s, a}, {b, c, d, t}) = T 1 + (-4) + • c(S 1, T 1) = c(a, c) + c(b, d) t 7/7 T 2 S 1 = 12 Lecture ? 13 + 10 + 12 = 35 20
WHY WE NEED NEGATIVE FLOWS • Reasons behind negative flow across a cut : ? /10 a s ? /10 c ? /5 b S ? /10 ? /5 5/10 s t d a T c 0/5 5/5 ? /10 5/10 b S 5/10 5/5 t d 5/10 T f(S, T) = f(a, c) – f(c, b) + f(b, d) = 5 – 0 + 5 = 10 = |f| CS 473 Lecture ? no neg. Flow across the cut 21
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 s 10/10 c 5/5 b S CS 473 10/10 5/5 f '(S, T) = f(a, c) – f(c, b) + f(b, d) = (5+5) – (5) + (5+5) t = 10 – 5 – 10 = 15 = | f | d 10/10 T Lecture ? 22
CUTS OF FLOW NETWORKS & UPPER BOUND ON MAX FLOW • L 3: 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 L 1(c) = f(S, V) + 0 = f(S, V) by L 1(a) = f(s (S – s), V) = f(s, V) + f(S – s, V) by L 1(c) = f(s, V) + 0 = f(s, V) = |f| by L 1(d) since S-s V – {s, t} CS 473 Lecture ? 23
CUTS OF FLOW NETWORKS & UPPER BOUND ON MAX FLOW • C 1: 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) = CS 473 Lecture ? 24
RESIDUAL NETWORKS • intuitively: the residual network Gf of 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) Vx. V: cf (u, v) > 0} CS 473 Lecture ? 25
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 3/5 u 2 v u 0/1 v 4 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 CS 473 Lecture ? 26
RESIDUAL NETWORKS (2) (u, v) E but (v, u) E and f(u, v) ≥ 0: (v, u) becomes an edge of Ef u u 5/5 3/5 v u 5 v 2 v u v 3 cf (u, v) = 5 – 5 = 0 ≤ 0 × cf (v, u) = 0 – (– 5) = 5 > 0 √ cf (u, v) = 5 – 3 = 2 > 0 √ cf (v, u) = 0 – (– 3) = 3 > 0 √ • |Ef| ≤ 2|E|, since (u, v) Ef only 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) CS 473 Lecture ? 27
FLOW SUMS • def: let f 1 and f 2 be flows on G flow sum f 1+f 2: Vx. V R (f 1+f 2)(u, v) = f 1(u, v)+f 2(u, v) • L 4: flow sum f 1 + f 2 satisfies (2) skew symmetry & (3) flow conservation – (2) (f 1 + f 2)(u, v) = f 1(u, v) + f 2(u, v) = – f 1(v, u) – f 2(v, u) = – (f 1(v, u) + f 2(v, u)) = – (f 1 + f 2)(u, v) – (3) • note: flow sum may violate (1) capacity constraint – f 1(u, v), f 2(u, v) ≤ c(u, v) may not mean that f 1(u, v)+f 2(u, v) ≤ c(u, v) CS 473 Lecture ? 28
FLOW SUMS • How a flow on Gf relates to a flow on the original network G? • L 5: let f be a flow on G and let f ' be a flow on Gf then, flow sum f+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 L 4, 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) CS 473 Lecture ? 29
FLOW SUMS • Second show that | f + f '| = | f |+| f '| – |f+f '| = = CS 473 = | f |+| f '| Lecture ? 30
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 CS 473 Lecture ? 31
AUGMENTING PATHS • L 6: let f be a flow on G, and let p be an augmenting path in Gf. Let fp be a flow on Gf with value | fp | = cf (p) > 0 defined as cf (p) if (u, v) p in Gf fp (u, v) = 0 otherwise then, f’ = f+fp is a flow on G with value | f’ | = | f | + | fp | > | f | CS 473 Lecture ? 32
AUGMENTING PATHS • example: a single path p on G – can easily say that it is not all of G since flow is not conserved on p p on G with f: p on Gf : s 3/5 2/6 2 4 5/5 5 s 3 2 2/4 t 2 t 1 2 – define flow fp on Gf with cf (p) = min{2, 4, 5, 2, 2, 2} = 2 2/2 fp on Gf : CS 473 2/4 2/5 s Lecture ? 2/2 t 33
AUGMENTING PATHS • example (cont. ): a single path p on G with f: fp on Gf : s 3/5 2/6 2/2 2/4 5/5 2/5 s 2/3 2/2 2/4 t 2/2 t – flow on p in G that results from augmenting along path p: f + fp on p of G: CS 473 s 5/5 4/6 3/5 0/3 4/4 +2 +2 -2 -2 +2 Lecture ? t 34
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) Gf contains no augmenting paths – (3) | f | = c(S, T) for some cut (S, T) of G CS 473 Lecture ? 35
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 L 6 flow sum f + fp is a flow on Gf with value > | f |, contradiction CS 473 Lecture ? 36
MAX-FLOW MIN-CUT THEOREM • proof (2) (3): Gf contains no augmenting path, i. e. , Gf contains 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 CS 473 Lecture ? 37
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 CS 473 u v …. S v …. s u u v so, by L 3, | f | = f(S, T) =c(S, T) V-S Lecture ? 38
MAX-FLOW MIN-CUT THEOREM • proof (3) (1): | f | = c(S, T) for some cut (S, T) of G – already proved by C 1 that | f | ≤ c(S, T) for all cuts (S, T) – so, | f | = c(S, T) implies that f is a max flow CS 473 Lecture ? 39