Dinic's algorithm

{{Short description|Algorithm for computing the maximal flow of a network}}

Dinic's algorithm or Dinitz's algorithm is a strongly polynomial algorithm for computing the maximum flow in a flow network, conceived in 1970 by Israeli (formerly Soviet) computer scientist Yefim Dinitz.{{cite journal | author = E. A. Dinic | author-link = Yefim Dinitz | title = Algorithm for solution of a problem of maximum flow in a network with power estimation | journal = Doklady Akademii Nauk SSSR | volume = 11 | year = 1970 | pages = 1277–1280 | url=http://www.cs.bgu.ac.il/~dinitz/D70.pdf}} The algorithm runs in O(|V|^2|E|) time and is similar to the Edmonds–Karp algorithm, which runs in O(|V||E|^2) time, in that it uses shortest augmenting paths. The introduction of the concepts of the level graph and blocking flow enable Dinic's algorithm to achieve its performance.

History

Dinitz invented the algorithm in January 1969, as a master's student in Georgy Adelson-Velsky's group. A few decades later, he would recall:

{{blockquote

| text=In Adel'son-Vel'sky's Algorithms class, the lecturer had a habit of giving the problem to be discussed at the next meeting as an exercise to students. The DA was invented in response to such an exercise. At that time, the author was not aware of the basic facts regarding [the Ford–Fulkerson algorithm]….

Ignorance sometimes has its merits. Very probably, DA would not have been invented then, if the idea of possible saturated edge desaturation had been known to the author.

| multiline=yes

}}

In 1970, Dinitz published a description of the algorithm in Doklady Akademii Nauk SSSR. In 1974, Shimon Even and (his then Ph.D. student) Alon Itai at the Technion in Haifa were very curious and intrigued by Dinitz's algorithm as well as Alexander V. Karzanov's related idea of blocking flow. However it was hard for them to decipher these two papers, each being limited to four pages to meet the restrictions of journal Doklady Akademii Nauk SSSR. Even did not give up, and after three days of effort managed to understand both papers except for the layered network maintenance issue. Over the next couple of years, Even gave lectures on "Dinic's algorithm", mispronouncing the name of the author while popularizing it. Even and Itai also contributed to this algorithm by combining BFS and DFS, which is how the algorithm is now commonly presented.

For about 10 years of time after the Ford–Fulkerson algorithm was invented, it was unknown if it could be made to terminate in polynomial time in the general case of irrational edge capacities. This caused a lack of any known polynomial-time algorithm to solve the max flow problem in generic cases. Dinitz's algorithm and the Edmonds–Karp algorithm (published in 1972) both independently showed that in the Ford–Fulkerson algorithm, if each augmenting path is the shortest one, then the length of the augmenting paths is non-decreasing and the algorithm always terminates.

Definition

Let G = ((V,E),c,f,s,t) be a network with c(u,v) and f(u,v) the capacity and the flow of the edge (u,v), respectively.

:The residual capacity is a mapping c_f\colon V\times V \to R^+ defined as,

:# if (u,v)\in E,

:#: c_f(u,v) = c(u,v) - f(u,v)

:# if (v,u)\in E,

:#: c_f(u,v) = f(v,u)

:# c_f(u,v) = 0 otherwise.

:The residual graph is an unweighted graph G_f = ((V, E_f), c_f|_{E_f}, s, t), where

:: E_f = \{(u,v)\in V \times V \colon\; c_f(u,v) > 0\}.

:An augmenting path is an st path in the residual graph G_f.

:Define \operatorname{dist}(v) to be the length of the shortest path from s to v in G_f. Then the level graph of G_f is the graph G_L = ((V, E_L), c_f|_{E_L}, s,t), where

:: E_L = \{(u,v)\in E_f \colon\; \operatorname{dist}(v) = \operatorname{dist}(u) + 1\}.

:A blocking flow is an st flow f' such that the graph G' = ((V,E_L'), s, t) with E_L' = \{(u,v) \colon\; f'(u,v) < c_f|_{E_L}(u,v)\} contains no st path. This means that the subgraph resulting from removing all saturated edges (edges (u,v) with f'(u,v)=c_f|_{E_L}(u,v)) does not contain any path from s to t. In other terms, the blocking flow is such that every possible path from s to t contains a saturated edge.{{sfn|Tarjan|1983|p=102}}

Algorithm

Dinic's Algorithm

: Input: A network G = ((V, E), c, s, t).

: Output: An st flow f of maximum value.

  1. Set f(e) = 0 for each e\in E.
  2. Construct G_L from G_f of G. If \operatorname{dist}(t) = \infty, stop and output f.
  3. Find a blocking flow f' in G_L.
  4. Augment flow f by f' and go back to step 2.

Analysis

It can be shown that the number of layers in each blocking flow increases by at least 1 each time and thus there are at most |V|-1 blocking flows in the algorithm. For each of them:

  • the level graph G_L can be constructed by breadth-first search in O(E) time
  • a blocking flow in the level graph G_L can be found in O(VE) timeFinding the blocking flow can be implemented in O(E) per path via a sequence of Advance and Retreat operations. See http://courses.csail.mit.edu/6.854/06/scribe/scribe11.pdf for more details.

with total running time O(E + VE) = O(VE) for each layer. As a consequence, the running time of Dinic's algorithm is O(V^2 E).{{cite book | first=Yefim | last=Dinitz | author-link=Yefim Dinitz | editor1=Oded Goldreich | editor-link1=Oded Goldreich | editor2=Arnold L. Rosenberg | editor-link2=Arnold L. Rosenberg | editor3=Alan L. Selman | editor-link3=Alan Selman | title=Theoretical Computer Science: Essays in Memory of Shimon Even | chapter=Dinitz' Algorithm: The Original Version and Even's Version | series=Lecture Notes in Computer Science | year=2006 | volume=3895 | publisher=Springer | isbn=978-3-540-32880-3 | pages=218–240 | doi=10.1007/11685654_10 | chapter-url=https://link.springer.com/chapter/10.1007/11685654_10}}

Using a data structure called dynamic trees, the running time of finding a blocking flow in each phase can be reduced to O(E \log V) and therefore the running time of Dinic's algorithm can be improved to O(VE \log V).

= Special cases =

In networks with unit capacities, a much stronger time bound holds. Each blocking flow can be found in O(E) time, and it can be shown that the number of phases does not exceed O(\sqrt{E}) and O(V^{2/3}).The O(V^{2/3}) bound assumes that no two edges connect the same pair of vertices in the same direction, while the O(\sqrt E) bound makes no such assumption. Thus the algorithm runs in O(\min\{V^{2/3}, E^{1/2}\}E) time.{{cite journal|last1=Even|first1=Shimon|last2=Tarjan|first2=R. Endre|year=1975|title=Network Flow and Testing Graph Connectivity|journal=SIAM Journal on Computing|volume=4|issue=4|pages=507–518|issn=0097-5397|doi=10.1137/0204043}}

In networks that arise from the bipartite matching problem, the number of phases is bounded by O(\sqrt{V}), therefore leading to the O(\sqrt{V} E) time bound. The resulting algorithm is also known as Hopcroft–Karp algorithm. More generally, this bound holds for any unit network — a network in which each vertex, except for source and sink, either has a single entering edge of capacity one, or a single outgoing edge of capacity one, and all other capacities are arbitrary integers.{{sfn|Tarjan|1983|p=102}}

Example

The following is a simulation of Dinic's algorithm. In the level graph G_L, the vertices with labels in red are the values \operatorname{dist}(v). The paths in blue form a blocking flow.

class="wikitable" style="text-align:center; width:915px;" border="1"
width="15px" |

! G

! G_f

! G_L

1.

| 300px

| 300px

| 300px

| align="left" colspan="3" |

The blocking flow consists of

  1. \{s, 1, 3, t\} with 4 units of flow,
  2. \{s, 1, 4, t\} with 6 units of flow, and
  3. \{s, 2, 4, t\} with 4 units of flow.

Therefore, the blocking flow is of 14 units and the value of flow |f| is 14. Note that each augmenting path in the blocking flow has 3 edges.

2.

| 300px

| 300px

| 300px

| align="left" colspan="3" |

The blocking flow consists of

  1. \{s, 2, 4, 3, t\} with 5 units of flow.

Therefore, the blocking flow is of 5 units and the value of flow |f| is 14 + 5 = 19. Note that each augmenting path has 4 edges.

3.

| 300px

| 300px

| 300px

| align="left" colspan="3" |

Since t cannot be reached in G_f, the algorithm terminates and returns a flow with maximum value of 19. Note that in each blocking flow, the number of edges in the augmenting path increases by at least 1.

See also

Notes

{{reflist|group=Note}}

{{Reflist}}

References

  • {{cite book | first=Yefim | last=Dinitz | author-link=Yefim Dinitz | editor1=Oded Goldreich | editor-link1=Oded Goldreich | editor2=Arnold L. Rosenberg | editor-link2=Arnold L. Rosenberg | editor3=Alan L. Selman | editor-link3=Alan Selman | title=Theoretical Computer Science: Essays in Memory of Shimon Even | chapter=Dinitz' Algorithm: The Original Version and Even's Version | series=Lecture Notes in Computer Science | year=2006 | volume=3895 | publisher=Springer | isbn=978-3-540-32880-3 | pages=218–240 | doi=10.1007/11685654_10 | chapter-url=https://link.springer.com/chapter/10.1007/11685654_10}}
  • {{cite conference | date=18 April 2019 | place=Ben-Gurion University | first1=Ilan | last1=Kadar | first2=Sivan | last2=Albagli | title=Dinitz's algorithm for finding a maximum flow in a network | no-pp=yes | url=https://slideplayer.com/slide/16480683/ | url-status=live | archive-url=https://web.archive.org/web/20231222225209/https://slideplayer.com/slide/16480683/ | archive-date=22 December 2023}}
  • {{cite book | last1=Korte | first1=B. H. | last2=Vygen | first2=Jens | title = Combinatorial Optimization: Theory and Algorithms (Algorithms and Combinatorics, 21) | chapter = 8.4 Blocking Flows and Fujishige's Algorithm | year = 2008 | publisher = Springer Berlin Heidelberg | isbn = 978-3-540-71844-4 | pages = 174–176}}
  • {{cite book | last=Tarjan | first=R. E. |year =1983 | title=Data structures and network algorithms }}

{{Optimization algorithms|combinatorial}}

Category:Network flow problem

Category:Graph algorithms