1 the max flow problem 5 10 2 -2 7 1 9 4 5 11. 2 ford-fulkerson method ford-fulkerson(g) f = 0...

31
1 The max flow problem 5 10 2 -2 7 1 9 4 5 11

Post on 20-Dec-2015

235 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1 The max flow problem 5 10 2 -2 7 1 9 4 5 11. 2 Ford-Fulkerson method Ford-Fulkerson(G) f = 0 while( 9 simple path p from s to t in G f ) f := f + f

1

The max flow problem

5

10

2-2

7

1

9

4

5

11

Page 2: 1 The max flow problem 5 10 2 -2 7 1 9 4 5 11. 2 Ford-Fulkerson method Ford-Fulkerson(G) f = 0 while( 9 simple path p from s to t in G f ) f := f + f

2

Ford-Fulkerson method

Ford-Fulkerson(G)

f = 0

while(9 simple path p from s to t in Gf)

f := f + fp

output f

Page 3: 1 The max flow problem 5 10 2 -2 7 1 9 4 5 11. 2 Ford-Fulkerson method Ford-Fulkerson(G) f = 0 while( 9 simple path p from s to t in G f ) f := f + f

3

S Tc(S,T)=26

A cut

Page 4: 1 The max flow problem 5 10 2 -2 7 1 9 4 5 11. 2 Ford-Fulkerson method Ford-Fulkerson(G) f = 0 while( 9 simple path p from s to t in G f ) f := f + f

4

Lemma 26.5 + Corollary 26.6

• Let f be a flow in G and let (S,T) be a cut in G. Then |f| = f(S,T).

• Let f be a flow in G and let (S,T) be a cut in G. Then |f| · c(S,T). This is a weak duality theorem.

Page 5: 1 The max flow problem 5 10 2 -2 7 1 9 4 5 11. 2 Ford-Fulkerson method Ford-Fulkerson(G) f = 0 while( 9 simple path p from s to t in G f ) f := f + f

5

Max Flow – Min Cut Theorem

Let f be a flow in G. The following three conditions are equivalent:

1. f is a maximum flow

2. Gf contains no augmenting path

3. There is a cut (S,T) so that |f|=c(S,T)

Page 6: 1 The max flow problem 5 10 2 -2 7 1 9 4 5 11. 2 Ford-Fulkerson method Ford-Fulkerson(G) f = 0 while( 9 simple path p from s to t in G f ) f := f + f

6

Max Flow – Min Cut Theorem

• The value of the maximum flow in G is equal to the capacity of the minimum cut in G.

• This is a strong duality theorem.

Page 7: 1 The max flow problem 5 10 2 -2 7 1 9 4 5 11. 2 Ford-Fulkerson method Ford-Fulkerson(G) f = 0 while( 9 simple path p from s to t in G f ) f := f + f

7

Remarks

• The solution values agree, not the solutions themselves – flows and cuts are completely different objects.

• Given a max flow we can easily find a min cut (follows from proof of max flow-min cut theorem). Going the other way is less obvious.

Page 8: 1 The max flow problem 5 10 2 -2 7 1 9 4 5 11. 2 Ford-Fulkerson method Ford-Fulkerson(G) f = 0 while( 9 simple path p from s to t in G f ) f := f + f

8

Consequence

• The Ford-Fulkerson method is partially correct, i.e., if it terminates it produces the flow with the maximum value.

Page 9: 1 The max flow problem 5 10 2 -2 7 1 9 4 5 11. 2 Ford-Fulkerson method Ford-Fulkerson(G) f = 0 while( 9 simple path p from s to t in G f ) f := f + f

9

Local search checklist

Design:• How do we find the first feasible solution? • Neighborhood design? • Which neighbor to choose? Analysis:• Partial correctness? (termination )correctness) • Termination? • Complexity?

٧٧

٧

Page 10: 1 The max flow problem 5 10 2 -2 7 1 9 4 5 11. 2 Ford-Fulkerson method Ford-Fulkerson(G) f = 0 while( 9 simple path p from s to t in G f ) f := f + f

10

Termination

• Suppose all capacities are integers.

• We start with a flow of value 0.

• In each iteration, we get a new flow with higher integer value.

• We always have a legal flow, i.e., one of value at most |f|.

• Hence we can have at most |f| iterations.

Page 11: 1 The max flow problem 5 10 2 -2 7 1 9 4 5 11. 2 Ford-Fulkerson method Ford-Fulkerson(G) f = 0 while( 9 simple path p from s to t in G f ) f := f + f

11

