Maximum Flow Networks

32
1 Maximum Flow Networks Suppose G = (V, E) is a directed network. Each edge (i,j) in E has an associated ‘capacity’ u ij . Goal: Determine the maximum amount of flow between two specified vertices s and t. The capacity v of a path P is the sum of its constituent edge flows: v = Σx ij where x ij is the flow from vertex i to vertex j. Applications to design: supply networks oil pipelines road traffic

description

Maximum Flow Networks. Suppose G = (V, E) is a directed network. Each edge (i,j) in E has an associated ‘capacity’ u ij . Goal: Determine the maximum amount of flow between two specified vertices s and t. The capacity v of a path P is the sum of its constituent - PowerPoint PPT Presentation

Transcript of Maximum Flow Networks

Page 1: Maximum Flow Networks

1

Maximum Flow Networks

Suppose G = (V, E) is a directed network. Each edge (i,j) in E has an

associated ‘capacity’ uij.

Goal: Determine the maximum amount of flow between two specified vertices s and t. The capacity v of a path P is the sum of its constituent

edge flows: v = Σxij where xij is the flow from vertex i to vertex j.

Applications to design:supply networksoil pipelines road traffic

Page 2: Maximum Flow Networks

2

BackgroundAssumptions:

• Integer data

• Directed network

• Nonnegative capacities on each arc

• Vertex s is the source

• Vertex t is the sink

Definitions:

• Residual network

• Cut

Techniques:

1. Augmenting Paths – Examine residual network for s-t paths.

2. Preflow-Push – Flow moved according to individual edge not path.

Page 3: Maximum Flow Networks

3

Maximum Flow as Linear Programming Problem

subject to

