Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 26 of CLSR Maximum Network Flow by me Dr. M. Sakalli Ch26 of CSLR and many other sources. Marmara Univ. Picture taken from without permission.

Similar presentations


Presentation on theme: "Chapter 26 of CLSR Maximum Network Flow by me Dr. M. Sakalli Ch26 of CSLR and many other sources. Marmara Univ. Picture taken from without permission."— Presentation transcript:

1 Chapter 26 of CLSR Maximum Network Flow by me Dr. M. Sakalli Ch26 of CSLR and many other sources. Marmara Univ. Picture taken from without permission

2 A Flow Network, terminology
Modeled as a flow graph which is a directed graph of G=(V,E). Flow – a function f : V ´ V ® R: Rate passing through the network from the source vertex s to the sinking vertex t. In literature called as s-t network. Net flow, |f(u,v)|. Source is vertex from which all the edges are leaving ‘s’, and sink is the vertex, all the edges incident to ‘t’ . 2/5 2/15 5/14 4/19 3/3 s t 0/9 a b

3 A Flow Network, Constraints
A flow is an assignment of real numbers xij to edges (i,j) of a given network that satisfy the following: flow-conservation requirements and capacity constraints Capacity constraint: Each edge has a maximum capacity ‘ce’ allowed to transmit through such that.. Net flow cannot exceed ce…  u, v Î V: f(u, v) £ c(u, v) Skew symmetry constraint:  u, v Î V: f(u,v) = –f(v,u) Flow conservation Law: The sum of the net flow incident to a vertex is equal to the net flow leaving the same vertex.  u, v Î V – {s, t}, ΣvVf(u, v)=0. for entire vertices. What goes in = what leaves out: ΣvVf(u, V)- ΣvVf(V, v) =0, s and t vertices: ΣvVf(v, s)=0, ΣvVf(t, v)=0, ΣvVf(s, v) = ΣvVf(v, t)>0 and R+, No leakage and no memory is allowed. Total value of flow, |f| = f(s, V) = f(V, t) Among the areas applied are traffic, freight, airflow, hydrodynamic, communications, and stocks, companies. The Maximum Flow Problem Definition: is to find a feasible flow through a single-source, single-sink flow network that is maximum. 2/5 2/15 5/14 4/19 3/3 s t 0/9 a b 3

4 Super source and super sink connected with infinite capacity.
Opposite flows bt two vertices (due to skew symmetry) will cancel each other. Super source and super sink connected with infinite capacity. Find paths to maximize |f|. f(X, Y) means ΣxXΣyYf(x, y) f(u, V – {s, t}) = 0 2/13 3/11 1/5 1/4 3/15 1/10 1/14 2/19 2/3 9 s a b c d t Max Flow, |f| = 19 Or is it? Best we can do? Lucky Puck Distribution Network

5 Cancellation of flows For X, Y, Z  V with X  Y =,
f(X  Y, Z) = f(X, Z) + f(Y, Z) flow between any x and y through Z…. f(Z, X  Y) = f(Z, X) + f(Z, Y) The value of a flow is the total net flow into the sink; that is, |f| = f(V, t), and from the source s |f| = f(s, V) (by definition) = f(V-{V-s}, V) = f(V, V) - f(V - s, V) = f(V, V - s) |f| = f(V, t) = f(V, t) + f(V, V - s - t) = f(V, t) (by flow conservation) Cancellation of flows 5/5 2/15 5/14 5/19 2/3 s t 2/9 a b 3/5 0/9

6 Maximum Flow as LP .

7 Minimum Cost Flow .

8 Ford-Fulkerson method
Initialize flow value to 0. Start to iterate (dynamic or greedy!).. Find augmenting paths Find a path p from s to t, such that there is some flow value x > 0, and for each edge (u, v) in p, add x units of flow to |f|, such that max{x}  min{cf(u, v): (u, v) is on p}. Increment flow, f(u, v) = f(u, v) + x Calculate residual capacities: cf(u,v) = c(u,v) – x i.e. the actual capacity minus the net flow (x) from u to v Flow may be negative!! That can be interpreted as increasing residual capacity. Residual network: Gf =(V, Ef), where Ef = {(u,v) Î V ´ V : cf(u,v) > 0} Continue till no any augmenting path (any forward channel) left through Observation – edges in Ef are either edges in E or their reversals: |Ef| £ 2|E| Augmenting Path? 13 a b 19 15 10 9 5 t s 4 14 11 3 c d

