58
Maximum Flow Chapter 26

Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Embed Size (px)

Citation preview

Page 1: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Maximum Flow

Chapter 26

Page 2: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Flow Concepts

• Source vertex s – where material is produced

• Sink vertex t – where material is consumed

• For all other vertices – what goes in must go out– Flow conservation

• Goal: determine maximum rate of material flow from source to sink

Page 3: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Introduction - networkExample: oil pipelineRepresentation

Flow network: directed graph G=(V,E)

S t

v1

v2

v3

v4

S t

v1

v2

v3

v4source sink

Page 4: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Introduction – max-flow problemRepresentation

Flow network: directed graph G=(V,E)

S t

v1

v2

v3

v4

S t

v1

v2

v3

v4source sink

Informal definition of the max-flow problem:

What is the greatest rate at which material can be shipped from the source to the sink without violating any capacity contraints?

Example: oil pipeline

Page 5: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Introduction - capacity

S t

v1

v2

v3

v4

RepresentationFlow network: directed graph G=(V,E)

S t

v1

v2

v3

v4

u v12

u v6

c(u,v)=12

c(u,v)=6

Big pipe

Small pipe

8

3

6

8

6

6

3

3

Example: oil pipeline

Page 6: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Introduction - capacity

S t

v1

v2

v3

v4

RepresentationFlow network: directed graph G=(V,E)

S t

v1

v2

v3

v4

8

3

6

8

6

6

3

3

Example: oil pipeline

v4

v2

v3

v4

If (u,v) E c(u,v) = 0

0

0

0

6

Page 7: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Introduction – flow

S t

v1

v2

v3

v4

RepresentationFlow network: directed graph G=(V,E)

S t

v1

v2

v3

v4

u v6/12

u v6/6

f(u,v)=6

f(u,v)=6

Flow below capacity

Maximum flow

8

3

6

8

6

6

3

3

Example: oil pipeline

Page 8: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Introduction – flow

S t

v1

v2

v3

v4

RepresentationFlow network: directed graph G=(V,E)

S t

v1

v2

v3

v4

8

3

6

8

6

6

3

3

Example: oil pipeline

Page 9: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Introduction – flow

S t

v1

v2

v3

v4

RepresentationFlow network: directed graph G=(V,E)

S t

v1

v2

v3

v4

8

3

6

6/8

6/6

6/6

3

3

Example: oil pipeline

Page 10: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Introduction – flow

S t

v1

v2 v4

v3

RepresentationFlow network: directed graph G=(V,E)

S t

v1

v2

v3

v4

8

3

6

6/8

6/6

6/6

3

3

Example: oil pipeline

Page 11: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Introduction – flow

S t

v1

v2 v4

v3

RepresentationFlow network: directed graph G=(V,E)

S t

v1

v2

v3

v4

3/8

3/3

3/6

6/8

6/6

6/6

3

3

Example: oil pipeline

Page 12: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Introduction – flow

S t

v1

v2 v4

v3

RepresentationFlow network: directed graph G=(V,E)

S t

v1

v2

v3

v4

3/8

3/3

3/6

6/8

6/6

6/6

3

3

Example: oil pipeline

Page 13: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Introduction – flow

S t

v1

v2 v4

v3

RepresentationFlow network: directed graph G=(V,E)

S t

v1

v2

v3

v4

5/8

3/3

3/6

8/8

6/6

6/6

2/3

3

Example: oil pipeline

Page 14: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Introduction – cancellation

S t

v1

v2 v4

v3

RepresentationFlow network: directed graph G=(V,E)

S t

v1

v2

v3

v4

5/8

3/3

3/6

8/8

6/6

6/6

2/3

3

Example: oil pipeline

Page 15: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Introduction – cancellation

S t

v1

v2 v4

v3

RepresentationFlow network: directed graph G=(V,E)

S t

v1

v2

v3

v4

6/8

3/3

4/6

8/8

5/6

6/6

3/3

1/3

u

v

10 4

u

v

8/10 4

u

v

8/10 3/4

u

v

5/10 4

Example: oil pipeline

Page 16: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Maximum Flow Problem• Given: Directed graph G=(V, E),

Supply (source) node O, demand (sink) node TCapacity function u: E R .

• Goal: Given the arc capacities, send as much flow as possible

from supply node O to demand node Tthrough the network.

• Example:

4

4

56

44

5

5

O

A

DB

C

T

Page 17: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Towards the Augmenting Path Algorithm

• Idea: Find a path from the source to the sink, and use it to send as much flow as possible.

• In our example, 5 units of flow can be sent through the path O B D T ;Then use the path O C T to send 4 units of flow.

