www.monash.edu.au 1 commonwealth of australia copyright regulations 1969 warning this material has...

30
www.monash.edu.au 1 COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University pursuant to Part VB of the Copyright Act 1968 (the Act). The material in this communication may be subject to copyright under the Act. Any further reproduction or communication of this material by you may be the subject of copyright protection under the Act. Do not remove this notice.

Upload: erica-jones

Post on 18-Dec-2015

218 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Www.monash.edu.au 1 COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf

www.monash.edu.au

1

COMMONWEALTH OF AUSTRALIA

Copyright Regulations 1969

WARNING

This material has been reproduced and communicated to you by or on behalf of Monash University pursuant to

Part VB of the Copyright Act 1968 (the Act). The material in this communication may be subject to copyright under

the Act. Any further reproduction or communication of this material by you may be the subject of copyright protection under the Act. Do not remove this notice.

Page 2: Www.monash.edu.au 1 COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf

www.monash.edu.au

FIT2004

Algorithms & Data Structures L15: Flow Problems

Prepared by: Bernd Meyer April 2007

Page 3: Www.monash.edu.au 1 COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf

www.monash.edu.au

3

Maximum Flow and Minimum Cut

• Max flow and min cut.– MaxFlow: determine the maximum possible flow from a

source node a to a sink node b in some capacity-limited transport network

– Min cut is dual to max flow.– Fundamental problems in combinatorial optimization.

• Many other problems reduce to max flow– scheduling (airlines, trains etc.)– transportation problems– matching problems– network routing– etc.

Page 4: Www.monash.edu.au 1 COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf

www.monash.edu.au

4

• single commodity transport network.• directed graph G = (V, E), no parallel edges.• s = source, t = sink.• c(e) = capacity of edge e.

Flow Networks

s

2

3

4

5

6

7

t

15

5

30

15

10

8

15

9

6 10

10

10

15 4

4capacity

source sink

Page 5: Www.monash.edu.au 1 COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf

www.monash.edu.au

5

• An s-t cut is a partition (A, B) of V with s A and t B. Its capacity is:

Cuts

Capacity = 10 + 5 + 15 = 30

s

2

3

4

5

6

7

t

15

5

30

15

10

8

15

9

6 10

10

10

15 4

4

A

cap( A, B) = c(e)e out of A

Page 6: Www.monash.edu.au 1 COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf

www.monash.edu.au

6

• An s-t cut is a partition (A, B) of V with s A and t B. Its capacity is:

Cuts

s

2

3

4

5

6

7

t

15

5

30

15

10

8

15

9

6 10

10

10

15 4

4

A

cap( A, B) = c(e)e out of A

Capacity = 9 + 15 + 8 + 30 = 62

Page 7: Www.monash.edu.au 1 COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf

www.monash.edu.au

7

• Find an s-t cut of minimum capacity.

Minimum Cut Problem

s

2

3

4

5

6

7

t

15

5

30

15

10

8

15

9

6 10

10

10 15 4

4 A

Capacity = 10 + 8 + 10 = 28

Page 8: Www.monash.edu.au 1 COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf

www.monash.edu.au

8

• An s-t flow is a function that satisfies:– (capacity) For each e E:

– (conservation) For each v V – {s, t}:

• The value of a flow f is:

Flows

Value = 4

f (e)e in to v

∑ = f (e)e out of v

0 ≤ f (e) ≤ c(e)

v( f ) = f (e) e out of s

∑ .

4

0

0

0

0 0

0 4 4

00

0

0

capacityflow

s

2

3

4

5

6

7

t

15

5

30

15

10

8

15

9

6 10

10

10

15 4

4 0

4

Page 9: Www.monash.edu.au 1 COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf

www.monash.edu.au

9

• An s-t flow is a function that satisfies:– (capacity) For each e E:

– (conservation) For each v V – {s, t}:

• The value of a flow f is:

Flows

Value = 24

f (e)e in to v

∑ = f (e)e out of v

0 ≤ f (e) ≤ c(e)

v( f ) = f (e) e out of s

∑ .

10

6

6

11

1 10

3 8 8

00

0

11

capacityflow

s

2

