22
1 Week 11.3, Friday, Nov 1 Midterm 2: Grading in progress Homework 6: Planned Released on Monday, November 4 th

Week 11.3, Friday, Nov 1 - Purdue University · 1 Week 11.3, Friday, Nov 1 Midterm 2: Grading in progress. Homework 6: Planned Released on Monday, November 4. th

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Week 11.3, Friday, Nov 1 - Purdue University · 1 Week 11.3, Friday, Nov 1 Midterm 2: Grading in progress. Homework 6: Planned Released on Monday, November 4. th

1

Week 11.3, Friday, Nov 1

Midterm 2: Grading in progressHomework 6: Planned Released on Monday, November 4th

Page 2: Week 11.3, Friday, Nov 1 - Purdue University · 1 Week 11.3, Friday, Nov 1 Midterm 2: Grading in progress. Homework 6: Planned Released on Monday, November 4. th

2

Chapter 7

Network Flow

Slides by Kevin Wayne.Copyright © 2005 Pearson-Addison Wesley.All rights reserved.

Page 3: Week 11.3, Friday, Nov 1 - Purdue University · 1 Week 11.3, Friday, Nov 1 Midterm 2: Grading in progress. Homework 6: Planned Released on Monday, November 4. th

Max Flow Recap

3

s

2

3

4

5

6

7

t

15

5

30

15

10

8

15

9

6 10

10

10154

4capacity

source

sink

Page 4: Week 11.3, Friday, Nov 1 - Purdue University · 1 Week 11.3, Friday, Nov 1 Midterm 2: Grading in progress. Homework 6: Planned Released on Monday, November 4. th

4

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.

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

locally optimality ⇒ global optimality

Page 5: Week 11.3, Friday, Nov 1 - Purdue University · 1 Week 11.3, Friday, Nov 1 Midterm 2: Grading in progress. Homework 6: Planned Released on Monday, November 4. th

5

Clicker Question: Greedy 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.

For which of the following graphs is the greedy algorithm guaranteed to find the maximum flow?

A. Graph G1 only B. Graph G2 only C. Graph G3 only

D. Graphs G3 and G2 E. None of them

s

1

2

t

10

10

20

20

40 s

1

2

t

10

10

20

20

30 s

1

2

t

100

10

20

20

30

(G1)(G2) (G3)

Page 6: Week 11.3, Friday, Nov 1 - Purdue University · 1 Week 11.3, Friday, Nov 1 Midterm 2: Grading in progress. Homework 6: Planned Released on Monday, November 4. th

6

Page 7: Week 11.3, Friday, Nov 1 - Purdue University · 1 Week 11.3, Friday, Nov 1 Midterm 2: Grading in progress. Homework 6: Planned Released on Monday, November 4. th

7

Clicker Question: Greedy 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.

For which of the following graphs is the greedy algorithm guaranteed to find the maximum flow?

A. Graph G1 only B. Graph G2 only C. Graph G3 only

D. Graphs G3 and G2 E. None of them

s

1

2

t

10

10

20

20

40 s

1

2

t

10

10

20

20

30 s

1

2

t

100

10

20

20

30

(G1) (G2) (G3)

10

10

1020

20

2010

10

10

Page 8: Week 11.3, Friday, Nov 1 - Purdue University · 1 Week 11.3, Friday, Nov 1 Midterm 2: Grading in progress. Homework 6: Planned Released on Monday, November 4. th

8

Page 9: Week 11.3, Friday, Nov 1 - Purdue University · 1 Week 11.3, Friday, Nov 1 Midterm 2: Grading in progress. Homework 6: Planned Released on Monday, November 4. th

9

Page 10: Week 11.3, Friday, Nov 1 - Purdue University · 1 Week 11.3, Friday, Nov 1 Midterm 2: Grading in progress. Homework 6: Planned Released on Monday, November 4. th

10

Page 11: Week 11.3, Friday, Nov 1 - Purdue University · 1 Week 11.3, Friday, Nov 1 Midterm 2: Grading in progress. Homework 6: Planned Released on Monday, November 4. th

11

Example

u

s t

v

15

5

20

15 5

5

Augmenting path s → v → u→ twith bottleneck capacity 5Results in a flow of 30

u

s t

v

20

20

30

10

10

u

s t

v

20

20

30

10

10

20

G, Gf

G,

f

20

515

5

20 5

5

5

f+f’20

10

1010

20

5

f’

