Presentation is loading. Please wait.

Presentation is loading. Please wait.

Dinitz's algorithm for finding a maximum flow in a network.

Similar presentations


Presentation on theme: "Dinitz's algorithm for finding a maximum flow in a network."— Presentation transcript:

1 Dinitz's algorithm for finding a maximum flow in a network.
Presented by: Ilan Kadar and Sivan Albagli April 18, 2019

2 Content Introduction Ford and Fulkerson Algorithm
Original Dinitz’ algorithm 2 2 DA April 18, 2019

3 Introduction The max flow problem definition
Capacitated directed graph G=(V,E,c,s,t). The capacities are non-negative. 1 G s t 2 source sink 2 1 3 3 DA April 18, 2019

4 Introduction The max flow problem definition
A flow f, is defined as a function on the directed edges satisfying the following: Capacity constraint: eE : 0f(e)c(e) Flow conservation: vV\{s,t}: (v,u)Ef(v,u) - (u,v)Ef(u,v)=0 4 4 DA April 18, 2019

5 Q: How do we know that the flow is maximum?
Introduction The max flow problem definition The goal is to find the maximum flow from the source to the sink. 1/1 G s t 0/2 source sink 0/1 Q: How do we know that the flow is maximum? 5 5 DA April 18, 2019

6 Introduction Motivation
Finding the maximal way to ship goods from a set of factories to a set of stores. Bipartite matching 6 6 6 DA April 18, 2019 6

7 Introduction Naïve algorithm
2 2 S 2 t 4 3 B 7 7 7 DA April 18, 2019 7

8 Introduction Naïve algorithm
2 2 S 2 t 4 3 B 8 8 8 DA April 18, 2019 8

9 Introduction Naïve algorithm
2/2 0/2 S 2/2 t 2/4 0/3 B 9 9 9 DA April 18, 2019 9

10 Introduction Naïve algorithm
2/2 0/2 S 2/2 t 2/4 0/3 B 10 10 10 DA April 18, 2019 10

11 There is no path where one can increase the flow
Introduction Naïve algorithm There is no path where one can increase the flow A B S t 2/2 0/2 4/4 2/3 Therefore, the algorithm terminates 11 11 11 DA April 18, 2019 11

12 Introduction Naïve algorithm
Is it the maximum flow? A 2/2 0/2 (Flow value = 4) S 2/2 t 4/4 2/3 B 12 12 12 DA April 18, 2019 12

13 Introduction Naïve algorithm
B S t 2/2 1/2 4/4 3/3 Maximum flow = 5 13 13 13 DA April 18, 2019 13

14 Introduction Equivalent flow function
For each edge add , if doesn’t exists, with capacity and flow zero. 5 1 8 source s t sink 1 2 2 G 14 14 14 DA April 18, 2019 14

15 Introduction Equivalent flow function
Define for each edge: 15 15 15 DA April 18, 2019 15

16 f Introduction Equivalent flow function 3/5 2/2 1/5 -1/2 v u v =3-2
=2-3 v DA April 18, 2019

17 Introduction Equivalent flow function
satisfy the following constraints: Capacity constraint v u 3/5 2/2 1/5 -1/2 f(v,u)<=c therefore, f(v,u)-(positive number)<=c 17 17 17 DA April 18, 2019 17

18 Introduction Equivalent flow function
satisfy the following constraints: 2. Skew symmetry v u 3/5 2/2 1/5 -1/2 Fnew(v,u)=f(v,u)-f(u,v) = -(f(v,u)-f(u,v))=f(u,v)-f(v,u)=-Fnew(u,v) 18 18 18 DA April 18, 2019 18

19 Introduction Equivalent flow function
satisfy the following constraints: 3. Flow conservation Flow conservation 19 19 19 DA April 18, 2019 19

20 Introduction Equivalent flow function
The net flow from v is defined as: The flow value is defined as the net flow from s: 20 20 20 DA April 18, 2019 20

21 Introduction Equivalent flow function
Edge is called saturated if Residual capacity (possibility to add flow) 1st representation 2nd representation Another equvalent is formed by considering a flow as a skew-symmetric function on the pairs of vertices connected by at least one edge 21 21 21 DA April 18, 2019 21

22 Edge is called saturated if:
Introduction Equivalent flow function Edge is called saturated if: saturated v u 5/5 0/2 -5/2 saturated DA April 18, 2019

23 Introduction Equivalent flow function
Unsaturated edges: unsaturated v u 5/5 1/2 4/5 -4/2 unsaturated DA April 18, 2019

