chapter 27 maximum flow maximum flow problem the ford-fulkerson method m bipartite matching

39
Chapter 27 Maximum Flow • Maximum Flow Problem • The Ford-Fulkerson method • m bipartite matching

Post on 21-Dec-2015

285 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Chapter 27 Maximum Flow Maximum Flow Problem The Ford-Fulkerson method m bipartite matching

Chapter 27 Maximum Flow

• Maximum Flow Problem

• The Ford-Fulkerson method

• m bipartite matching

Page 2: Chapter 27 Maximum Flow Maximum Flow Problem The Ford-Fulkerson method m bipartite matching

Background:

• Just as we can model a road map as a directed graph in order to find the shortest path from one point to another, we can also interpret a directed graph as a “flow network” and use it to answer questions about material coursing through a system from a source,where the material is produced, to a sink, where it is consumed.

Page 3: Chapter 27 Maximum Flow Maximum Flow Problem The Ford-Fulkerson method m bipartite matching

Flow networks:

• A flow network G=(V,E) is a directed graph in which each edge (u,v)E has a nonnegative capacity c(u,v)>=0.If (u,v)E, we assume that c(u,v)=0.We distinguish two vertices in a flow network:a source s and a sink t.

s t

16

12

20

10 4 9 7

413

14

Page 4: Chapter 27 Maximum Flow Maximum Flow Problem The Ford-Fulkerson method m bipartite matching

Flow:

• Let G=(V,E) be a flow network (with capacity function c). Let s be the source of the network, and let t be the sink.A flow in G is a real-valued function f:V*V R that satisfies the following three properties:

• Capacity constraint: For all u,v V, we require f(u,v) <= c( u,v).• Skew symmetry: For all u,v V,we require f(u,v)=-f(v,u).• Flow conservation: For all u V-{s,t}, we require f(u,v) =0 vV

Page 5: Chapter 27 Maximum Flow Maximum Flow Problem The Ford-Fulkerson method m bipartite matching

Net flow and value of a flow f:

• The quantity f (u,v), which can be positive or negative, is called the net flow from vertex u to vertex v.

• The value of a flow is defined as

Vv

