48
Flow Networks [email protected]

Flow Networks [email protected]. Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut

Embed Size (px)

Citation preview

Page 1: Flow Networks zichun@comp.nus.edu.sg. Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut

Flow [email protected]

Page 2: Flow Networks zichun@comp.nus.edu.sg. Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut

Formalization

Basic Results

Ford-Fulkerson

Edmunds-Karp

Bipartite Matching

Min-cut

Page 3: Flow Networks zichun@comp.nus.edu.sg. Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut

Flow Network

• Directed Graph G = (V, E)• Each edge has a capacity

Page 4: Flow Networks zichun@comp.nus.edu.sg. Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut

Properties of Flow

Capacity Constraint

Skew Symmetry

Flow Conservation

Page 5: Flow Networks zichun@comp.nus.edu.sg. Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut

Maximum Flow

– Returns Maximum Flow of G

Value of Flow

|𝒇 |=∑𝑣∈𝑉

𝑓 (𝑠 ,𝑣 )

Page 6: Flow Networks zichun@comp.nus.edu.sg. Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut

Motivating Problem

s

v1

v2

v3

v4

tFact

ory

Warehouse

16

10 4

1220

9 7

4

14

13

Page 7: Flow Networks zichun@comp.nus.edu.sg. Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut

Motivating Problem

s

v1

v2

v3

v4

tFact

ory

Warehouse

11/16

10 1/4

12/12

15/20

4/9 7/7

4/4

11/14

8/13

Page 8: Flow Networks zichun@comp.nus.edu.sg. Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut

s

v1

v2

v3

v4

tFact

ory

Warehouse

11/16

10 1/4

15/20

4/9 7/7

4/4

11/14

8/13

12/12

Page 9: Flow Networks zichun@comp.nus.edu.sg. Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut

Multiple Sources / Sinks

s1

v1

v2

v3

v4

t1

16

10 4

1220

9 74

14

13

t24s2

4

Page 10: Flow Networks zichun@comp.nus.edu.sg. Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut

Multiple Sources / Sinks

s1

v1

v2

v3

v4

t1

16

10 4

1220

9 74

14

13

t24s2

4

S t∞

∞ ∞

Page 11: Flow Networks zichun@comp.nus.edu.sg. Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut

Implicit Summation Notation

Page 12: Flow Networks zichun@comp.nus.edu.sg. Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut

Key EqualitiesLet G = (V, E) be a flow network, and let f be a flow in G. Then

Page 13: Flow Networks zichun@comp.nus.edu.sg. Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut

Capacity Constraint

Skew Symmetry

Flow Conservation

Homomorphism

Page 14: Flow Networks zichun@comp.nus.edu.sg. Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut

Flow Value

Prove

DefinitionHomomorphismFlow Conservation

Skew SymmetryHomomorphismFlow Conservation

Page 15: Flow Networks zichun@comp.nus.edu.sg. Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut

Ford-Fulkerson

flow=0while(augmenting path p)) { augment flow f along p}return flow

Page 16: Flow Networks zichun@comp.nus.edu.sg. Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut

Residual network

Induced network from G=(V, E) and flow f

Page 17: Flow Networks zichun@comp.nus.edu.sg. Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut

s

v1

v2

v3

v4

tFact

ory

Warehouse

11/16

10 1/4

12/12

15/20

4/9 7/7

4/4

11/14

8/13

s

v1

v2

v3

v4

tFact

ory

Warehouse

11

5

12

15

411

811

4 7

5

3

0

5

3

00

5

Page 18: Flow Networks zichun@comp.nus.edu.sg. Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut

Augmenting Path

A path of

non-zero weight

from s to t in Gf

Page 19: Flow Networks zichun@comp.nus.edu.sg. Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut

s

v1

v2

v3

v4

tFact

ory

Warehouse

11/16

10 1/4

12/12

15/20

4/9 7/7

4/4

11/14

8/13

s

v1

v2

v3

v4

tFact

ory

Warehouse

11

5

12

15

411

811

4 7

5

3

0

5

3

00

5

Page 20: Flow Networks zichun@comp.nus.edu.sg. Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut

s

v1

v2

v3

v4

tFact

ory

Warehouse

11/16

10 1/4

12/12

15/20

4/9 7/7

4/4

11/14

8/13

s

v1

v2

v3

v4

tFact

ory

Warehouse

11

5

12

15

411

811

4 7

5

3

0

5

3

00

5

Page 21: Flow Networks zichun@comp.nus.edu.sg. Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut

s

v1

v2

v3

v4

tFact

ory

Warehouse

11/16

10 1/4

12/12

15/20

4/9 7/7

4/4

11/14

8/13

s

v1

v2

v3

v4

tFact

ory

Warehouse

11

5

12

15

411

811

4 7

5

3

0

5

3

00

5

Page 22: Flow Networks zichun@comp.nus.edu.sg. Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut

s

v1

v2

v3

v4

tFact

ory

Warehouse

11/16

10 1/4

12/12

20/20

0/9 7/7

4/4

11/14

13/13

s

v1

v2

v3

v4

tFact

ory

Warehouse

11

5

12

20

411

1311

0 7

0

3

0

9

3

00

0

Page 23: Flow Networks zichun@comp.nus.edu.sg. Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut

S-T Cut

• A cut C=(S, T) of a flow network G=(V, E) is a partition of V into S and T = V – S

• Net flow across• Capacity of cut:

Page 24: Flow Networks zichun@comp.nus.edu.sg. Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut

s

v1

v2

v3

v4

tFact

ory

Warehouse

11/16

10 1/4

12/12

15/204/9 7/

7

4/4

11/14

8/13

f(S, T) = 12 – 4 + 11 = 19c(S, T) = 12 + 14 = 26