Correctness of Ford-Fulkerson

• Since Ford-Fulkerson is partially correct and it terminates if capacities are integers it is a correct algorithm for finding the maximum flow if capacities are integers.

• Exercise: It is also correct if capacities are rationals.

Page 12: 1 The max flow problem 5 10 2 -2 7 1 9 4 5 11. 2 Ford-Fulkerson method Ford-Fulkerson(G) f = 0 while( 9 simple path p from s to t in G f ) f := f + f

12

Does Ford-Fulkerson always terminate?

• In case of irrational capacities, not necessarily! (Exercise)

• But we can’t give irrational capacities as inputs to digital computers anyway.

• In case of floating point capacities, who knows?

Page 13: 1 The max flow problem 5 10 2 -2 7 1 9 4 5 11. 2 Ford-Fulkerson method Ford-Fulkerson(G) f = 0 while( 9 simple path p from s to t in G f ) f := f + f

13

Integrality Theorem (26.11)

If a flow network has integer valued capacities, there is a maximum flow with an integer value on every edge. The Ford-Fulkerson method will yield such a maximum flow.

The integrality theorem is often extremely important when “programming” and modeling using the max flow formalism.

Page 14: 1 The max flow problem 5 10 2 -2 7 1 9 4 5 11. 2 Ford-Fulkerson method Ford-Fulkerson(G) f = 0 while( 9 simple path p from s to t in G f ) f := f + f

14

Reduction: Maximum Matching ! Max Flow

What is the maximum cardinality matching in G?

Page 15: 1 The max flow problem 5 10 2 -2 7 1 9 4 5 11. 2 Ford-Fulkerson method Ford-Fulkerson(G) f = 0 while( 9 simple path p from s to t in G f ) f := f + f

15

G

Page 16: 1 The max flow problem 5 10 2 -2 7 1 9 4 5 11. 2 Ford-Fulkerson method Ford-Fulkerson(G) f = 0 while( 9 simple path p from s to t in G f ) f := f + f

16

G’

s t

All capacities are 1

Page 17: 1 The max flow problem 5 10 2 -2 7 1 9 4 5 11. 2 Ford-Fulkerson method Ford-Fulkerson(G) f = 0 while( 9 simple path p from s to t in G f ) f := f + f

17

Finding a balanced set of Representatives

• A city has clubs C1, C2,…,Cn and parties P1, P2,…,Pm. A citizen may be a member of several clubs but may only be a member of one party.

• A balanced city council must be formed by including exactly one member from each club and at most uk members from party Pk.

(Ahuja, Application 6.2)

Page 18: 1 The max flow problem 5 10 2 -2 7 1 9 4 5 11. 2 Ford-Fulkerson method Ford-Fulkerson(G) f = 0 while( 9 simple path p from s to t in G f ) f := f + f

18

Page 19: 1 The max flow problem 5 10 2 -2 7 1 9 4 5 11. 2 Ford-Fulkerson method Ford-Fulkerson(G) f = 0 while( 9 simple path p from s to t in G f ) f := f + f

19

Local search checklist

Design:• How do we find the first feasible solution? • Neighborhood design? • Which neighbor to choose? Analysis:• Partial correctness? (termination )correctness) • Termination? • Complexity?

٧٧

٧٧

Page 20: 1 The max flow problem 5 10 2 -2 7 1 9 4 5 11. 2 Ford-Fulkerson method Ford-Fulkerson(G) f = 0 while( 9 simple path p from s to t in G f ) f := f + f

20

Complexity of Ford-Fulkerson

• We have at most |f| improvement steps (iterations of the while-loop).

• Is this the best possible bound?

Page 21: 1 The max flow problem 5 10 2 -2 7 1 9 4 5 11. 2 Ford-Fulkerson method Ford-Fulkerson(G) f = 0 while( 9 simple path p from s to t in G f ) f := f + f

21

Complexity

• We have at most |f| improvement steps (iterations of the while-loop) and this bound cannot be improved for the general Ford-Fulkerson method.

• How fast can we implement a single improvement step?

Page 22: 1 The max flow problem 5 10 2 -2 7 1 9 4 5 11. 2 Ford-Fulkerson method Ford-Fulkerson(G) f = 0 while( 9 simple path p from s to t in G f ) f := f + f

22

Complexity

• Assume |V|-1 · |E|. Otherwise the graph is not connected.

• Then, Ford-Fulkerson can be implemented to run in time at most O(|E| |f|).

• Is this fast?