24 Introduction Equivalent flow function
Residual capacity (possibility to add flow): cf = 5-3+2=4 v u 3/5 2/2 1/5 -1/2 =cf cf = 5-1=4 =cf DA April 18, 2019

25 Introduction Equivalent flow function
We will use the second representation, denoting it by f DA April 18, 2019

26 Ford and 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. 2 1 -1/0 -2/0 1/4 s t 1/1 1/2 2/2 0/5 G 3 5 1 Gf The idea is to make iterations of finding a flow augmenting path p from s to t in the residual network Gf, and updating Gf along p, until it such a path cannot be found. 1 -1/0 1 -1/0 0/0 DA April 18, 2019

27 Ford and Fulkerson Algorithm
A path is an augmenting path if it contains only unsaturated edges. for example: A B S t 1/2 3/4 3/3 0/0 Wikipedia claimed 1956. DA April 18, 2019

28 Ford and Fulkerson Algorithm
Ford&Fulkerson(G,s,t) 1. initialize flow f(v,u) to 0 2. while there exists an augmenting path P do: augment flow f along P 4. return f Published in 1956 When no augmenting path exists, the current flow is maximum (Ford & Fulkerson Theorem). Wikipedia claimed 1956. DA April 18, 2019

29 Ford and Fulkerson Algorithm
Ford&Fulkerson(G,s,t) 1. for each edge (u,v) Ef do: f(u,v)0 f(v,u)0 4. while there exists a path P from s to t in the Gf do: cf(P) = min ePcf(e)>0 for each edge (u,v) in P do: f(u,v)  f(u,v) + cf(P) f(v,u)  f(u,v) - cf(P) לכל קשת ולקשת ההופכית שלה נאתחל את הזרעמה ל0 DA April 18, 2019

30 Ford and Fulkerson Algorithm
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. אחרי כל איטרציה, השינוי ברשת השירוית הוא: הוא "מאבד" את כל הקשתות שנהיו רוויות במסלול הנבחר להעביר זרימה, ומקבל קשתות חדשות - בכיוון הפוך מהקשתות שנהיו רוויות במסלול הנ"ל. DA April 18, 2019

31 Ford and Fulkerson Example
0/1 s t G 1 Gf DA April 18, 2019

32 Ford and Fulkerson Example
0/1 s t G 1 s t Gf First iteration DA April 18, 2019

33 First iteration – continue
Ford and Fulkerson Example 0/1 s t 1/1 G 1 s t Gf First iteration – continue DA April 18, 2019

34 First iteration – continue
Ford and Fulkerson Example 0/1 s t 1/1 G 1 s t Gf First iteration – continue DA April 18, 2019

35 Ford and Fulkerson Example
0/1 s t 1/1 G 1 s t Gf Second iteration DA April 18, 2019

36 Second iteration-continue
Ford and Fulkerson Example 1/1 s t 0/1 G 1 s t Gf Second iteration-continue DA April 18, 2019

37 There is no path at the residual network Gf
Ford and Fulkerson Example 1/1 s t 0/1 G 1 s t Gf There is no path at the residual network Gf The flow is maximal DA April 18, 2019

38 Ford and Fulkerson Time analysis
With rational capacities, the algorithm will always terminate. With irrational capacities, the algorithm may run forever. Runtime is bounded by O(E*|f*|) when the capacities are integers. DA April 18, 2019

39 Ford and Fulkerson Problem 1 (Integer case)
The algorithm runs in pseudo polynomial time: How many iterations?? DA April 18, 2019

40 Ford and Fulkerson Problem 1 (Integer case)
The algorithm runs in pseudo polynomial time: How many iterations?? 2,000,000 DA April 18, 2019

41 Ford and Fulkerson Problem 2 (General case)
Convergence isn’t guaranteed : DA April 18, 2019

42 Ford and Fulkerson Open question?
The question of the existence of a polynomial, or finite algorithm, for the general case, remained open, for almost 10 years. This was settled by Edmonds and Karp and by Y. Dinitz independently, at the late 60s. Both algorithms are modifications of F&F. Maybe to change 10 to ___ DA April 18, 2019

43 Ford and Fulkerson Edmonds-Karp(1972)
A small fix to the Ford-Fulkerson algorithm makes it work in polynomial time. Compute the augmenting path using BFS on the residual network. Run in time O(VE2) Maybe to change 10 to ___ DA April 18, 2019

44 Dinitz’ Algorithm A Historical Remark
The DA was invented in response to a pre-class-exercise in Adel’son-Vel’sky’s Algorithm class. At that time, the author was not aware the basic facts regarding FF DA April 18, 2019

