Dinic's algorithm

From testwiki
Jump to navigation Jump to search

Template:Short description 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 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:[2] Template: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 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 cf:V×VR+ defined as,
  1. if (u,v)E,
    cf(u,v)=c(u,v)f(u,v)
  2. if (v,u)E,
    cf(u,v)=f(v,u)
  3. cf(u,v)=0 otherwise.
The residual graph is an unweighted graph Gf=((V,Ef),cf|Ef,s,t), where
Ef={(u,v)V×V:cf(u,v)>0}.
An augmenting path is an st path in the residual graph Gf.
Define dist(v) to be the length of the shortest path from s to v in Gf. Then the level graph of Gf is the graph GL=((V,EL),cf|EL,s,t), where
EL={(u,v)Ef:dist(v)=dist(u)+1}.
A blocking flow is an st flow f such that the graph G=((V,EL),s,t) with EL={(u,v):f(u,v)<cf|EL(u,v)} contains no st path. [Note 1]Template:Sfn

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 eE.
  2. Construct GL from Gf of G. If dist(t)=, stop and output f.
  3. Find a blocking flow f in GL.
  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 GL can be constructed by breadth-first search in O(E) time
  • a blocking flow in the level graph GL can be found in O(VE) time[Note 2]

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

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

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(E) and O(V2/3).[Note 3] Thus the algorithm runs in O(min{V2/3,E1/2}E) time.[3]

In networks that arise from the bipartite matching problem, the number of phases is bounded by O(V), therefore leading to the O(VE) 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.Template:Sfn

Example

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

G Gf GL
1.

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.

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.

Since t cannot be reached in Gf, 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

Template:Reflist Template:Reflist

References

Template:Optimization algorithms


Cite error: <ref> tags exist for a group named "Note", but no corresponding <references group="Note"/> tag was found