9 Ford-Fulkerson method
Contains several algorithms: Residue networks Augmenting paths Find a path p from s to t (augmenting path), such that there is some value x > 0, and for each edge (u,v) in p we can add x units of flow f(u,v) + x  c(u,v) Augmenting Path? 8/13 a b 10/15 13/19 10 t s 2/4 9 5/5 6/14 8/11 3/3 c d 9

10 Residual Network To find augmenting path we can find any path in the residual network: Residual capacities: cf(u,v) = c(u,v) – f(u,v) i.e. the actual capacity minus the net flow from u to v Net flow may be negative Residual network: Gf =(V,Ef), where Ef = {(u,v) Î V ´ V : cf(u,v) > 0} Observation – edges in Ef are either edges in E or their reversals: |Ef| £ 2|E| 5/15 10 Sub-graph With c(u,v) and f(u,v) Residual Sub-Graph a b 5/6 a b 1 c c 0/14 19 5 10

11 Residual Graph Compute the residual graph of the graph with the following flow: 8/13 a b 10/15 13/19 10 t s 2/4 9 5/5 6/14 8/11 3/3 c d 11

12 Residual Capacity and Augmenting Path
Finding an Augmenting Path Find a path from s to t in the residual graph The residual capacity of a path p in Gf: cf(p) = min{cf(u,v): (u,v) is in p} i.e. find the minimum capacity along p Doing augmentation: for all (u,v) in p, we just add this cf(p) to f(u,v) (and subtract it from f(v,u)) Resulting flow is a valid flow with a larger value. 12

13 Residual network and augmenting path
f(p1:(s, v1),…) = 11, as far as cf(s,v1)<16, and as far as sum v1=0, and f(p2:(s, v2),…), calculate final residual graph Gf, and next search augmentation path. 13

14 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. Steps 1, 2, O(E), and 4-7 O(E) times for each unit of |f*|. If chosen poorly the algorithm might not terminate. 14

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

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

17 Path augmenting scenarios
Fig 27.4 of CLSR: The flow network G with f. 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).

18 The Ford-Fulkerson algorithm, Residual Capacity and Augmenting Path
In each iteration find any path augmenting the flow along by the residual capacity câ(p). Following algo computes the max f in G = (V, E) by updating the net â[u, v] between connected vertices; u, v. If not connected, implicit assumption is that â[u, v] = 0. Assumption: the c(u, v) is a constant-time function, which is 0 if (u, v)  E. c(u, v) might be derived from fields stored within vertices and their adjacency lists. The residual capacity: câ(u, v).. Here the câ(p) is a temporary variable for the câ(u, v) of the path p. () refers a function [] refers a mutable identifier. Ford-Fulkerson(G,s,t) 1 for each edge (u,v)  G.E do //Initializing 2 f(u,v) ¬ f(v,u) ¬ 0 3 while  path p from s to t in residual network Gf do *** 4 cf = min{cf(u,v): (u,v)  p} // determining augmentation 5 for each edge (u,v)  p do // updating residual capacities, new Gf f(u,v) ¬ f(u,v) + cf f(v,u) ¬ -f(u,v) 8 return f T(n) depends on how line 3 is implemented and the algorithms based on this differ in how to determine p. If chosen poorly the algorithm might not terminate. Finding an Augmenting Path Find a path from s to t in the residual graph The residual capacity of a path p in Gf: cf(p) = min{cf(u,v): (u,v) is in p} i.e. find the minimum capacity along p Doing augmentation: for all (u,v) in p, we just add this cf(p) to f(u,v) (and subtract it from f(v,u)) Resulting flow is a valid flow with a larger value.

19 Execution a b t s c d Residual Graphs Augmented Flow 12 20 16 9 7 4 10
13 14 4 c d Residual Graphs Augmented Flow

20 Execution of Ford-Fulkerson
Residual Graph Augmented Flow 12 a b 1/19 5/11 9 3/11 7 t s 13 4 c 3/11 d Observe that terminates when there is no a path from s to t whose all edges are in forward direction. And observe that the edges whose capacities are depleted form bottleneck, which is the minimum cut and their total capacity of the maximum achivible.