45 Dinitz’ Algorithm Motivation
All parts of an iteration of FF except of finding an augmenting path P cost O(|P|). Finding an augmenting path is the bottleneck of an iteration– O(|E|). Improving FF by using a smart data structure. DA April 18, 2019

46 Dinitz’ Algorithm Motivation
Example BFS Tree: s t 1 5 2 4 3 DA April 18, 2019

47 Dinitz’ Algorithm Motivation
Example BFS Tree: s t 1 5 2 4 3 DA April 18, 2019

48 Dinitz’ Algorithm Motivation
saturated s t 1 5 2 4 3 DA April 18, 2019

49 Dinitz’ Algorithm Motivation
s t 5 2 1 3 4 There is no easy means to connect them again using unsaturated edges. s and t become disconnected in the BFS tree! DA April 18, 2019

50 Dinitz’ Algorithm Extended BFS
Dist = dist from s Dist=2 Dist=3 Dist=4 s t Dist=1 Dist=3 Dist=2 Dist=1 Dist=3 Dist=2 Extended BFS includes the first edge found, leading to each vertex from the previous layer. DA April 18, 2019

51 Dinitz’ Algorithm Layered Network – L(s)
V0 V1 V2 V3 V4 s t Vi is the set of all nodes with distance i from s Ei is the set of all edges going from Vi-1 to Vi DA April 18, 2019

52 Dinitz’ Algorithm Layered Network – L(s)
V0 V1 V2 V3 V4 s t L(s) = (Vi , Ei) – the union of all shortest paths from s in the graph. DA April 18, 2019

53 Running time of regular BFS == Running time of extended BFS
Dinitz’ Algorithm Layered Network: Definitions 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 time of regular BFS == Running time of extended BFS DA April 18, 2019

54 Dinitz’ Algorithm Layered Network
s t BFS from s in G L(s) – extended BFS from s in G DA April 18, 2019

55 Dinitz’ Algorithm Layered Network: next step
Goal: we want to maintain our data structure as the union of all the shortest paths from s to t. s t How can it be done? Prune into Run extended BFS from t on L(s), in the opposite edge direction DA April 18, 2019

56 Dinitz’ Algorithm Layered Network: next step
How can it be done? Prune into s t L(s) in the opposite edge direction Then run BFS from t on L(s) DA April 18, 2019

57 Dinitz’ Algorithm Layered Network: next step
How can it be done? Prune into s t s t DA April 18, 2019

58 Dinitz’ Algorithm Layered Network
Claim: is the union of all the shortest paths from s to t(Invariant). Property of : Doesn't have vertices with no any incoming edge, except s. Doesn’t have vertices with no any outgoing edge, except t. DA April 18, 2019

59 Dinitz’ Algorithm Augmenting path finding
Just “walk” from s over After l steps t is reached. 1 s t 1 2 2 We could walk from t to s( usually that’s what we do) 1 1 1 DA April 18, 2019

60 Dinitz’ Algorithm Augmenting path finding
Remove the saturated edges. 1 s t 1 2 2 Just walk from s over After l steps t is reached. This is the current augmenting path. 1 1 1 DA April 18, 2019

61 Dinitz’ Algorithm Augmenting path finding
Just “walk” from s over After l steps t is reached 1 s t 1 1 1 Just walk from s over After l steps t is reached. This is the current augmenting path. 1 1 DA April 18, 2019

62 Dinitz’ Algorithm Cleaning dead ends
We might have vertices without outgoing edges called the dead-ends vertices. We wish to remove them, so the next augmenting path finding from s won’t get stuck and will work in O(l) time. - After an edge removing we might have vertexes with no out-coming edges. This kind of vertexes is called dead-ends vertex. - We wish to remove them, so the next augmenting path finding from s won’t got stuck and will work in short time – O(l) DA April 18, 2019

63 Dinitz’ Algorithm Cleaning dead ends
Initialize two queues Ql and Qr by the list of saturated edges sat that were removed. Define two procedures: Left pass Right Pass - After an edge removing we might have vertexes with no out-coming edges. This kind of vertexes is called dead-ends vertex. - We wish to remove them, so the next augmenting path finding from s won’t got stuck and will work in short time – O(l) DA April 18, 2019

64 Dinitz’ Algorithm Cleaning dead ends – Left Pass
1 a d c s t b 1 2 2 - After an edge removing we might have vertexes with no out-coming edges. This kind of vertexes is called dead-ends vertex. - We wish to remove them, so the next augmenting path finding from s won’t got stuck and will work in short time – O(l) 1 1 1 (d,t) Ql DA April 18, 2019

