chapter 26 maximum flow how do we transport the maximum amount data from source to sink? some of...

76
Chapter 26 Maximum Flow ow do we transport the maximum amount data from source to sin Some of these slides are adapted from Lecture Notes of Kevin Wa

Upload: arline-baker

Post on 25-Dec-2015

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Chapter 26

Maximum Flow

How do we transport the maximum amount data from source to sink?

Some of these slides are adapted from Lecture Notes of Kevin Wayne.

Page 2: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Contents

Contents. Maximum flow problem. Minimum cut problem. Max-flow min-cut theorem. Augmenting path algorithm. Capacity-scaling. Shortest augmenting path.

Page 3: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Networks

communication

Network

telephone exchanges,computers, satellites

Nodes Arcs

cables, fiber optics,microwave relays

Flow

voice, video,packets

circuitsgates, registers,processors

wires current

mechanical joints rods, beams, springs heat, energy

hydraulicreservoirs, pumpingstations, lakes

pipelines fluid, oil

financial stocks, currency transactions money

transportationairports, rail yards,street intersections

highways, railbeds,airway routes

freight,vehicles,passengers

chemical sites bonds energy

biological genes pathways interactions

Page 4: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Max flow and min cut.Two very rich algorithmic problems.Cornerstone problem in combinatorial

optimization.Beautiful mathematical duality.

Nontrivial applications / reductions.Network connectivity.Bipartite matching.Data mining. Image processing. Airline scheduling.Project selection.Network reliability.

Security of statistical data.

Distributed computing.

Egalitarian stable matching.

Distributed computing.

Computational biology.

Many many more . . .

Maximum Flow & Minimum Cut

Page 5: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Flow network: G = (V, E, s, t, c). (V, E) = weighted directed graph. Two distinguished vertices (nodes):

s=source, t=sink. c(u,v) = capacity of edge (arc) e=(u,v).

Flow Network

Capacity

s

2

3

4

5

6

7

t

15

5

30

15

10

8

15

9

6 10

10

10 15 4

4

Page 6: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

A positive s-t flow is a func. p: V ´ V ® R that satisfies: For all u, v Î V: 0 p(u,v) c(u,v) (capacity

constrain)

For all u V–{s, t}: (flow conservation)

(flows out) (flows in)

Positive Flows

VvVv