The total flow is 5 + 4 = 9 at this point.• Can we send more?

O

A

DB

C

T

4

4

5 644 5

5

5 5

44

5

Page 18: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Towards the Augmenting Path Algorithm

• If we redirect 1 unit of flow from path O B D T to path O B C T,

then the freed capacity of arc D T could be used to send 1 more unit of flow through path O A D T,

making the total flow equal to 9+1=10 .• To realize the idea of redirecting the flow in a systematic way,

we need the concept of residual capacities.

O

A

DB

C

T

44

5 644 5

5

5 55

44

44

1 5

1 1

Page 19: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Residual Network• The network given by the undirected arcs and residual capacities

is called residual network.• In our example,

the residual network before sending any flow:

Note that the sum of the residual capacities on both ends of an arc is equal to the original capacity of the

arc.• How to increase the flow in the network

based on the values of residual capacities?

O

A

DB

C

T

4

4

5 6

445

5

0

0

0

000

0 0

Page 20: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Residual capacities• Suppose we have an arc with capacity 6 and current flow 5:

• Then there is a residual capacity of 6-5=1 for any additional flow through B D .

• On the other hand, at most 5 units of flow can be sent back from D to B, i.e.,

5 units of previously assigned flow can be canceled. In that sense, 5 can be considered as

the residual capacity of the reverse arc D B .• To record the residual capacities in the network,

we will replace the original directed arcs with undirected arcs:

B D

6

5

B D1 5 The number at B is the residual capacity of BD;

the number at D is the residual capacity of DB.

Page 21: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Augmenting paths• An augmenting path is a directed path

from the source to the sink in the residual network such that

every arc on this path has positive residual capacity.• The minimum of these residual capacities

is called the residual capacity of the augmenting path. This is the amount

that can be feasibly added to the entire path.• The flow in the network can be increased

by finding an augmenting path and sending flow through it.

Page 22: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Updating the residual network by sending flow through augmenting paths

Continuing with the example, • Iteration 1: O B D T is an augmenting path

with residual capacity 5 = min{5, 6, 5}.• After sending 5 units of flow

through the path O B D T, the new residual network is:

O

A

DB

C

T

4

4

44

5

0

0

000

0 1 0 5

5 55 6 5 0

0 0

Page 23: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Updating the residual network by sending flow through augmenting paths

• Iteration 2: O C T is an augmenting path

with residual capacity 4 = min{4, 5}.• After sending 4 units of flow

through the path O C T, the new residual network is:

O

A

DB

C

T

4

4

0

0

0

4

50

0

0 1 0 5

5 50

14

4

4

Page 24: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Updating the residual network by sending flow through augmenting paths

• Iteration 3: O A D B C T is an augmenting path

with residual capacity 1 = min{4, 4, 5, 4, 1}.• After sending 1 units of flow

through the path O A D B C T , the new residual network is:

O

A

DB

C

T

00 5

5

0

4

4

4

0

0

0

1 5

1

4

4

3

3

1

1

1

2 4

0

5

3

Page 25: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Terminating the Algorithm:Returning an Optimal Flow

• There are no augmenting paths in the last residual network.So the flow from the source to the sink cannot be increased further, and the current flow is optimal.

• Thus, the current residual network is optimal.The optimal flow on each directed arc of the original network

is the residual capacity of its reverse arc:flow(OA)=1, flow(OB)=5, flow(OC)=4,

flow(AD)=1, flow(BD)=4, flow(BC)=1, flow(DT)=5, flow(CT)=5.The amount of maximum flow through the network is

5 + 4 + 1 = 10(the sum of path flows of all iterations).

Page 26: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Flow properties

Flow in G = (V,E): f: V x V R with 3 properties:

1) Capacity constraint: For all u,v V : f(u,v) < c(u,v)

2) Skew symmetry: For all u,v V : f(u,v) = - f(v,u)

3) Flow conservation: For all u V \ {s,t} : f(u,v) = 0 v V

Page 27: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Flow properties

Flow in G = (V,E): f: V x V R with 3 properties:

1) Capacity constraint: For all u,v V : f(u,v) < c(u,v)

2) Skew symmetry: For all u,v V : f(u,v) = - f(v,u)

3) Flow conservation: For all u V \ {s,t} : f(u,v) = 0 v V

S t

v1

v2

v3

v4

10

8/13

12/12

11/16

1/4

4/4

11/14

15/207/

7

4/9

Flow network G = (V,E)Note:

by skew symmetry

f (v3,v1) = - 12

Page 28: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Net flow and value of a flow

Net Flow: positive or negative value of f(u,v) Value of a Flow f: Def:

