+ All Categories
Home > Documents > Algorithm Design and Analysis

Algorithm Design and Analysis

Date post: 02-Jan-2016
Category:
Upload: diana-schultz
View: 38 times
Download: 3 times
Share this document with a friend
Description:
L ECTURES 18-19 Network Flows Flows, cuts Ford-Fulkerson Min-cut/max- flow theorem. Algorithm Design and Analysis. CSE 565. Adam Smith. Detecting Negative Cycles. Theorem. Can find negative cost cycle in O(mn ) time. Add new node t and connect all nodes to t with 0-cost edge. - PowerPoint PPT Presentation
Popular Tags:
40
10/4/10 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne Adam Smith Algorithm Design and Analysis LECTURES 18-19 Network Flows Flows, cuts Ford-Fulkerson Min-cut/max-flow theorem
Transcript
Page 1: Algorithm Design and Analysis

10/4/10A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne

Adam Smith

Algorithm Design and Analysis

LECTURES 18-19Network Flows• Flows, cuts• Ford-Fulkerson• Min-cut/max-flow theorem

Page 2: Algorithm Design and Analysis

Detecting Negative Cycles

Theorem. Can find negative cost cycle in O(mn) time. Add new node t and connect all nodes to t with 0-cost edge. Check if OPT(n, v) = OPT(n-1, v) for all nodes v.

– if yes, then no negative cycles– if no, then extract cycle from shortest path from v to t

Last lecture we proved: if OPT(n, v) < OPT(n-1, v) then we can find a neg.-cost cycle on a path from v to t

Questions to think about: 1. Prove that if there is a negative-cost cycle,

then OPT(n, v) < OPT(n-1, v) for some v (Hint: what would happen ifwe kept running Bellman-

Ford for many iterations?)2. Why do we bother with the extra node t?

v

18 2

5 -23

-15

-11

6

t

0

0

0 0 0

Page 3: Algorithm Design and Analysis

A. Smith; based on slides by S. Raskhodnikova and K. Wayne

Network Flow and Linear Programming

10/15/2008

Page 4: Algorithm Design and Analysis

Soviet Rail Network, 1955

Reference: On the history of the transportation and maximum flow problems.Alexander Schrijver in Math Programming, 91: 3, 2002.

Page 5: Algorithm Design and Analysis

Maximum Flow and Minimum Cut

Max flow and min cut. Two very rich algorithmic problems. Cornerstone problems in combinatorial optimization. Beautiful mathematical duality.

Nontrivial applications / reductions. Data mining. Open-pit mining. Project selection. Airline scheduling. Bipartite matching. Image segmentation. Clustering Network connectivity.

Network reliability. Distributed computing. Egalitarian stable matching. Network intrusion detection. Multi-camera scene reconstruction. Data privacy. Many many more …

Page 6: Algorithm Design and Analysis

Flow network. Abstraction for material flowing through the edges. G = (V, E) = directed graph, no parallel edges. Two distinguished nodes: s = source, t = sink. c(e) = capacity of edge e.

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

capacity

source sink

Page 7: Algorithm Design and Analysis

Def. An s-t cut is a partition (A, B) of V with s A and t B.

Def. The capacity of a cut (A, B) 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

Capacity = 10 + 5 + 15 = 30

A

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

we don’t count

edges into A

Page 8: Algorithm Design and Analysis

s

2

3

4

5

6

7

t

15

5

30

15

10

8

15

9

6 10

10

10 15 4

4 A

Cuts

Def. An s-t cut is a partition (A, B) of V with s A and t B.

Def. The capacity of a cut (A, B) is:

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

Capacity = 9 + 15 + 8 + 30 = 62

Page 9: Algorithm Design and Analysis

Min s-t cut problem. 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 10: Algorithm Design and Analysis

Def. An s-t flow is a function f from E to real numbers that satisfies:

For each e E: [capacity] For each v V – {s, t}: [conservation]

Flows

4

0

0

0

0 0

0 4 4

0

0

0

0

0 f (e) c(e)

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

4

veve

