39
CS 473 Lecture ? 1 CS473-Algorithms I Lecture ? Network Flows Flow Networks & Flows

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

Embed Size (px)

Citation preview

Page 1: CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Flow Networks & Flows

CS 473 Lecture ? 1

CS473-Algorithms I

Lecture ?

Network Flows

Flow Networks & Flows

Page 2: CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Flow Networks & Flows

CS 473 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 }, s v t,

i.e., every vertex v lies on some path from s to t.

Page 3: CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Flow Networks & Flows

CS 473 Lecture ? 3

• A positive flow p on G: a fn p:VxV R0 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

0),(),( VvVv

uvpvup u V- { s,t }

FLOW NETWORKS & FLOWS

Page 4: CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Flow Networks & Flows

CS 473 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

Vv VvVvVv

vtptvpsvpvspp ),(),(),(),(

s

v1 v3

v2 v4

t

2/2

2/21/3 2/3

0/1 1/2

1/2

2/31/3

2/3

note: flow capacity at every edge

note: flow conservation holds

at every vertex (except s and t)1/1

Page 5: CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Flow Networks & Flows

CS 473 Lecture ? 5

FLOW NETWORKS & FLOWS

312),(),(

30)21(),(),(),(

43

221

tvptvpp

svpvspvspp

s

v1 v3

v2 v4

t

2/2

2/21/3 2/3

0/1 1/2

1/2

2/31/3

2/3

1/1

Page 6: CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Flow Networks & Flows

CS 473 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

vu5/6

2/4

vu3/6

0/4

Page 7: CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Flow Networks & Flows

CS 473 Lecture ? 7

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:VxV 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) 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|= net flow out of the source

Vv

vuf 0),(

Vv

vsf ),(

Page 8: CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Flow Networks & Flows

CS 473 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.

),(),(),(),(0),(&),(),()1( vucuvpvupvufuvpvucvup

),(),(),(),(),(),()2( uvfvupuvpuvpvupvuf

VvVvVvVv

vufuvpvupuvpvup ),(),(),(),(),(0)3(

Page 9: CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Flow Networks & Flows

CS 473 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)=

Page 10: CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Flow Networks & Flows

CS 473 Lecture ? 10

NET FLOW VERSUS POSITIVE FLOW DEFINITIONS

),(),(),(),()1( vucvupvucvuf

0),(

0

0),(0),( 0

),(),(),(),(0)2(vufvufvufVv

vufvufvufvuf

• proof of (2) flow conservation in net flow model means that

– positive net flow leaving a vertex = positive net flow

entering the vertex

split summation

0),(0),(

;0),(),(uvfvuf

uvfvuf

because of skew symmetry

VvVv

uvpvup ),(),(0

Vv

vuf 0),(

Page 11: CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Flow Networks & Flows

CS 473 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

Page 12: CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Flow Networks & Flows

CS 473 Lecture ? 12

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}

Page 13: CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Flow Networks & Flows

CS 473 Lecture ? 13

s110

FLOW NETWORKS & MAXIMUM FLOW PROBLEM

s2

s3

s4

v1

v1

v1

t1

t1

Example: A flow network with multiple sources and sinks

6

475

3

14

6

4

7

s110

s1

s1

s1

v1

v1

v1

t1

t1

6

475

3

14

6

4

7

ts

Page 14: CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Flow Networks & Flows

CS 473 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

fvtfssff

tvfttftvsfssfs

vufvufletVvu

n

i Vvi

m

ii

Vviii

Vviii

