 Download Download Presentation Dinitz Algorithm: The Original Version & Even's Version

# Dinitz Algorithm: The Original Version & Even's Version

Télécharger la présentation ## Dinitz Algorithm: The Original Version & Even's Version

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
##### Presentation Transcript

1. Dinitz Algorithm: The Original Version & Even's Version Presentation By: Ilan Orlov

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 s t 2 1 1 1 G

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)Ef(v,u) - (u,v)Ef(u,v) The purpose is to find the maximum flow from the source to the sink. 1/1 0/1 0/1 1/1 1/1 source sink s t 0/2 1/1 1/1 1/1 G

4. 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 net flow from v is defined as . The value of the flow is defined as .

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

6. Ford&Fulkerson Algorithm Define Gf=(V,Ef) – the residual network. Ef - the unsaturated edges with capacity cf(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 Gf, and updating Gfalong 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) Ef 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 Gf 5. do cf(P) = min ePcf(e)>0 6. for each edge (u,v) in p do 7. f(u,v)  f(u,v) - cf(P) 8. f(v,u) -f(u,v) Comments: Notice that it is not certain that E = Ef, 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. Ford&Fulkerson Algorithm Example 0/1 1 0/1 1 s t s t 1 0/1 1 0/1 1 0/1 Gf G

9. Ford&Fulkerson Algorithm Example 0/1 1 0/1 1 s t s t 1 0/1 1 0/1 1 0/1 Gf G

10. Ford&Fulkerson Algorithm Example 1/1 1 0/1 1 s t s t 1 1/1 1 0/1 1 1/1 Gf G

11. Ford&Fulkerson Algorithm Example 1/1 1 0/1 1 s t s t 1 1/1 1 0/1 1 1/1 Gf G

12. Ford&Fulkerson Algorithm Example 1/1 1 0/1 1 s t s t 1 1/1 1 0/1 1 1/1 Gf G

13. Ford&Fulkerson Algorithm Example 1/1 1 1/1 1 s t s t 1 0/1 1 1/1 1 1/1 Gf G

14. Ford&Fulkerson Algorithm Example 1/1 1 1/1 1 s t s t 1 0/1 1 1/1 1 1/1 Gf G

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

17. Phase Iteration

18. DA structure - PHASEstructure in general: - At the beginning of phase, the extended BFS builds a layered network structure, of length l using the residual network Gf. - 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 .

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

20. 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 Gf. This version is called extended BFS. 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)

21. s t s t s t G BFS from s in G L(s) – extended BFS from s in G

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

23. 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 , 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. s t

24. 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 , 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. in the opposite edge direction s t

25. 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 , 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. BFS from t in with the opposite edge direction s t

26. s t s t Building network data structure – next step Prune into , 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. i=2 l-i=3-2=1 i=2 l-i=3-2=1 s t s t G 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.

28. 1 1 0 1 1 s t s t 1 1 1 0 1 1 1 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. 1 1 1 s t 2 1 1 1

29. 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) s t

30. s t s t • Layered network maintenance – Cleaning dead ends. • - how should it be done. • - Initialize two queues Ql and Qr by the list of saturated edges sat thatwereremoved. • - 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. RightPass

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

32. Phase Iteration

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

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

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

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

37. Algorithm Analysis Remove edge = O(1); Checking edges’ two end vertices = O(1); Checking if the list is empty = O(1); 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|) becausethenetworkisconnected

38. 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|) becausethenetworkisconnected

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

40. 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”: consists of existed edges. • “New path”: consists of at least one added edge, which was added • when the edge opposite direction was added. s t s t Augmenting path New path

41. 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 gfcan’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 Gf, then no edges were saturated. •  P contained in current layered  none edges were saturated  P in Gf. • There is no augmenting old path of length shorter then l.

42. 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 exactly1 on new edges. d(node) decreases by atmost1 on old edges. d(t)=l and P’ has k new edges so P’ has to have atleastl+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 Gf does not contain paths of length at most l, by the above proposition. The length of the layered network grows from phase to phase. +1 +1 -1 New path s t s t +1 +1 Augmenting path

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

44. 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|)

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

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

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

48. 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). Besidesforward steps there are backward steps, but a backward step causeanedge 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 totalcost of between two events - O(l). - This version of DA running time is O( l ·|E|) =O(|V||E|) per phase.