Английская Википедия:Dinic's algorithm

Материал из Онлайн справочника
Перейти к навигацииПерейти к поиску

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.[1] The algorithm runs in <math>O(|V|^2|E|)</math> time and is similar to the Edmonds–Karp algorithm, which runs in <math>O(|V||E|^2)</math> 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:[2] Шаблон:Blockquote

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.[2]

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 <math>G = ((V,E),c,f,s,t)</math> be a network with <math>c(u,v)</math> and <math>f(u,v)</math> the capacity and the flow of the edge <math>(u,v)</math>, respectively.

The residual capacity is a mapping <math>c_f\colon V\times V \to R^+</math> defined as,
  1. if <math>(u,v)\in E</math>,
    <math>c_f(u,v) = c(u,v) - f(u,v) </math>
  2. if <math>(v,u)\in E</math>,
    <math>c_f(u,v) = f(v,u) </math>
  3. <math>c_f(u,v) = 0</math> otherwise.
The residual graph is an unweighted graph <math>G_f = ((V, E_f), c_f|_{E_f}, s, t)</math>, where
<math>E_f = \{(u,v)\in V \times V \colon\; c_f(u,v) > 0\}</math>.
An augmenting path is an <math>s</math>–<math>t</math> path in the residual graph <math>G_f</math>.
Define <math>\operatorname{dist}(v)</math> to be the length of the shortest path from <math>s</math> to <math>v</math> in <math>G_f</math>. Then the level graph of <math>G_f</math> is the graph <math>G_L = ((V, E_L), c_f|_{E_L}, s,t)</math>, where
<math>E_L = \{(u,v)\in E_f \colon\; \operatorname{dist}(v) = \operatorname{dist}(u) + 1\}</math>.
A blocking flow is an <math>s</math>–<math>t</math> flow <math>f'</math> such that the graph <math>G' = ((V,E_L'), s, t)</math> with <math>E_L' = \{(u,v) \colon\; f'(u,v) < c_f|_{E_L}(u,v)\}</math> contains no <math>s</math>–<math>t</math> path. [Note 1]Шаблон:Sfn

Algorithm

Dinic's Algorithm

Input: A network <math>G = ((V, E), c, s, t)</math>.
Output: An <math>s</math>–<math>t</math> flow <math>f</math> of maximum value.
  1. Set <math>f(e) = 0</math> for each <math>e\in E</math>.
  2. Construct <math>G_L</math> from <math>G_f</math> of <math>G</math>. If <math>\operatorname{dist}(t) = \infty</math>, stop and output <math>f</math>.
  3. Find a blocking flow <math>f'</math> in <math>G_L</math>.
  4. Add augment flow <math>f</math> by <math>f'</math> 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 <math>|V|-1</math> blocking flows in the algorithm. For each of them:

  • the level graph <math>G_L</math> can be constructed by breadth-first search in <math>O(E)</math> time
  • a blocking flow in the level graph <math>G_L</math> can be found in <math>O(VE)</math> time[Note 2]

with total running time <math>O(E + VE) = O(VE)</math> for each layer. As a consequence, the running time of Dinic's algorithm is <math>O(V^2 E)</math>.[2]

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

Special cases

In networks with unit capacities, a much stronger time bound holds. Each blocking flow can be found in <math>O(E)</math> time, and it can be shown that the number of phases does not exceed <math>O(\sqrt{E})</math> and <math>O(V^{2/3})</math>.[Note 3] Thus the algorithm runs in <math>O(\min\{V^{2/3}, E^{1/2}\}E)</math> time.[3]

In networks that arise from the bipartite matching problem, the number of phases is bounded by <math>O(\sqrt{V})</math>, therefore leading to the <math>O(\sqrt{V} E)</math> 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

Example

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

<math>G</math> <math>G_f</math> <math>G_L</math>
1. Файл:Dinic algorithm G1.svg Файл:Dinic algorithm Gf1.svg Файл:Dinic algorithm GL1.svg

The blocking flow consists of

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

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

2. Файл:Dinic algorithm G2.svg Файл:Dinic algorithm Gf2.svg Файл:Dinic algorithm GL2.svg

The blocking flow consists of

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

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

3. Файл:Dinic algorithm G3.svg Файл:Dinic algorithm Gf3.svg Файл:Dinic algorithm GL3.svg

Since <math>t</math> cannot be reached in <math>G_f</math>, 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 Шаблон:Reflist

References

Шаблон:Optimization algorithms


Ошибка цитирования Для существующих тегов <ref> группы «Note» не найдено соответствующего тега <references group="Note"/>