Presentation is loading. Please wait.

Presentation is loading. Please wait.

The max-flow problem Defined on a capacitated directed graph G=(V,E,c). The capacities are non-negative. 1 1 1 1 1 1 2 G st 11.

Similar presentations


Presentation on theme: "The max-flow problem Defined on a capacitated directed graph G=(V,E,c). The capacities are non-negative. 1 1 1 1 1 1 2 G st 11."— Presentation transcript:

1

2 The max-flow problem Defined on a capacitated directed graph G=(V,E,c). The capacities are non-negative. 1 1 1 1 1 1 2 G st 11

3 The flow function defined on the directed edges and fulfill: - capacity constraint (flow  capacities)  e  E : 0  f(e)  c(e) - flow conservation (flow into a node= flow from a node)  v  V\{s,t}:  (v,u)  E f(v,u) -  (u,v)  E f(u,v) The purpose is to find the maximum flow from the source to the sink. 1/1 G st 0/2 1/1 sourcesink 0/1

4 The net flow from v is defined as. Alternative definition for a flow function Add the opposite edge if not exist with capacity 0 and define: satisfies the following three constraints: - capacity constraint:. - flow conservation:. - anti-symmetry:. The value of the flow is defined as.

5 First representation Edge is called saturated if Residual capacity (Additional flow) Second representation

6 Ford&Fulkerson Algorithm Define G f =(V,E f ) – the residual network. E f - the unsaturated edges with capacity c f (u,v)=c(u,v)-f(u,v)>0. The idea is to make iterations of finding a flow augmenting path p from s to t in the residual network G f, and updating G f along p, until it can’t be done. Ford&Fulkerson(G,s,t) 1. initalize flow f to 0 2. while there exists an augmenting path p (should find it first) 3. do augment flow f along p 4. return f When no augmenting path exists, the current flow is maximum (Ford & Fulkerson Theorem).

7 Ford&Fulkerson Algorithm Ford&Fulkerson(G,s,t) 1. for each edge (u,v)  E f 2. do f(u,v)  0 3. f(v,u)  0 4. while there exists a path p from s to t in the residual network G f 5. do c f (P) = min e  P c f (e)>0 6. for each edge (u,v) in p do 7. f(u,v)  f(u,v) - c f (P) 8. f(v,u)  -f(u,v)Comments: Notice Notice that it is not certain that E = E f, as sending flow on (u,v) might close (u,v) (it is saturated), and may open a new edge (v,u) in the residual network. For example: An edge (u,v) with flow 5 is equivalent, in a sense, to an opposite direction edge (v,u) with capacity equal to 5.

8 1 1 1 1 st 1 0/1 st Ford&Fulkerson Algorithm Example G GfGfGfGf

9 1 1 1 1 st 1 0/1 st Ford&Fulkerson Algorithm Example G GfGfGfGf

10 1 1 1 1 st 1 0/1 st 1/1 0/1 Ford&Fulkerson Algorithm Example G GfGfGfGf

11 1 1 1 1 st 1 0/1 st 1/1 0/1 Ford&Fulkerson Algorithm Example G GfGfGfGf

12 1 1 1 1 st 1 GfGfGfGf 0/1 st 1/1 0/1 G

13 1 1 1 1 st 1 1/1 st 0/1 1/1 Ford&Fulkerson Algorithm Example G GfGfGfGf

14 1 1 1 1 st 1 1/1 st 0/1 1/1 Ford&Fulkerson Algorithm Example G GfGfGfGf

15 Disadvantage of the algorithm: - Is finite only for integer capacities. - Finding an augmenting path is expensive. The time cost is O(|E|)=O(|V| 2 ) for each iteration. (The bottleneck of the algorithm )

16

17

18

19 DA structure - PHASE structure in general : - At the beginning of phase, the extended BFS builds a layered network structure, of length l using the residual network G f. - A phase contains iterations, changing the flow using shortest augmenting paths of a fixed length l. - The layered network is maintained during the phase as the union of all shortest augmenting paths of length l. - When the layered network vanishes, there is no augmenting path of length  l. Therefore, at the next phase the length of the layered network > l.

20 DA structure - ITERATION structure in general : - Finding an augmenting path p at the layered network structure that was already built, in short time – O(l). - Change the flow along the augmenting path p – O(l). - Maintain the layered network using dead-end vertex removing. There is no need of building layered network from scratch. So at the next iteration, augmenting path finding will cost O(l) as well.