3

4

5

6

7

t

15

5

30

15

10

8

15

9

6 10

10

10 15 4

4 0

4

Page 10: Www.monash.edu.au 1 COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf

www.monash.edu.au

10

• Find s-t flow of maximum value.

Maximum Flow Problem

10

9

9

14

4 10

4 8 9

1

0 0

0

14

capacity

flow

s

2

3

4

5

6

7

t

15

5

30

15

10

8

15

9

6 10

10

10 15 4

4 0

Value = 28

Page 11: Www.monash.edu.au 1 COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf

www.monash.edu.au

11

• Flow value lemma. Let f be any flow, let (A, B) be any s-t cut. The net flow across the cut is equal to the amount leaving s.

Flows and Cuts

10 6 6

11

1 10

3 8 8

0

0

0

11

s

2

3

4

5

6

7

t

15

5

30

15

10

8

15

9

6 10

10

10 15 4

4 0

Value = 24

f (e)e out of A

∑ − f (e)e in to A

∑ = v( f )

4

A

Page 12: Www.monash.edu.au 1 COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf

www.monash.edu.au

12

• Flow value lemma. Let f be any flow, let (A, B) be any s-t cut. The net flow across the cut is equal to the amount leaving s.

Flows and Cuts

10

6

6

11

1 10

3 8 8

0

0

0

11

s

2

3

4

5

6

7

t

15

5

30

15

10

8

15

9

6 10

10

10 15 4

4 0

Value = 24

f (e)e out of A

∑ − f (e)e in to A

∑ = v( f )

4

A

Page 13: Www.monash.edu.au 1 COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf

www.monash.edu.au

13

• Flow value lemma. Let f be any flow, let (A, B) be any s-t cut. The net flow across the cut is equal to the amount leaving s.

Flows and Cuts

10

6

6

11

1 10

3 8 8

0

0

0

11

s

2

3

4

5

6

7

t

15

5

30

15

10

8

15

9

6 10

10

10 15 4

4 0

Value = 24

f (e)e out of A

∑ − f (e)e in to A

∑ = v( f )

4

A

Page 14: Www.monash.edu.au 1 COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf

www.monash.edu.au

14

Flows and Cuts

• Weak duality. Let f be any flow, and let (A, B) be any s-t cut. The value of the flow is at most the capacity of the cut.

Cut capacity = 30 Flow value 30

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

A

Page 15: Www.monash.edu.au 1 COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf

www.monash.edu.au

15

Certificate of Optimality

• Corollary. Let f be any flow, let (A, B) be any s-t cut. If v(f) = cap(A, B), then f is a max flow and (A, B) is a min cut.

Value of flow = 28Cut capacity = 28 Flow value 28

10

9

9

14

4 10

4 8 9

1

0 0

0

14

s

2

3

4

5

6

7

t

15

5

30

15

10

8

15

9

6 10

10

10 15 4

4 0A

Page 16: Www.monash.edu.au 1 COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf

www.monash.edu.au

16

Towards a Max Flow Algorithm

• Greedy algorithm.– Start with f(e) = 0 for all edge e E.

– Find an s-t path P where each edge has f(e) < c(e).

– Augment flow along path P.

– Repeat until you get stuck.s

1

2

t

10

10

0 0

0 0

0

20

20

30

Flow value = 0

Page 17: Www.monash.edu.au 1 COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf

www.monash.edu.au

17

Towards a Max Flow Algorithm

• Greedy algorithm.– Start with f(e) = 0 for all edge e E.

– Find an s-t path P where each edge has f(e) < c(e).

– Augment flow along path P.

– Repeat until you get stuck.s

1

2

t

10

10

20 0

0 20

20

20

20

30

Flow value = 20

Page 18: Www.monash.edu.au 1 COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf

www.monash.edu.au

18

Towards a Max Flow Algorithm

greedy = 20

s

1

2

t

20 10

10 20

30

20 0

0

20

20

opt = 30

s

1

2

t

20 10

10 20

30

20 10

10

10

20

This is only a local optimum!

Page 19: Www.monash.edu.au 1 COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf

www.monash.edu.au

19

Residual Graph