|f| = f(s,v) v V

S t

v1

v2

v3

v4

6/8

3/3

4/6

8/8

5/6

6/6

3/3

1/3

u

v

8/10 3/4

u

v

5/10 4

f(u,v) = 5

f(v,u) = -5

Page 29: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

The max-flow problem

Informal definition of the max-flow problem:

What is the greatest rate at which material can be shipped from the source to the sink without violating any capacity contraints?

Formal definition of the max-flow problem:

The max-flow problem is to find a valid flow for a given weighted directed graph G, that has the maximum value over all valid flows.

Page 30: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

The Ford-Fulkerson methoda way how to find the max-flow

This method contains 3 important ideas: 

      1) residual networks

    2) augmenting paths

    3) cuts of flow networks

 

Page 31: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Ford-Fulkerson – pseudo code

1 initialize flow f to 0

2 while there exits an augmenting path p

3 do augment flow f along p

4 return f

Page 32: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Ford Fulkerson – residual networks

S t

v1

v2

v3

v4

10

8/13

12/12

11/16

1/4

4/4

11/14

15/20

7/7

4/9

The residual network Gf of a given flow network G with a valid flow f consists of the same vertices v V as in G which are linked with residual edges (u,v) Ef that can admit more strictly positive net flow.

The residual capacity cf represents the weight of each edge Ef and is the amount of additional net flow f(u,v) before exceeding the capacity c(u,v)

Flow network G = (V,E)

cf(u,v) = c(u,v) – f(u,v)

S t

v1

v2

v3

v4

residual network Gf = (V,Ef)

5

11

8

5

Page 33: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Ford Fulkerson – residual networks

S t

v1

v2

v3

v4

10

8/13

12/12

11/16

1/4

4/4

11/14

15/20

7/7

4/9

Flow network G = (V,E)

cf(u,v) = c(u,v) – f(u,v)

S t

v1

v2

v3

v4

residual network Gf = (V,Ef)

1111

8

12

5

3

43

5

7

5

11

5

154

The residual network Gf of a given flow network G with a valid flow f consists of the same vertices v V as in G which are linked with residual edges (u,v) Ef that can admit more strictly positive net flow.

The residual capacity cf represents the weight of each edge Ef and is the amount of additional net flow f(u,v) before exceeding the capacity c(u,v)

Page 34: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Ford Fulkerson – augmenting paths

S t

v1

v2

v3

v4

10

8/13

12/12

11/16

1/4

4/4

11/14

15/20

7/7

4/9

cf(p) = min{cf (u,v): (u,v) is on p}

Flow network G = (V,E) residual network Gf = (V,Ef)

Definition: An augmenting path p is a simple (free of any cycle) path from s to t in the residual network Gf

Residual capacity of p

S t

v1

v2

v3

v4

11

8

12

5

3

43

5

7

5

11

5

11

154

Page 35: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Ford Fulkerson – augmenting paths

S t

v1

v2

v3

v4

10

8/13

12/12

11/16

1/4

4/4

11/14

15/20

7/7

4/9

cf(p) = min{cf (u,v): (u,v) is on p}

Flow network G = (V,E)

S t

v1

v2

v3

v4

11

8

12

5

3

43

5

7

5

residual network Gf = (V,Ef)

11

5

11

154

Definition: An augmenting path p is a simple (free of any cycle) path from s to t in the residual network Gf

Residual capacity of p

Augmenting path

Page 36: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Ford Fulkerson – augmenting paths

S t

v1

v2

v3

v4

10

8/13

12/12

11/16

1/4

4/4

11/14

15/20

7/7

4/9

Flow network G = (V,E)

S t

v1

v2

v3

v4

11

8

12

5

3

43

5

7

5

residual network Gf = (V,Ef)

11

5

11

154

We define a flow: fp: V x V R such as:

cf(p) if (u,v) is on p

fp(u,v) = - cf(p) if (v,u) is on p

0 otherwise

Page 37: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Ford Fulkerson – augmenting paths

S t

v1

v2

v3

v4

10

8/13

12/12

11/16

1/4

4/4

11/14

15/20

7/7

4/9

Flow network G = (V,E)

S t

v1

v2

v3

v4

11

-4/8

12

5

3

43

4/5

7

-4/5

residual network Gf = (V,Ef)

11

4/5

11

-4/154/4

Our virtual flow fp along the augmenting path p in Gf

cf(p) if (u,v) is on p

fp(u,v) = - cf(p) if (v,u) is on p

0 otherwise

We define a flow: fp: V x V R such as:

Page 38: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Ford Fulkerson – augmenting paths

S t

v1

v2

v3