vsff ),(

Page 6: Chapter 27 Maximum Flow Maximum Flow Problem The Ford-Fulkerson method m bipartite matching

s t

11/16

12/12

15/20

10 1/4 4/9 7/7

4/48/13

11/14

A flow f in G with value . 19f

Page 7: Chapter 27 Maximum Flow Maximum Flow Problem The Ford-Fulkerson method m bipartite matching

v1

v2

10 4

v1

v2

8/10 4

v1

v2

8/10 3/4

v1

v2

5/10 4

v1

v2

10 2/4

(a) (b) (c) (d) (e)

Cancellation.(a) Vertices v1 and v2,with c(v1,v2)=10 and c(v2,v1)=4.(b)How we indicate the net flow 8 from v1 to v2. (c) An additional shipment of 3 is madefrom v2 to v1. (d) By cancelling flow going in opposite directions,we can represent the situation in (c) with positive net flow in onedirection only.(e) Another 7 is shipped from v2 to v1.

Page 8: Chapter 27 Maximum Flow Maximum Flow Problem The Ford-Fulkerson method m bipartite matching

Maximum-flow problem:

• Given a flow network G with source s and sink t

• Find a flow of maximum value from s to t.

• How to solve it efficiently?

Page 9: Chapter 27 Maximum Flow Maximum Flow Problem The Ford-Fulkerson method m bipartite matching

The Ford-Fulkerson method:

• This section presents the Ford-Fulkerson method for solving the maximum-flow problem.We call it a “method” rather than an “algorithm” because it encompasses several implementations with different running times.The Ford-Fulkerson method depends on three important ideas that transcend the method and are relevant to many flow algorithms and problems: residual networks,augmenting paths,and cuts. These ideas are essential to the important max-flow min-cut theorem,which characterizes the value of maximum flow in terms of cuts of the flow network.

Page 10: Chapter 27 Maximum Flow Maximum Flow Problem The Ford-Fulkerson method m bipartite matching

Continue:

• FORD-FULKERSON-METHOD(G,s,t)

• initialize flow f to 0

• while there exists an augmenting path p

• do augment flow f along p

• return f

Page 11: Chapter 27 Maximum Flow Maximum Flow Problem The Ford-Fulkerson method m bipartite matching

Residual networks:

• Intuitively,given a flow network and a flow, the residual network consists of edges that can admit more net flow.More formally,suppose that we have a flow network G=(V,E) with source s and sink t.Let f be a flow in G, and consider a pair of vertices u,vV.The amount of additional net flow we can push from u to v before exceeding the capacity c(u,v) is the residual capacity of (u,v), given by: cf(u,v)=c(u,v)-f(u,v)

• Given a flow network G=(V,E) and a flow f,the residual network of G induced by f is Gf=(V,Ef),where Ef={(u,v)V*V: cf (u,v) > 0}

Page 12: Chapter 27 Maximum Flow Maximum Flow Problem The Ford-Fulkerson method m bipartite matching

Continue:

• Lemma 27.2

• Let G=(V,E) be a flow network with source s and sink t, and let f be a flow in G.Let Gf be the residual network of G induced by f,and let f’ be a flow in Gf.Then, the flow sum f+f’ is a flow in G with value .'' ffff

Page 13: Chapter 27 Maximum Flow Maximum Flow Problem The Ford-Fulkerson method m bipartite matching

Augmenting paths:

• Given a flow network G=(V,E) and a flow f, an augmenting path is a simple path from s to t in the residual network Gf.

• We call the maximum amount of net flow that we can ship along the edges of an augmenting path p the residual capacity of p, given by cf(p)=min{cf(u,v):(u,v) is on p}.

Page 14: Chapter 27 Maximum Flow Maximum Flow Problem The Ford-Fulkerson method m bipartite matching

Example:

• (a)The flow network G and flow f .

• (b)The residual network Gf with augmenting path p shaded; its residual capacity is cf(p)=c(v2,v3)=4.

• (c) The flow in G that results from augmenting along path p by its residual capacity 4.

• (d) The residual network induced by the flow in (c).

Page 15: Chapter 27 Maximum Flow Maximum Flow Problem The Ford-Fulkerson method m bipartite matching

4/9s

v2 v4

t

v3v111/16

8/13

12/12

10 1/4

15/20

4/4

7/7

11/14

5s

v2 v4

t

v3v15

8

12

11 3

5

4

7

11

4

3

511 15

9s

v2 v4

t

v3v111/16

12/13

12/12

10 1/4

19/20

4/4

7/7

11/14

117s

v2 v4

t

v3v15

12

12

11 3

1

4

11

9

3

119

(a) (b)

(c) (d)

Page 16: Chapter 27 Maximum Flow Maximum Flow Problem The Ford-Fulkerson method m bipartite matching

Continue:

• Lemma 27.3

• Let G=(V,E) be a flow network, let f be a flow in G,and let p be an augmenting path in Gf.Define a function fp:V*V R by

• if (u,v) is on p,

• fp(u,v)= if (v,u) is on p,

• otherwise.

• Then, fp is a flow in Gf with value .

0

)(

)(

pc

pc

f

f

0)( pcf fp

Page 17: Chapter 27 Maximum Flow Maximum Flow Problem The Ford-Fulkerson method m bipartite matching

Continue:

• Corollary 27.4

• Let G=(V,E) be a flow network, let f be a flow in G,and let p be an augmenting path in Gf. Let fp be defined as in Lemma 27.3.Define a function f’:V*V R by f’=f+fp. Then, f’ is a flow in G’ with value .

ffff p '

Page 18: Chapter 27 Maximum Flow Maximum Flow Problem The Ford-Fulkerson method m bipartite matching

Cuts of flow networks:

• The Ford-Fulkerson method repeatedly augments the flow along augmenting paths until a maximum flow has been found.The max-flow min-cut theorem,which we shall prove shortly, tells us that a flow is maximum if and only if its residual network contains no augmenting path.

• A cut (S,T) of flow network G=(V,E) is a partition of V into S and T=V-S such that sS and t T.If f is a flow, then the net flow across the cut (S,T) is defined to be f(S,T).The capacity of the cut (S,T) is c(S,T).

Page 19: Chapter 27 Maximum Flow Maximum Flow Problem The Ford-Fulkerson method m bipartite matching

s

v2

v1

t

v4

v311/16

8/13

10 1/4

12/12

11/14

4/9

15/20

4/4

7/7

S T

A cut (S,T) in the flow network G,where S={s,v1,v2} and T={v3,v4,t}.The vertices in S are black,and the vertices inT are white.The net flow across (S,T) is f(S,T)=19,and thecapacity is c(S,T)=26.

Page 20: Chapter 27 Maximum Flow Maximum Flow Problem The Ford-Fulkerson method m bipartite matching

Continue:

• Lemma 27.5

• Let f be a flow in a flow network G with source s and sink t,and let (S,T) be a cut of G.Then, the net flow across (S,T) is f(S,T)= .f

Page 21: Chapter 27 Maximum Flow Maximum Flow Problem The Ford-Fulkerson method m bipartite matching

Continue:

• Corollary 27.6

• The value of any flow f in a flow network G is bounded from above by the capacity of any cut of G.

Page 22: Chapter 27 Maximum Flow Maximum Flow Problem The Ford-Fulkerson method m bipartite matching

Continue:

• Theorem 27.7(Max-flow min-cut theorem)

• If f is a flow in a flow network G=(V,E) with source s and sink t,then the following conditions are equivalent:

• f is a maximum flow in G;

• The residual network Gf contains no augmenting paths;

• =c(S,T) for some cut (S,T) of G.f

Page 23: Chapter 27 Maximum Flow Maximum Flow Problem The Ford-Fulkerson method m bipartite matching

The basic Ford-Fulkerson algorithm:

• FORD-FULKERSON(G,s,t)• for each edge (u,v) E[G]• do f[u,v] 0• f[v,u] 0

• while there exists a path p from s to t in the residual network Gf

• do cf(p) min{cf(u,v): (u,v) is in p}

• for each edge (u,v) in p

• do f[u,v] f[u,v]+cf(p)

• f[v,u] -f[u,v]

Page 24: Chapter 27 Maximum Flow Maximum Flow Problem The Ford-Fulkerson method m bipartite matching

Example:

• The execution of the basic Ford-Fulkerson algorithm.(a)-(d) Successive iterations of the while loop. The left side of each part shows the residual network Gf from line 4 with a shaded augmenting path p.The right side of each part shows the new flow f that results from adding fp to f.The residual network in (a) is the input network G.(e) The residual network at the last while loop test.It has no augmenting paths,and the flow f shown in (d) is therefore a maximum flow.

Page 25: Chapter 27 Maximum Flow Maximum Flow Problem The Ford-Fulkerson method m bipartite matching

s

20

79

v2 v4

t

v3v116

13

12

10 4

4

14

4/9s

v2 v4

t

v3v14/16

13

4/12

10 4

20

4/4

7

4/14

(a)

Page 26: Chapter 27 Maximum Flow Maximum Flow Problem The Ford-Fulkerson method m bipartite matching

5s

v2 v4

t

v3v112

13

8

10 4

20

4

7

4

44

4

104/9

s

v2 v4

t

v3v111/16

13

4/12

7/10 4

7/20

4/4

7/7

11/14

(b)

Page 27: Chapter 27 Maximum Flow Maximum Flow Problem The Ford-Fulkerson method m bipartite matching

5s

v2 v4

t

v3v15

13

8

3 11

4

7

11

1144

3

13

74/9

s

v2 v4

t

v3v111/16

8/13

12/12

10 1/4

15/20

4/4

7/7

11/14

(c)

Page 28: Chapter 27 Maximum Flow Maximum Flow Problem The Ford-Fulkerson method m bipartite matching

5s

v2 v4

t

v3v15

8

11 3

4

7

11

11

12

4

3

5

155 9

s

v2 v4

t

v3v111/16

12/13

12/12

10 1/4

19/20

4/4

7/7

11/14

(d)

Page 29: Chapter 27 Maximum Flow Maximum Flow Problem The Ford-Fulkerson method m bipartite matching

s

v2 v4

t

v3v15

12

12

11 3

1

4

11

9

3

1197

(e)

Page 30: Chapter 27 Maximum Flow Maximum Flow Problem The Ford-Fulkerson method m bipartite matching

Time complexity:

• If each c(e) is an integer, then time complexity is O(|E|f*), where f* is the maximum flow.

• Reason: each time the flow is increased by at least one.

• This might not be a polynomial time algorithm since f* can be represented by log (f*) bits. So, the input size might be log(f*).

Page 31: Chapter 27 Maximum Flow Maximum Flow Problem The Ford-Fulkerson method m bipartite matching

The Edmonds-Karp algorithm

• Find the augmenting path using breadth-first search.

• Breadth-first search gives the shortest path for graphs with edge length 1.

• Time complexity of Edmonds-Karp algorithm is O(VE2).

Page 32: Chapter 27 Maximum Flow Maximum Flow Problem The Ford-Fulkerson method m bipartite matching

• Lemma: With each flow augmentation, the shortest-path distance between s and u for any u increases monotonically.

• Proof: (Fun part, not required)• Prove it by contradiction. • Let f’ is obtained from f by an augmentation and

d(f’,s,v)<d(f, s, v). • Assume that v is a node such that d(f’, s, v) is the

minimum satisfying d(f’,s,v)<d(f, s, v).

Page 33: Chapter 27 Maximum Flow Maximum Flow Problem The Ford-Fulkerson method m bipartite matching

• Consider u with d(f’, s, u)=d(f’, s, v)-1.• Based on the choice of v, we know that

d(f’, s, y)>=d(f, s, u).

Then (u, v) is not in e(

Page 34: Chapter 27 Maximum Flow Maximum Flow Problem The Ford-Fulkerson method m bipartite matching

Maximum bipartite matching:

• Given an undirected graph G=(V,E), a matching is a subset of edges ME such that for all vertices vV,at most one edge of M is incident on v.We say that a vertex v V is matched by matching M if some edge in M is incident on v;otherwise, v is unmatched. A maximum matching is a matching of maximum cardinality,that is, a matching M such that for any matching M’, we have . 'MM

Page 35: Chapter 27 Maximum Flow Maximum Flow Problem The Ford-Fulkerson method m bipartite matching

L R

A bipartite graph G=(V,E) with vertex partition V=LR.(a)A matching with cardinality 2.(b) A maximum matching with cardinality 3.

(a)L R

(b)

Page 36: Chapter 27 Maximum Flow Maximum Flow Problem The Ford-Fulkerson method m bipartite matching

Finding a maximum bipartite matching:

• We define the corresponding flow network G’=(V’,E’) for the bipartite graph G as follows. Let the source s and sink t be new vertices not in V, and let V’=V{s,t}.If the vertex partition of G is V=L R, the directed edges of G’ are given by E’={(s,u):uL} {(u,v):u L,v R,and (u,v) E} {(v,t):v R}.Finally, we assign unit capacity to each edge in E’.

• We will show that a matching in G corresponds directly to a flow in G’s corresponding flow network G’. We say that a flow f on a flow network G=(V,E) is integer-valued if f(u,v) is an integer for all (u,v) V*V.

Page 37: Chapter 27 Maximum Flow Maximum Flow Problem The Ford-Fulkerson method m bipartite matching

L R(a)

L R(b)

s t

(a)The bipartite graph G=(V,E) with vertex partition V=LR. A maximum matching is shown by shaded edges.(b) The correspondingflow network shown.Each edge has unit capacity.Shaded edges have a flow of 1,and all other edges carry no flow.

Page 38: Chapter 27 Maximum Flow Maximum Flow Problem The Ford-Fulkerson method m bipartite matching

Continue:

• Lemma 27.10

• Let G=(V,E) be a bipartite graph with vertex partition V=LR,and let G’=(V’,E’) be its corresponding flow network.If M is a matching in G, then there is an integer-valued flow f in G’ with value .Conversely, if f is an integer-valued flow in G’,then there is a matching M in G with cardinality .

Mf

fM

Page 39: Chapter 27 Maximum Flow Maximum Flow Problem The Ford-Fulkerson method m bipartite matching

The End: