class on design and analysis of algorithms, lecture 13 notes

20
Design and Analysis of Algorithms 6.046J/18.401J LECTURE 13 Network Flow Flow networks Maximum-flow problem Cuts Residual networks Augmenting paths Max-flow min-cut theorem Ford Fulkerson algorithm

Upload: buithuan

Post on 01-Jan-2017

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Class on Design and Analysis of Algorithms, Lecture 13 Notes

       

Design and Analysis ofAlgorithms6.046J/18.401J

LECTURE 13 Network Flow • Flow networks • Maximum-flow problem • Cuts • Residual networks • Augmenting paths • Max-flow min-cut theorem • Ford Fulkerson algorithm

Page 2: Class on Design and Analysis of Algorithms, Lecture 13 Notes

Flow networks Definition. A flow network is a directed graphG = (V, E) with two distinguished vertices: a source s and a sink t. Each edge (u, v) ∈ E has a nonnegative capacity c(u, v). If (u, v) ∉ E, then c(u, v) = 0.

Example:

s t

3 2

3

3

2 3

3

2

1

Design and Analysis of Algorithms L13.2© 2001–15 by Leiserson et al

Page 3: Class on Design and Analysis of Algorithms, Lecture 13 Notes

  

A flow on a network

s t

1:3 2:2

2:3

1:3

1:2 2:3

1:3

2:2

flow capacity

u

