Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


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

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

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 x ij 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 ‘c e ’ allowed to transmit through such that.. Net flow cannot exceed c e … –  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  V f(u, v)=0. for entire vertices. –What goes in = what leaves out: Σ v  V f(u, V)- Σ v  V f(V, v) =0, –s and t vertices: Σ v  V f(v, s)=0, Σ v  V f(t, v)=0, Σ v  V f(s, v) = Σ v  V f(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. Aim is to maximize the flow from source to sink. 2/5 2/15 5/14 4/19 3/3 s t 0/9 a b

4 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  Y f(x, y) f(u, V – {s, t}) = 0 Lucky Puck Distribution Network Max Flow, |f| = 19 Or is it? Best we can do? 2/13 3/11 1/51/4 3/15 1/10 1/14 2/19 2/3 9 s ab cd t

5 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 2/15 5/14 5/19 2/3 s t 0/9 a b

6 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{c f (u, v): (u, v) is on p}. –Increment flow, f(u, v) = f(u, v) + x Calculate residual capacities: c f (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: G f =(V, E f ), where E f = {(u,v)  V  V : c f (u,v) > 0} Continue till no any augmenting path (any forward channel) left through Observation – edges in E f are either edges in E or their reversals: |E f |  2|E| ba c d s 13 11 5 4 15 10 14 19 3 t 9 Augmenting Path?

7 Path augmenting scenarios Fig 27.4 of CLSR: The flow network G with f. The residual network G f with augmenting path p shaded; its residual capacity is c f (p) = c(v 2, v 3 ) = 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).

8 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  a path p from s to t in residual network G f do *** 4 c f = min{c f (u,v): (u,v)  p} // determining augmentation 5 for each edge (u,v)  p do // updating residual capacities, new G f 6 f(u,v)  f(u,v) + c f 7 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. http://www-b2.is.tokushima-u.ac.jp/~ikeda/suuri/maxflow/Maxflow.shtml

9 Execution Residual GraphsAugmented Flow ba c d s 12 14 7 4 16 9 13 20 4 t 10

10 Execution of Ford-Fulkerson Residual Graph Augmented Flow 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. ba c d s 12 3/11 7 5/11 9 13 1/19 4 t 3/11

11 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 8/11 5/5 2/4 10/15 10 6/14 13/19 3/3 s t 9 a b c d Cut capacity = 24Min Cut capacity = 21

12 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  T f(u, v)  Σ u  S Σ v  T c(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  T f(u, v)  Σ u  S Σ v  T c(u, v) = c(S, T)

13 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 G f 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.)

14 Proof 1→2 Use contradiction. If it does not hold, then the residual network G f 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 G f has no augmenting path, that is, that G f contains no path from s to t. Define S={v  V: there exists a path from s to v in G f } 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 G f. 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)  E f, which would place v in set S. Thus, flow value of f=c(S,T). (Lemma: flow value f=f(S,T))

15 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  T f(u, v)  Σ u  S Σ v  T c(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.

16 Worst case analysis The augmenting-path method does not prescribe a specific way of flow- augmenting paths, a bad sequence of augmenting paths could deteriorate the method’s efficiency. 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 max flow. In the example of clrs, program starts to traverse through path  1, s  u  v  t and alternates to the path  2, 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/11/1 UU U U 11 t s v u 1 (U-1)/1 1/(U-1) 11 t s v u 1 1000000-1/1 U U 22 U=1000000

17 If searching path p in line 3 (page 8), 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(VE 2 ), t ake 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(VE 2 ) or O(nm 2 ) for this representation. Running time O(VE 2 ), 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. Found using algorithm similar to Dijkstra (shortest path) and Prim (minimum spanning tree). Algorithm uses max heap. (Fibonacci heap version takes time) 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.

18 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 d f’ (s,v)=d f (s,u)+1 d f’ (s,u)=d f’ (s,v)+1 ≥d f (s,v)+1 (paths increase monotonically) =d f (s,u)+2 First time critical Later Second time critical 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.

19 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: 1 st label – indicates the amount of additional flow that can be brought from the previous to the current vertex being labeled. 2 nd 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 r ij = u ij –f(u ij, v ij ) (forward edge), vertex j is labeled with l j, i +, where l j = min{l i, r ij }. –from j to i with positive flow x ji (backward edge), vertex j is labeled l j,i -, where l j = min{l i, x ji }

20

21 Time Efficiency 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(nm 2 ) for this representation More efficient algorithms have been found that can run in close to O(nm) time, but these algorithms don’t fall into the iterative-improvement paradigm

22 If the sink ends up being labeled, then there is an augmentation path by the amount min{c p } 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 32 5 t 0/2 0/3 0/1 0/5 0/30/4 s 4 32 5 t 0/2 0/3 0/1 0/5 0/3 0/4 ∞,- 2,1 + 2,2 + 2,3 + 2,2 + 3,1 + Queue: 1 2 4 3 5 6 ↑ ↑ ↑ ↑ Augment the flow by 2 (the sink’s first label) along the path 1→2→3→6

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

24 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)

25 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 11 5 4 15 10 14 13 3 s t 9 a b c d 11 5 4 15 10 14 13 3 x y 9 e f g h 4 11 5 4 15 10 14 13 3 9 a b c d 11 5 4 15 10 14 13 3 9 e f g h 4 s i j k l t    

26 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 –Neither polygamy nor polyandry are allowed.. Each vertex can be assigned only one vertex of the other group. –solve this problem by creating a flow network out of a bipartite graph

27 Rush maximum possible amount of flow f through each edge with no leaks, or extra flow strictly to improve flow to sinking t. Network Flow Prbl: Rush maximum possible amount of flow f through each edge with no leaks, or extra flow strictly to improve flow to sinking t. Constraints: Constraints:.. 1- Edge capacity. There flow through each edge f cannot exceed allowed capacity c >=0. 2- Node constraint: For each node v: f = -f 2- Node constraint: For each node v: Skew Symmetry f = -f Inflow= Outflow  u f -  w f =0, except in source and sink nodes. a) Source s  u f > 0, in general  v f = 0 or smaller. b) Sink t  u f > 0, in general  v f = 0. 3- For NW Source out = Sink (t) in. 3- For NW Source out = Sink (t) in. Flow Conservation  u f -  v f = 0

28 Summary Must satisfy 3 properties: Capacity constraint:  u,v  V:f(u,v)  c(u,v) Skew symmetry:  u,v  V:f(u,v) = –f(v,u) Flow conservation:  u  V–{s,t}:f(u,V) = f(V,u) = 0 What goes in must go out. Total value of flow f: |f| = f(s,V) = f(V,t)

29 Max Flow = Min Cut: Prove:  F,C rate(F)  cap(C) Path augmentation algorithm. Ford Fulkerson, at every iteration seeks and improvement. The amount of flow t improvement is provided through the remaining capacity of forward edges + used capacity of backward edges, residual graphs. Path augmentation algorithm. Ford Fulkerson, at every iteration seeks and improvement. The amount of flow t improvement is provided through the remaining capacity of forward edges + used capacity of backward edges, residual graphs. Improvement is shortest paths from s to t and first labeled first scanned algorithm = push-relable algorithmImprovement is shortest paths from s to t and first labeled first scanned algorithm = push-relable algorithm RELAXATION IS THE fundamental SEED OF DP.RELAXATION IS THE fundamental SEED OF DP.


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

Similar presentations


Ads by Google