11

),(),(ˆˆ

),(),(ˆ0:&),(),(ˆ0:

),(),(ˆ ;,

Page 15: CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Flow Networks & Flows

CS 473 Lecture ? 15

IMPLICIT SUMMATION NOTATION

Xx Yy

yxfYXf ),(),( where X,Y V

0),(),(},,{

VufvuftsVuVv

),(),( VsfvsffVv

• functions over sets imply summation; because will write

lots of summations.

Example: value of a flow f =

Example: flow conservation :

Page 16: CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Flow Networks & Flows

CS 473 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 XY=– 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

YXu Zz

zufZYXf ),(),(

),(),(),(),( ZYfZXfzyfzxfYy ZzXx Zz

Page 17: CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Flow Networks & Flows

CS 473 Lecture ? 17

IMPLICIT SUMMATION NOTATION

X X Y

f(x,y)

f(X,X) = 0

f(y,x)

X

Y

Z

f(x,z)

f(y,z)

XY

f(X,Y) = – f(Y,X)

f(XY,Z) = f(X,Z) + f(Y,Z)

Page 18: CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Flow Networks & Flows

CS 473 Lecture ? 18

IMPLICIT SUMMATION NOTATION

• (d) For any X V – {s,t}; f(X,V) = 0 f(V,X) = – f(X,V) = 0

00),(),( Xx Xx

VxfVXf

),(),( VsfvsffVv

due to flow conservation

• L2: |f| = f(V,t)

),(0),(

),(),())(,(

),(),(0

),(),()),((

tVftVf

tsVVftVftsVtVf

sVVfVsVf

VsVfVVfVsVVf

Page 19: CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Flow Networks & Flows

CS 473 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)

Page 20: CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Flow Networks & Flows

CS 473 Lecture ? 20

(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

a c15/2011/16

11/14

12/12

b d

s t

4/4

4/9

8/13

T1

Example:

0/101/47/7

S1 T1

S2 T2

CUTS OF FLOW NETWORKS & UPPER BOUND ON MAX FLOW

Page 21: CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Flow Networks & Flows

CS 473 Lecture ? 21

WHY WE NEED NEGATIVE FLOWS

• Reasons behind negative flow across a cut :

S

f(S,T) = f(a,c) – f(c,b) + f(b,d)

= 5 – 0 + 5 = 10 = |f| no neg. Flow across the cut

a c?/5?/10

?/10

?/10

b d

s t

?/10

?/5

?/5

T S

a c 5/55/10

5/10

5/10

b d

s t

5/10

0/5

5/5

T

Page 22: CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Flow Networks & Flows

CS 473 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

S

a c5/510/10

10/10

10/10

b d

s t

10/10

5/5

5/5

T

f '(S,T) = f(a,c) – f(c,b) + f(b,d)

= (5+5) – (5) + (5+5)

= 10 – 5 – 10 = 15 = | f |

Page 23: CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Flow Networks & Flows

CS 473 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}

Page 24: CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Flow Networks & Flows

CS 473 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) =

Tv SuSu Tv

uvfvuf ),(),(

Su Tv

vuf ),(

),(),( TScvucSu Tv

Page 25: CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Flow Networks & Flows

CS 473 Lecture ? 25

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)VxV: cf (u, v) > 0}

Vvu ,

Page 26: CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Flow Networks & Flows

CS 473 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

u v

3/5

0/1u v

2

4

Page 27: CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Flow Networks & Flows

CS 473 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)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)

u v5/5

u v5 cf (u, v) = 5 – 5 = 0 ≤ 0 ×

cf (v, u) = 0 – (– 5) = 5 > 0 √

u v3/5

u v

2

3

cf (u, v) = 5 – 3 = 2 > 0 √

cf (v, u) = 0 – (– 3) = 3 > 0 √

Page 28: CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Flow Networks & Flows

CS 473 Lecture ? 28

FLOW SUMS• def: let f1 and f2 be flows on G

flow sum f1+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)

Vvu ,

000),(),()),(),((),()( 212121 VvVvVvVv

vufvufvufvufvuff

Page 29: CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Flow Networks & Flows

CS 473 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 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 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)

Vvu ,

Page 30: CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Flow Networks & Flows

CS 473 Lecture ? 30

FLOW SUMS

• Second show that | f + f '| = | f |+| f '|

– |f+f '| =

= = | f |+| f '|

VvVv

vsfvsfvsff )),('),((),()'(

VvVv

vsfvsf ),('),(

Page 31: CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Flow Networks & Flows

CS 473 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

)},({min),(

vuc fpvu

Page 32: CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Flow Networks & Flows

CS 473 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 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 |

Page 33: CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Flow Networks & Flows

CS 473 Lecture ? 33

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

– define flow fp on Gf with cf (p) = min{2, 4, 5, 2, 2, 2} = 2

s t3/5 2/6 5/5 2/3 2/4

p on G with f:

s t

2

3

4

2

52

1

2

2p on Gf :

s t

2/2 2/42/5

2/2 2/2

fp on Gf :

Page 34: CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Flow Networks & Flows

CS 473 Lecture ? 34

AUGMENTING PATHS

• example (cont.): a single path p on G

– flow on p in G that results from augmenting along path p:

s t3/5 2/6 5/5 2/3 2/4

p on G with f:

s t5/5 4/6 3/5 0/3 4/4

f + fp on p of G:+2 +2 -2-2 +2

s t

2/2 2/42/5

2/2 2/2

fp on Gf :

Page 35: CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Flow Networks & Flows

CS 473 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) Gf contains no augmenting paths

– (3) | f | = c(S, T) for some cut (S, T) of G

Page 36: CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Flow Networks & Flows

CS 473 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

Page 37: CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Flow Networks & Flows

CS 473 Lecture ? 37

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

Page 38: CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Flow Networks & Flows

CS 473 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

u v

s

S V-S

u v

….…. so, by L3, | f | = f(S, T) =c(S,T)

Page 39: CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Flow Networks & Flows

CS 473 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