efef ofout into

)()(water flowing

from source to sink

Page 11: Algorithm Design and Analysis

Def. An s-t flow is a function f from E to real numbers that satisfies:

For each e E: [capacity] For each v V – {s, t}: [conservation]

Def. The value of a flow f is:

Flows

4

0

0

0

0 0

0 4 4

0

0

0

Value = 40

0 f (e) c(e)

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

4

veve

efef ofout into

)()(

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

.water flowing

from source to sink

Page 12: Algorithm Design and Analysis

Def. An s-t flow is a function f from E to real numbers that satisfies:

For each e E: [capacity] For each v V – {s, t}: [conservation]

Def. The value of a flow f is:

Flows

10

6

6

11

1 10

3 8 8

0

0

0

11

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 = 24

veve

efef ofout into

)()(

0 f (e) c(e)

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

.

4

water flowing from source to

sink

Page 13: Algorithm Design and Analysis

Max flow problem. 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 14: Algorithm Design and Analysis

Flow value lemma. Let f be any flow, and let (A, B) be any s-t cut. Then, 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 15: Algorithm Design and Analysis

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

Flows and Cuts

10

6

6

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

f (e)e out of A

f (e)e in to A

v( f )

Value = 6 + 0 + 8 - 1 + 11 = 24

4

11

A

Page 16: Algorithm Design and Analysis

Flow value lemma. Let f be any flow, and let (A, B) be any s-t cut. Then, 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

f (e)e out of A

f (e)e in to A

v( f )

Value = 10 - 4 + 8 - 0 + 10 = 24

4

A

Page 17: Algorithm Design and Analysis

Flows and Cuts

Flow value lemma. Let f be any flow, and let (A, B) be any s-t cut. Then

Proof.

f (e)e out of A

f (e) v( f )e in to A

.

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

v A f (e)

e out of v f (e)

e in to v

f (e)e out of A

f (e).e in to A

by flow conservation, all termsexcept v = s are 0

Page 18: Algorithm Design and Analysis

Question

Two problems• min cut• max flow

• How do they relate?

Page 19: Algorithm Design and Analysis

Flows and Cuts

Weak duality. Let f be any flow, and let (A, B) be any s-t cut. Then 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

Big Optimization Idea #1:

Look for structural constraints, e.g.max flow min-cut

Page 20: Algorithm Design and Analysis

Weak duality. Let f be any flow. Then v(f) cap(A, B), for any s-t cut (A, B).

Pf.

Flows and Cuts

v( f ) f (e)e out of A

f (e)e in to A

f (e)e out of A

c(e)e out of A

cap(A, B)

s

t

A B

7

6

8

4

Page 21: Algorithm Design and Analysis

Certificate of Optimality

Corollary. Let f be any flow, and 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 s-t 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 22: Algorithm Design and Analysis

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 23: Algorithm Design and Analysis

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

20

Flow value = 20

10

10 20

30

0 0

0 0

0

X

X

X

20

20

20

Page 24: Algorithm Design and Analysis

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

How can we get from greedy to opt here? What if we

push water back across middle

edge?

Page 25: Algorithm Design and Analysis

Residual Graph

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

Residual edge. e = (u, v) and eR = (v, u). Residual capacity:

If e in E:– unused capacity

If eR in E:– ability of sent less water, or “undo“ flow

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 26: Algorithm Design and Analysis

Ford-Fulkerson Algorithm

s

2

3

4

5 t 10

10

9

8

4

10

10 6 2

G:capacity

Page 27: Algorithm Design and Analysis

Ford-Fulkerson Algorithm

s

2

3

4

5 t 10

10

9

8

4

10

10 6 2

0

0

0

0 0 0

0

0

G:

Flow value = 0

0

flowcapacity

Page 28: Algorithm Design and Analysis

Ford-Fulkerson Algorithm

s

2

3

4

5 t 10

10

9

8

4

10

10 6 2

0

0

0

0 0 0

0

0

G:

s

2

3

4

5 t 10 9

4

10 6 2

Gf:10 8

10

8 8

8

X X

X

0

Flow value = 0

capacity

residual capacity

flow

Page 29: Algorithm Design and Analysis

Ford-Fulkerson Algorithm

s

2

3

4

5 t 10

10

9

8

4

10

10 6 2

8

0

0

0 0 8

8

0 0

G:

s

2

3

4

5 t 10

4

10 6 Gf:

8

8

8

9

22

2

10

210

X

X

X2X

Flow value = 8

Page 30: Algorithm Design and Analysis

0

Ford-Fulkerson Algorithm

s

2

3

4

5 t 10

10

9

8

4

10

10 6 2

10

0

0

0 2 10

8

2

G:

s

2

3

4

5 t

4

2

Gf:

10

810

2

10 7

10 6

X

66

6

X

X

8X

Flow value = 10

Page 31: Algorithm Design and Analysis

Ford-Fulkerson Algorithm

s

2

3

4

5 t 10

10

9

8

4

10

10 6 2

10

0

6

6 8 10

8

2

G:

s

2

3

4

5 t1

6 Gf:

10

8 10

8

6

6

6

4

4

4

2

X

8

2

8

X

X

0X

Flow value = 16

Page 32: Algorithm Design and Analysis

Ford-Fulkerson Algorithm

s

2

3

4

5 t 10

10

9

8

4

10

10 6 2

10

2

8

8 8 10

8

0

G:

s

2

3

4

5 t

6 2

Gf:

10

10

8

6

8

8

2

2 1

2

8 2

X

9

7 9

X

X

9X

X 3

Flow value = 18

Page 33: Algorithm Design and Analysis

Ford-Fulkerson Algorithm

s

2

3

4

5 t 10

10

9

8

4

10

10 6 2

10

3

9

9 9 10

7

0

G:

s

2

3

4

5 t 1 9

1

1 6 2

Gf:

10

7 10

6

9

9

3

1

Flow value = 19

Page 34: Algorithm Design and Analysis

Ford-Fulkerson Algorithm

s

2

3

4

5 t 10

10

9

8

4

10

10 6 2

10

3

9

9 9 10

7

0

G:

s

2

3

4

5 t 1 9

1

1 6 2

Gf:

10

7 10

6

9

9

3

1

Flow value = 19Cut capacity =

19

Page 35: Algorithm Design and Analysis

Augmenting Path Algorithm

Augment(f, c, P) { b bottleneck(P) foreach e P { if (e E) f(e) f(e) + b else f(e) f(e) - b } return f}

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

while (there is an s-t path P in Gf) { f Augment(f, c, P) update Gf

} return f}