v4

10

8/13

12/12

11/16

1/4

4/4

11/14

15/20

7/7

4/9

Flow network G = (V,E)

S t

v1

v2

v3

v4

11

-4/8

12

5

3

43

4/5

7

-4/5

residual network Gf = (V,Ef)

11

4/5

11

-4/154/4

Our virtual flow fp along the augmenting path p in Gf

cf(p) if (u,v) is on p

fp(u,v) = - cf(p) if (v,u) is on p

0 otherwise

We define a flow: fp: V x V R such as:

Page 39: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Ford Fulkerson – augmenting the flow

S t

v1

v2

v3

v4

10

12/13

12/12

11/16

1/4

4/4

11/14

19/20

7/7

0/9

Flow network G = (V,E)

S t

v1

v2

v3

v4

11

8

12

5

3

43

4/5

7

5

residual network Gf = (V,Ef)

11

4/5

11

154/4

Our virtual flow fp along the augmenting path p in Gf

New flow: f´: V x V R : f´=f + fp

cf(p) if (u,v) is on p

fp(u,v) = - cf(p) if (v,u) is on p

0 otherwise

We define a flow: fp: V x V R such as:

Page 40: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Ford Fulkerson – new valid flowproof of capacity constraint

Proof:

fp (u ,v) < cf (u ,v) = c (u ,v) – f (u ,v)

(f + fp) (u ,v) = f (u ,v) + fp (u ,v) < c (u ,v)

Lemma:

f´ : V x V R : f´ = f + fp in G

Capacity constraint:

For all u,v V, we require f(u,v) < c(u,v)

cf(p) if (u,v) is on p

fp(u,v) = - cf(p) if (v,u) is on p

0 otherwise

cf(p) = min{cf (u,v): (u,v) is on p}

cf(u,v) = c(u,v) – f(u,v)

Page 41: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

The Ford-Fulkerson method

Ford-Fulkerson(G,s,t) 1 for each edge (u,v) in G.E do 2 f(u,v) f(v,u) 0 3 while there exists a path p from s to t in residual

network Gf do4 cf = min{cf(u,v): (u,v) is in p} 5 for each edge (u,v) in p do6 f(u,v) f(u,v) + cf

7 f(v,u) -f(u,v)8 return f

The algorithms based on this method differ in how they choose p in step 3.If chosen poorly the algorithm might not terminate.

Page 42: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Execution of Ford-Fulkerson (1)

Left Side = Residual Graph Right Side = Augmented Flow

Page 43: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Execution of Ford-Fulkerson (2)

Left Side = Residual Graph Right Side = Augmented Flow

Page 44: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Cuts• Does the method find the minimum flow?

– Yes, if we get to the point where the residual graph has no path from s to t– A cut is a partition of V into S and T = V – S, such that s S and t T– The net flow (f(S,T)) through the cut is the sum of flows f(u,v), where s S

and t T• Includes negative flows back from T to S

– The capacity (c(S,T)) of the cut is the sum of capacities c(u,v), where s S and t T• The sum of positive capacities

– Minimum cut – a cut with the smallest capacity of all cuts.|f|= f(S,T) i.e. the value of a max flow is equal to the capacity of a min cut.

8/13

8/11

5/52/4

10/15

10

6/14

13/19

3/3

s t9

a b

c dCut capacity = 24 Min Cut capacity = 21

Page 45: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Max Flow / Min Cut Theorem1. Since |f| c(S,T) for all cuts of (S,T) then if |f| =

c(S,T) then c(S,T) must be the min cut of G2. This implies that f is a maximum flow of G3. This implies that the residual network Gf contains

no augmenting paths.• If there were augmenting paths this would contradict

that we found the maximum flow of G

• 1231 … and from 23 we have that the Ford Fulkerson method finds the maximum flow if the residual graph has no augmenting paths.

Page 46: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Worst Case Running Time

• Assuming integer flow• Each augmentation increases the value of the flow by some

positive amount.• Augmentation can be done in O(E).• Total worst-case running time O(E|f*|), where f* is the max-

flow found by the algorithm.• Example of worst case:

Augmenting path of 1 Resulting Residual Network Resulting Residual Network

Page 47: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Application – Bipartite Matching

• Example – given a community with n men and m women

• Assume we have a way to determine which couples (man/woman) are compatible for marriage– E.g. (Joe, Susan) or (Fred, Susan) but not (Frank, Susan)

• Problem: Maximize the number of marriages– No polygamy allowed– Can solve this problem by creating a flow network out of a

bipartite graph

Page 48: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Bipartite Graph

