Presentation is loading. Please wait.

Presentation is loading. Please wait.

Maximum Flow Chapter 26.

Similar presentations


Presentation on theme: "Maximum Flow Chapter 26."— Presentation transcript:

1 Maximum Flow Chapter 26

2 Flow Concepts Source vertex s Sink vertex t
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

3 Introduction - network
Representation Example: oil pipeline Flow network: directed graph G=(V,E) v1 v3 v1 v3 S S t t v2 v4 source v2 v4 sink

4 Introduction – max-flow problem
Representation Example: oil pipeline Flow network: directed graph G=(V,E) v1 v3 v1 v3 S S t t v2 v4 source v2 v4 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?

5 Introduction - capacity
Representation Example: oil pipeline Flow network: directed graph G=(V,E) 8 3 6 S t v1 v2 v3 v4 v1 v3 S t v2 v4 12 u v c(u,v)=12 c(u,v)=6 Big pipe u v 6 Small pipe

6 Introduction - capacity
Representation Example: oil pipeline Flow network: directed graph G=(V,E) 3 v1 v3 v1 v3 6 8 3 S S t t 3 6 8 v2 v4 v2 v4 6 If (u,v)  E  c(u,v) = 0 6 v2 v4 v4 v3

7 Introduction – flow Representation Example: oil pipeline
Flow network: directed graph G=(V,E) 8 3 6 S t v1 v2 v3 v4 v1 v3 S t v2 v4 6/12 u v f(u,v)=6 Flow below capacity 6/6 u v Maximum flow

8 Introduction – flow Representation Example: oil pipeline
Flow network: directed graph G=(V,E) 8 3 6 S t v1 v2 v3 v4 v1 v3 S t v2 v4

9 Introduction – flow Representation Example: oil pipeline
Flow network: directed graph G=(V,E) 8 3 6 6/8 6/6 S t v1 v2 v3 v4 v1 v3 S t v2 v4

10 Introduction – flow Representation Example: oil pipeline
Flow network: directed graph G=(V,E) 8 3 6 6/8 6/6 S t v1 v2 v3 v4 v1 v3 S t v2 v4

11 Introduction – flow Representation Example: oil pipeline
Flow network: directed graph G=(V,E) 3/8 3/3 3/6 6/8 6/6 3 S t v1 v2 v3 v4 v1 v3 S t v2 v4

12 Introduction – flow Representation Example: oil pipeline
Flow network: directed graph G=(V,E) 3/8 3/3 3/6 6/8 6/6 3 S t v1 v2 v3 v4 v1 v3 S t v2 v4

13 Introduction – flow Representation Example: oil pipeline
Flow network: directed graph G=(V,E) 5/8 3/3 3/6 8/8 6/6 2/3 3 S t v1 v2 v3 v4 v1 v3 S t v2 v4

14 Introduction – cancellation
Representation Example: oil pipeline Flow network: directed graph G=(V,E) 5/8 3/3 3/6 8/8 6/6 2/3 3 S t v1 v2 v3 v4 v1 v3 S t v2 v4

15 Introduction – cancellation
Representation Example: oil pipeline Flow network: directed graph G=(V,E) S t v1 v2 v3 v4 6/8 3/3 4/6 8/8 5/6 6/6 1/3 v1 v3 S t v2 v4 u u u u 10 4 8/10 4 8/10 3/4 5/10 4 v v v v

16 Maximum Flow Problem Given: Directed graph G=(V, E),
Supply (source) node O, demand (sink) node T Capacity function u: E  R . Goal: Given the arc capacities, send as much flow as possible from supply node O to demand node T through the network. Example: O A D B C T 4 5 6

17 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 = 9 at this point. Can we send more? A 4 4 5 5 O B 5 D 5 6 T 4 5 4 4 4 C 5

18 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. A 1 4 1 4 4 5 5 O B 5 4 D 5 6 T 4 5 4 4 1 4 5 C 5

19 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 D B C T 4 5 6

20 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: 5 B D 6 1 5 B D The number at B is the residual capacity of BD; the number at D is the residual capacity of DB.

21 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.

22 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 D B C T 4 4 5 6 1 5 4 4 5

23 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 D B C T 4 4 5 1 5 1 4 4 5 5 4

24 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 D B C T 3 1 2 4 5 4 1 5 5 5 4

25 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(OA)=1, flow(OB)=5, flow(OC)=4, flow(AD)=1, flow(BD)=4, flow(BC)=1, flow(DT)=5, flow(CT)=5. The amount of maximum flow through the network is = 10 (the sum of path flows of all iterations).

26 Flow properties

27 Flow properties Flow network G = (V,E) Note: by skew symmetry
12/12 v1 v3 Note: by skew symmetry f (v3,v1) = - 12 11/16 15/20 10 1/4 7/7 S t 4/9 4/4 8/13 v2 v4 11/14

28 Net flow and value of a flow
f(u,v) = 5 f(v,u) = -5 8/10 3/4 5/10 4 v v 3/3 v1 v3 4/6 6/8 3/3 S t 1/3 6/6 8/8 v2 v4 5/6

29 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.

30 The Ford-Fulkerson method a way how to find the max-flow
This method contains 3 important ideas:        1) residual networks     2) augmenting paths     3) cuts of flow networks

31 Ford-Fulkerson – pseudo code
1 initialize flow f to 0 2 while there exits an augmenting path p do augment flow f along p 4 return f

32 Ford Fulkerson – residual networks
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) residual network Gf = (V,Ef) 12/12 v1 v3 v1 v3 5 11 11/16 15/20 10 1/4 7/7 S t S t 4/9 8 5 4/4 8/13 v2 v4 v2 v4 11/14 cf(u,v) = c(u,v) – f(u,v)