Ej)(i, ux0 ijij

v maximize

ts, ieach for 0xxj

jij

ij

vj

sjx

xj

jt v

0v

Page 4: Maximum Flow Networks

4

Example

ts

2

3

43,9

1,2

2,4

8,8 7,9

4,7

2,6

Each edge is labeled as (xij, uij) = (flow, capacity).However, this flow value, v(x) = 11, is not a maximum.

Page 5: Maximum Flow Networks

5

Residual Network

Given a current flow x, keep track of how much further the flow can be increased in each direction of the edge.

For any edge in G: i jxij, uij

The corresponding

edge (with capacities)

in residual network of G:

i j

uij -xij

xij

The residual network of G, G(x), has edges with positive residual capacity,

rij = uij – xij + xji. In general, it is the amount by which we can further

increase flow from i to j in the current network.

Page 6: Maximum Flow Networks

6

Example – Re-examined

ts

2

3

43,9

1,2

2,4

8,8 7,9

4,7

2,6

Network with flows and capacities.

ts

2

3

43

1

2

82

3

2

Residual network with capacities.

7

4

2

6

16

We know this network flow is not a maximum. How can we get a better one?What do we do in general?

Page 7: Maximum Flow Networks

7

A cut is defined by a partition of the vertex set E into subsets S and S* = E – S.

The cut [S,S*] consists of all edges with one endpoint in S and the other in S*.

The forward edges of [S,S*] are denoted (S, S*). The backward edges are

denoted as (S*,S). An s-t cut [S,S*] has s in S and t in S*.

The removal of the forward edges in an s-t cut will separate vertices s and t.

That is, there is no longer a directed s to t path.

The capacity of any cut [S,S*], u[S,S*], is the sum of the capacities of the

forward edges of the cut. u[S,S*] is an upper bound on the amount of flow

sent from S to S*. A minimum s-t cut has the smallest capacity among all s-t

cuts.

Cuts

Page 8: Maximum Flow Networks

8

61

2

3 5

410

5

10 8

8

8

5

61

2

3 5

410

5

10 8

8

8

5

Examples of 1-6 cuts

S = { }

S* = { }

Forward edges of [S,S*]=

{ }

u[S, S*] = =

4 4

S = { }

S* = { }

Forward edges of [S,S*]=

{ }

u[S, S*] = =

Page 9: Maximum Flow Networks

9

Theorem

If x is any feasible flow and if [S,S*] is any s-t cut, then the flow value, v(x),

from s to t is at most u[S,S*].

Corollary

the max flow value ≤ the minimum cut capacity

Max-Flow Min-Cut Theorem

For any capacitated network, the value of the maximum

s-t flow, x’, equals the capacity of a minimum s-t cut, [S,S*].

v(x’) = u [S,S*]

Theorems

Page 10: Maximum Flow Networks

10

• Given the flow x, look for a path P from s to t in the residual network G(x) along which flow can be sent. Then send as much flow along P as possible.

• We call any directed path P from s to t in the residual network an augmenting path. The residual capacity of such a path is δ(P) = min{rij:(i, j) P).

• To augment along P is to send δ(P) units of flow along each edge of the path. We then modify x and the residual capacities rij appropriately.

• rij := rij – δ(P) for each edge (i,j) P

• rji := rji + δ(P) for each edge (i, j) P

• Result: flow value, v, increases by δ(P).

Improving a Flow

Page 11: Maximum Flow Networks

11

Example

ts

2

3

43,9

1,2

2,4

8,8 7,9

4,7

2,6

Network with flows and capacities. v =11

ts

2

3

43

1

2

82

3

2

Residual network with capacities.

7

4

2

6

16

Augment along path P = s-2-4-t. δ(P) = min{6, 2, 3} = 2. new flow value =13

ts

2

3

45,9

1,2

4,4

8,8 7,9

6,7

2,6 ts

2

3

45

1

82

1

2

7

6

4

6

14

Page 12: Maximum Flow Networks

12

Example – Augmenting Paths

61

2

3 5

46

2

4

8 5

83

2

6

61

2

3 5

42

2

4

8 5

43

2

6

Step 1: Push 4 units along path 1-2-4-6

44

Step 2: Push 5 units along path 1-3-5-6

61

2

3 5

42

2

4

3 5

43

21

44

5

5

Step 3: Push 2 units along path 1-2-5-4-6

61

2

3 5

46

2

4

3 5

21

21

6

5

5

Step 4: Push 1 units along path 1-3-5-4-6

2

Step 0: initial residual graph is original

Page 13: Maximum Flow Networks

13

Example – continued

61

2

3 5

46

2

4

2 5

13

26

7

6

No more augmenting paths

Maximum Flow in G is 12

61

2

3 5

46,6

0,2

4,4

6,8 5,5

7,8

3,32,2

6,6

61

2

3 5

46

2

4

8 5

83

2

6

Page 14: Maximum Flow Networks

14

THEOREM

The following are equivalent statements

1. The s-t flow x’ with value v(x’) is maximum

2. G(x’) contains no augmenting path.

3. There is an s-t cut [S,S*] with u[S,S*] = v(x’)

Page 15: Maximum Flow Networks

15

Generic Augmenting Path Algorithm• In this algorithm, we keep sending flow along augmenting paths until no s-t path

exists in the residual network.• Can carry out calculations entirely on G(x).• Flows in G are found at the very end.

algorithm augmenting_path;

begin

x := 0

while G(x) contains a directed path from s to t do

begin

P = Find_Path(s, t, G(x));

δ(P) := min{rij: (i,j) P};

augment δ(P) units of flow along P;

update G(x);

end;

end;

Page 16: Maximum Flow Networks

16

Find_Path Options• More than one way to pick an augmenting path

• “Poor” choices can lead to many augmentations.

• Info lost when successive paths are found.

• Balance effort to find a “good” path with the reduction in # of augmentations.

• Maximum capacity – select path P such that δ(P) is as large as possible.• Shortest path – use the path with the minimum number of edges.• Scaling – successively solve subproblems with a certain capacity.

1

3

2

4

50

1

50

50 50

Page 17: Maximum Flow Networks

17

Distance Labels• For the “shortest path” version of the augmenting path algorithm and for another max

flow algorithm, the pre-flow push, the notion of distance labels is needed.• The distance label d(j) is a nonnegative integer assigned to each j in G(x).• The distance labels are valid if

d(t) = 0d(i) ≤ d(j)+1 for each (i,j) G(x)

• If d(j) are valid, then d(j) is a lower bound on the shortest distance from j to t.• If d(s) ≥ n then there is no s-t path in G(x). (n = number of vertices in G)• An admissible edge in G(x) is one where d(i) = d(j) + 1.• An admissible path is a path from s to t consisting of admissible edges and is a shortest

augmenting path from s to t.

1

3

2

4

5

Page 18: Maximum Flow Networks

18

Shortest Distance Algorithm• Admissible paths are successively built by advancing until vertex t is reached.• If no admissible edge is available at some point, then retreat and relabel will be a

way of updating distances in the new residual graph.• In this way, we maintain valid distance labels without starting from scratch.

algorithm shortest augmenting path;

begin

x:= 0; calculate exact distance labels, d(j) to vertex t;

j := s;

while d(s) <n do

begin

if j has an admissible edge then

begin

advance(j);

if j = t then

augment and set j := s;

end;

else retreat(j);

end;

end;

Page 19: Maximum Flow Networks

19

algorithm retreat(j);

begin

d(j) := min{d(k)+1: (j,k) in E(j) with rjk > 0};

if E(j) with rjk > 0 empty then d(j) = n;

if j ≠ s then j := pred(k);

end;

algorithm advance(j);

begin

let (j,k) be an admissible edge from j;

pred(k)=j;

j := k;

end;

algorithm augment;

begin

derive path P from pred;

δ(P) := min{rij: (i,j) P};

augment δ(P) units of flow along P;

end;

Page 20: Maximum Flow Networks

20

Example

1

3

2

4

4

3

5

2

1

1. Calculate d(j)

d(3)=1

d(2)=1

1

3

2

4

4

3

5

2

1

d(4)=0d(1)=2

2. Advance 1-2-4, δ(P) =1, augment

d(3)=1

d(2)=1

1

3

2

4

4

3

5

1 1

d(4)=0d(1)=2

1

4. Advance 1-3-4, δ(P) =4, augment

d(3)=1

3. Advance 1-2, retreat, relabel vertex 2

d(2)=2

1

3

2

4

4

3

5

1 1

d(4)=0d(1)=2

1

Page 21: Maximum Flow Networks

21

Example

5. Advance 1, retreat relabel 1

6. Advance 1-2-3-4, δ(P) =1, augment

d(3)=1

d(2)=2

1

3

2

4

4

2

5

2 1

d(4)=0d(1)=3

7. Advance 1, retreat, relabel 1

8. Maximum Flow achieved

d(2)=2

1

3

2

4

4

3

4

1 1

d(4)=0d(1)=3

1

1

d(3)=1

1

d(2)=2

1

3

2

4

4

2

5

2 1

d(4)=0d(1)=4

1

d(3)=1

d(2)=2

1

3

2

4

4

3

4

1 1

d(4)=0d(1)=2

1

1

d(3)=1

Page 22: Maximum Flow Networks

22

Example - Results

1

3

2

4

4,4

1,3

5,5

2,2

1,1

Note monotonicity of path lengths1-2-41-3-4

1-2-3-4

Note monotonicity of distance labels

1 2 3 4 5 6 7

d(1) 2 2 2 2 3 3 4

d(2) 1 1 2 2 2 2 2

d(3) 1 1 1 1 1 1 1

d(4) 0 0 0 0 0 0 0

Page 23: Maximum Flow Networks

23

Additional Exercises

1

3

2

4

22

11

25

13 17

5

6

7

8

17

21

30

24

26

18

19

22

1

3

2

4

8

10

11

9 5

6

5

7

6

11

9

6 7

7

8

1

3

2

4

32

1

31

5

6

1

12

7

4

2

source

source

sourcesink

sink

sink

Page 24: Maximum Flow Networks

24

Preflow-push Algorithm• Distance labels – d(t) = 0; d(i) ≤d(j) + 1 for each (i,j) in G(x)• Excess flow – e(i) = excess at each vertex for a given preflow• Active vertices – vertices with positive excess• Admissible edges – edges that satisfy the condition that d(i) = d(j) + 1• Preflow – infeasible solution; • Algorithm strives for feasibility/optimality when all excess at sink and source

algorithm preflow-push;

begin

preprocess;

while network contains an active vertex do

begin

select an active node i;

push/relabel(i);

end;

end;

Page 25: Maximum Flow Networks

25

algorithm push/relabel(i);

begin

if the networks contains an admissible edge (i,j) then

push δ = min{e(i), rij} units of flow from vertex i to vertex j;

else replace d(i) by min{d(j)+1: (i,j) in E(i) and rij > 0};

end;

algorithm preprocess;

begin

x := 0;

compute the exact distance labels d(i) from s;

xsj := usj for each edge (s,j) in E(s);

d(s) := n

end;

Page 26: Maximum Flow Networks

26

Example

1

3

2

4

4

3

5

2 1

e(4)=0d(4)=0

e(3)=0d(3)=1

e(2)=0d(2)=1

e(1)=0d(1)=2

1

3

2

4

4

3

5

2 1

e(4)=0d(4)=0

e(3)=4d(3)=1

e(2)=2d(2)=1

e(1)=0d(1)=4

1. Network G

Active nodes:

2. preprocess: first residual graph

Active nodes: 2, 3

Page 27: Maximum Flow Networks

27

Example

1

3

2

4

4

3

1

2 1

e(4)=5d(4)=0

e(3)=0d(3)=1

e(2)=1d(2)=2

e(1)=0d(1)=4

1

3

2

4

4

3

5

2 1

e(4)=1d(4)=0

e(3)=4d(3)=1

e(2)=1d(2)=2

e(1)=0d(1)=4 4

3. Saturating push of 1 unit along 2-4; Relabel distance node 2

Selected node: 2Active nodes: 3

Active nodes: 3, 2

4. Push of 4 units along 3-4

Selected node: 3Active nodes: 2

Active nodes: 2

Page 28: Maximum Flow Networks

28

Example

1

3

2

4

4

2 1

e(4)=6d(4)=0

e(3)=0d(3)=1

e(2)=0d(2)=2

e(1)=0d(1)=4 5

5. Push of 1 unit along 2-3

Selected node: 2Active nodes:

Active nodes: 3

6. Saturating Push of 1 units along 3-4

Selected node: 3Active nodes:

Active nodes:

1

3

2

4

4

2

1

2 1

e(4)=5d(4)=0

e(3)=1d(3)=1

e(2)=0d(2)=2

e(1)=0d(1)=4 4

1 2 1

Page 29: Maximum Flow Networks

29

61

2

3 5

410

5

10 8

8

8

5

Preflow-Push: Example 2

Page 30: Maximum Flow Networks

30

• Let G = (V,E) be a network with supplies and demands at each vertex• b(j) > 0 indicates supply at vertex j• b(j)<0 indicates demand at vertex j• Assumption: Σb(j) = 0• Does a flow, x, exist?

• Transform into a maximum flow network, G’• Add a source vertex, s, and a sink vertex, t.• Add edge (s, j) with capacity, rsj=b(j), if b(j)>0 • Add edge (j, t) with capacity, rjt=b(j), if b(j)<0 • Solve max flow from s to t

• Result: If the max flow in G’ saturates all the source and sink edges, then the original problem has a feasible solution. Otherwise, infeasible.

Checking if feasible flow exists

Page 31: Maximum Flow Networks

31

1

2

3

46 4

24

8

b(1) = 4

Example 1-Feasible Flow?

b(2) = 5

b(3) = -2

b(4) = -7

Page 32: Maximum Flow Networks

32

1

2

3

46 4

31

8

b(1) = 4

Example 2-Feasible flow?

b(2) = 5

b(3) = -2

b(4) = -7