10=f(u,v) – f’(v,u) = 15-5(flow negates on reverse edge

Page 12: Week 11.3, Friday, Nov 1 - Purdue University · 1 Week 11.3, Friday, Nov 1 Midterm 2: Grading in progress. Homework 6: Planned Released on Monday, November 4. th

13

Page 13: Week 11.3, Friday, Nov 1 - Purdue University · 1 Week 11.3, Friday, Nov 1 Midterm 2: Grading in progress. Homework 6: Planned Released on Monday, November 4. th

15

Ford-Fulkerson Algorithm

s

2

3

4

5 t10

10

9

8

4

10

1062

G:capacity

play

Initialize: f(e)=0 //empty flow While there remains an augmenting path P // s-t path in residual graph Gf

Augment(f,c,P) // Increases v(f)Update Gf

Page 14: Week 11.3, Friday, Nov 1 - Purdue University · 1 Week 11.3, Friday, Nov 1 Midterm 2: Grading in progress. Homework 6: Planned Released on Monday, November 4. th

16

Augmenting Path Algorithm

Augment(f, c, P) {b ← bottleneck(P) foreach e ∈ P {

if (e ∈ E) f(e) ← f(e) + belse f(eR)← f(eR) - b

}return f

}

Ford-Fulkerson(G, s, t, c) {foreach e ∈ E f(e) ← 0Gf ← residual graph

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

}return f

}

forward edgereverse edge

Page 15: Week 11.3, Friday, Nov 1 - Purdue University · 1 Week 11.3, Friday, Nov 1 Midterm 2: Grading in progress. Homework 6: Planned Released on Monday, November 4. th

17

Max-Flow Min-Cut Theorem

Augmenting path theorem. Flow f is a max flow iff there are no augmenting paths.

Max-flow min-cut theorem. [Elias-Feinstein-Shannon 1956, Ford-Fulkerson 1956]

The value of the max flow is equal to the value of the min cut.

Pf. We prove both simultaneously by showing TFAE:(i) There exists a cut (A, B) such that v(f) = cap(A, B).

(ii) Flow f is a max flow.(iii) There is no augmenting path relative to f.

(i) ⇒ (ii) This was the corollary to weak duality lemma.

(ii) ⇒ (iii) We show contrapositive. Let f be a flow. If there exists an augmenting path, then we

can improve f by sending flow along path.

Page 16: Week 11.3, Friday, Nov 1 - Purdue University · 1 Week 11.3, Friday, Nov 1 Midterm 2: Grading in progress. Homework 6: Planned Released on Monday, November 4. th

18

Proof of Max-Flow Min-Cut Theorem

(iii) ⇒ (i) (No augmenting paths relative to f cap(A,B)=v(g) for some cut A,B) Let f be a flow with no augmenting paths. Let A be set of vertices reachable from s in residual graph. By definition of A, s ∈ A. By definition of f, t ∉ A.

original network

s

t

A B

Must be 0 since there is noEdge from A to B in residual graph

Must be c(e) since there is no edgefrom A to B in residual graph

Page 17: Week 11.3, Friday, Nov 1 - Purdue University · 1 Week 11.3, Friday, Nov 1 Midterm 2: Grading in progress. Homework 6: Planned Released on Monday, November 4. th

19

Proof of Max-Flow Min-Cut Theorem

(iii) ⇒ (i) Let f be a flow with no augmenting paths. Let A be set of vertices reachable from s in residual graph. By definition of A, s ∈ A. By definition of f, t ∉ A.

original network

s

t

A B

Must be 0 since there is noEdge from A to B in residual graph

Page 18: Week 11.3, Friday, Nov 1 - Purdue University · 1 Week 11.3, Friday, Nov 1 Midterm 2: Grading in progress. Homework 6: Planned Released on Monday, November 4. th

20

Pseudo-polynomial

Page 19: Week 11.3, Friday, Nov 1 - Purdue University · 1 Week 11.3, Friday, Nov 1 Midterm 2: Grading in progress. Homework 6: Planned Released on Monday, November 4. th

21

Ford-Fulkerson: Exponential Number of Augmentations

Q. Is generic Ford-Fulkerson algorithm polynomial in input size?

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

s

v

w

t

C

C

0 0

0 0

0

C

C

1 s

v

w

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

m, n, and log C

Page 20: Week 11.3, Friday, Nov 1 - Purdue University · 1 Week 11.3, Friday, Nov 1 Midterm 2: Grading in progress. Homework 6: Planned Released on Monday, November 4. th

22

Page 21: Week 11.3, Friday, Nov 1 - Purdue University · 1 Week 11.3, Friday, Nov 1 Midterm 2: Grading in progress. Homework 6: Planned Released on Monday, November 4. th

7.3 Choosing Good Augmenting Paths

Page 22: Week 11.3, Friday, Nov 1 - Purdue University · 1 Week 11.3, Friday, Nov 1 Midterm 2: Grading in progress. Homework 6: Planned Released on Monday, November 4. th

24

Choosing Good Augmenting Paths

Use care when selecting augmenting paths. Some choices lead to exponential algorithms. Clever choices lead to polynomial algorithms. If capacities are irrational, algorithm not guaranteed to terminate!

Goal: choose augmenting paths so that: Can find augmenting paths efficiently. Few iterations.

Choose augmenting paths with: [Edmonds-Karp 1972, Dinitz 1970] Max bottleneck capacity. Sufficiently large bottleneck capacity. Fewest number of edges e.g., BFS in residual graph.

Interested in knowing more about MaxFlow?2014 CACM Review paper by Goldberg and Tarjan posted on Piazza

http://cacm.acm.org/magazines/2014/8/177011-efficient-maximum-flow-algorithms/abstract