33 Ford Fulkerson – residual networks
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) residual network Gf = (V,Ef) 12/12 12 v1 v3 v1 v3 5 11/16 5 15/20 11 4 10 1/4 7/7 11 3 7 15 S t S t 4/9 5 5 4/4 4 8/13 8 3 v2 v4 v2 v4 11/14 11 cf(u,v) = c(u,v) – f(u,v)

34 Ford Fulkerson – augmenting paths
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 cf(p) = min{cf (u,v): (u,v) is on p} Flow network G = (V,E) residual network Gf = (V,Ef) 12/12 12 v1 v3 v1 v3 5 11/16 5 15/20 11 4 10 1/4 7/7 11 3 7 15 S t S t 4/9 5 5 4/4 4 8/13 8 3 v2 v4 v2 v4 11/14 11

35 Ford Fulkerson – augmenting paths
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 cf(p) = min{cf (u,v): (u,v) is on p} Flow network G = (V,E) residual network Gf = (V,Ef) 12/12 12 v1 v3 v1 v3 5 11/16 5 15/20 11 4 10 1/4 7/7 11 3 7 15 S t S t 4/9 5 5 4/4 4 8/13 3 v2 v4 8 v2 v4 11/14 11 Augmenting path

36 Ford Fulkerson – augmenting paths
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 otherwise Flow network G = (V,E) residual network Gf = (V,Ef) 12/12 12 v1 v3 v1 v3 5 11/16 5 15/20 11 4 10 1/4 7/7 11 3 7 15 S t S t 4/9 5 5 4/4 4 8/13 v2 v4 8 3 v2 v4 11/14 11

37 Ford Fulkerson – augmenting paths
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 otherwise Flow network G = (V,E) residual network Gf = (V,Ef) 12/12 12 v1 v3 v1 v3 5 11/16 4/5 15/20 11 4/4 10 1/4 7/7 11 3 7 -4/15 S t S t 4/9 -4/5 4/5 4/4 4 8/13 3 v2 v4 -4/8 v2 v4 11/14 11 Our virtual flow fp along the augmenting path p in Gf

38 Ford Fulkerson – augmenting paths
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 otherwise Flow network G = (V,E) residual network Gf = (V,Ef) 12/12 12 v1 v3 v1 v3 5 11/16 4/5 15/20 11 4/4 10 1/4 7/7 11 3 7 -4/15 S t S t 4/9 -4/5 4/5 4/4 4 8/13 3 v2 v4 -4/8 v2 v4 11/14 11 Our virtual flow fp along the augmenting path p in Gf

39 Ford Fulkerson – augmenting the flow
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 otherwise Flow network G = (V,E) residual network Gf = (V,Ef) 12/12 12 v1 v3 v1 v3 5 11/16 4/5 19/20 11 4/4 10 1/4 7/7 11 3 7 15 S t S t 0/9 5 4/5 4/4 4 12/13 3 v2 v4 8 v2 v4 11/14 11 New flow: f´: V x V  R : f´=f + fp Our virtual flow fp along the augmenting path p in Gf

40 Ford Fulkerson – new valid flow proof of capacity constraint
cf(p) if (u,v) is on p fp(u,v) = cf(p) if (v,u) is on p otherwise Lemma: f´ : V x V  R : f´ = f + fp in G cf(p) = min{cf (u,v): (u,v) is on p} Capacity constraint: For all u,v  V, we require f(u,v) < c(u,v) cf(u,v) = c(u,v) – f(u,v) 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)

41 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 do 4 cf = min{cf(u,v): (u,v) is in p} 5 for each edge (u,v) in p do f(u,v) ¬ f(u,v) + cf 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.

42 Execution of Ford-Fulkerson (1)
Left Side = Residual Graph Right Side = Augmented Flow

43 Execution of Ford-Fulkerson (2)
Left Side = Residual Graph Right Side = Augmented Flow

44 Cuts Does the method find the minimum flow? a b t s c d
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 a b 10/15 13/19 10 t s 2/4 9 5/5 6/14 8/11 3/3 c d Cut capacity = 24 Min Cut capacity = 21

45 Max Flow / Min Cut Theorem
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 G This implies that f is a maximum flow of G 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 1231 … and from 23 we have that the Ford Fulkerson method finds the maximum flow if the residual graph has no augmenting paths.

46 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

47 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

48 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.

49 Model for Matching Problem
Men on leftmost set, women on rightmost set, edges if they are compatible A A A X X X B B B Y Y Y C C C Z Z Z D D D Men Women A matching Optimal matching

50 Solution Using Max Flow
Add a supersouce, supersink, make each undirected edge directed with a flow of 1 A A X X B B t Y s Y C C Z Z D D Since the input is 1, flow conservation prevents multiple matchings

51 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 demand Capacity function u: E  R Goal: Find a feasible flow through the network which satisfies the total demand (if such a flow exists). Ex.: 11 2 19 4 5 15 9 17 A D1 B C S1 D2 S2 8 16

52 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 2 19 4 5 15 9 17 11 A D1 B C S1 D2 S2 17 11 T O 16 8 8 16

53 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. 17 8 13 18 1 2 4 5 17 9 16 11 4 A D1 B C S1 D2 S2 5 5 2 17 2 11 5 T O 16 2 15 5 8 4 19 9 8 16

54 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 1 A C B people D E F 1 jobs x y z u v w 1 T

55 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. 1 A C B people D E jobs x y z u v 1

56 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 . O 1 1 A C B people D E 1 jobs x y z u v 1 1 T

57 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 1 A C B people D E F 1 jobs x y z u v w 1 T

58 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 1 A C B people D E F 1 jobs x y z u v w 1 T


Download ppt "Maximum Flow Chapter 26."

Similar presentations


Ads by Google