21 Layered network data structure for accelerating iterations The bottleneck of the Ford&Fulkerson algorithm is the finding an augmenting path, with the time cost O(|E|)=O(|V| 2 ), for each one. We use layered network data structure for accelerating iterations. How layered network data structure is built? - Run a special version of BFS from the source node at G f. This version is called extended BFS. allonly the first It adds all edges from previous layer and not only the first edge found. This layered network is called L(s). This is the union of all the shortest paths from s. (Can be prove easily)

22 G st BFS from s in G stst L(s) extended BFS L(s) – extended BFS from s in G

23 Extended BFS - Definitions dist(v,u) - distance between v and u. dist(v) = dist(s,v). V i – the i layer: dist(v)=i  v  V i E i – edges from V i-1 to V i. L(s) = (  V i,  E i ) – the union of all shortest paths from s in the graph. regularextended Running regular BFS time = Running extended BFS time = O(|E|). stst st G BFS from s in G L(s) extended BFS L(s) – extended BFS

24 st Building network data structure – next step Goal: Reduce the layered network so we will able continuancly to find an augmenting path in a short time. How can it be done: Prune into, t That is the union of all the shortest paths from s to t. This can be done using a BFS from t on L(s), in the opposite edge direction.

25 st in the in the opposite edge direction Building network data structure – next step Goal: Reduce the layered network so we will able continuancly to find an augmenting path in a short time. How can it be done: Prune into, t That is the union of all the shortest paths from s to t. This can be done using a BFS from t on L(s), in the opposite edge direction.

26 st BFS from t in with the opposite edge direction Building network data structure – next step Goal: Reduce the layered network so we will able continuancly to find an augmenting path in a short time. How can it be done: Prune into, t That is the union of all the shortest paths from s to t. This can be done using a BFS from t on L(s), in the opposite edge direction.

27 st Building network data structure – next step Prune into, t That is the union of all the shortest paths from s to t. This can be done using a BFS from t on L(s), in the opposite edge direction. st

28 Proof that network is the union of all the shortest paths from s to t Proof that any shortest path from s to t is at. - For any shortest path from s to t, its i vertex is at distance i from s, While t is at distance l-i from it. Proof that any path from s to t at at is at length of the shortest path from s to t. - For any vertex v in there is a path from s to t of length i and a path from v to t of length l-i. - Their concatenation is a the shortest path going via v. st G i=2l-i=3-2=1 st i=2l-i=3-2=1

29 Augmenting path finding and flow improving - Just walk from s over. After l steps t is reached. This is the current augmenting path. - Improve the flow with this augmenting path, and put the saturated edges into a list called sat. - Update capacities in the sub layered network along the augmenting path. - Remove saturated edges. 0 st 1 1 1 1 0 1 st 1 1 1 1 1 1 st 1 2 1 1 1 1

30 Layered network maintenance – Cleaning dead ends. - motivation (why should we do it) - After an edge removing we might have vertexes with no incoming edges. This kind of vertexes is called dead-ends vertex. - We have to remove them, so the next augmenting path finding won’t got stuck and will work in short time – O(l) (l increased by one) st

31 Layered network maintenance – Cleaning dead ends. - how should it be done. - Initialize two queues Q l and Q r by the list of saturated edges sat that were removed. - Define two procedure RightPass and LeftPass: -The graph cleaning consists of a loop of RightPass and LeftPass. It might remove all the edges of the graph. Then it reports on its vanishing. st st RightPass

32 Layered network maintenance – Cleaning dead ends. - comments and additional information. - No path from s to t could be removed. Any element that was removed is absent in all path from s to t - The cleaned layered network, if not vanished, has some useful properties as the original layered network: - Next augmenting path of length l can be fount at O(l). - The next founded path is truly augmenting path, it means that all its edges are not saturated by the current flow.

33

34 Algorithm Analysis Constructing of the layered network using two BFS, at the beginning of a phase costs O(|E|).

35 Algorithm Analysis Augmenting path finding using walk from s over the layered network costs O(l)=O(|V|) every time thanks to the cleaning maintenance.

36 Algorithm Analysis The path length at the iteration number l is l, so flow updating costs O(l)=O(|V|) as well.

37 Algorithm Analysis Remove edge = O(1); Checking edges’ two end vertices = O(1); Checking if the list is empty = O(1);

38 Algorithm Analysis In practice a single iteration might cost Omega(|E|+|V|) because we should remove every edge and vertex from the graph. Omega(|E|+|V|)= O (|E|) because the network is connected Remove edge = O(1); Checking edges’ two end vertices = O(1); Checking if the list is empty = O(1);