Flow conservation (like Kirchoff's current law):• Flow into u is 2 + 1 = 3. • Flow out of u is 1 + 2 = 3.

INTUITION: View flow as a rate, not a quantity. © 2001–15 by Leiserson et al Design and Analysis of Algorithms L13.3

Page 4: Class on Design and Analysis of Algorithms, Lecture 13 Notes

The maximum-flow problem Maximum-flow problem: Given a flow network G, find a flow of maximum value on G.

s t

2:3 2:2

2:3

1:3

2:2 3:3

0:3

2:2

The value of the maximum flow is 4. © 2001–15 by Leiserson et al Design and Analysis of Algorithms L13.4

Page 5: Class on Design and Analysis of Algorithms, Lecture 13 Notes

Flow network Assumptions Assumption. If edge (u, v) ∈ E exists, then

(v, u) ∉ E. Assumption. No self-loop edges (u, u) exist

s 1

2 u s 1

2 u

u’ 1

© 2001–15 by Leiserson et al Design and Analysis of Algorithms L13.5

Page 6: Class on Design and Analysis of Algorithms, Lecture 13 Notes

Net Flow Definition. A (net) flow on G is a function f : V × V → R satisfying the following: • Capacity constraint: For all u, v ∈ V,

f (u, v) ≤ c(u, v). • Flow conservation: For all u ∈ V – {s, t},

∑ f (u,v) = 0. v∈V

• Skew symmetry: For all u, v ∈ V, f (u, v) = –f (v, u).

Note: CLRS defines positive flows and net flows; these areequivalent for our flow networks obeying our assumptions.

© 2001–15 by Leiserson et al Design and Analysis of Algorithms L13.6

Page 7: Class on Design and Analysis of Algorithms, Lecture 13 Notes

Notation

Definition. The value of a flow f, denoted by | f |, is given by

f = ∑ f (s,v) v∈V

= f (s,V ) . Implicit summation notation: A set used in an arithmetic formula represents a sum over the elements of the set. • Example — flow conservation: f (u, V) = 0 for all u ∈ V – {s, t}.

© 2001–15 by Leiserson et al Design and Analysis of Algorithms L13.7

Page 8: Class on Design and Analysis of Algorithms, Lecture 13 Notes

   

Simple properties of flow Lemma. • f (X, X) = 0, • f (X, Y) = – f (Y, X), • f (X∪Y, Z) = f (X, Z) + f (Y, Z) if X∩Y = ∅.

Theorem. | f | = f (V, t). Proof.

| f | = f (s, V) = f (V, V) – f (V–s, V) Omit braces. = f (V, V–s) = f (V, t) + f (V, V–s–t) = f (V, t).

© 2001–15 by Leiserson et al Design and Analysis of Algorithms L13.8

Page 9: Class on Design and Analysis of Algorithms, Lecture 13 Notes

Flow into the sink

s t

2:3 2:2

2:3

1:3

2:2 3:3

0:3

2:2

| f | = f (s, V) = 4 f (V, t) = 4

© 2001–15 by Leiserson et al Design and Analysis of Algorithms L13.9

Page 10: Class on Design and Analysis of Algorithms, Lecture 13 Notes

Cuts Definition. A cut (S, T) of a flow network G = (V, E) is a partition of V such that s ∈ S and t ∈ T. If f is a flow on G, then the flow across the cut is f (S, T).

s t

2:3 2:2

2:3

1:3

2:2 3:3

0:3

2:2

∈ S ∈ T

f (S, T) = (2 + 2) + (– 2 + 1 – 1 + 2) = 4 © 2001–15 by Leiserson et al Design and Analysis of Algorithms L13.10

Page 11: Class on Design and Analysis of Algorithms, Lecture 13 Notes

Another characterization of flow value

Lemma. For any flow f and any cut (S, T), we have | f | = f (S, T). Proof. f (S, T) = f (S, V) – f (S, S)

= f (S, V) = f (s, V) + f (S–s, V) = f (s, V) = | f |.

© 2001–15 by Leiserson et al Design and Analysis of Algorithms L13.11

Page 12: Class on Design and Analysis of Algorithms, Lecture 13 Notes

Capacity of a cut Definition. The capacity of a cut (S, T) is c(S, T).

s t

2:3 2:2

2:3

1:3

2:2 3:3

0:3

2:2

c(S, T) = (3 + 2) + (1 + 3) = 9

∈ S ∈ T

© 2001–15 by Leiserson et al Design and Analysis of Algorithms L13.12

Page 13: Class on Design and Analysis of Algorithms, Lecture 13 Notes

Upper bound on the maximumflow value

Theorem. The value of any flow is boundedabove by the capacity of any cut. Proof. f = f (S,T )

= ∑∑ f (u, v) u∈S v∈T

≤ ∑∑c(u, v) u∈S v∈T

= c(S,T ) .

© 2001–15 by Leiserson et al Design and Analysis of Algorithms L13.13

Page 14: Class on Design and Analysis of Algorithms, Lecture 13 Notes

Residual network Definition. Let f be a flow on G = (V, E). The residual network Gf (V, Ef ) is the graph with strictly positive residual capacities

cf (u, v) = c(u, v) – f (u, v) > 0. Edges in Ef admit more flow.

If (v, u) ∉ E, c(v, u) = 0, but f (v, u) = – f (u, v).

|Ef | ≤ 2 |E|.

© 2001–15 by Leiserson et al Design and Analysis of Algorithms L13.14

Page 15: Class on Design and Analysis of Algorithms, Lecture 13 Notes

Flow and Residual Network

s

u v

t

x y

1:3 2:2

2:3

1:3

1:2 2:3

1:3

2:2

G

© 2001–15 by Leiserson et al Design and Analysis of Algorithms L13.15

s

u v

t

x y

2 2

1

2

1 2

2

2

1 1

2

1

1 1

Gf

Page 16: Class on Design and Analysis of Algorithms, Lecture 13 Notes

Augmenting paths Definition. Any path from s to t in Gf is an aug­menting path in G with respect to f. The flow value can be increased along an augmentingpath p by c f ( p) = min {c f (u,v)}.

(u,v)∈p

s

u v

t

x y

2 2

1

2

1 2

2

2

1 1

2

1

1 1

Gf

p = {s, u, x, v, t}, cf (p) = 1 © 2001–15 by Leiserson et al Design and Analysis of Algorithms L13.16

Page 17: Class on Design and Analysis of Algorithms, Lecture 13 Notes

Augmented Flow Network

p = {s, u, x, v, t}, cf (p) = 1

G s

u v

t

x y

2:3 2:2

3:3

1:3

1:2 2:3

0:3

2:2

The value of the maximum flow is 4. Note: Some flows on edges decreased.

© 2001–15 by Leiserson et al Design and Analysis of Algorithms L13.17

Page 18: Class on Design and Analysis of Algorithms, Lecture 13 Notes

    

Max-flow, min-cut theorem Theorem. The following are equivalent:1. | f | = c(S, T) for some cut (S, T). 2. f is a maximum flow. 3. f admits no augmenting paths. Proof. Next time!

© 2001–15 by Leiserson et al Design and Analysis of Algorithms L13.18

Page 19: Class on Design and Analysis of Algorithms, Lecture 13 Notes

Ford-Fulkerson max-flow algorithm

Algorithm:f [u, v] ← 0 for all u, v ∈ V while an augmenting path p in G wrt f exists

do augment f by cf (p)

© 2001–15 by Leiserson et al Design and Analysis of Algorithms L13.19

Page 20: Class on Design and Analysis of Algorithms, Lecture 13 Notes

MIT OpenCourseWarehttp://ocw.mit.edu

6.046J / 18.410J Design and Analysis of AlgorithmsSpring 2015

For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.