An Incremental Algorithm For The Maximum
An Incremental Algorithm For The Maximum
1
© 2003 Kluwer Academic Publishers. Printed in the Netherlands.
Key words: incremental computation, maximum flow, combinatorial optimization, network flows.
1. Introduction
Maximum flow problem with edge capacities is an interesting and well studied
problem in operation research and other fields [1]. The max-flow problem can be
defined as follows. Let G = (V , E) be a directed graph having a set V of n vertices
and a set E of m edges. There are two distinguished vertices in G: one is the source
vertex s, while other one is the sink vertex t. Further, a positive real-valued capacity
c(v, w) is associated with each edge (v, w). For simplicity, we assume zero valued
capacity for each nonexisting edge, i.e., c(v, w) = 0 if (v, w) ∈ / E. A flow on G is
a real valued function f on V × V if it satisfies the following three conditions:
Now, if at any vertex v, except source and the sink, the incoming flow exceeds the
outgoing flow then that vertex is termed as active vertex. This approach processes
these active vertices and relieve them from excess by pushing flow from vertex
toward the sink or toward the source vertex.
Based on this approach the generic preflow push algorithm having O(n2m) com-
plexity has been proposed by Goldberg and Tarjan [11]. The time complexity of the
algorithm depends the way of prcessing the active vertices. If the active vertices are
processed in First-In-First-Out order, the complexity is of O(n3 ). But if they √ are
processed in the order of their distance labels then the complexity is of O(n2 m).
Preflow push algorithm has the better time complexity than the augmenting path
algorithms.
The first parallel algorithm for the max-flow problem is due to Shiloach and
Vishkin [15]. They have used the idea of Dinic [4] to design the parallel algorithm
which takes O(n2 log n) using O(n) processors on CREW PRAM model. Gold-
berg and Tarjan [11] also presented the parallel version of preflow push algorithm
with the same complexity as that of Shiloach and Vishkin but √ with less space.
Later Goldberg [12] observed that there was a gap of O(n/ m log n) between
running time of one variation of the sequential push-relabel algorithm and the
processor-time product of the parallel algorithm of Goldberg and Tarjan [11]. He
AN INCREMENTAL ALGORITHM FOR THE MAXIMUM FLOW PROBLEM 3
i.e. the total incoming flow in any vertex v ∈ V − {s} does not exceed the total
outgoing flow. Excess ef (v) of a vertex v is defined as the net flow into v. A vertex
v ∈ V − {s, t} with a positive excess (i.e. ef (v) > 0) is termed as an Active vertex.
The preflow push algorithm works by examining each of these active vertices and
pushing its excess towards one of its adjacent estimated to be closer to the sink t,
with the goal of getting as much excess as possible to t. If t is not reachable then
the excess is pushed back to the source by pushing the excess towards the vertex
estimated to be closer to the source. This estimation is done by using a distance
labelling which is described later. Finally the algorithm reaches a state where the
excess of each vertex (except the source and the sink vertices) is zero. At this point
preflow f becomes the maximum flow.
To find the vertices to which the excess will be pushed from a vertex the resid-
ual graph is used. Residual capacity rf (v, w) of an edge (v, w) with respect to a
4 S. KUMAR AND P. GUPTA
Push_Operation Algorithm
Push(v, w)
Applicability : v is active, rf (v, w) > 0 and, d(v) = d(w) + 1.
Action: Send δ = min{ef (v), rf (v, w)} units of flow from v to w as follows
f (v, w) ← f (v, w) + δ ; f (w, v) ← f (w, v) − δ ;
ef (v) ← ef (v) − δ ; ef (w) ← ef (w) + δ ;
In order to estimate the distance of a vertex from the source s or the sink t a valid
labeling d is used d(s) = n, d(t) = 0 and d(v) d(w)+1, ∀(v, w) ∈ Gf (V , Ef ).
A distance label d(v) < n is the lower bound on the distance of v from t. While
d(v) n means d(v) − n is the lower bound on the distance from v to s and t is
not reachable from v in residual graph Gf . The following algorithm performs the
relabel operation which may be used to maintain the distance labels.
Relabel_Operation Algorithm
Relabel(v)
Applicability : v is active and ∀w ∈ V , rf (v, w) > 0 ⇒ d(v) d(w)
Action : relabel d(v) = min{d(w) + 1 : rf (v, w) > 0}
The generic preflow push algorithm begins with the preflow f that is equal to
the edge capacity on each edge leaving the source s and zero on all other edges,
and f with some initial sink labeling d. The algorithm repeatedly performs the
basic operations Push and Relabel. The basic operations modify the preflow f
and the labelling d. A push from v to w increases f (v, w) and ef (w) by δ =
min{ef (v), rf (v, w)} and decreases f (w, v) and ef (v) by the same amount. After
the push from v to w, if rf (v, w) = 0, then the push is termed as saturating push;
otherwise it is a non-saturating push. A relabeling of a vertex v sets its label, i.e.
d(v) equal to the largest value allowed by the valid labeling constraints. When there
does not exist any active vertices the algorithm terminates. The generic preflow
push algorithm is given below.
AN INCREMENTAL ALGORITHM FOR THE MAXIMUM FLOW PROBLEM 5
Once we have got the solution to an instance of the maxflow problem and the
final residual graph Gf for network G, we can have the following lemmas for the
unit change in G which is applicable for the residual graph Gf .
LEMMA 2.1. For some vertex v if d(v) < n in Gf , no extra flow can be sent from
the source s to the vertex v.
Proof. This can be proved by the method of contradiction. Let us assume that
we can send fa (s, v) units of flow from s to v. Since d(v) < n, there exists a
path from v to t in residual graph. Let the capacity of this path be bounded by
fa (v, t). So, we can now send δ = min{fa (s, v), fa (v, t)} from s to t. It means
the maximum flow calculated earlier by preflow push algorithm can be increased
by δ units. In that case the flow calculated is not the maximum flow. Hence, it is a
contradiction. ✷
LEMMA 2.2. For some vertex v if d(v) n in Gf , no more flow can be sent from
the vertex v to the sink t.
Proof. This can again be proved by method of contradiction. Let us assume that
we can send fa (v, t) units of flow from v to t. Since v is at a distance n − d(v)
from s. There exists a path from s to v in the residual graph and let its flow capacity
be bounded by fa (s, v). So, we are now able to send δ = min{fa (s, v), fa (v, t)}
from s to t. In that case the maximum flow calculated is increased by δ. Thus the
6 S. KUMAR AND P. GUPTA
3. Incremental Algorithms
In this section we present incremental algorithms which update the solution of the
max-flow problem after a single edge is inserted or deleted into the edge set E
of the network G. Note that inserting (deleting) an edge is equivalent to increasing
(decreasing) the capacity of an edge. This is because of the fact that the insertion of
an edge can be considered as the special case of an edge capacity being increased
from 0 to a larger value and the increase in an edge capacity can be considered as
the insertion of a new edge parallel to the relevant edge. Similarly is the case of
deletion of an edge and decreasing the edge capacity.
Our algorithms work in two phases. Let us consider the case of inserting an
edge. When an edge v → w is inserted in the network there may exist new
augmenting paths from source to sink through which some more additional flow
can be sent. Let all the vertices which lie in at least one of these augmenting
paths be termed as affected vertices and form a set AFFECTED. In first phase we
generate the set AFFECTED. Next phase tries to use the Mod_Max-Flow algorithm
to route the additional flow through the augmenting paths consisting of these ver-
tices.
Search (FBFS) algorithm from w to the sink t. As all the augmenting paths from u
to v will consist of edges with positive capacity, in BBFS (FBFS) from v to u
we take only the vertices which have an incoming (outgoing) edge with positive
capacity. Both BBFS and FBFS algorithms are given below and are illustrated later
with the help of examples.
BBFS Algorithm
BBFS(v, u)
Applicability : Find all the affected vertices from v to u
Action :
[1]WORKSET = {v}
[2]AFFECTED = {v}
[3]while(WORKSET = φ )do
[4]begin
[5] remove an element x from WORKSET
[6] if x = u break;
[7] for all edges (y → x) ∈ E(G) do
[8] begin
[9] if (c[y][x] > 0)do
[10] begin
[11] AFFECTED = AFFECTED {y}
[12] WORKSET = WORKSET {y}
[13] end
[14] end
[15] end
FBFS Algorithm
FBFS(v, u)
Applicability : Find all the affected vertices from v to u
Action :
[1]WORKSET = {v}
[2]AFFECTED = {v}
[3]while(WORKSET = φ )do
[4]begin
[5] remove an element x from WORKSET
[6] if x = u break;
[7] for all edges (x → y) ∈ E(G) do
[8] begin
[9] if (c[x][y] > 0)do
[10] begin
[11] AFFECTED = AFFECTED {y}
[12] WORKSET = WORKSET {y}
[13] end
[14] end
[15]end
(ii) maintaining distance labels of the affected vertices in the new network. Now,
we have the following observations.
(1) Each flow starts from the source s and passes through v in route to the sink t.
Flow on other vertices that do not lead to v are useless because they return to
the source.
(2) From Lemma 2.1, from s to v, the vertices x with a distance label d(x) n
are the actual candidates to be in the set of affected vertices.
(3) From Lemma 2.2, from w to t, the vertices x with distance label d(x) < n are
the actual candidates to be in the set of affected vertices.
(4) An edge x → y can route the additional flow if it has a positive residual
capacity (i.e., c(x, y) − f (x, y) > 0).
Based on the above observations, we can find the set AFFECTED from v to source
by invoking the BBFS algorithm with the arguments v and s and by adding two
more constraints d(x) n and c(x, y) − f (x, y) > 0 at line 9 of the BBFS algo-
rithm. Similarly the affected vertices from w to sink t can be found and appended
in the set AFFECTED by invoking the FBFS algorithm with two arguments w and
sink t and by adding two more constraints d(x) n and c(x, y) − f (x, y) > 0 at
line 9 of the FBFS algorithm.
In order to maintain the distance labels of each affected vertices we follow the
idea of the preflow push algorithm. The distance label of the source is initialized
to n and for all other affected vertices it is initialized to zero; i.e. d(s) = n and,
d(x) = 0, ∀x ∈ AFFECTED − {s}. For every residual edge (x, y) the distance label
in the intermediate residual graph is set as,
= n, if x = s,
d(x) = 0, if d = t,
d(y) + 1, otherwise.
The incremental algorithm first finds the affected vertices by calling the
BBFS(v, source) algorithm and the FBFS(w, sink) algorithm and then initial-
izes the preflow f by residual edge capacity on each edge leaving the source
to the affected vertices and zero on all other edges. This can be done by the
Mod_Preprocess algorithm as given below.
Mod_Preprocess Algorithm
Mod_Preprocess
Application : Initialize the additional preflow and distance label of all
vertices v ∈ AFFECTED
Action :
begin
compute the exact distance labels for all vertices i ∈ AFFECTED
f (s, j ) = f (s, j ) + rf (s, j )∀(s, j ) ∈ A(s) with j ∈ AFFECTED
d(s) = n
end
10 S. KUMAR AND P. GUPTA
The algorithm then follows the approach of basic preflow push algorithm. It
performs the basic operations, Push and Relabel. We modify the basic preflow
algorithm and design the Mod_Push_Relabel algorithm so that these operations
apply only on the affected vertices. The algorithm is given below.
Mod_Push_Relabel Algorithm
Mod_Push_Relabel(i)
begin
if (∃ (i, j ) ∈ Ef , j ∈ AFFECTED) do
begin
push δ = min{e(i), rf (i, j )} from i to j
f (j, i) = f (j, i) − δ; f (i, j ) = f (i, j ) + δ;
e(j ) = e(j ) + δ; e(i) = e(i) − δ
end
else
begin
replace d(i) by min{d(j ) + 1 : (i, j ) ∈ A(i) ∋ j ∈ AFFECTED &
rf (i, j ) > 0}
end
end
3.3. AN EXAMPLE
Let us consider an example to illustrate the incremental algorithm. Let G be the
original graph in Figure 1 with 7 vertices. let 1 be the source and 7 be the sink. The
figure also shows the residual graph G′ of G after calculating the max-flow. The
max-flow value in G is 20 units.
Now, suppose we insert the edge 3 → 5 in G with capacity of 10 units and we
like to compute the maxflow. First we find the affected vertices. As the distance
label of 3 is 8 which is greater than 7. Again the distance label of 5 is 1 and is
less than 7. So, there is a change in max-flow value in G. We find the affected
vertices by invoking the BBFS algorithm from 3 to 1. The set AFFECTED after this
phase consists 3 and, 1. Then the FBFS algorithm from 5 to 7 has been invoke
to include vertices 5 and 7 in the set AFFECTED. Now, the algorithm starts with a
preflow of 5 units from 1 to 3 and the set active consists 3. The algorithm stops
with an additional flow of 5 units. The overall max-flow in G is 25 units which
is same as the max-flow calculated by the generic preflow push algorithm in the
modified graph.
flow f (v, w) through these augmenting paths which may change the flow value on
these edges. To calculate the new value of flow on these two set of edges, the flow
is pushed from t to v on augmenting paths having the edge v → w and this flow
is to be subtracted from excess(t). We start the Mod_Push_Relabel algorithm with
set ACTIVE having two vertices v and w and try to push their excesses towards t
and s. Thus there are three processes to be performed – (i) Pushing flow from t
to w, (ii) Pushing flow from w to v and (iii) Pushing flow from v and w towards t
and s.
For the first process we use the graph GR obtained by reversing all the residual
edges in graph G. However, there is no need explicitly to construct the graph GR .
With this graph the basic preflow push problem remains same except with the new
source t and the sink w. Since not all the vertices constitute the augmenting paths
from t to w, we need to push this flow to the vertices which are on the augmenting
paths from t to w. For this, the FBFS algorithm is invoked with two arguments w
and t. As the flow will be returned only through the edges which have a positive
incoming flow, the constraint f (x, y) > 0 can be added at line 9 of the FBFS
algorithm.
Consider one such subproblem which is to push flow from t to w. We need
new set of distance labels d ′ to find the vertices estimated closer to w from t
in GR . These distance labels are initialized to zero except t and d ′ (t) is initial-
ized to |n|. The Mod_Push_Relabel algorithm modifies these distance labels to
give exact distance from t to w and pushes the flow from t to w. The algorithm
starts with pushing f (x, t) amount of flow from t to each incoming vertex x
such that (x, t) ∈ E(G). All these vertices x are added in the set ACTIVE. The
Mod_Push_Relabel algorithm is operated on this set ACTIVE until this set is empty.
Once the flow is pushed to the vertex w, this excess is sent to v; i.e., f (v, w)
amount of flow is sent from w to v. Then the edge v → w is deleted and flow on
this edge becomes zero. Observe that in case the distance label of v, i.e. if d(v) n
then t is not reachable from v. In this case the excess at v simply routes back to s.
The different vertices that constitute augmenting paths from v to t and v to w are
found. Let these vertices be termed as affected vertices. If d(v) n then we need
not to find the affected vertices from v to t. This can be done by using the FBFS
algorithm with arguments v and t and the BBFS algorithm with arguments v and s.
We have already calculated the set AFFECTED for vertex w. Observe that there are
two sets of AFFECTED; one is for v and other for w. To avoid working with these two
sets of AFFECTED at a time, we can first initiate the Mod_Push_Relabel algorithm
with set ACTIVE consisting w only.
After pushing flow from w to t and adding this new flow to excess of t, the
Mod_Push_Relabel algorithm with set ACTIVE consisting of vertex v is invoked.
The flow pushed towards t is added to excess of t to give the new value of max-
flow. Rest of the excess is pushed back to s. The incremental algorithm to find the
maximum flow in the network after deleting an edge v → w in G is given below.
AN INCREMENTAL ALGORITHM FOR THE MAXIMUM FLOW PROBLEM 13
As the number of affected vertices is n, we can easily show that like insertion
algorithm, the time complexity of this algorithm is also O((n)2m).
Mod_Maxflow_Deletion Algorithm
Mod_Maxflow_Deletion
begin
if (f [v][w] <> 0) then
begin
FBFS(w, t)
reverse the graph G. Let it be GR
assign a label 0 to distnace label set d ′ to all affected vertices
except the vertex t in GR
assign a label equal to the number of affected vericies to t in GR
Mod_Push_Relabel(w) in GR
delete v → w from E(G)
BBFS(v, s )
initialize label of distance label set d of all affected verticies to 0 in G
Mod_Push_Relabel(w)
Mod_Push_Relabel(v)
end
end
4. Experimental Results
In this section we are presenting some experimental results. We have collected dif-
ferent set of experimental data for different networks. The networks are generated
randomly. Further, we have considered the cases only when there is a change in
max-flow after inserting an edge.
Basically, Ev-ratio is the ratio of the number of edges to total number of ver-
tices in G. Observe that in both the algorithms, push and relabel are the two basic
operations. We have counted the number of each of these operations that are used
by each algorithm for the network of different sizes. Let N-Push, N-Relabel be
the number of push and relabel operations performed by the FIFO preflow-push
algorithm [11] and I-Push, I-relabel be the number of corresponding operations
performed by our incremental algorithm. Our algorithm first tries to find the af-
fected vertices on which these operations are performed. Let NAV be the number
of affected vertices. Av-ratio is used to denote the ratio of Number of affected
vertices to the total number of vertices in G. The Gain of our algorithm w.r.t. the
original graph may be defined as follows:
I-Push + I-Relabel
Gain = 1 − .
N-Push + N-Relabel
14 S. KUMAR AND P. GUPTA
We have tested and compared our algorithm with the FIFO preflow push algo-
rithm [11] on random graphs for NV number of vertices and Ev-ratio×NV number
of edges where NV = 100, 200, . . . , 1000 and Ev-ratio = 2, 3, 4, 5, . . . . Here we
have shown the results for the random graphs with 500 and 1000 vertices. We create
Tables I and II which give the information about affected vertex ratio and gain for
different Ev-ratio in a network with 500 and 1000 vertices, respectively. Using
AN INCREMENTAL ALGORITHM FOR THE MAXIMUM FLOW PROBLEM 15
these tables we obtain two graphs – (i) Av-ratio vs Ev-ratio as shown in Figure 2
and (ii) Gain vs Ev-ratio as shown in Figure 3. Observe that Gain is more when
NAV is less. Both I-Push and I-Relabel go on increasing for increasing number of
Ev-ratio. As NAV tends to the total number of vertices in the network, Av-ratio
tends to 1 and Gain is reduced to zero.
References
1. Ahuja, R. K., Magnati, T. and Orlin, J. B.: Network Flows, Prentice-Hall, Englewood Cliffs,
1993.
2. Cheriyan, J. and Maheshawari, S. N.: Analysis of preflow push algorithms for maximum
network flow, SIAM J. Comput. 18 (1989), 1057–1086.
16 S. KUMAR AND P. GUPTA
3. Cherkasky,
√ R. V.: An algorithm for constructing maximum flows in networks with complexity
of O(V 2 (E)), Math. Methods Solution Econ. Probl. 7 (1977), 112–125.
4. Dinic, E. A.: Algorithm for solution of a problem of a maximum flow in networks with power
estimation, Soviet Math. Dokl. 11 (1970), 1277–1280.
5. Edmonds, J. and Karp, R. M.: Theoretical improvements in algorithmic efficiency for network
flow problems, J. Assoc. Comput. Mach. 19 (1972), 248–264.
6. Ford, L. R. and Fulkerson, D. R.: Maximal flows through a network, IRE Trans. Inform. Theory
2 (1956), 117–119.
7. Gabow, H. N.: Scaling algorithms for network problems, J. Comput. System Sci. 31 (1985),
148–168.
8. Galil, Z.: An O(V 5/3 E 2/3 ) algorithm for the maximum flow problem, Acta Inform. 14 (1980),
221–242.
9. Galil, Z. and Naamad, A.: An O(EV (log V )2 ) algorithm for the maximum flow problem,
J. Comput. System Sci. 21 (1980), 203–217.
10. Goldberg, A. V.: A new max-flow algorithm, Tech. Rep. MIT/LCS/TM-291, Laboratory for
Comp. Sci., MIT, Cambridge, Mass., 1985.
11. Goldberg, A. V. and Tarjan R. E.: A new approach to the maximum flow problem, J. Assoc.
Comput. Mach. 35 (1988), 921–940.
12. Goldberg, A. V.: Processor efficient implementation of a maximum flow algorithm, Inform.
Process. Lett. 38 (1991), 179–185.
13. Karzanov, A. V.: Determining the maximal flow in a network by the method of preflows, Soviet
Math. Dokl. 15 (1974), 434–437.
14. Malhotra, V. M., Kumar, P. and Maheshwari, M. N.: An O(|V |3 ) algorithm for finding
maximum flows in networks, Inform. Process. Lett. 57 (1978), 1251–1254.
15. Shiloach, Y. and Vishkin, U.: An O(n2 log n) parallel max-flow algorithm, J. Algorithms 3
(1982), 128–146.
16. Tarjan, R. E.: A simple version of Karzanov’s blocking flow algorithm, Oper. Res. Lett. 2 (1984)
265–268.
17. Goldberg, A. V. and Tarjan, R. E.: A new approach to the maximum flow problem, Proc. 18th
ACM Sympos. Theory of Computing, ACM, New York, 1986, pp. 136–146.
18. Yang, H. H. and Wang, D. F.: Processor efficient implementation of a maximum flow algorithm,
IEEE Trans. CAD 15 (1996), 1533–1540.