65 Dinitz’ Algorithm Cleaning dead ends – Left Pass
1 a d c s t b 1 2 2 - After an edge removing we might have vertexes with no out-coming edges. This kind of vertexes is called dead-ends vertex. - We wish to remove them, so the next augmenting path finding from s won’t got stuck and will work in short time – O(l) 1 (c,d) 1 (a,d) Ql DA April 18, 2019

66 Dinitz’ Algorithm Cleaning dead ends – Left Pass
1 a c s t b 1 2 - After an edge removing we might have vertexes with no out-coming edges. This kind of vertexes is called dead-ends vertex. - We wish to remove them, so the next augmenting path finding from s won’t got stuck and will work in short time – O(l) 1 (s,c) Ql DA April 18, 2019

67 Dinitz’ Algorithm Cleaning dead ends – Left Pass
1 a s t b 1 2 - After an edge removing we might have vertexes with no out-coming edges. This kind of vertexes is called dead-ends vertex. - We wish to remove them, so the next augmenting path finding from s won’t got stuck and will work in short time – O(l) (s,c) Ql DA April 18, 2019

68 Dinitz’ Algorithm Cleaning dead ends
After applying LeftPass all the vertices(except t) have outgoing edge. After applying RightPass all the vertices(except s) have incoming edge. Why we need both procedures??? DA April 18, 2019

69 Dinitz’ Algorithm Cleaning dead ends
No path in the layered network from s to t could be removed. Next augmenting path of length l can be found in O(l) time incase the cleaned layer is not vanished. DA April 18, 2019

70 Dinitz’ Algorithm The original algorithm
Phase Until when, Phases? Iteration DA April 18, 2019

71 Dinitz’ Algorithm The original algorithm
Constructing of the layered network using two BFS-es, at the beginning of a phase costs O(|E|). Phase Iteration DA April 18, 2019

72 Dinitz’ Algorithm The original algorithm
Phase Augmenting path finding using a walk from s over the layered network costs O(l)=O(|V|) every time thanks to the cleaning maintenance . Iteration DA April 18, 2019

73 Dinitz’ Algorithm The original algorithm
Phase Flow updating costs O(l)=O(|V|) as well. Iteration DA April 18, 2019

74 Dinitz’ Algorithm The original algorithm
Phase Cleaning dead ends vertices Iteration DA April 18, 2019

75 Dinitz’ Algorithm The original algorithm
Phase In practice a single iteration might cost Ω(|E|+|V|) because we should remove every edge and vertex from the graph. Iteration DA April 18, 2019

76 E Dinitz’ Algorithm Time analysis V How many Iterations?
Cost of the algorithm O(#iterations * |V|+ #Phases* |E|) E V How many Iterations? How many Phases? DA April 18, 2019

77 Dinitz’ Algorithm Time analysis
Intuition: After any iteration, there is no augmenting path of length less then l. s t s t Augmenting path New path DA April 18, 2019

78 Dinitz’ Algorithm Time analysis
If there are paths of length l they are contained in s t s t - Augmenting path New path DA April 18, 2019

79 Dinitz’ Algorithm Time analysis
In the end of the phase(when the layer vanish), doesn’t contain paths of length l. “We” can prove that the residual network doesn’t contain paths of length l. Conclusion: The length of the layered network grows from phase to phase. DA April 18, 2019

80 Dinitz’ Algorithm Time analysis
- In every iteration at least one edge is being removed (min edge of path augmenting). - At most |E| edges are being removed during a phase  There are at most |E| iterations during a phase. Phase Iteration DA April 18, 2019

81 Dinitz’ Algorithm Time analysis
Constructing of the layered network = O(|E|) Path finding and capacity updating =O(l)=O(|V|). It is done at most |E| times during a phase. Maintenance of the layered network = O(|E|). So, a phase costs O(|E|+|E||V|+|E|)=O(|E||V|). Phase Phase Iteration DA April 18, 2019

82 Dinitz’ Algorithm Time analysis
- Distance(s,t)|V|-1  There are at most |V|-1 phases in DA Phase Iteration DA April 18, 2019

83 Dinitz’ Algorithm Time analysis
DA running time is O(|E||V||V|) = O(|V|2|E|) Phase Iteration DA April 18, 2019

84 Further Progress Time Method Discover Year O(|V| * |E|2) Shortest Path
Edmonds and Karp 1972 O(|V|3) Preflow-push Karzanov’s Algorithm 1974 Dynamic trees Sleator-Tarjan 1983 FIFO preflow-push Goldberg-Tarjan 1986 Length function Goldberg-Rao 1997


Download ppt "Dinitz's algorithm for finding a maximum flow in a network."

Similar presentations


Ads by Google