21 Minimum cut – a cut with the smallest capacity of all cuts.
Does the method find the maximum flow? Yes, if program can get to the point where the residual graph has no path from s to t. Which is the moment when the G(V, E) is partitioned into two disjoint sets, by a definite split, minimum cut, c(S, V-S) = c(S, T), such that s  S and t  T. And the net flow (f(S,T)) through the cut (or the capacity) is the total capacity of the flows f(u,v), where s  S and t  T which includes negative flows back from T to S as well. Think about it from the graph… 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 5/5 2/4 9 6/14 8/11 3/3 c d Cut capacity = 24 Min Cut capacity = 21

22 f(S, T) = ΣuSΣvTf(u, v)  ΣuSΣvTc(u, v) = c(S, T).
Cut properties.. A cut (S, T) of flow network G = (V, E) is a partition (or a disjoint set) of V into S and T = V - S such that s  S and t  T. MST cut was for undirected graphs, here a directed graph is cut such that (tails) s  S and (heads) t  T.) If f is a flow, then the net flow across the cut (S, T) is defined to be â(S, T). The capacity of the cut (S, T) is c(S, T). f(S, T) = ΣuSΣvTf(u, v)  ΣuSΣvTc(u, v) = c(S, T). The value of any flow â in a flow network G is bounded from above by the capacity of any cut of G. Proof Let (S, T) be any cut of G and let â be any flow. By |â| = â(S, T) (Lemma 27.5 clrs) and the capacity constraints, = ΣuSΣvTf(u, v)  ΣuSΣvTc(u, v) = c(S, T)

23 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: 1. f is a maximum flow in G. 2. The residual network Gf contains no augmenting paths. 3. Flow value of f = c(S, T) for some cut (S,T) of G. (This cut is called min-cut. Bottleneck. Among all the cuts of G(S, T), it is the cut that returns the minimum capacity.)

24 Proof 1→2 Use contradiction. If it does not hold, then the residual network Gf must have some augmenting paths. So the net flow |f| could be further increased which contradicts to that |f| is a maximum flow in G. 2→3 Suppose that Gf has no augmenting path, that is, that Gf contains no path from s to t. Define S={vV: there exists a path from s to v in Gf} and T=V-S. The partition (S,T) is a cut: we have s  S trivially and t T because there is no path from s to t in Gf. For each pair of vertices u and v such that uS and vT, we have f(u,v)=c(u,v) since otherwise (u,v)Ef, which would place v in set S. Thus, flow value of f=c(S,T). (Lemma: flow value f=f(S,T))

25 The end of Proof 3→1 The value of any flow f in a flow network G is bounded from above by the capacity of any cut of G. flow value f(S, T)=ΣuSΣvTf(u, v)  ΣuSΣvTc(u, v) = c(S, T). so the cut capacity c(S,T) is the upper bound of flow f. Now the flow value f=c(S,T) thus implies that f is a maximum flow.

26 Worst case analysis In the worst case, suppose that at each step Ford-Fulkerson’s algorithm performs some small incremental (integer) augmentations of ∆f, then the number of iterations to reach to the maximum flow, |f*|/∆f, where f* is maximum flow. In the given example (clrs) programs starts to traverse through path p1, suvt and alternates to the path p2, svut. instead of completing the algorithm in two steps. The running time of Ford-Fulkerson’s algorithm is O(|f*|(E)) t s v u 1/1 p1 1 /1 1/ p2

27 Edmonds-Karp algorithm
If searching path p in line 3, is implemented with a BFS in the residual network, and if the augmentation path is a shortest path from s to t, regardless of the weights of edges, Edmonds-Karp algorithm. O(VE2), take shortest augmentation path. How do we find such a shortest path? DFS or BFS.. The number of augmenting paths needed by the shortest-augmenting-path algorithm never exceeds nm/2, where n and m are the number of vertices and edges, respectively Since the time required to find shortest augmenting path by breadth-first search is in O(n+m)=O(m) for networks represented by their adjacency lists, the time efficiency of the shortest-augmenting-path algorithm is in O(VE2) or O(nm2) for this representation. Running time O(VE2), because the number of augmentations is O(VE) More efficient algorithms have been found that can run in close to O(nm) time BFS and AP and Maximum Capacity Path (MCP) - find an A.P. that maximizes incremental flow How many augmenting paths for each method? Edmonds-Karp - A.P.s to give overall time. Critical edge on A.P. No capacity will remain on a critical edge after A.P. is recorded Observations: Edge may become critical several times. A vertex cannot get closer to source in later rounds of BFS. CHAPTER 11: NETWORK FLOWS