39 Algorithm Analysis s In practice a single iteration might cost Omega(|E|+|V|) because we should remove every edge and vertex from the graph. Omega(|E|+|V|)= O (|E|) because the network is connected

40 Algorithm Analysis - The cost of a Phase is: Constructing of the layered network = O(|E|). Maintenance of the layered network = O(|E|). - The cost of a Iterations is: Path finding and capacity updating = O(l)=O(|V|). ==================================================== - The cost of DA is: O( [total number of iterations] x |V| + [number of phases] x |E| ). - The cost of FF is: O( [number of iterations] x |E| ). Next, we should evaluate the number of phases at DA algorithm.

41 Proposition: After any iteration in the phase of DA with the layered network of length l, the updated layered network is the union of all augmenting paths of length l, while there is no shorter augmenting path.Conclusion: The length of the layered network grows strictly from phase to phase. After any iteration, if the layered network hasn’t vanished we get two kinds of paths: “Old path”: “Old path”: consists of existed edges. “New path”: “New path”: consists of at least one added edge, which was added when the edge opposite direction was added. stst New path Augmenting path

42 Proof that an “old” path P’ is at least l long d(v) – distance of v from s at the beginning of a phase - Flow on (v,u) is increased only if d(u)=d(v)+1. - Flow on (u,v) is decreased only if d(v)=d(u)-1– and they are called “new edges”. - The removed edge from g f can’t be restored during the same phase. -P is an “old” path of length l. If it is assumed that P contained in at the beginning of a phase and after some iteration in G f, then no edges were saturated.  P contained in current layered  none edges were saturated  P in G f. There is no augmenting old path of length shorter then l.

43 Proof that “new” path P’ is at least l+2 long Assume P’ has k new edges. P’ new  k>0. d(node) increases by exactly 1 on new edges. d(node) decreases by at most 1 on old edges. d(t)=l and P’ has k new edges so P’ has to have at least l+k old edges  The length of P’ is at least l+2k ≥ l +2. Thus, after any iteration of the phase, there is no augmenting path of length less than l, If there are paths of length l they are contained in At the end of a phase, since does not contain paths of length l, then also G f does not contain paths of length at most l, by the above proposition. The length of the layered network grows from phase to phase. stst New path Augmenting path +1 +1

44 Algorithm Analysis - At most |E| edges are being removed during a phase  There are at most |E| iterations during a phase

45 Algorithm Analysis Constructing of the layered network = O(|E|) Path finding and capacity updating =O(l)=O(|V|). It is done at most |E| times furing a phase. Maintenance of the layered network = O(|E|). So phase costs O(|E|+|E||V|+|E|)=O(|E||V|)

46 Algorithm Analysis - Distance(s,t)  |V|-1  There are at most |V|-1 phases in DA

47 Algorithm Analysis DA running time is O(|E||V||V|) = O(|V| 2 |E|)

48

49 The version of Shimon Even and Alon Itai - Using the L(s) graph that has been built using BFS until the i level instead of using both L(s) and. - Canceled Cleaning procedure. Instead of removing the dead ends, use the “burn their bridges behind them principle”: When a dead end is found, go backward and, in addition, remove that edge from L(s). - Scan graph L(s) using DFS with backtracking when needed, until vertex t is found or the graph is vanished.

50 The version of Shimon Even and Alon Itai - Analysis - The running time of a phase is counted as intervals between events of two types: *** Finding an augmenting path. *** Arrivals at a dead end. How much events are there? - At most |E| such events because each one of them causes the removing of an edge. What is the time cost between two events? - At most l forward steps between edge removing- costs O(l). Besides forward steps there are backward steps, but a backward step cause an edge removing so the cost of both are O(l). If we found the path for t vertax we have to remove the saturated edges along the founded path – costs O(l). However, the total cost of between two events - O(l). - This version of DA running time is O( l ·|E|) =O(|V||E|) per phase.

51 The implementation of DA by Cherkassky

52

53 Further progress of Max-Flow Finding - Edmons’ and Karp’s version of Ford&Fulkerson- (|V||E| 2 )=O(|V| 5 ) (which is higher then O(|V||E| 2 )=O(|V| 5 ) of DA). - Karzanov’s Algorithm- O(|V| 3 ) - Cherkassky – - Galil – - Galil and Naaman - - Sleator and Tarjan – - Goldberg and Rao - Where U is the maximal capacity. Unless U is very big number, this time bound is better then O(|V||E|)


Download ppt "The max-flow problem Defined on a capacitated directed graph G=(V,E,c). The capacities are non-negative. 1 1 1 1 1 1 2 G st 11."

Similar presentations


Ads by Google