Page 23: 1 The max flow problem 5 10 2 -2 7 1 9 4 5 11. 2 Ford-Fulkerson method Ford-Fulkerson(G) f = 0 while( 9 simple path p from s to t in G f ) f := f + f

23

Polynomial time algorithms

• Defintion: A polynomial time algorithm is an algorithm than runs in time polynomial in n, where n is the number of bits of the input.

• How we intend to encode the input influences if we have a polynomial algorithm or not. Usually, some “standard encoding” is implied.

• In this course: Polynomial ¼ Fast Exponential ¼ Slow

Page 24: 1 The max flow problem 5 10 2 -2 7 1 9 4 5 11. 2 Ford-Fulkerson method Ford-Fulkerson(G) f = 0 while( 9 simple path p from s to t in G f ) f := f + f

24

java MaxFlow ??????????

How to encode max flow instance?

Page 25: 1 The max flow problem 5 10 2 -2 7 1 9 4 5 11. 2 Ford-Fulkerson method Ford-Fulkerson(G) f = 0 while( 9 simple path p from s to t in G f ) f := f + f

25

java MaxFlow 6#0|16|13|0|0|0#0|0|10|12|0|0 #0|4|0|0|14|0#0|0|9|0|0|20 #0|0|0|7|0|4|#0|0|0|0|0|0

How to encode max flow instance?

Page 26: 1 The max flow problem 5 10 2 -2 7 1 9 4 5 11. 2 Ford-Fulkerson method Ford-Fulkerson(G) f = 0 while( 9 simple path p from s to t in G f ) f := f + f

26

Complexity of Ford-Fulkerson

• With standard (decimal or binary) representation of integers, Ford-Fulkerson is an exponential time algorithm.

Page 27: 1 The max flow problem 5 10 2 -2 7 1 9 4 5 11. 2 Ford-Fulkerson method Ford-Fulkerson(G) f = 0 while( 9 simple path p from s to t in G f ) f := f + f

27

java MaxFlow 111111#|1111111111111111|1111111111111|||#||1111111111|111111111111||#|1111|||11111111111111|#||111111111|||11111111111111111111#|||1111111||1111 #|||||

Page 28: 1 The max flow problem 5 10 2 -2 7 1 9 4 5 11. 2 Ford-Fulkerson method Ford-Fulkerson(G) f = 0 while( 9 simple path p from s to t in G f ) f := f + f

28

Complexity of Ford-Fulkerson

• With unary (4 ~ 1111) representation of integers, Ford-Fulkerson is a polynomial time algorithm.

• Intuition: When the input is longer it is easier to be polynomial time as a function of the input length.

• An algorithm which is polynomial if integer inputs are represented in unary is called a pseudo-polynomial algorithm.

• Intuitively, a pseudo-polynomial algorithm is an algorithm which is fast if all numbers in the input are small.

Page 29: 1 The max flow problem 5 10 2 -2 7 1 9 4 5 11. 2 Ford-Fulkerson method Ford-Fulkerson(G) f = 0 while( 9 simple path p from s to t in G f ) f := f + f

29

Edmonds-Karp

Edmonds-Karp algorithm for Max Flow:

Implement Ford-Fulkerson by always choosing the shortest possible augmenting path, i.e., the one with fewest possible edges.

Page 30: 1 The max flow problem 5 10 2 -2 7 1 9 4 5 11. 2 Ford-Fulkerson method Ford-Fulkerson(G) f = 0 while( 9 simple path p from s to t in G f ) f := f + f

30

Complexity of Edmonds-Karp

• Each iteration of the while loop can still be done in time O(|E|).

• The number of iterations are now at most O(|V||E|) regardless of capacities – to be seen next.

• Thus, the total running time is O(|V| |E|2) and Edmonds-Karp is a polynomial time algorithm for Max Flow.

Page 31: 1 The max flow problem 5 10 2 -2 7 1 9 4 5 11. 2 Ford-Fulkerson method Ford-Fulkerson(G) f = 0 while( 9 simple path p from s to t in G f ) f := f + f

31

Why at most O(|V| |E|) iterations?

When executing Edmonds-Karp, the residual network Gf gradually changes (as f changes). This sequence of different residual networks Gf satisfies:

Theorem (~ Lemma 26.8 and Theorem 26.9): 1) The distance between s and t in Gf never decreases: After each

iteration of the while-loop, it either increases or stays the same. 2) The distance between s and t in Gf can stay the same for at most |

E| iterations of the while-loop before increasing.

As the distance between s and t can never be more than |V|-1 and

it starts out as at least 1, it follows from the theorem that we have at most (|V|-2)|E| iterations.