Abstract
Full Text
UDC 518.5
MATHEMATICS
E. A. DINIC
AN ALGORITHM FOR SOLVING THE PROBLEM OF MAXIMUM FLOW IN A NETWORK WITH A POWER ESTIMATE
(Presented by Academician I. G. Petrovskii, March 9, 1970)
Various formulations of the problem of a maximum stationary flow in a network and its numerous applications are given in [1]. There an algorithm is also given that solves the problem in the case where the initial data are integers (or, equivalently, commensurable). In the general case this algorithm requires preliminary rounding of the initial data, i.e., only an approximate solution of the problem is possible. In this case the estimate of the convergence rate of the algorithm is inversely proportional to the relative accuracy.
In the present paper an algorithm is proposed that solves the problem exactly in the general case in no more than (Cn^2p) (machine) operations, where (n) is the number of vertices of the network, (p) is the number of arcs in it, and (C) is a constant independent of the network. For integer data this algorithm, like the Ford–Fulkerson algorithm, gives an integer solution with an additional estimate of the number of operations (C_1np) plus the latter estimate.
Statement of the problem. By a network (\Gamma) we shall mean a directed graph (\Gamma) without multiple arcs, with distinguished vertices (s) (the source) and (t) (the sink), for each arc (q) of which a nonnegative number, its capacity (\rho(q)), is given. Let (V(\Gamma)) be the set of vertices of the graph (\Gamma), and (Q(\Gamma)) the set of its arcs.
A flow (f) in the network (\Gamma) will mean a collection of nonnegative numbers, the flow values (f(q)), assigned to all arcs of the network, such that:
[
\mathrm{I.}\quad \operatorname{Div}(v)=
\sum_{[v,x]\in Q(\Gamma)} f([v,x])-
\sum_{[y,v]\in Q(\Gamma)} f([y,v])=0
\quad \forall v\in V(\Gamma),\ v\ne s,t.
]
[
\mathrm{II.}\quad 0\le f(q)\le \rho(q)\quad \forall q\in Q(\Gamma).
]
The quantity (M=\operatorname{Div}(s)) will be called the value of the flow (f).
It is required, in the given network (\Gamma), to find a flow of maximum value.
We may assume that in the graph (\Gamma) for every arc (q=[a,b]) there exists the opposite arc (\bar q=[b,a]). Indeed, adding missing arcs with zero capacities does not change the problem. The number of arcs is thereby increased by at most a factor of two.
Construction of the algorithm. The proposed algorithm, like the Ford–Fulkerson algorithm ([1], Ch. I, § 8), is an iterative process, each step of which consists of the following: having a flow (f) in the network (\Gamma), we find some path (L) from (s) to (t) in the class of augmenting paths (definition below); then we construct a flow (f'): (M(f')>M(f)), changing the flow (f) on the arcs of the path (L) and on the arcs opposite to them. The process may start from any flow (integer in the case of integer data), for example from the zero flow, and ends with the construction of a flow that admits no augmenting paths. In [1], Ch. I, § 5, it is proved that such a flow is maximum.
Let a flow (f) be given in the network (\Gamma). Introduce the quantity
[
\delta(q)=\rho(q)-f(q)+f(\bar q),
]
defined for each arc of (\Gamma). It may be regarded as the capacity, in the presence of the flow (f), of the pair of arcs (q,\bar q) in the direction of the arc (q). We shall call a directed path (L) from (s) to (t) augmenting the flow if for all (q\in L) the condition (\delta(q)>0) is satisfied. This definition is equivalent to the definition used in [1].
Having such a path, one can construct a flow (f'): (M(f')=M(f)+\Delta M), where
[
\Delta M=\min_{q\in L}\delta(q)>0.
]
For this it suffices to change the flow in the arcs of the path (L) and in the arcs opposite to them so that for all (q\in L)
[
[f'(q)-f(q)]+[f(\bar q)-f'(\bar q)]=\Delta M.
]
Let us note that under such a change (\delta'(q)=\delta(q)-\Delta M) and (\delta'(\bar q)=\delta(\bar q)+\Delta M) for all (q\in L) (here and below primes denote the corresponding quantities for the flow (f')). For the remaining arcs, evidently, (\delta'(q)=\delta(q)).
Let us now consider the problem of finding a path that increases the flow. We shall agree to call the number of its arcs the length of a path, and the distance (l(a,b)) between vertices (a) and (b) the length of a shortest path between them.
The main idea of the algorithm, which ensures convergence, is that at each step of the algorithm one finds the shortest augmenting paths.
Consider the part (\widetilde\Gamma) of the graph (\Gamma) whose arcs are defined by the inequality (\delta(q)>0). It is obvious that the condition (L\subset \widetilde\Gamma) is necessary and sufficient for the directed path (L) from (s) to (t) to be a path increasing the flow. To find shortest paths from (s) to (t) in the graph (\widetilde\Gamma), we shall use the following auxiliary object.
Reference graph. We shall call the union of all shortest paths from (s) to (t) in the graph (\widetilde\Gamma) the reference graph (S) of the graph (\widetilde\Gamma). Let us prove several assertions about its structure.
Let (l(s,t)=k) in the graph (\widetilde\Gamma).
- (v\in V(S)\Longleftrightarrow v\in V(\widetilde\Gamma)), (l(s,v)+l(v,t)=k).
Consider a vertex (v\in V(\widetilde\Gamma)) possessing the indicated property. It lies on a shortest path from (s) to (t), which is the union of shortest paths from (s) to (v) and from (v) to (t). The converse assertion follows from the fact that any segment of a shortest path is a shortest path between its endpoints.
Let us reformulate the assertion as follows:
[
1'.\quad V(S)=\bigcup_{i=0}^{k} V_i,\quad \text{where } v\in V_i \Longleftrightarrow v\in V(\widetilde\Gamma),\ l(s,v)=i,\ l(v,t)=k-i.
]
[
2.\quad Q(S)=\bigcup_{i=1}^{k} Q_i,\quad \text{where } [a,b]\in Q_i \Longleftrightarrow [a,b]\in Q(\widetilde\Gamma),\ a\in V_{i-1},\ b\in V_i.
]
The assertion follows almost obviously from the preceding one. A direct proof is analogous to that given above.
Fig. 1
The reference graph can be constructed in the following way. Suppose the graph (\widetilde\Gamma) is given. Construct the sets of vertices (A_i) ((0\le i\le l(s,t))), where (a\in A_i\Longleftrightarrow a\in V(\widetilde\Gamma)), (l(s,a)=i). Obviously (A_0={s}). Suppose the sets (A_i) ((i<j)) have been constructed, and the vertices belonging to them have been marked with the index (i). Then, going through all arcs leaving the vertices of (A_{j-1}), mark all vertices not previously marked with the index (j) and form from them the set (A_j). We finish the process, wh—
then (t) will enter some set (A_k). Hence (l(s,t)=k). We now recursively construct the desired sets (V_i) and (Q_i). It is known that (V_k={t}). Suppose the set (V_j) ((j\leq k)) has been constructed. Then (Q_j) consists of those arcs that lead from (A_{j-1}) into (V_j), and (V_{j-1}) consists of the initial vertices of these arcs. The justification of the method is trivial. Let us note that, for the construction, it is convenient if, for every vertex, all arcs entering it and all arcs leaving it have been listed in advance.
Thus, suppose that a guide (S) of the graph (\widetilde{\Gamma}) is given. Then some shortest path from (s) to (t) is easily constructed by successively finding in the guide arbitrary arcs of the form ([s,a_1]), ([a_1,a_2]), ..., ([a_{k-1},a_k]). Here, obviously, (a_i\in V_i), whence (a_k=t), as required. The correctness of the construction follows from the fact that (\forall v\in V(S)), (v\ne s,t), (\exists [x,v]), ([v,y]\in Q(S)) (by the definition of a guide).
Similarly, one can construct a path containing a given arc (or vertex) from (S), extending it both toward (t) and toward (s).
Changing the guide. We shall show how, in almost all cases, one can change the guide (S) so as to obtain a guide (S').
Lemma. Suppose the flow (f') is obtained from the flow (f) by changing it with the aid of a shortest path (L), and (l(s,t)=k).
Then: a) (l'(s,t)\geq k); b) if (l'(s,t)=k), then (S'\subset S) (as parts of the graph (\Gamma)).
Consider the difference (\widetilde{\Gamma}'\setminus \widetilde{\Gamma}) (in the graph (\Gamma)). By definition, (q\in Q(\widetilde{\Gamma}'\setminus \widetilde{\Gamma}) \Longleftrightarrow q\in Q(\Gamma)), (\delta(q)=0), (\delta'(q)>0). Since the quantity (\delta) increased only on arcs opposite to arcs of (L), one may assert that (\widetilde{\Gamma}'\setminus \widetilde{\Gamma}) consists only of arcs opposite to arcs of (S). We shall prove that adding one arc of this type to the graph does not change the guide; hence it will follow by induction that the guide of the graph (\widetilde{\Gamma}'\cup \widetilde{\Gamma}) coincides with (S).
Consider an arbitrary path from (s) to (t) in the new graph that contains a new edge ([a,b]). Its segment from (s) to (a) consists only of old edges, and therefore its length is at least (l(s,a)). Similarly, the segment of the path from (b) to (t) is no shorter than (l(s,b)). Hence the length of the path is not less than
[
l(s,a)+1+l(b,t)=l(s,a)+l(a,t)+2=k+2.
]
The assertion follows from the definition of a guide.
In view of the inclusion (\widetilde{\Gamma}'\subseteq \widetilde{\Gamma}'\cup\widetilde{\Gamma}), we have the inclusion (S'\subseteq S), if (l'(s,t)=l(s,t)). It is strict, since in the graph (\widetilde{\Gamma}') there will be none of the arcs of the path (L) for which (\delta(q)=\min_{q\in L}\delta(q)). The lemma is proved.
We shall show how to construct (S') by a successive reduction of (S) in the case (l'(s,t)=l(s,t)).
Obviously, from (S) it is necessary to throw out all arcs that do not lie in (\widetilde{\Gamma}'). In doing so, “dead ends” may appear in it, i.e., vertices from which no arc leaves or into which no arc enters. Such vertices cannot belong to a guide; therefore they must be thrown out together with all arcs incident to them. If “dead ends” appear again, this process must be continued until we obtain a part (R) of the graph (\Gamma') without “dead ends.” Let us note that in it one can construct a path from (s) to (t) containing any arc or any vertex, by the method described above for a guide. The length of such a path is (k), since it lies in (S). Hence, if (R) is nonempty, then (S'=R). If, however, (R) turns out to be empty, then there are no paths of length (k) from (s) to (t), and (l'(s,t)\geq k+1). In this case the guide (S') must be constructed anew.
Proof of convergence. Let us note that, as a result of increasing the flow with the aid of a shortest path from (s) to (t), either the number of arcs in the guide decreases, or the distance from (s) to (t) increases. Since the first is always finite, and the second does not exceed the number of vertices of the graph (\Gamma), after a finite number of steps we shall arrive at a flow (\bar f), to which there corresponds
graph (\tilde{\Gamma}) without paths from (s) to (t). Hence, for such a flow there are no augmenting paths, and, by Ford and Fulkerson, it is maximal, as was required.
Estimate of the order of the number of operations necessary for carrying out the algorithm described.
The main part of this number (Q) is made up of the operations necessary for finding paths and for changing the function (\delta). At each step this requires on the order of (n) operations. The number of arcs in the auxiliary network is no more than (p), and the number of distinct distances from (s) to (t) is no more than (n). Hence we have a term (Q) of order (n^2p). Here, possibly, the estimate of the average number of steps needed to express one auxiliary network is somewhat overstated.
For the construction of one auxiliary network, generally speaking, on the order of (p) operations is required. Hence there appears a term (Q) of order (np).
When the auxiliary network is changed, the number of operations needed to change the information relating to the deleted arc or vertex does not exceed some constant independent of (n) and (p). Hence it follows that in each auxiliary network no more than (C(n+p)) such operations will be performed, and the resulting term has order (np).
Thus, (Q) is bounded above by a quantity (Cn^2p), and in the integral case the number of operations in excess of those in the Ford–Fulkerson algorithm is no more than (C_1np).
Upon careful consideration of the algorithm one can note that asymptotically (C) is a quantity of no more than zeroth (decimal) order (the operations are counted as machine operations).
Modification of the auxiliary network. By the large auxiliary network (\Gamma) we shall mean the graph (\tilde{\Gamma}), for each node (v) of which (l(s,v)) and (l(v,t)) have been computed and the “usefulness” of each of its arcs has been determined in the following sense. An arc ([a,b]) is called useful as an outgoing arc if (l(s,b)=l(s,a)+1); useful as an incoming arc if (l(a,t)=l(b,t)+1), and completely useful if both conditions are satisfied. It is easy to prove that the set of completely useful arcs coincides with the set of arcs of the auxiliary graph (\tilde{\Gamma}) described above.
The change of the large auxiliary network at each step of the algorithm consists:
a) in changing the graph (\tilde{\Gamma}); b) in correcting the functions (l(s,v)) and (l(v,t)) for nodes that were called dead ends above; c) in the corresponding change of the usefulness of the arcs incident to them.
Thus, the large auxiliary network (\Gamma) successfully replaces the auxiliary graph (\tilde{\Gamma}), and at no point in the process of the algorithm is it necessary to construct it anew.
Moscow State University
named after M. V. Lomonosov
Central Scientific Research Institute
of Patent Information
Moscow
Received
18 II 1970
CITED LITERATURE
- L. R. Ford, D. R. Fulkerson, Flows in Networks, Moscow, 1966.