emis 8374 the ford-fulkerson algorithm (aka the labeling algorithm) updated 4 march 2008

53
EMIS 8374 The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

Upload: duer

Post on 05-Jan-2016

42 views

Category:

Documents


1 download

DESCRIPTION

EMIS 8374 The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008. Ford-Fulkerson Algorithm. begin x := 0; label node t ; while t is labeled do begin unlabel all nodes; pred( j ) := 0 for all j in N ; label s ; LIST := { s }; - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

EMIS 8374

The Ford-Fulkerson Algorithm (aka the labeling algorithm)

Updated 4 March 2008

Page 2: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

Ford-Fulkerson Algorithmbegin x := 0; label node t; while t is labeled do begin unlabel all nodes; pred(j) := 0 for all j in N; label s; LIST := {s}; while LIST is not empty and t is not labeled do begin remove a node i from LIST; for all {j in N: (i, j) in A and rij > 0} do if j is unlabeled then pred(j) := i, label j, add j to LIST; end; if t is labeled then augment flow on path from s to t end;end; Slide 2

Page 3: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

Labeling Algorithm Example

s t1

2 4

3

(0,2)

(0,6)

5(0,5)

6

(0,5) (0,4)

(0,4)

(0,7)

Slide 3

Page 4: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

The Residual Network G(x)

s t1

2 4

3 5

6

5

0

0

6

2

0

5

0

40

4

0

07

Slide 4

Page 5: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

Iteration 1: LIST = {1}, Labeled = {1}

s t1

2 4

3 5

6

5

0

0

6

2

0

5

0

40

4

0

70

i = 1

Slide 5

Page 6: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

Iteration 1: LIST = {1}, Labeled = {1}

• i = 1• LIST = {}• Arc (1,2)

– pred(2) =1– label 2– LIST = {2}

• Arc (1,3) – pred (3) = 1– label 3– LIST = {2, 3}

Slide 6

Page 7: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

Iteration 1: LIST = {2,3}, Labeled= {1,2,3}

s t1

2 4

3 5

6

5

0

0

6

2

0

5

0

40

4

0

07

pred(2) = 1

pred(3) = 1 Slide 7

Page 8: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

Iteration 1: LIST = {2,3}, Labeled = {1,2,3}

• i = 2• LIST = {3}• Arc (2,4)

– pred(4) =2– label 4– LIST = {3,4}

• Arc (2,5) – pred (5) = 2– label 5– LIST = {3,4,5}

• Arc (2,1)– residual capacity of

(2,1) = 0

Slide 8

Page 9: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

Iteration 1: LIST = {3,4,5}, Labeled= {1,2,3,4,5}

s t1

2 4

3 5

6

5

0

0

6

2

0

5

0

40

4

0

07

pred(2) = 1

pred(3) = 1 pred(5) = 2

pred(4) = 2

Slide 9

Page 10: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

Iteration 1: LIST = {3,4,5}, Labeled = {1,2,3,4,5}

• i = 3

• LIST = {4,5}

• Arc (3,5)– 5 is already labeled

• Arc (3,1) – residual capacity of (3,1) = 0

Slide 10

Page 11: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

Iteration 1: LIST = {4,5}, Labeled = {1,2,3,4,5}

• i = 4• LIST = {5}• Arc (4,2)

– residual capacity of (4,2) = 0

• Arc (4,6) – pred(6) =4– label 6– LIST = {5,6}

Slide 11

Page 12: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

Iteration 1: LIST = {5,6}, Labeled= {1,2,3,4,5,6}

s t1

2 4

3 5

6

5

0

0

6

2

0

5

0

40

4

0

07

pred(2) = 1

pred(3) = 1 pred(5) = 2

pred(4) = 2

pred(6) = 4

Slide 12

Page 13: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

Iteration 1: The sink is labeled

• Use pred labels to trace back from the sink to the source to find path P– P = 1 → 2 → 4 → 6

= min {rij: (i, j) in P) = 2

• Send 2 units of flow from to s to t along path P

Slide 13

Page 14: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

Flow x After Iteration 1

s t1

2 4

3

(2,2)

(0,6)

5(0,5)

6

(2,5) (2,4)

(0,4)

(0,7)

v = 2

Slide 14

Page 15: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

The Residual Network G(x)

s t1

2 4

3 5

6

3

2

0

6

0

2

5

0

40

2

2

07

Slide 15

Page 16: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

Iteration 2: LIST = {1}, Labeled = {1}

• i = 1• LIST = {}• Arc (1,2)