forward edge

reverse edge

Min residual capacity of an edge in P

Page 36: Algorithm Design and Analysis

Ford-Fulkerson: Summary so far

Ford-Fulkerson: • While you can,

• Greedily push flow• Update residual graph

Lemma 1: This outputs a valid flow.

Proof: (Check conservation conditions… see book.)

Still to do:• Running time (in particular, termination!)• How good a flow?

Page 37: Algorithm Design and Analysis

Running Time

Assumption. All capacities are integers between 1 and C.

Invariant. Every flow value f(e) and every residual capacity cf (e)

remains an integer throughout the algorithm.

Proof: exercise.

Theorem. The algorithm terminates in at most v(f*) nC iterations.Pf. Each augmentation increase value by at least 1. ▪

Running time of Ford-Fulkerson: O(mnC). Space: O(m+n).Corollary. If C = 1, Ford-Fulkerson runs in O(mn) time.

Page 38: Algorithm Design and Analysis

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 s-t cut.

Pf. We prove both simultaneously by showing (i) -- (iii) are equivalent. (i) There exists an s-t cut (A, B) such that v(f) = cap(A, B). (ii) Flow f is a max flow, and (A,B) is min s-t cut. (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 39: Algorithm Design and Analysis

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. Observation: No edges of the residual graph go from A to B.

Claim 1: If e goes from A to B, then f(e) =c(e).Proof: Otherwise there would be residual capacity, and the residual graph would have an edge A to B.

Claim 2: If e goes from B to A, then f(e)=0.Proof: Otherwise residual edge would go from A to B.

v( f ) f (e)e out of A

f (e)e in to A

c(e)e out of A

cap(A, B)

original network

s

t

A B

Page 40: Algorithm Design and Analysis

Summary

Assumption. All capacities are integers between 1 and C.

Running time: The FF algorithm terminates in at most v(f*) nC iterations. Running time = O(mnC). Space: O(m+n).

Important special case: if C = 1, Ford-Fulkerson runs in O(mn) time.

Integrality theorem. If all capacities are integers, then there exists a max flow f for which every flow value f(e) is an integer.


Recommended