• Original edge: e = (u, v) E.– Flow f(e), capacity c(e).

• Residual edge.– "Undo" flow sent.– e = (u, v) and eR = (v, u).– Residual capacity:

• Residual graph: Gf = (V, Ef ).– Residual edges with positive

residual capacity.– Ef = {e : f(e) < c(e)} {eR : c(e) > 0}.

u v 17

6

capacity

u v 11

residual capacity

6

residual capacity

flow

c f (e) =c(e)− f (e) if e ∈ E

f (e) if eR ∈ E

⎧ ⎨ ⎩

Page 20: Www.monash.edu.au 1 COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf

www.monash.edu.au

20

Example 1

1 2 3

4

5

60/2 0/2

0/30/1

0/5

0/3 0/4

Augmenting path:1→2 →3 →6

flow/capacity

Page 21: Www.monash.edu.au 1 COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf

www.monash.edu.au

21

1 2 3

4

5

62/2 2/2

0/30/1

2/5

0/3 0/4

Augmenting path:1 →4 →3←2 →5 →6

Example 1 (cont.)

Page 22: Www.monash.edu.au 1 COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf

www.monash.edu.au

22

1 2 3

4

5

62 2

31

3

3 4

Augmenting path:1 →4 →3←2 →5 →6

Example 1 (cont., Residual Graph)

2

Page 23: Www.monash.edu.au 1 COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf

www.monash.edu.au

23

1 2 3

4

5

62/2 2/2

1/31/1

1/5

1/3 1/4

max flow value = 3

Example 1 (maximum flow)

Page 24: Www.monash.edu.au 1 COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf

www.monash.edu.au

24

Augmenting Path Algorithm

Augment(f, P) { b bottleneck(P) foreach e P { if (e E) f(e) f(e) + b else f(eR) f(e) - b } return f} Ford-Fulkerson(G, s, t) {

foreach e E f(e) 0 Gf residual graph

while (there exists augmenting path P) { f Augment(f, P) update Gf

} return f}

forward edge

reverse edge

Page 25: Www.monash.edu.au 1 COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf

www.monash.edu.au

25

Augmenting Path Theorem

• Augmenting path theorem. Flow f is a max flow iff 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.

Page 26: Www.monash.edu.au 1 COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf

www.monash.edu.au

26

Ford-Fulkerson: Exponential Number of Augmentations

• Q. Is generic Ford-Fulkerson algorithm polynomial in input size? (m, n, and log C)

• A. No. If max capacity is C, then algorithm can take C iterations.

s

1

2

t

C

C

0 0

0 0

0

C

C

1 s

1

2

t

C

C

1

0 0

0 0

0X 1

C

C

X

X

X

1

1

1

X

X

1

1X

X

X

1

0

1

Page 27: Www.monash.edu.au 1 COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf

www.monash.edu.au

27

Choosing Good Augmenting Paths

• Use care when selecting augmenting paths.– Some choices lead to exponential algorithms.– Clever choices lead to polynomial algorithms.

• Goal:– Can find augmenting paths efficiently.– Few iterations.

• Choose augmenting paths with: [Edmonds-Karp 1972, Dinitz 1970]

– Max bottleneck capacity but can we find this cheaply?

– Sufficiently large bottleneck capacity.– Shortest augmenting path (fewest edges)

Page 28: Www.monash.edu.au 1 COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf

www.monash.edu.au

28

Capacity Scaling

• Intuition. Choosing path with highest bottleneck capacity increases flow by max possible amount.

– 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 29: Www.monash.edu.au 1 COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf

www.monash.edu.au

29

Capacity Scaling

Scaling-Max-Flow(G, s, t, c) { foreach e E f(e) 0 smallest power of 2 greater than or equal to C Gf residual graph

while ( 1) { Gf() -residual graph while (there exists augmenting path P in Gf()) { f augment(f, P) update Gf() } / 2 } return f}

Page 30: Www.monash.edu.au 1 COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf

www.monash.edu.au

30

Capacity Scaling: Running Time

• The scaling max-flow algorithm finds a max flow in O(m log C) augmentations. It can be implemented to run in O(m2 log C) time.