28 Each augmentation has complexity O(E)
First time critical Later Second time critical Each augmentation has complexity O(E) Numbers of augmentations is O(VE) Each edge can be a critical edge at most |V|/2-1 times Once edge is critical, its flow is saturated Must appear in path the other way next Since previous path is shortest, this reversing path must be two edges longer df’(s,v)=df(s,u)+1 df’(s,u)=df’(s,v)+1 ≥df(s,v)+1 (paths increase monotonically) =df(s,u)+2 The number of distances available for the tail of a repeated critical edge is (V-2)/2. The number of edges that become critical is < E. Thus, A.P.s overall. Flow must be sent in opposite direction by another A.P. before an edge can become critical again.

29 Shortest-Augmenting-Path Algorithm
Generate augmenting path with the least number of edges by BFS. Start at s, perform BFS traversal by marking new (unlabeled) vertices with two labels and a sign mark: 1st label – indicates the amount of additional flow that can be brought from the previous to the current vertex being labeled. 2nd label – indicates the vertex from which the vertex being labeled was reached, with “+” or “–” in forward or in backward, respectively. Vertex labeling: The start is always labeled with ∞,- All other vertices are labeled as follows: If unlabeled vertex j is connected to the front vertex i with the edge from i to j with unused capacity rij = uij –f(uij, vij) (forward edge), vertex j is labeled with lj, i+, where lj = min{li, rij}. from j to i with positive flow xji (backward edge), vertex j is labeled lj,i-, where lj = min{li, xji}

30 If the sink ends up being labeled, then there is an augmentation path by the amount min{cp} which indicated is with the sink’s first label. The augmentation path is traced along the path from sink to source; the current flow quantities are increased on the forward edges and decreased on the backward edges of this path. If the sink remains unlabeled after the traversal queue becomes empty, the algorithm returns the current flow as maximum and terminates. s 4 3 2 5 t 0/2 0/3 0/1 0/5 0/4 s 4 3 2 5 t 0/2 0/3 0/1 0/5 0/4 ∞,- 2,1+ 2,2+ 2,3+ 3,1+ ↑ ↑ ↑ ↑ Queue: Augment the flow by 2 (the sink’s first label) along the path 1→2→3→6

31 No augmenting path (the sink is unlabeled) the current flow is maximum
4 3 2 5 t 2/2 0/3 0/1 2/5 0/4 s 4 3 2 5 t 2/2 0/3 0/1 2/5 0/4 ∞,- 1,3- 1,2+ 1,5+ 1,4+ 3,1+4 ↑ ↑ ↑ ↑ ↑ Queue: 5 1/3 1/4 Augment the flow by 1 (the sink’s first label) along the path 1→4→3←2→5→6 2/2 1/5 2/2 s 2 3 t 1/3 1/1 5 4 1/3 1/4 ∞,- 2/2 1/5 2/2 Queue: 1 4 ↑ ↑ s 2 3 t 1/3 1/1 4 2,1+ No augmenting path (the sink is unlabeled) the current flow is maximum

32 S : (∞, 1, +) B : (S, 8, +) E : (S, 28, +) F : (S, 15, +)
A : (B, 8, +) C : (B, 8, +) D : (B, 6, -) T : (A, 8, +) f updated by 8. P = (S,B, A, T) CHAPTER 11: NETWORK FLOWS, WILLIAM T. TROTTER AND MITCHEL T. KELLER

33 Multiple Sources or Sinks
What if you have a problem with more than one source and more than one sink? Modify the graph to create a single supersource and supersink 13 13 a b a b 15 13 15 13 10 k 10 t i 9 5 s 4 9 5 4 14 11 3 14 11 3 c d c d t s 4 4 13 13 e f e f 15 13 15 13 10 l 10 y j 9 5 x 9 5 4 4 14 11 3 14 11 3 g h g h

34 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 solve this problem by creating a flow network out of a bipartite graph

35 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  V2 or vice versa. That is, all edges go between the two sets V1 and V2 and not within V1 and V2.

36 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

37 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


Download ppt "Chapter 26 of CLSR Maximum Network Flow by me Dr. M. Sakalli Ch26 of CSLR and many other sources. Marmara Univ. Picture taken from without permission."

Similar presentations


Ads by Google