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

Slides:



Advertisements
Similar presentations
Maximum flow Main goals of the lecture:
Advertisements

Lecture 7. Network Flows We consider a network with directed edges. Every edge has a capacity. If there is an edge from i to j, there is an edge from.
1 EE5900 Advanced Embedded System For Smart Infrastructure Static Scheduling.
1 Maximum flow sender receiver Capacity constraint Lecture 6: Jan 25.
Introduction To Algorithms CS 445 Discussion Session 8 Instructor: Dr Alon Efrat TA : Pooja Vaswani 04/04/2005.
The Maximum Network Flow Problem. CSE Network Flows.
Advanced Algorithm Design and Analysis (Lecture 8) SW5 fall 2004 Simonas Šaltenis E1-215b
Lectures on Network Flows
1 Efficient implementation of Dinic’s algorithm for maximum flow.
CS138A Network Flows Peter Schröder. CS138A Flow Networks Definitions a flow network G=(V,E) is a directed graph in which each edge (u,v)
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Spring, 2001 Lecture 4 Tuesday, 2/19/02 Graph Algorithms: Part 2 Network.
1 Maximum flow problems. 2 - Introduction of: network, max-flow problem capacity, flow - Ford-Fulkerson method pseudo code, residual networks, augmenting.
A New Approach to the Maximum-Flow Problem Andrew V. Goldberg, Robert E. Tarjan Presented by Andrew Guillory.
Maximum Flows Lecture 4: Jan 19. Network transmission Given a directed graph G A source node s A sink node t Goal: To send as much information from s.
The max-flow problem Defined on a capacitated directed graph G=(V,E,c). The capacities are non-negative G st 11.
1 Maximum flow: The preflow/push method of Goldberg and Tarjan (87)
3/3/ Alperovich Alexander. Motivation  Find a maximal flow over a directed graph  Source and sink vertices are given 3/3/
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2004 Lecture 5 Wednesday, 10/6/04 Graph Algorithms: Part 2.
MAX FLOW CS302, Spring 2013 David Kauchak. Admin.
Maximum Flow Chapter 26.
Single Source Shortest-Path: The General Case (with negative edges) Bellman-Ford algorithm. Iteratively relax all edges |V|-1 times Running time? O(VE).
CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Finding Max Flow.
Max Flow – Min Cut Problem. Directed Graph Applications Shortest Path Problem (Shortest path from one point to another) Max Flow problems (Maximum material.
1 WEEK 11 Graphs III Network Flow Problems A Simple Maximum-Flow Algorithm Izmir University of Economics.
Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices.
1 EE5900 Advanced Embedded System For Smart Infrastructure Static Scheduling.
Theory of Computing Lecture 12 MAS 714 Hartmut Klauck.
A directed graph G consists of a set V of vertices and a set E of arcs where each arc in E is associated with an ordered pair of vertices from V. V={0,
Instructor Neelima Gupta Edited by Divya Gaur(39, MCS '09) Thanks to: Bhavya(9), Deepika(10), Deepika Bisht(11) (MCS '09)
The Maximum Network Flow Problem
TU/e Algorithms (2IL15) – Lecture 8 1 MAXIMUM FLOW (part II)
Ford-Fulkerson Recap.
Network Flow What is a network? Flow network and flows
Maximum Flow Chapter 26.
The Maximum Network Flow Problem
Maximum Flow Chapter 26.
Data Structures and Algorithms (AT70. 02) Comp. Sc. and Inf. Mgmt
Graph Algorithms Minimum Spanning Tree (Chap 23)
CS4234 Optimiz(s)ation Algorithms
Lectures on Network Flows
Algorithms and Networks Hans Bodlaender
Network flow problem [Adapted from M.Chandy].
CSCI 3160 Design and Analysis of Algorithms Tutorial 8
Edmunds-Karp Algorithm: Choosing Good Augmenting Paths
Max Flow – Min Cut Problem
Algorithms and Networks
Network Flow 2016/04/12.
Instructor: Shengyu Zhang
Edmonds-Karp Algorithm
Network Flows and Matching (Supplementary)
Maximum Flow c v 3/3 4/6 1/1 4/7 t s 3/3 w 1/9 3/5 1/1 3/5 u z 2/2
CSE Algorithms Max Flow Problems 11/21/02 CSE Max Flow.
Chapter 7 Network Flow Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
Lecture 10 Network flow Max-flow and Min-cut Ford-Fulkerson method
Analysis of Algorithms
Flow Networks Topics Flow Networks Residual networks
Lecture 5 Tuesday, 3/2/10 Graph Algorithms: Part 2
Network Flows and Matching (Supplementary)
Flow Networks General Characteristics Applications
Flow Networks and Bipartite Matching
Algorithms (2IL15) – Lecture 7
Network Flow CSE 373 Data Structures.
EE5900 Advanced Embedded System For Smart Infrastructure
Max Flow / Min Cut.
Text Book: Introduction to algorithms By C L R S
MAXIMUM flow by Eric Wengert.
Maximum Flow Neil Tang 4/8/2008
Maximum flow: The preflow/push method of Goldberg and Tarjan (87)
Maximum Bipartite Matching
Advanced Graph Homer Lee 2013/10/31.
Presentation transcript:

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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: 3. 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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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