uvpvup ),(),(

s

2

3

4

5

6

7

t

15

5

30

15

10

8

15

9

6 10

10

10 15 4

4

4

0

0

0

0

0 0

0 4 4

04 0

00Capacity

Flow

Page 7: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Positive Flows A positive s-t flow is a func. p: V ´ V ® R that satisfies: For all u, v Î V: 0 p(u,v) c(u,v) (capacity

constrain) For all u V–{s, t}: (flow

conservation)

(flows out) (flows in)MAX FLOW: positive s-t flow that maximizes net flow out of the source.

VvVv

uvpvup ),(),(

Vv

vspp ),(

0

Value = 4

Capacity

0

s

2

3

4

5

6

7

t

15

5

30

15

10

8

15

9

6 10

10

10 15 4

4

4 0

0

0 0

0 4 4

04 0

00

Flow

Page 8: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Positive Flows A positive s-t flow is a func. p: V ´ V ® R that satisfies: For all u, v Î V: 0 p(u,v) c(u,v) (capacity

constrain) For all u V–{s, t}: (flow

conservation)

(flows out) (flows in) MAX FLOW: find positive s-t flow that maximizes net flow out of the source.

VvVv

uvpvup ),(),(

Vv

vspp ),(

s

2

3

4

5

6

7

t

15

5

30

15

10

8

15

9

6 10

10

10 15 4

4

10

6

6

11

11

1 10

3 8 8

04 0

Value = 2400

Capacity

Flow

Page 9: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Positive Flows A positive s-t flow is a func. p: V ´ V ® R that satisfies: For all u, v Î V: 0 p(u,v) c(u,v) (capacity

constrain) For all u V–{s, t}: (flow

conservation)

(flows out) (flows in) MAX FLOW: positive s-t flow that maximizes net flow out of the source.

VvVv

uvpvup ),(),(

Vv

vspp ),(

s

2

3

4

5

6

7

t

15

5

30

15

10

8

15

9

6 10

10

10 15 4

4

10

9

9

14

14

4 10

4 8 9

10 0

Value = 2800

Capacity

Flow

Page 10: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Maximum flow problem

Maximize the flow over a flow network.

s

2

3

4

5

6

7

t

15

5

30

15

10

8

15

9

6 10

10

10 15 4

4

10

9

9

14

14

4 10

4 8 9

10 0

Value = 2800

Capacity

Flow

Page 11: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Problem formulation

Page 12: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Net flow Net flow

Graph G=(V,E) – a flow network Directed, each edge has capacity c(u,v) ³ 0 Two special vertices: source s, and sink t For any other vertex v, there is a path s®…®v®…®t

A (net) s-t flow is a func. f : V ´ V ® R that satisfies Capacity constraint: For all u, v Î V: f(u,v) £

c(u,v) Skew symmetry: For all u, v Î V: f(u,v) = –

f(v,u) Flow conservation: For all u Î V – {s, t}:

, or( , ) ( , ) 0

( , ) ( , ) 0v V

v V

f u v f u V

f v u f V u

Page 13: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Cancellation of flows

Do we want to have flows going in both directions between two vertices? No! such flows cancel (maybe partially)

each other Skew symmetry – notational

convenience

13

11

54

15

10

14

19

3

s t9

a b

c d

2 5

3

3

6

6

13

11

54

15

10

14

19

3

s t9

a b

c d

3

3

3

6

6

Page 14: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Equivalence of Definitions

Define net flow in terms of positive flows

f(u, v) = p(u, v) - p(v, u)

How do we know f defined this way is a net flow?

Capacity constrain Flow conservation Skew symmetry

Page 15: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Equivalence of Definitions

Define positive flow in terms of net flow

p(u, v) = f(u, v) if f(v, u) >0 = 0 o.w.

How do we know p defined this way is a positive flow?

Capacity constrain Flow conservation

In literature, 2 views of flow are used. The current version (3rd edition) of our book uses positive flow.

Page 16: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Flow conservation Define positive flow in terms of net flow

p(u, v) = f(u, v) if f(v, u) >0 = 0 o.w.

0),(

),(),(

show toNeed

Vv

VvVv

vuf

Given

uvpvup

0),(),(

),(),(

),(),(

0),(0),(

0),(0),(

VvVv

vufVv

vufVv

vufVv

vufVv

uvpvup

uvpvup

vufvuf

Page 17: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Implicit Summation Notation

Function over sets summation:

Flow conservation for positive flow:

Flow conservation for net flow:

},{ ),,(),( tsVuuVpVup

YyXx

yxfYXf ),(),(

},{ ,0),( tsVuVuf

Page 18: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Flow Conservation Theorem

proof: ?

( , ) ( , ) ( , )v V

f f s v f s V f V t

s

2

3

4

5

6

7

t

15

5

30

15

10

8

15

9

6 10

10

10 15 4

4

10

9

9

14

14

4 10

4 8 9

10 0

Value = 2800

Capacity

Flow

28 28

Page 19: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Lemma G = (V,E) is a flow network. f is a net flow

in G. f (X,X) = 0, X, Y V f (X,Y) = − f (Y,X), X, Y V f (XY, Z) = f (X,Z)+ f (Y,Z), X,Y,ZV & XY= f (Z, XY) = f (Z,X)+ f (Z,Y), X,Y,ZV & XY=

Proof: …

Page 20: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Flow Conservation Theorem

proof:

. ),(

),(),(

}),{,(),(

),(

),(),(),(

},{

tVf

uVftVf

tsVVftVf

sVVf

VsVfVVfVsff

tsVu

( , ) ( , ) ( , )v V

f f s v f s V f V t

).,(),(

)},{}({),(0

VsVfVsf

VssVfVVf

Flow conservation

Page 21: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

An s-t cut is a node partition (S, T) s.t. s S, t T. The capacity of an s-t cut (S, T) is:

Min s-t cut: find an s-t cut of minimum capacity.

Cuts

Vvu

TvSu

vuc

,,

).,(

s

2

3

4

5

6

7

t

15

5

30

15

10

8

15

9

6 10

10

10 15 4

4

Capacity = 30

Page 22: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Cuts An s-t cut is a node partition (S, T) s.t. s S, t T. The capacity of an s-t cut (S, T) is:

Min s-t cut: find an s-t cut of minimum capacity.

s

2

3

4

5

6

7

t

15

5

30

15

10

8

15

9

6 10

10

10 15 4

4

Capacity = 62

Vvu

TvSu

vuc

,,

).,(

Page 23: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Cuts An s-t cut is a node partition (S, T) s.t. s S, t T. The capacity of an s-t cut (S, T) is:

Min s-t cut: find an s-t cut of minimum capacity.

Vvu

TvSu

vuc

,,

).,(

s

2

3

4

5

6

7

t

15

5

30

15

10

8

15

9

6 10

10

10 15 4

4

Capacity = 28

Page 24: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Recall the example

s

2

3

4

5

6

7

t

15

5

30

15

10

8

15

9

6 10

10

10 15 4

4

10

9

9

14

14

4 10

4 8 9

10 0

Value = 2800

Capacity

Flow

Page 25: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Lemma 1. Let f be a net flow, and let (S, T) be a cut. Then, the net flow sent across the cut is equal to the amount reaching t.

Flows and Cuts

Value = 24

s

2

3

4

5

6

7

t

15

5

30

15

10

8

15

9

6 10

10

10 15 4

4

10

6

6

10

10

0 10

4 8 8

0

4 0

00

Page 26: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Flows and Cuts

10

6

6

10

10

0 10

4 8 8

04 0

00

s

2

3

4

5

6

7

t

15

5

30

15

10

8

15

9

6 10

10

10 15 4

4

Value = 24

Lemma 1. Let f be a flow, and let (S, T) be a cut. Then, the net flow sent across the cut is equal to the amount reaching t.

Page 27: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Flows and Cuts

Value = 24

Lemma 1. Let f be a flow, and let (S, T) be a cut. Then, the net flow sent across the cut is equal to the amount reaching t.

10

6

6

10

10

0 10

4 8 8

04 0

0

s

2

3

4

5

6

7

t

15

5

30

15

10

8

15

9

6 10

10

10 15

4 0

4

Page 28: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Proof of the Lemma 1 For any flow f , the flow across any

cut (S, T) is the flow value | f |, i.e. f (S, T) = | f | = f (s, V).

Proof:f (S, T) = f (S, V−S) = f (S, V) –

f (S, S) = f (s, V) + f (S-s, V) = | f |.

(flow conservation)

(lemma 1)

Page 29: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Flows and CutsLemma 2. f is a flow & (S, T) is a cut. Then |f| c(S, T).

Proof.

Corollary. Let f be a flow, and let (S, T) be a cut. If |f| = c(S, T), then f is a max flow and (S, T) is a min cut.

s

t

S T

7

6

84

Su Tv

Su Tv

TScvuc

vufTSff

),(),(

),(),(||

Page 30: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Max Flow and Min Cut

Corollary. Let f be a flow, and let (S, T) be a cut. If |f| = c(S, T), then f is a max flow and (S, T) is a min cut.

Flow value = 28

s

2

3

4

5

6

7

t

15

5

30

15

10

8

15

9

6 10

10

10 15 4

4

10

9

9

14

14

4 10

4 8 9

1

0 0

00

Cut capacity = 62

Page 31: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Max Flow and Min Cut

Corollary. Let f be a flow, and let (S, T) be a cut. If |f| = c(S, T), then f is a max flow and (S, T) is a min cut.

Flow value = 28

s

2

3

4

5

6

7

t

15

5

30

15

10

8

15

9

6 10

10

10 15 4

4

10

9

9

14

14

4 10

4 8 9

1

0 0

00

Cut capacity = 28

Page 32: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Summary

Lemma 1. Let f be a flow, and let (S, T) be a cut. Then, the net flow sent across the cut is equal to the amount reaching t.

Lemma 2. f is a flow & (S, T) is a cut. Then |f| c(S, T).Corollary. Let f be a flow, and let (S, T)

be a cut. If |f| = c(S, T), then f is a max flow and (S, T) is a min cut.

Page 33: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Contents

Maximum flow problem. Minimum cut problem. Max-flow min-cut theorem. Augmenting path algorithm. Capacity-scaling. Shortest augmenting path.

Page 34: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Max-Flow Min-Cut Theorem

MAX-FLOW MIN-CUT THEOREM (Ford-Fulkerson, 1956): In any network, the value of the max flow is equal to the value of the min cut.Proof: ?

Flow value = 28

s

2

3

4

5

6

7

t

15

5

30

15

10

8

15

9

6 10

10

10 15 4

4

10

9

9

14

14

4 10

4 8 9

1

0 0

00

Cut capacity = 28

Page 35: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Flow value = 0

s

4

2

5

3 t

4

0 0

0 0 0

0

40

4 4

10 13 10

Towards an Algorithm Find an s-t path where each edge e=(u,v) has c(e) > f(e) and "augment" flow along the path.

Page 36: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Towards an Algorithm Find an s-t path where each arc e=(u,v) has c(e) > f(e) and "augment" flow along the path. Repeat until you get stuck.

Flow value = 10

s

4

2

5

3 t

4

0 0

0 0 0

0

40

4 4

10 13 1010 10 10

A Greedy AlgorithmThe design of this algorithm?

Page 37: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Towards an Algorithm Find an s-t path where each arc has u(e) > f(e) and "augment" flow along the path. Repeat until you get stuck. The straight forward greedy algorithm fails. Flow value = 10

s

4

2

5

3 t 10 13 10

4

0 00

40

4 4

10 10 10

Flow value = 14

s

4

2

5

3 t 10 13 10

4 4

4 4

10

4 4

106

4

4

Page 38: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Residual Network Let f be a flow on G = (V, E). The residual

network Gf = (V, Ef ) is the graph with strictly positive residual capacities:

cf (u,v) = c(u,v)−f (u,v) > 0, (where f (u,v) >0)

Ef = {(u,v)VV| cf (u,v)>0}. Gf contains edges of G that can admit more net

flow.(Gf GGT, where GT has G’s edges in reverse.)

s

2

3

5

6

t 5

11

11

5

4

15

5 12 5

8 3

41

79

s

2

3

5

6

t

13

16

14

9

12

4

20

7

11

12

15

811

4

4

7110

flow network and flow f

residual network

Page 39: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Residual Arcs Original graph G = (V, E). Flow f(u,v). Arc e = (u, v) E.

Residual graph: Gf = (V, Ef ). Residual arcs e = (u, v) and eR = (v, u). "Undo" flow sent.

u v 17

6

Capacity

Flow

u v 11

Residual capacity

6

Residual capacity

Page 40: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Residual Graph & Augmenting Paths

Residual graph: Gf = (V, Ef ).

s

4

2

5

3 t 10 13 10

4

4

4 4G

s

4

2

5

3 t 10 10 10

4

4

4 4

3

Gf

10 10 10

Page 41: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

s

4

2

5

3 t 10 13 10

4

4

4 4G

s

4

2

5

3 t 10 10 10

4

4

4 4

3

Gf

10 10 10

Augmenting Path Augmenting path = path in residual graph.

Page 42: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Relation between flows on G & Gf

Lemma: Let f be a flow on G=(V,E), f ’ be a flow on the residual network Gf of G. Then the flow sum (f +f ’)(u,v) f (u,v)+f ’(u,v) is a flow on G and |f +f ’|=|f |+|f ’|.

Proof: f +f ’ is a flow on G (flow conservation, capacity constrain, skew

symmetry)

|f +f ’| = |f |+|f ’|

.|'|||

),('),(

),)('(|'|

ff

vsfvsf

vsffff

Vv Vv

Vv

Page 43: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Augmenting Path Augmenting path = path in residual graph. Max flow no augmenting paths ???

s

4

2

5

3 t 10 13 10

4

4

4 4G

s

4

2

5

3 t 10 10 10

4

4

4 4

3

Gf

10 10 10

Flow value = 14

Page 44: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Max-Flow Min-Cut Theorem

Augmenting path theorem (Ford-Fulkerson, 1956): A flow f is a max flow if and only if there are no augmenting paths.

MAX-FLOW MIN-CUT THEOREM (Ford-Fulkerson, 1956): the value of the max flow is equal to the value of the min cut.

We prove both theorems simultaneously by showing the TFAE: (i) f is a max flow. (ii) There is no augmenting path relative to f. (iii) There exists a cut (S, T) such that |f| = c(S,

T).

Page 45: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Proof We prove both simultaneously by showing the TFAE: (i) f is a max flow. (ii) There is no augmenting path relative to f. (iii) There exists a cut (S, T) such that |f| = c(S,

T).

(i) (ii) Let f be a flow. If there exists an augmenting path, then we

can improve f by sending flow along path. (proof by contradiction)

(iii) (i) This was the Corollary to Lemma 2.

Page 46: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Proof (ii) (iii)Let f be a flow with no augmenting paths. Let S be set of vertices reachable from s in

residual graph. Let T=V−S. Is t T. ?

(clearly s S, and t S by definition of f , o.w. augmenting path)

For each u S, v T, f (u,v) = c(u,v). ? (o.w. cf (u,v)=c(u,v)−f (u,v)>0, then v S).

Therefore: ?|f | = f (S,T) = c(S,T).

Residual Network

s

t

S T

Page 47: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Ford-Fulkerson algorithm

Let G=(V, E) be a flow network.

Ford-Fulkerson(G,s,t,c) 01 for each edge (u,v) in E do 02 f(u,v) ¬ f(v,u) ¬ 0 03 while there exists a path p from s to t in residual network Gf do04 cf = min{cf(u,v): (u,v) is in p} 05 for each edge (u,v) in p do06 f(u,v) ¬ f(u,v) + cf

07 f(v,u) ¬ -f(u,v)08 return f

Cost?

(E)

(V+E)depth first search orbreadth first search

(E)

( ? )

Page 48: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Performance

If capacities are integers, O(|E|f *), f *

is max flow found by the algorithm (not a polynomial algorithm).

Example: 1000

0

s

4

2

t 1

100

100

0

0

0

100

Page 49: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Performance

1001

s

4

2

t 1

100

100

1

1100

Original network and flow1

99

s

4

2

t 1

99

99

0

1100

1

0

Residual network

Page 50: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Performance

Maximum flow: 200

100

s

4

2

t

100

1

1

0

1

1100

100

1

200 iterations possible.

Net flow: 2.

Page 51: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Performance

For noninteger capacities, might never terminate.

Need more efficient algorithm (Edmonds-Karp, 1972): Augment along breadth-first augmenting

path in Gf (shortest path) Augment along max-capacity

augmenting path in Gf (capacity-scaling)

Page 52: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

BFS for Shortest Paths

Finished Discovered Undiscovered

S2

2

2

2

22

S

3

3 3

3

3

S11

1

Data structure for BFS?

Page 53: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Edmonds-Karp Algorithm

Takes only two iterations.

100 100

100 100100

s

4

2

t 1

100

100

100

Page 54: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Shortest Augmenting Path

Intuition: choosing path via breadth first search. Easy to implement.

may implement by coincidence! Finds augmenting path with fewest number of

arcs.

FOREACH e E f(e) 0Gf residual graph

WHILE (there exists augmenting path) //find such a path P by BFS f augment(f, P) update GfRETURN f

ShortestAugmentingPath(V, E, s, t)

Cost?

Page 55: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Shortest Augmenting Path: Overview of

AnalysisLemma1. Throughout the algorithm, the length of the shortest path increases. Proof ahead.

Lemma2. After at most |E| shortest path augmentations, the length of the shortest augmenting path increases at least by one. Proof ahead.

Theorem. The shortest augmenting path algorithm runs in O(|V||E|2) time. O(|V|+|E|) time to find a shortest augmenting path via

BFS. O(|E| + |E||V|) augmenting paths. (lemma 2)

(If there is an augmenting path, it must be a simple one.)

Þ O(|V||E|) augmentations.Þ O((|V|+|E|)*(|V||E|)) = O(|V||E|2) running time.

Page 56: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Shortest Augmenting Path: Analysis

Level graph of (V, E, s). For each vertex v, define (v) to be the length (number of

edges) of shortest path from s to v. LG = (V, EG) is subgraph of G that contains only those edges

(v, w) E

with (w) = (v) + 1.

s

2

3

5

6 t

= 0 = 1 = 2 = 3

LG:

s

2

3

5

6 t

G:

Page 57: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Shortest Augmenting Path: Analysis

Level graph of (V, E, s). For each vertex v, define (v) to be the length of shortest

path from s to v. L = LG = (V, F) is subgraph of G that contains only those

edges (v,w) E with (w) = (v) + 1.

Compute in O(|V|+|E|) time using BFS, deleting back and side edges.

P is a shortest s-v path in G if and only if it is an s-v path in L.

s

2

3

5

6 t

= 0

= 1

= 2

= 3

L:

Page 58: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Shortest Augmenting Path: Analysis

Lemma1. the length of the shortest path increases. Let f and f' be flow before and after a shortest path

augmentation. Let L and L' be level graphs of residual network Gf and Gf '

Only back edges added to Gf ' path with back edge has length greater than previous length

s

2

3

5

6 t

= 0 = 1 = 2 = 3

L

s

2

3

5

6 t

L'

Page 59: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Shortest Augmenting Path: Analysis

Lemma2. After at most |E| shortest path augmentations, the length of the shortest augmenting path strictly increases. At least one edge (the bottleneck edge) is deleted from L

after each augmentation. No new edges added to L until length of shortest path to t

strictly increases.

s

2

3

5

6 t

= 0 = 1 = 2 = 3

L

s

2

3

5

6 t

L'

Length=3

Length=3

Page 60: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Shortest Augmenting Path: Review of AnalysisTheorem. The shortest augmenting path algorithm runs in O(|V||E|2) time. O(|V|+|E|) time to find a shortest augmenting path via

BFS. O(|V||E|) augmentations.Þ O((|V|+|E|)*(|V||E|)) = O(|V||E|2) running time.

More rigorous proof is given in our textbook.

Other approaches: Augment along max-capacity augmenting path in Gf

(capacity-scaling)

Page 61: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Capacity Scaling Intuition: choosing path with highest bottleneck capacity increases flow by max possible amount. In practice, don't worry about finding exact highest

bottleneck path. Maintain scaling parameter . Let Gf () be the subgraph of the residual graph consisting

of only arcs with capacity at least .

110

s

4

2

t 1

170

102

122

Gf

110

s

4

2

t

170

102

122

Gf (100)

Page 62: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Capacity Scaling Assumption: all capacities are integers

between 0 & U.

FOREACH e E, f(e) 0(smallest power of 2 greater than or equal to U)/2

WHILE ( 1) Gf() -residual graph WHILE (there exists augmenting path P in Gf()) f augment(f, P) update Gf() / 2 RETURN f

ScalingMaxFlow(V, E, s, t)

Theorem. The algorithm runs in O(|E|2 log (2U) ) time.

Page 63: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Capacity Scaling: Analysis

L1. If all edges capacities are integers, then throughout the algorithm, all flow and residual capacity values remain integers. Thus, = 1 Gf() = Gf , so upon termination f is a max flow.

L2. The outer while loop repeats 1 + log2 U times. Initially U/2 < U, and decreases by a factor of 2 each

iteration.

L3. Let f be the flow at the end of a -scaling phase. Then value of the maximum flow is at most | f |+| E |. (proof ahead)

L4. There are at most 2|E| augmentations per scaling phase. Let f be the flow at the end of the previous scaling phase. L3 |f*| | f | + |E| (2). Each augmentation in a -phase increases | f | by at least .

Theorem. The algorithm runs in O(|E|2 log (2U) ) time.

Page 64: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Capacity Scaling: Analysis

L3. Let f be the flow at the end of a -scaling phase. Then value of the maximum flow is at most |f| + |E| . We show that at the end of a -phase, there exists a cut (S,

T) such that c(S, T) | f | + |E| . Choose S to be the set of nodes reachable from s in Gf().

clearly s S, and t S by definition of S

Δ|E|-T)c(S,

)v,s(c

))v,s(c(

)s,v(f)v,s(ff

VvVvVv

VvVv

VvVv

s

t

Original Network

S T

Page 65: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Choosing Good Augmenting Paths:

Summary

First 4 rules assume edge capacities are between 0 and U.

Method Augmentations

Augmenting path |V|U

Max capacity |E| log U

Capacity scaling |E| log U

Shortest path |E||V|

Running time

|E||V|U

|E| log U (|E| + |V| log |V|)

|E|2 log U

|E|2|V|

Improved shortest path |E||V| |E||V|2

Improved capacity scaling |E| log U |E||V| log U

Page 66: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

History

Dantzig

Discoverer

Simplex

Method Big-Oh

|E||V|2U1951

Year

Ford, Fulkerson Augmenting path |E||V|U1955

Edmonds-Karp Shortest path |E|2|V|1970

Dinitz Shortest path |E||V|21970

Edmonds-Karp, Dinitz Capacity scaling |E|2 log U1972

Dinitz-Gabow Capacity scaling |E||V| log U1973

Karzanov Preflow-push |V|31974

Sleator-Tarjan Dynamic trees |E||V| log |V|1983

Goldberg-Tarjan FIFO preflow-push |E||V| log (|V|2 / |E|)1986

. . . . . . . . .. . .

Goldberg-Rao Length function|E|3/2 log (|V|2 / |E|) log U

|E||V|2/3 log (|V|2 / |E|) log U1997

Page 67: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Network with multiple sources and sinks

Can be reduced to a single source & single sink max problem

15

14

19

30

s1 t1

a b

c d

11

1

9

13

s2 t2

e b

f d

5

4

12

23

s3 t3

g b

h d

k9 4s t

Page 68: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Maximum bipartite matching

Bipartite graph G=(V,E): Undirected V = V1V2, V1V2=. e=(u, v)E, uV1 and vV2

Complete bipartite: u V1, u is joined with every v V2

Matching: set of edges with no vertex included twice

Maximum matching: a matching of maximum cardinality i.e. no matching contains more edges

Page 69: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Applications

Dating assignment L – women, R – men. An edge between vertices: they have a chance

to be “compatible” (can be matched) Job placement

Companies make job offers Students have job choices An edge between vertices: the student can fit

the job

Page 70: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Example Problem: Given N men and M women, find

a matching between men and women. Participants list members of opposite sex they

like to date.

Zeus Amy Diane

Yancey Amy ClareDiane

Xavier Amy ClareErika

Wyatt Diane AmyBertha

Victor Diana Amy

Man 1st 2nd 3rd

Men’s Preference List

Can we find a perfect match? What is the max match?

Page 71: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Example Problem: Job placement

Can we find a perfect match? What is the max match?

Eliza IBM GoogleSun

Dave Apple Dell

Carol HP SunIBM

Bob Apple GoogleDell

Alice Apple HPDell

Student 1st 2nd 3rd

Students Preference List

Frank HP GoogleSun

Page 72: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Maximum bipartite matching

How can we reformulate this problem to become a max-flow problem?

Page 73: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Maximum bipartite matching

How can we reformulate this problem to become a max-flow problem? Keep all edges & vertices Add source connected to all vertices in one set Add sink connected to all vertices in another

set Set all capacities to 1

Theorem: The set of edges in the maxflow solution gives the solution to the maximum matching problem. Proof homework

Page 74: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Matching

s t

A

D

B

C

E

F

A

I

D

H

S

G

Eliza Sun

Dave Apple

Carol IBM

Bob Dell

Alice HP

Student 1st 2nd 3rd

Solution

Frank Google

111

1

1

1

11 1

11

1 11

1 1

1 1

11

1

111111

Page 75: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

LemmaLemma 1:

Let G=(V,E), V = V1V2, V1V2=.Let G’=(V’,E’), V’ = V{s,t}, E’=…. flow networkThen: If M is a matching, then there is an integer valued flow f on

G’ with |f|=|M|. If f is an integer valued flow on G’, then there is a matching

M on G with cardinality |M|=|f|Proof:

M →f, s.t.|f|=|M|If (u,v)M, define: f(s,u)=f(u,v)=f(v,t)=1; f(u,s)=f(v,u)=f(t,v)=-1; (u,v)M, f(u,v)=0,then f is a flow and |f|=|M| ?

f →M, s.t.|M|=|f|since f is an integer valued flow, f(u,v)=1 or 0.|M|=f(V1’, V2’) = |f|

(skew symmetry, capacity constraints, flow conservation)

Page 76: Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin Wayne

Integrality TheoremIntegrality Theorem: If the capacity of a flow

network is an integer function, maximum flow f produced by Ford-Fulkerson method is an integer-valued flow.

Proof: homework

Corollary: If |M| is the cardinality of a maximum matching M, then the value of a maximum flow f = |M|.

Proof: ? Show contrapositive.suppose M is a max matching and f is not a max flow,

i.e. f ’,s.t.|f ’|>|f|Then M’, s.t.|M’|=|f ’|>|f|=|M|Contradicting our assumption that M is a

maximum matching.