• A bipartite graph is an undirected graph G=(V,E) in which V can be partitioned into two sets V1 and V2 such that (u,v) E implies either u V1 and v V12 or vice versa.

• That is, all edges go between the two sets V1 and V2 and not within V1 and V2.

Page 49: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Model for Matching Problem

• Men on leftmost set, women on rightmost set, edges if they are compatible

A

B

C

D

X

Y

Z

Men Women

A

B

C

D

X

Y

Z

A matching

A

B

C

D

X

Y

Z

Optimal matching

Page 50: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Solution Using Max Flow

• Add a supersouce, supersink, make each undirected edge directed with a flow of 1

A

B

C

D

X

Y

Z

A

B

C

D

X

Y

Z

st

Since the input is 1, flow conservation prevents multiple matchings

Page 51: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Transshipment Problem• Given: Directed network G=(V, E)

Supply (source) nodes Si with supply amounts si, i=1,…,p

Demand (sink) nodes Di with demand amounts di, i=1,…,q

Total supply ≥ total demandCapacity function u: E R

• Goal: Find a feasible flow through the network which satisfies the total demand (if such a flow exists).

• Ex.:

A

D1B

C

S1

D2S2

11

16

17

8

22

19

4

2

4

5

15 59

5

5

Page 52: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Solving the Transshipment Problem via Maximum Flow• The transshipment problem can be solved by creating and solving a related

instance of maximum flow problem:– Create a supersource O. For each supply node Si, add an arc O Si with

capacity equal to the supply amount of Si .

– Create a supersink T. For each demand node Di, add an arc Di T with capacity equal to the supply amount of Di .

– Find the maximum flow from O to T in the resulting auxiliary network.– If maximum flow value = total demand

then the current maximum flow is a feasible flow for the transshipment problem,else the problem is infeasible

A

D1B

C

S1

D2S2

22

19

4

2

4

5

15 59

5

5

11

16

17

8

OT

11

16

17

8

Page 53: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Solving the Transshipment Problem via Maximum Flow• In our example,– The maximum flow from O to T is obtained by applying the

Augmenting Path algorithm. The maximum flow value is 25.The bold red numbers on the arcs show the flow values.

– Since the maximum flow value = 25 = 17+8 = total demand, the current maximum flow is a feasible flow

for the transshipment problem.

22

19

4

2

4

5

15

A

D1B

C

S1

D2S2

59

5

5

11

16

17

8

OT

11

16

17

8

8

13

18

1

2

45

2

217

8

9

16

Page 54: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Showing the infeasibility of an assignment problem using minimum-cut-based arguments

• The O-side of the minimum cut is {O, A, B, D, x, y, z} (the set of the nodes that are reachable from O via augmenting paths)

• Return to the original network (delete nodes O and T and the arcs incident to them).

O

T1

1 1 1

1

11

111

A CBpeople D E F

jobs x y z u v w1 1 1 1

1

Page 55: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Solving the Assignment Problem via Maximum Flow• The assignment problem can be solved by creating and solving a related instance

of the transshipment problem:– Each person-node is considered as a supply node with supply amount 1.– Each job-node is considered as a demand node with demand amount 1.– Assign capacity 1 to each arc.– Solve the resulting transshipment problem by finding maximum flow in the

auxiliary network.– If maximum flow value = n

then the current maximum flow gives a feasible assignment,else the assignment problem is infeasible.

A CBpeople D E

jobs x y z u v

1 1 1 1 1

1 1 1 1 1

Page 56: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Solving the Assignment Problem via Maximum Flow• In our example,

the red numbers on the arcs show the optimal flow values.Since the maximum flow value is 5,

the assignment problem is feasible.The feasible assignment is A x , B y, C u , D z , E v .

A CBpeople D E

jobs x y z u v

1 1 1 1 1

1 1 1 1 1

O

T

11 1 1

1

1 11

11

11111

Page 57: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Showing the infeasibility of an assignment problem using maximum-flow-based arguments

• Let’s solve the assignment problem below via maximum flow.The red numbers on the arcs show the optimal flow values.Since the maximum flow value = 5 < 6 = number of jobs,

the assignment problem is infeasible.

O

T1

1 1 1

1

11

111

A CBpeople D E F

jobs x y z u v w1 1 1 1

1

Page 58: Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices

Showing the infeasibility of an assignment problem using minimum-cut-based arguments

• The O-side of the minimum cut is {O, A, B, D, x, y, z} (the set of the nodes that are reachable from O via augmenting paths)

• Return to the original network (delete nodes O and T and the arcs incident to them).

O

T1

1 1 1

1

11

111

A CBpeople D E F

jobs x y z u v w1 1 1 1

1