– pred(2) =1– label 2– LIST = {2}

• Arc (1,3) – pred (3) = 1– label 3– LIST = {2, 3}

Slide 16

Page 17: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

Iteration 2: LIST = {2,3}, Labeled={1,2,3}

s t1

2 4

3 5

6

3

2

0

6

0

2

5

0

40

2

2

07

p=1

p=1 Slide 17

Page 18: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

Iteration 2: LIST = {2,3}, Labeled = {1,2,3}

• i = 2• LIST = {3}• Arc (2,4)

– residual cap (2,4) = 0

• Arc (2,5) – pred (5) = 2– label 5– LIST = {3,5}

• Arc (2,1)– residual capacity of

(2,1) = 0

Slide 18

Page 19: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

Iteration 2: LIST = {3,5}, Labeled={1,2,3,5}

s t1

2 4

3 5

6

3

2

0

6

0

2

5

0

40

2

2

07

p=1

p=1 p=2 Slide 19

Page 20: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

Iteration 2: LIST = {3,5}, Labeled = {1,2,3,5}

• i = 3• LIST = {5}• Arc (3,5)

– 5 is already labeled

• Arc (3,1) – residual capacity of

(3,1) = 0

• i = 5

• LIST = {}

• Arc (5,2)– residual cap = 0

• Arc (5,3)– residual cap = 0

• Arc (5,6) – pred(6) = 5

– label 6

– LIST = {6}

Slide 20

Page 21: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

Iteration 2: LIST = {6}, Labeled={1,2,3,5,6}

s t1

2 4

3 5

6

3

2

0

6

0

2

5

0

40

2

2

07

p=1

p=1 p=2

p=5

Slide 21

Page 22: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

Iteration 2: The sink is labeled

• Use pred labels to trace back from the sink to the source to find path P– P = 1 -> 2 -> 5 -> 6

= min {rij: (i,j) in P) = 3

• Send 3 units of flow from to s to t along path P

Slide 22

Page 23: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

Flow x After Iteration 2

s t1

2 4

3

(2,2)

(0,6)

5(0,5)

6

(5,5) (2,4)

(3,4)

(3,7)

v = 5

Slide 23

Page 24: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

The Residual Network G(x)

s t1

2 4

3 5

6

0

5

0

6

0

2

5

0

13

2

2

04

Slide 24

Page 25: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

Iteration 3: LIST = {1}, Labeled = {1}

• i = 1• LIST = {}• Arc (1,2)

– residual capacity = 0

• Arc (1,3) – pred (3) = 1– label 3– LIST = {3}

Slide 25

Page 26: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

Iteration 3: List = {3}, Labeled = {1,3}

s t1

2 4

3 5

6

0

5

0

6

0

2

5

0

13

2

2

04

p=1 Slide 26

Page 27: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

Iteration 3: LIST = {3}, Labeled = {1,3}

• i = 3• LIST = {}• Arc (3,1)

– residual capacity = 0

• Arc (3,5) – pred (5) = 3– label 5– LIST = {5}

Slide 27

Page 28: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

Iteration 3: List = {5}, Labeled = {1,3,5}

s t1

2 4

3 5

6

0

5

0

6

0

2

5

0

13

2

2

04

p=1 p=2 Slide 28

Page 29: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

Iteration 3: LIST = {5}, Labeled = {1,3,5}

• i = 5, LIST = {}• Arc (5,2)

– pred(2) = 5– label 2– LIST = {2}

• Arc (5,3): residual capacity = 0• Arc (5,6)

– pred (6) = 5– label 6– LIST = {2,6}

Slide 29

Page 30: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

Iteration 3: List = {2,6}, Labeled = {1,2,3,5,6}

s t1

2 4

3 5

6

0

5

0

6

0

2

5

0

13

2

2

04

p=1 p=2

p=5

p=5

Slide 30

Page 31: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

Iteration 3: The sink is labeled

• Use pred labels to trace back from the sink to the source to find path P– P = 1 -> 3 -> 5 -> 6

= min {rij: (i,j) in P) = 4

• Send 4 units of flow from to s to t along path P

Slide 31

Page 32: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

Flow x After Iteration 3

s t1

2 4

3

(2,2)

(4,6)

5(4,5)

6

(5,5) (2,4)

(3,4)

(7,7)

v = 9

Slide 32

Page 33: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

The Residual Network G(x)

s t1

2 4

3 5

6

0

5

4

2

0

2

1

4

13

2

2

70

Slide 33

Page 34: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