Page 25: Flow Networks zichun@comp.nus.edu.sg. Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut

Let f be a flow in a flow network G with source s and sink t, and let (S, T) be a cut of G. Then the net flow across (S, T) is f(S, T) = |f|

HomomorphismFlow ConservationHomomorphism

Flow ConservationDefinition

Page 26: Flow Networks zichun@comp.nus.edu.sg. Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut

|𝑓 |= 𝑓 (𝑆 ,𝑇 )The value of any flow f in a flow network G is bounded by the capacity of any cut of G

Page 27: Flow Networks zichun@comp.nus.edu.sg. Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut

Min-Cut Max-Flow

1. f is a maximum flow in G2. The residual network Gf contains no

augmenting path3. |f|= c(S, T) for some cut (S, T) of G

Page 28: Flow Networks zichun@comp.nus.edu.sg. Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut

(1 )⇒(2)1. Premise: f is a max-flow in G2. Assume Gf has augmenting path p

3. We can augment Gf with p to get a flow f’ > f– Contradicts [1]

• Hence Gf has no augmenting paths

Page 29: Flow Networks zichun@comp.nus.edu.sg. Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut

(2 )⇒(3)1. Premise: Gf has no augmenting paths

2. Let

1. T = V-S

3. (S, T) is a cut

1. Otherwise

Page 30: Flow Networks zichun@comp.nus.edu.sg. Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut

(3 )⇒(1)

1. , |f| is maximum

The value of any flow f in a flow network G is bounded by the capacity of any cut of G

Page 31: Flow Networks zichun@comp.nus.edu.sg. Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut

Ford-Fulkerson

flow=0while(augmenting path p)) { augment flow f along p}return flow

Termination: Gf has no augmenting path iff flow is maximum

Page 32: Flow Networks zichun@comp.nus.edu.sg. Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut

Run-time

flow=0while(augmenting path p)) { augment flow f along p}return flow

O(E|f*|) where |f*| is the maximum flow

Page 33: Flow Networks zichun@comp.nus.edu.sg. Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut

s

v1

v2

t1

1,000,000 1,000,000

1,000,0001,000,000

Page 34: Flow Networks zichun@comp.nus.edu.sg. Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut

s

v1

v2

t1

1,000,000 1,000,000

1,000,0001,000,000

Page 35: Flow Networks zichun@comp.nus.edu.sg. Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut

s

v1

v2

t1

999,999 1,000,000

1,000,0001,000,000

1

1

Page 36: Flow Networks zichun@comp.nus.edu.sg. Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut

s

v1

v2

t1

999,999 1,000,000

1,000,0001,000,000

1

1

Page 37: Flow Networks zichun@comp.nus.edu.sg. Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut

s

v1

v2

t1

999,999 999,999

1,000,000999,999

1

11

1

Page 38: Flow Networks zichun@comp.nus.edu.sg. Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut

s

v1

v2

t1

999,999 999,999

1,000,000999,999

1

11

1

Page 39: Flow Networks zichun@comp.nus.edu.sg. Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut

Edmunds Karp

flow=0while(augmenting path p)) { find augmenting path by BFS augment flow f along p}return flow

Run-time: O(VE2)

Page 40: Flow Networks zichun@comp.nus.edu.sg. Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut

s

v1

v2

v3

v4

tFact

ory

Warehouse

11

5

12

15

411

811

4 7

5

3

0

5

3

00

5

Critical Edge

Page 41: Flow Networks zichun@comp.nus.edu.sg. Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut

s

v1

v2

v3

v4

tFact

ory

Warehouse

11

5

12

15

411

811

4 7

5

3

0

5

3

00

5

Critical Edge

Lemma: Edges can be critical at most times

Page 42: Flow Networks zichun@comp.nus.edu.sg. Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut

s

v1

v2

v3

v4

tFact

ory

Warehouse

11

5

12

15

411

811

4 7

5

3

0

5

3

00

5

𝛿 𝑓 (𝑢 ,𝑣 )≔ h𝑠 𝑜𝑟𝑡𝑒𝑠𝑡− h𝑝𝑎𝑡 h𝑙𝑒𝑛𝑔𝑡 𝑓𝑟𝑜𝑚𝑢→𝑣

Page 43: Flow Networks zichun@comp.nus.edu.sg. Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut

𝛿 𝑓 (𝑢 ,𝑣 )≔ h𝑠 𝑜𝑟𝑡𝑒𝑠𝑡− h𝑝𝑎𝑡 h𝑙𝑒𝑛𝑔𝑡 𝑓𝑟𝑜𝑚𝑢→𝑣1. Assume (u, v) is a critical edge2. Augmenting-paths are shortest path [by EK]3. [from 1]4. After flow-augmentation, cf(u,v) = 0• (u, v) cannot be critical path until another

augmenting path containing (v, u).• Let the flow at this point be f’5.

6. i.e, each time (u, v) is augmenting-path, path length increases by 2

7. (u, v) can be critical edge at most times

Page 44: Flow Networks zichun@comp.nus.edu.sg. Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut

Lemma: Edges can be critical at most times

Since there are O(E) edges, the number of augmenting path is bounded by O(VE) [by Lemma].

Run-time: O(VE2)

Page 45: Flow Networks zichun@comp.nus.edu.sg. Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut

Bipartite Matching

Page 46: Flow Networks zichun@comp.nus.edu.sg. Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut

Bipartite Matching

Page 47: Flow Networks zichun@comp.nus.edu.sg. Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut

Bipartite Matching MaxFlow

s t

Page 48: Flow Networks zichun@comp.nus.edu.sg. Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut

Bipartite Matching MaxFlow

s t