Iteration 4: LIST = {1}, Labeled = {1}

• i = 1• LIST = {}• Arc (1,2)

– residual capacity = 0

• Arc (1,3) – pred (3) = 1– label 3– LIST = {3}

Slide 34

Page 35: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

Iteration 4: List = {3}, Labeled = {1,3}

s t1

2 4

3 5

6

0

5

4

2

0

2

1

4

13

2

2

70

p=1 Slide 35

Page 36: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

Iteration 4: LIST = {3}, Labeled = {1,3}

• i = 3• LIST = {}• Arc (3,1)

– 1 is labeled

• Arc (3,5) – pred (5) = 3– label 5– LIST = {5}

Slide 36

Page 37: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

Iteration 4: List = {5}, Labeled = {1,3,5}

s t1

2 4

3 5

6

0

5

4

2

0

2

1

4

13

2

2

70

p=1 p=3 Slide 37

Page 38: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

Iteration 4: LIST = {5}, Labeled = {1,3,5}

• i = 5• LIST = {}• Arc (5,2)

– pred(2) = 5– label 2– LIST = {2}

• Arc (5,6) – residual capacity = 0

Slide 38

Page 39: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

Iteration 4: List = {2}, Labeled = {1,2,3,5}

s t1

2 4

3 5

6

0

5

4

2

0

2

1

4

13

2

2

70

p=1 p=3

p=5

Slide 39

Page 40: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

Iteration 4: LIST = {2}, Labeled = {1,2,3,5}

• i = 2 LIST = {}

• Arc (2,1)– 1 is already labeled

• Arc(2,4)– residual capacity = 0

• Arc (2,5) – 5 is already labeled

Slide 40

Page 41: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

Iteration 4

• List = {}

• The sink is not labeled

• Algorithm ends with optimal flow x

Slide 41

Page 42: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

Correctness

• At the end of each iteration, the algorithm either augments the flow or terminates because it can’t label the sink.

• Let S be the set of labeled nodes when the algorithm terminates. Let T = N \ S.

• We need to show that when the algorithm terminates v = u[S, T] which implies x is a maximum flow.

Slide 42

Page 43: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

Correctness: arcs in (S, T)

Slide 43

i js

ijij

jiijij

jiijijij

ij

ux

xux

xxur

r

0

Page 44: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

Correctness: arcs in (T, S)

• Implies s can reach node i in G(x) • Implies i is labeled (i.e., node i is in S)• Implies xij = 0• Contradiction. If i in T and j in S, then xij = 0

i j s

Slide 44

• Suppose xij > 0

• rji = uji – xji + xij

• Implies rji > 0 since uji xji

Page 45: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

Complexity

• Let U = max {(i, j) in A} uij.– If S = {s} and T = N\{s}, then u[S, T] ≤ nU.– The maximum flow is at most nU.– The inner loop runs at most nU times.

• An iteration of the inner while loop is O(m):– Each arc is inspected at most once– Finding is O(n)– Updating the flow on P is O(n)

• Complexity is O(nmU).

Slide 45

Page 46: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

Pathological Example

s 1

2

3

5

(0,106) (0,106)

(0,106)(0,106)

(0,1) t

Slide 46

Page 47: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

Pathological Example: First Augmenting Path

s 1

2

3

5

(0,106) (0,106)

(0,106)(0,106)

(0,1) t

Slide 47

v = 1

Page 48: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

Residual Network

s 1

2

3

5

106-1 106

106-1106

t111

Slide 48

Page 49: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

An Augmenting Path in the Residual Network

s 1

2

3

5

106-1 106

106-1106

t111

Slide 49

Page 50: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

Updated Flow in G

s 1

2

3

5

(1,106) (1,106)

(1,106)(1,106)

(0,1) t

v = 2 Slide 50

Page 51: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

Updated Residual Network

s 1

2

3

5

106-1 106 -1

106-1106 -1

1 t1 1

11

Slide 51

Page 52: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

Next Augmenting Path in the Residual Network

s 1

2

3

5

106-1 106 -1

106-1106 -1

1 t1 1

11

This will take 2 million iterations to find the maximum flow! Slide 52

Page 53: EMIS 8374  The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008

Polynomial Max Flow Algorithms (Chapter 7)

• Always augment along the shortest augmenting path in the residual network.– Use breadth-first search to find augmenting path– O(n2m)

• Always augment along the maximum-capacity augmenting path in the residual network.– O(nm log U)

• Goldberg’s algorithm (preflow-push) with highest-label implementation.– O(n2m1/2)

Slide 53