Professional Documents
Culture Documents
Chapter H
NETWORK FLOWS
Annals of Operations Research 13(1988)83-123 83
Donald GOLDFARB
Department of Industrial Engineering and Operations Research, Columbia University,
New York, N Y 10027, USA
and
Michael D. GRIGORIADIS
Department of Computer Seience, Rutgers University,New Brunswiek, NJ 08903, USA
Abstract
1. Introduction
where FA (u) and BA(u) are the forward and backward adjacency lists of node o,
respectively. The value Ill of flow f is the net flow out of the source (equivalently,
into the sink):
*This research was supported in part by the National Science Foundation under Grant Nos. MCS-
8113503 and DMS-8512277.
A flow f * is maximum if If*l ~ Ill for all flows f. A cut (X, X ) is a partition of V
such that s E X, t E X, X A .~ = 0, and X t.) X = IF. The capacity of a cut (X, X) is
c (X, X) =___Eo~ x, ,, ~ y.__c(v, w), the flow across the cut is f ( X , X ) = Eo ~ x, w ~ ~ f(v, w),
and f ( X , X ) <<. c(X, X). The max-flow min-cut theorem [9] states that the value of
a maximum flow is equal to the capacity of a minimum cut.
The problem was first introduced in 1956 by Ford and Fulkerson, who also
devised an augmenting path method for its solution [9]. Their algorithm runs in
pseudopolynomial time for integer data. The method may converge incorrectly in the
presence of irrational arc capacities, but this is of little concern in practice. Edmonds
and Karp [7], and independently Dinic [6], observed that this algorithm, suitably
modified to push flow only along shortest augmenting paths, runs in strongly poly-
nomial time, assuming O(1) time for addition and comparison of reals. We list the
theoretical improvements that followed [9] in table 1, where Cmax denotes the
maximum arc capacity.
Table 1
Maximum flow algorithms and their complexities
the amount entering a node may exceed the amount leaving it, i.e. (1.2) holds with
"<<." instead of "= ". Algorithms C- 1,2 and 3 use prefiows. Those in C- 1 are the fastest
algorithms for dense graphs, the simplest of which appears to be Tarjan's wave method
[35]. The MPM [27] rendition of Karzanov's idea of preflows is very popular, but the
performance of its practical implementations is not entirely satisfactory. Tarjan
observes that the method tends to route flow through "narrow bottlenecks", and it
thus causes too many augmentations [34]. Algorithms C-2 and 3 use substantially
more complicated data structures to decrease the time per node saturation for sparse
graphs.
For a more detailed discussion of maximum flow algorithms, the reader is
referred to the books by Ford and Fulkerson [10], Lawler [26], Even [8],
Papadimitriou and Steiglitz [29], and Tarjan [34].
Algorithms B-1 through B-4 and C-1 through C-3 augment the flow along
shortest augmenting paths. Goldberg and Tarjan's recent algorithm (C-4) [13] uses
Karzanov's idea of a preflow, but it augments the flow along paths that are only
"estimated" to be the shortest. A straightforward implementation of this algorithm
is much simpler than any of those in C-l, and it runs in O(n 3) time provided that
nodes with excess flow are scanned in first-in first-out order. A more complicated
variant of it uses the Sleator-Tarjan dynamic tree data structure [33] and runs in
O(nmlog(n2/m)) time. This bound subsumes all others in table 1, uniformly for all
densities. Computational experimentation is needed to assess whether this will also
be the case in practice.
Despite its O(n2m)running time, experimental evidence [5,14,17] suggests
that even simple implementations of Dinic's method are more efficient than most
other methods listed in table 1. There are two reasons for this. First, a large constant
multiplier to the time complexity is created due to the complicated data structures
used by the other methods, and second, the instances that can arise in practice today
are not sufficiently large to exhibit the asymptotic behavior of these algorithms.
Therefore, a well-implemented, tested and documented Dinic code can be a valuable
practical tool, in addition to serving experimental and educational needs. In sects. 2
and 3, we review this method and design a storage-efficient implementation that.is
well suited for solving large sparse instances on small computers.
Next, we compare the Dinic method with the network simplex method,
rather than supplement the computational comparisons mentioned earlier. In sect. 4,
we review the network simplex method and develop a partial-pricing variant of the
"steepest-edge" criterion for the maximum flow problem, as originally implemented
in the code RNET [18,20]. We state the data structures used by this code, and we
show how this strategy can be implemented in other existing network simplex codes.
In sect. 5, we present our computational results for a set of randomly generated,
sparse and structured network flow problems, obtained on a small computer. The
network simplex method requires substantially less storage than Dinic's method
and runs surprisingly faster for these problems. However, our results indicate that
86 D. Goldfarb, M.D. Grigoriadis, Dinic and network simplex methods for max flow
Dinic's method will eventually overtake the network simplex method for problems
that are too large to be stored in the main memory of today's personal computers.
*The length o f a flow a u g m e n t i n g path is the n u m b e r o f arcs it contains. F o r each successive pair
o f nodes o and w o n such a p a t h , there is either a forward arc (v, w) with f(o, w) < c(v, w) or a
backward arc with f(w, u) > 0.
D. Goldfarb, M.D. Grigoriadis,Dinic and network simplex methods for max flow 87
The procedure uses the original data of N, and computes the augmenting
capacity of each arc of R k when it is needed. It visits each node u E V - {s } in first-in
first-out order, and (implicitly) installs in L k forward arcs (u, w) with positive augment-
ing capacity leading to new nodes w, and backward arcs (w, o) with positive flow
from new nodes w. Queue is maintained by the functions POP(Queue) and
APPEND (w, o, Queue). Each invocation of these takes O (1)time. The former removes
the node found at the head of the queue and returns it as node o. The latter appends w,
the neighbor of o, at the tail of the queue and assigns d(w) := d(u) + 1. Thus, the
distance of a node from the source is defined only once, whenever the node is first
reached in BFS order; nodes that have not been reached carry the label "oo" The
query "o E Queue?" is thus answered in O(1) time and no extra space is required.
We now return to the task of computing a maximum flow in L k. Dinic suggests
a procedure that works for an acyclic network Lt¢: use DFS to fred an s- t path in
Lk, augment the flow along this path, delete every saturated arc on the path, and
repeat by starting from the end node of the deleted arc closest to the source. If DFS
reaches a node w along an arc (v, w) and w has no outgoing arcs, then w and all arcs
into w are deleted and DFS resumes from o. Procedure DNDFS implements this
approach.
88 D. GoIdfarb, M.D. Grigoriadis, Dinic and network simplex methods for max flow
The distance labeling d is not used by DNDFS since the arcs of L k were
previously selected and recorded b y DNBFS in LarcF and LarcB. DNDFS records
a flow augmenting path by the pair of node-labelings P(parent) and D(direction),
and uses a node-labeling F to record flow increments. Space can be saved by storing
the lists LarcF, LarcB and D as the sign bits of the otherwise positive-valued lists
FA, BA and P, respectively. The actual flow augmentation is done by DNPUSH
as follows.
else
f(o,w):=f(o,w)+
if f(v, w) = c(o, w) then LArcF(v, w) := closed, k := v endif;
endif;
until o = s;
end DNPUSH;
Clearly, DNPUSH takes O(n) time. Does DNDFS run in O(nm) time? We
shall assume that the repeat loop of DNDFS scans FA (u) backward, and that a pointer
to the first arc from the end of FA(o) that is open is maintained. The statement
"if 3 w E FA(o) . . ." searches FA(v) backward, starting from the arc given by this
pointer. The search continues until either an open arc is found (in which case the
pointer is moved up to this arc), or none is found (in which case the pointer is set
to null, indicating that there are no open arcs from v). The search of BA(o) is imple-
mented in the same manner. This works because no arc can be opened once it is
closed; the lists FA(v) and BA(o) are reviewed only once for each o E V. Further-
more, each sequence of at most n - 1 forward or backward steps results in a push or
in a backup step. In either case, an arc is closed. Consequently, the time complexity
is O(nm) for DNDFS, and O(n2m) for the overall procedure DNSUB defined
below. The pointers require 2m space.
Procedure D N S UB (N )
f:=0;
repeat
d, LArcF, LArcB := DNBFS(N, f);
if d(t) < oo then f : = DNDFS(d, LarcF, LArcB), endif;
until d ( t ) = oo ;
report d,/'as d*, f*;
end DNS UB;
3. Data structures
and in the second, a bypass arc (s, t) with unit cost p (s, t) = 1 is appended to the
network. The extra arc has infinite capacity, and all original arcs have zero unit cost.
The so-augmented problem is a linear program of the form:
where the matrix A is the n x m node-arc incidence matrix of rank n - 1 and n < m
(m includes the appended arc). For each arc ] = (v, w) there is a column ai of the
matrix A having aoi = 1 and a w i = - 1 as its only nonzero elements. The m-vectors
c, p, and f are the capacities, costs and flows, respectively, and the null flow is feasible.
We shall use the first formulation, the second one is analogous.
The correspondence between the algebra and geometry of this linear program
and simple graph-theoretic concepts provides the basis for implementing the simplex
method efficiently. These properties and their use in devising an implementation are
discussed in [18]. Here, we state some of them, specifically for the maximum flow
problem, and we derive a steepest-edge variant o f the network simplex method.
The polytope P = { l i A r = O, 0 <~ f <~ c} is the set of flows. The flow value
Ifl is the flow f(t, s) in the circulation arc. A basis B for the matrix ( - e s, A) is a set
of arcs that forms a (spanning) basis tree T of N, rooted at the source. The column
- e s represents an artificial arc (having zero cost and infinite capacity) from a fictitious
:C~,,,,) =
c(~,,,)
root
s~ (, ,~(~,) = 0
//"* f(~, ~) = 0
ce./'/'/--
e~
origin
p(,,,) = -1, oCt, s) = ~o
f ( t , s) - I/I
node, called the origin, to the source. A vertex of P [a basic feasible solution of (4.1)]
is a flow such that arcs not in T are either saturated or have zero flow. Every feasible
tree T contains the artificial arc at zero flow, and the circulation arc. Removing the
circulation arc decomposes T into two subtrees Ts and Tt, rooted at s and t,
respectively (see fig. 1). We denote the set of nodes of Ts by X and those of Tt by X.
92 D. Goldfarb, M.D. Grigoriadis, Dinic and network simplex methods for max flow
Now consider a path VOP(o) in T from some node v to the origin node. The
column % of B-1, corresponding to node u, is an encoding of this path as follows:
~iv =
- 1 if arc i E VOP(o) in T is directed away from the origin
0 otherwise.
We see that the value of the Lagrange multiplier u (o) for the vth row of A f = 0 is the
cost of the path VOP(v), which is zero if v E X and - 1 otherwise. The vector (u, rr),
where lr(v, w) = u(v) - u(w) is the value of the dual variable for the constraint
f(v, w) <~ c (v, w), is feasible for the dual of problem (4.1). The vector u records the cut
(X, .~) whose capacity is the sum of the capacities of nontree arcs directed from nodes
of X to nodes of X. By duality, such a cut is of minimum capacity and the flow in the
circulation arc is maximum if and only if these two values are equal. (This also follows
from the max-flow min-cut theorem [9] .) Otherwise, there is at least one nontree arc
(v, w), o E X, w ~ X or an arc (w, v) w E X', v E X of residual capacity c(v, w). We refer
to the set of such arcs as candidate arcs (see fig. 1). The (unique) s-t path in T that
a candidate arc defines may or may not be flow augmenting. In the next few para-
graphs, we will discuss the manner in which one candidate arc is selected for a possible
augmentation, a task that is usually referred to as pricing.
Let B be a basis and, for notational convenience, let ( - e s, A) = (BIR)
= ( - e s, al . . . . . an- i lan . . . . . am) be a partition of A into n - 1 basic and m - n + 1
nonbasic columns o f A. Similarly, let the vectors p, c, and f be conformally parti-
tioned to (PB, PR ), ( CB, CR) and ( fB, fR ), respectively, and let Yl = B-l ai = % - aw"
This n-vector is an encoding of the path FAP(w, v), from w to v in T, where
Now consider a general linear program of the form (4.1). Let B be a feasible non-
degenerate basis for A, and let (fB, fR) be the corresponding vertex of P. For each
j E { n . . . . . m}, the m-vector ( - y j , ej), where ei denotes the ( j - n + 1)-th column
of I m - n . 1, is a direction along an edge of the polytope P from its vertex at (fB, fR)
to an adjacent vertex at (fB, f n ) + * ( - Y p ei) for some ~. > 0 (see e.g. Best and
Ritter [1] ). In the original simplex method, the direction taken is the one that corre-
sponds to the largest reduced cost (-Yk, ek)P, found by
For general linear programs, it has been empirically found that this criterion, or an
appropriate relaxation of it, produces a larger portion of nondegenerate pivots and
less iterations, overall, than pricing strategies that use pure reduced costs [16,21,25,37].
However, the amount of work to achieve this is prohibitive unless updating formulae,
such as those proposed by Goldfarb and Reid [16], are used to maintain the values
of the squares of the norms of the edge direction vectors at each iteration.
For the special case of minimum-cost network flow problems, the product
yj y~ for each j = (o, w) E A \ T is easier to compute since it is precisely t FAP(w, o)1.
However, the O(n) time required per nontree arc is still too expensive in relation to
the O(1) time for computing its reduced cost and to the O(n) time for a pivot.
Experience indicates that such is the case even when F A P lengths are updated rather
than recomputed at each iteration (see e.g. [17,18,28] ). We note that the cycle identi-
fied by (4.2) with the z~ defined by (4.3) is a minimum cycle mean (Karp [23] ) over
all elementary cycles corresponding to the current basis tree.
*Recall that cos 0 = ab/( [a I" [b I) for any two nonzero vectors a, b E IRm.
94 D. Goldfarb, M.D. Gtqgoriadis,Dinic and network simplex methods for max flow
The work necessary to make this choice is still too expensive in relation to that required
to implement the pivot, i.e. determining the arc to leave the tree, reordering the basis
tree, and updating the values of the flows and dual variables. The effort is substantially
reduced by employing partial pricing strategies. Here, we use the strategy implemented
by the MAXFLO option of the code RNET: scan a small, arbitrarily-selected
fraction o f the nontree arcs with positive reduced cost, and among these, select an
arc (uk, wk) with the shortest FAP(w k, uk) to enter the basis tree [18,20]. Much
more elaborate strategies are possible, but this ad hoc procedure provides a basis for
a fair comparison.
A nondegenerate pivot step corresponds to a flow augmentation along the s- t
path determined by the entering arc (ug, wk) and its FAP(wk, uk). This path is flow
augmenting if and only if both subpaths, s to uk in Ts and wk to t in Tt, are flow
augmenting. An augmentation results in at least one of the following cases: (1) One
or more forward arcs become saturated, (2) one or more backward arcs have their
flows reduced to zero, or (3) the entering arc becomes saturated if it is a forward arc,
or its saturating flow is reduced to zero if it is a backward arc. If arc capacities are
integer, it follows that there can be at most If*l ~< nCmax augmentations or non-
degenerate pivots.
Unfortunately, even when appropriate anticycling rules are used, there can be
at most n - 2 consecutive degenerate pivots preceding each nondegenerate pivot step.
Such is the case for the method of keeping flows basic, proposed by Johnson [22],
and for the network simplex method with strong feasibility rules studied by Cunning-
ham [3 ]. For the maximum flow problem, a basis tree is strongly feasible if all arcs
in Ts [ Tt] having zero flow are directed away from the source [sink], and if saturated
arcs in Ts [Tt] are directed toward the source [sink], respectively. Each basis tree can
be made to have this property by initially constructing a strongly feasible tree for
f = 0, and by resolving ties in the choice of the leaving arc at each subsequent iteration
in favor of the one closest to the source. In the worst case, such a network simplex
method requires O(n2Cmax) pivots and runs in O(n2mCmax) time for integer data,
regardless of the pricing strategy used to select the entering arc.
D. Goldfarb, M.D. Grigoriadis, Dinic and network simplex methods for max flow 95
5. C o m p u t a t i o n a l results
where bnc = max{bn, bc} and brnc = max{bin, be}. For any feasible set of sizes and
arrangements, 1.1 ~< So/SR ~< 2. The space sR can be reduced further by at least
bn(m - n) + 2n bytes by dropping some incidental functions of R N E T , by using
96 D. Goldfarb, M.D. Grigoriadis, Dinic and n e t w o r k simplex m e t h o d s f o r m a x f l o w
,-- t
(si,,k)
b ufraFnes~
n o d e s / f r a?m~e. .) ~ ~ _ _ _ ."
. . . /.."
.'"
at
nodl~
ares
a 2 b a c k w a r d ares
°/*
¢g
(source)
n ode8
Fig. 2. S t r u c t u r e o f RMFGEN-generated p r o b l e m s .
the adjacency list input structure of D N S U B , by combining the Boolean array U with
another positive-valued list, and by minor reprogramming. We have not undertaken
these tasks.
For the testing reported in this paper,we generated both D N S U B and R N E T F
for b n = 2, b m = b c = 4, and we diminished both programs to the (smaller) sizes
dictated by D N S U B , i.e. 4700 nodes and 27 000 arcs. For this case, SD/sR ~ 1.78.
The selection bm = 2 would have been sufficient for our test problems; we used
b m = 4 in order to better assess the performance of the codes for realistic situations
where m might exceed 32 767.
We used the program R M F G E N [19] to generate our test cases. This program
accepts values for four parameters a, b, c~ and c 2 ( > cl), and creates networks with
the structure depicted in fig. 2. The graph can be visualized as having b frames, each
of which has a 2 nodes at the lattice points of the square of side a. Each frame is a
symmetric subgraph: each node in a frame is connected to its neighbors on the lattice
by a pair of oppositely directed arcs. There are 4 a b ( a - 1 ) s u c h "in-frame" arcs with
capacity equal to c2a 2 . There are a 2 arcs from the nodes of one frame to a pseudo-
random permutation of the nodes of the next (one to one), with pseudorandom
integer capacities in the range [c~, c2 ]. Similarly, there are a 2 arcs from a frame to
its preceding one. This portion of the graph is not symmetric. The generated graphs
have n = a2b nodes and m = 6a2b - 4ab - 2a 2 arcs, source node s = 1 (at the lower
left of the first frame in fig. 2 ) and sink node t = a2b (at the upper right of
the last frame in fig. 2). Nodes have in- and out-degrees of 3, 4, 5 or 6. Since
m / n = 6 - 4/a - 2/b ~ 6 for sufficiently large a and b, these form a relatively dense
D. Goldfarb, M.D. Grigoriadis, Dinic and network simplex methods for max ]'low 97
set of *'sparse" instances. Their solution involves flow augmenting paths whose length
is at least b. The minimum cut is located between two consecutive frames and it
contains a 2 arcs.
We generated ten replications of each problem defined by the R M F G E N
parameters a and b listed in table 2, with different seeds for the pseudorandom
number generator but with [cl, c2 ] = [ 1, 1000] for all of them. We executed R N E T F
with parameter values Po = 1.0, ff = 1.5 and with a pricing sample size ofmin{35, m}
arcs [18]. The running times we report are averages of ten replications per problem,
and do not include I/O operations for either code.
We used an IBM Personal Computer AT (Intel 80826 processor operating at
8 MHz, and 640 K bytes of 150 ns main memory) to develop D N S U B and to run
our experiments. Both codes were compiled with the two-pass Microsoft FORTRAN
77 V3.31 compiler, linked with the Microsoft 8086 Object Linker V3.04, and executed
under the IBM Personal Computer DOS V3.00 operating system. The blank cells in
table 2 correspond to problems that cannot be stored in the 640 K main memory of
an IBM/AT computer, e.g. the cell at the lower right would be a problem of 147 456
nodes and 867 841 arcs, and would require 17.1 Mbytes of array storage for D N S U B
and 9.6 Mbytes for R N E T F .
At first sight, the results of table 2 indicate that R N E T F is more efficient
than D N S U B : it solves all problems in 5 120 seconds versus 6 703 for D N S U B , and
it requires less space than DNSUB. Furthermore, our problem set is sufficiently
diverse, it has a large enough range of arc capacities and a large Cmax . We see, however,
that D N S U B runs appreciably faster for "cell" (a, b) = (12, 32) of table 2, and
slightly faster for cells (16, 16) and (8, 32). In fig. 3, we plot tn/t D, the ratio of
the average D N S U B to R N E T F running times, as a function of n. This plot shows
that R N E T F ' s advantage in running times diminishes with increasing problem size.
The question naturally arises whether this trend might accelerate for larger
problems. This can occur to the extent of a constant factor for an R N E T F equipped
with strong feasibility rules, for integer data and for fixed Cmax. For our specific
implementations, the question can be addressed with additional large-scale computa-
tional testing, but our results suggest that such an acceleration is possible for some
problems. If it occurs, it would be due to an excessive number of pivots or time per
pivot, or both. Let tg/t D = (nR/nD)(rR/rD) , where nR, rR and nD, r D denote the
number of R N E T F pivots and time per pivot, and the number of D N S U B augmenta-
tions and time per augmentation, respectively. We have plotted these ratios in figs. 4
and 5. We observe from fig. 4 that ng/n D can be approximated by a nondecreasing
concave function; fig. 5 shows that the ratio rR/r D deteriorates for large n. Thus, the
relative efficiency of R N E T F diminishes due to the time it spends to select and
implement a pivot, rather than a disproportionate increase in the number of pivots.
Although a better pricing strategy than the ad hoc procedure used by R N E T F could
lead to some improvements, these results indicate that the drop in efficiency is mainly
Table 2 "4)
CO
Test results with set of RMFGENproblems
average
Side of square Number of frames, b (see notes in caption) times
DNSU8
~ame, a 2 4 8 16 32 64 RNETF
3 18; 66 36: 150 72; 318 144: 654 288; 1326 576; 2670
6 9 0.1 10 22 0A 11 35 0.9 15 59 2.4 19 96 6.1 31 175 19.7 29.6
8 0.1 32 0.2 65 0.5 97 1.1 158 2.9 308 9.8 14.6
4 32; 128 64: 288 128; 6O8 256; 1248 512: 2528 1024: 5088
9 17 0.3 14 41 1.0 17 73 2.4 25 141 7.3 35 254 21.0 57 481 68.3 100.3
21 0.1 80 0.4 169 1.3 293 3.9 500 11.7 950 40.8 58.2
72; 312 144; 696 288; 1464 576; 3000 1152; 6072 2304; 12216
16 45 1.2 22 97 3~ 31 203 10~ 40 379 27.5 60 733 83.9 83 1300 230.2 357,0 t~
69 0.3 233 1.4 495 5.3 884 17.1 1682 61.6 2885 189.5 275.2
8 128; 576 256; 1280 512; 2688 1024; 5504 2048; 11136 4096; 22400
22 86 3.1 35 190 10.4 40 371 24.8 50 709 62.5 78 1389 196.2 120 2631 604.8 901.8
144 0.7 494 3.8 987 13.8 1812 46.7 3416 170.1 6353 607.3 842.4
12 288; 1344 576; 2976 1152; 6240 2304; 12768 4608; 25824
36 216 11A 53 442 37.0 68 927 98.6 91 1836 261.3 121 3534 702~ llll.l
432 2.7 1265 14.3 2657 60.5 5158 231.9 9520 848.1 1157.5
48 4608; 22656
168 4530 940.0 940.0
10273 414.4 414.4
Z average times
DNSUB: 1359.5 1218.7 1189,4 996.2 I011,2 927.7 6702.7
RNETF: 540.7 660,4 994.0 981.0 I095.0 849.3 5120,4
Numbers in cells are: n; m (first row). Average pivots and R N E T F time t R (third row).
Average stages, augmentations and DNSUB time rD (second row). Times arc IBM/AT seconds.
D. Goldfarb, M.D. Grigoriadis, Dinic and network simplex methods for max flow 99
OJ
I I I I
Legend:
X = 2 frames
= q 4rames
= 8 Statues
0 = IS ~rSmes
= 32 frames
o
oJ = 6~ ~rames
I--
I,L
l--
b.l
Z
ZC
I I I I
0 iO 20 ~]O qo 50
NODES ~I0 ~
due to the pivot step. This step is more expensive for longer FAPs because larger
subtrees have to be reordered. Figure 5 shows this to be the case: the pivot time
increases faster for problems with more frames rather than for problems with more
nodes per frame.
As a practical matter, such arguments assume that the growth of nR/n D is not
caused by a disproportionate change in the "mix" of degenerate and nondegenerate
pivots. This was indeed the case for our problems. Degenerate pivots accounted for
50, 35, 23, 18, 16 and 15 percent of all pivots for problems with n i> 500 and with
b = 2, 4, 8, 16, 32 and 64 frames, respectively. These percentages remained fairly
constant for alt problems larger that 1000 nodes.
Regardless of its relative efficiency, R N E T F runs much faster than its worst
case. This is true for D N S U B as well: we see from fig. 6 that the number of stages
is at most 0.07n (much less than n - I) and the number of augmentations per stage
is at most 30 (much less than m) for all problems larger than 1000 nodes. The product
o
100 ~-
~-
m
~N
~-
/ 0 = 32 f r a m e s
i [] = 6~ f r a m e s
I................. I I
10 20 30 qO 50
NODE5 ~I02
Fig. 4. Ratio o f R N E T F pivots to D N S U B augmentations.
I I I I
Legend:
X -- 2 frames
+i
O_
~x
G
[]
=
=
B frames
16 f r a m e s
= 32 f r a m e s
-- 6~ f r a . +
~
,.e~-/
- -
/
~/" ~]
Z TM° _
Ic
I I I I
I0 20 30 YO 50
NODES ~I0 ~
Fig. 5. Ratio o f R N E T F p i v o t t o D N S U B augmentation times.
D. Goldfarb , M.D. Grigoriadis, Dinic and network simplex methods for max flow 101
#
6 • I t. . . . . . . . . . . . . . . . . . I t
Legend:
X = 2 frame~
i + = t~ f r a m e s
-- 8 fr~tmes
l~] = 6~ fr~tmes _
o_ o_
; °
I I I I o
0 I0 20 30 YO 50
NOOE5 ~I0 z
of the two sets of curves gives corresponding curves for augmentations, all of which
are bounded above by approximately 0.9n. This is substantially smaller than the
worst case of (n - 1)m ~ 6n 2 augmentations for the type of problems we have
considered.
References
[ 1] M.J.Best and K. Ritter, Linear Programming:Active Set Analysis and Computer Programs
(Prentice-HaU, EnglewoodCliffs, New Jersey, 1985).
[2] R.V.Cherkasky, Algorithms of construction of maximum flow in networks with complexity
O(V2x/E) operations, Mathematical Methods of Solution of Economical Problems 7(1977)
112 (in Russian).
[3] W.H.Cunningham, A network simplex method, Math. Progr. 1(1976)105.
[4] W.H.Cunningham, Theoretical properties of the network simplex method, Math. of Oper.
Res. 4(1979)196.
102 D. Goldfarb, M.D. Grigoriadis, Dinic and network simplex methods for max flow
[5] T-Y. Cheung, Computational comparison of eight methods for the maximum network flow
problem, ACM Trans. on Math. Software 6(1980)1.
[6] E.A. Dinic, Algorithms for solution of a problem of maximum flow in networks with
power estimation, Soy. Math. Doklady 11(1970)1277.
[7] J. Edmonds and R.M. Karp, Theoretical improvements in algorithmic efficiency for network
flow problems, J. Assoc. Computing Machinery 19(1972)248.
[8] S. Even, GraphAlgorithms (Computer Science Press, Potomac, Maryland, 1979).
[9] L.R. Ford, Jr. and D.R. Fulkerson, Maximal flow through a network, Can. J. Math. 8(1956)
399.
[10] L.R. Ford, Jr. and D.R. Fulkerson, F/ows in Networl~ (Princeton University Press, New
Jersey, 1962).
[1t] Z. Galil, An O(VS#E~#) algorithm for the maximum flow problem, Acta Informatica
14(1980)221.
[12] Z. Galll and A. Naamad', An O(EVlog 2 V) algorithm for the maximum flow problem,
J. Comput. Syst. Sci. 21(1980)203.
[13] A.V. Goldberg and R.E. Tarjan, A new approach to the maximum flow problem, 18th
Annual ACM Symp. on Theory of Computing (1986) pp. 136 - 146.
[14] F. Glover, D. Klingman, J. Mote and D. Whitman, An extended abstract of an indepth
algorithmic and computational study for maximum flow problems, Discr. Appl. Math.
2(1980)251.
[15] D. Goldfarb, Steepest edge simplex algorithms for network flow problems, Technical
Report RC 6649, T.J. Watson Research Laboratory, IBM Corporation, Yorktown Heights,
New York (1977).
[16] D. Goldfarb and J.K. Reid, A practicable steepest-edge simplex algorithm, Math. Progr.
12(1977)361.
[17] D. Goldfarb and M.D. Grigoriadis, An efficient steepest edge algorithm for the maximum
flow problem, paper presented at the Xth Int. Symp. on Math. Progr., Montreal, Canada
(1979).
[18] M.D. Grigoriadis, An efficient implementation of the network simplex method, Math.
Progr. Study 26(1986)83.
[19] M.D. Grigoriadis, RMFGEN - A generator for a class of maximum flow networks (in
preparation).
[20] M.D. Grigoriadis and T. Hsu, RNET, SIGMAP Bulletin (1978).
[21] P.M.J. Harris, Pivot selection methods of the Devex LP code, Math. Progr. 5(1973)1.
[22] E. Johnson, Networks and basic solutions, Oper. Res. 14(1966)619.
[23] R.M. Karp, A characterization of the minimum cycle mean in a digraph, Discr. Math. 23
(1978)309.
[24] A.V. Karzanov, Determining the maximal flow in a network by the method of preflows,
Soy. Math. Doklady 15(1974)434.
[25] H.W. Kuhn and R.E. Quandt, An experimental study of the simplex method, in: Proc.
of Symposia in Applied Math., Vol. XV, ed. Metropolis et al. (Amer. Math. Assoc., 1963).
[26] E.L. Lawler, Combinatorial Optimization: Networks and Matroids (Holt, Rinehart and
Winston, New York, 1976).
[27] V.M. Malhotra, M. Pramodh Kumar and S.N. Maheshwari, An O(IVI a) algorithm for finding
maximum flows in networks, Inf. Proc. Lett. 7(1978)277.
[28] J.M. Mulvey, Pivot strategies for primal-simplex network codes, J. Assoc. Computing Mach.
25(1978)266.
[29] C. Papadimitriou and K. Steiglitz, Combinatorial Opnmization: Algorithms and Complex-
ity (Prentice-Hall, Englewood Cliffs, New Jersey, 1982).
D. Goldfarb , M.D. Grigoriadis, Dinic and network simplex methods for max flow 103
Appendix
*** T H E P R O G R A M IS B A S E D ON T H E P A P E R **t
*** D. G O L D F A R B , M.D. G R I G O R I A D I S "A C O M P U T A T I O N A L ***
*** C O M P A R I S O N OF T H E D I N I C A N D N E T W O R K S I M P L E X **t
*** M E T H O D S F O R M A X I M U M FLOW", ***
*** A N N A L S O F O P E R A T I O N S RESEARCH, THIS V O L U M E ***
*** A L L T H E S U B R O U T I N E S A R E W R I T T E N IN A M E R I C A N ***
*** S T A N D A R D F O R T R A N A N D A R E A C C E P T E D BY T H E ***
*** PFORT VERIFIER. **t
*** Q U E S T I O N S A N D C O M M E N T S S H O U L D BE D I R E C T E D TO ***
*** D. G O L D F A R B ***
*** C O L U M B I A U N I V E R S I T Y , N E W YORK, NY 10028, U.S.A. ***
*** M. G R I G O R I A D I S ***
*** R U T G E R S U N I V E R S I T Y , N E W B R U N S W I C K , NJ 08903, ***
*** U.S.A. ***
************************************************************
C D I M E N S I O N T H E S E TO AT L E A S T MAX N U M B E R OF N O D E S + 2:
INTEGER DNLIST(4700>~DNDIST(4700)
INTEGER DNFAPT<~700),DNPTRF(4700),DNBAPT(4700),
* DNFLAB(4700),DNPTRB(4700)
C D I M E N S I O N T H E S E TO AT L E A S T MAX N U M B E R OF A R C S + I:
INTEGER DNFADJ(27000),DNFROM(27000),DNTO(27000),DNBADJ(27000)
INTEGER DNCAP(27000)~DNGCAP(27000),DNFLOW(27000),DNBTOF(27000)
C
COMMON /DNOI/DNFAPT/DNO2/DNFADJ/DN03/DNCAP/DN04/DNFROM
COMMON /DN05/DNFLOW/DN06/DNGCAP/DN08/DNPTRF/DN09/DNLIST
COMMON /DNIO/DNBAPT/DNII/DNFLAB/DNI2/DNPTRB
C
INTEGER DNNODE,NODPI2,DNSRCE,DNSINK, I2,112,K2,J2~IHEAD2~
ITAIL2~QHEAD2~QTAIL2,KP2,KSAT2,DNNOP2,LAYMAX,K2DST,K2DPI,MAXD2
INTEGER DNARC,DNFVA,DNAUG,DNLFVA,DNLAUG~DNSTGE~DNIBIG
COMMON /DN00/DNARC,DNFVA~DNAUG~DNLFVA,DNLAUG,DNSTGE,
DNELTM~DNIBIG,DNNODE~DNSRCE,DNSINK,DNNOP2
EQUIVALENCE (DNFLOW(1),DNTO(I>), <DNFLAB<I)~DNDIST(I>),
(DNFROM(I>~DNBADJ(1)), (DNGCAP<I),DNBTOF<I))
C
C INITIALIZE:
C
C M A X I M U M P R O B L E M S I Z E B A S E D U P O N S I Z E S OF A R R A Y S AS D I M E N S I O N E D :
MAXNOD=4700
MAXNOD=MAXNOD-I
MAXARC=27000
C DEFINE INPUT~OUTPUT AND REPORT FILES
LINP=5
LOUT=6
LREP=8
C READ INPUT DATA FOR NEXT PROBLEM
C T Y P I C A L INPUT F I L E
106 D. Goldfarb, M.D. Grigoriadis, Dinic and network simplex methods for max flow
C R E C O R D I: N O D E S ~ N A R C S ~ I S O U , ISNK
C RECORDS 2~...,NARCS+I:FROMNODE,TONODE,ARCCAPACITY
C (ARCAPACITY=O IMPLIES INFINITE)
READ(LINP,20I)NODES~NARCS~ISOU, ISNK
201 FORMAT(4IIO)
IF(MAXNOD.GE.NODES) G O T O 100
WRITE(LOUT,203)
203 FORMAT(2X,14HTO0 MANY NODES)
STOP
100 I F ( M A X A R C . G E . N A R C S ) G O T O 110
WRITE(LOUT~205)
205 FORMAT(2X~I3HTO0 MANY ARCS)
STOP
110 IMAXS=O
IMAXT=O
D O 10 a = I ~ N A R C S
READ<LINP,20I)DNFROM<J)~DNTO<J),DNGCAP(J)
IF(DNFROM<J).EQ. ISOU)IMAXS=IMAXS+DNGCAP(J)
IF(DNTO(J).EQ. ISNK)IMAXT=IMAXT+DNGCAP(d)
I0 CONTINUE
IMAXC=IMAXT
IF(IMAXS.LT.IMAXT) IMAXC=IMAXS
D O II J = I , N A R C S
ii IF(DNGCAP<J).GT. IMAXC)DNGCAP(J)=IMAXC
C C R E A T E I N P U T D A T A IN F W D A D a A C E N C I E S AS R E Q U I R E D BY D I N S U B :
CALL DNFWD(NODES~NARCS~IRETN)
IF(IRETN.EQ.O) GO TO 30
WRITE(LOUT~33)
33 FORMAT(IX~I7H INPUT DATA ERROR)
STOP
30 CONTINUE
C SOLVE PROBLEM:
C A L L DNSUB(NODES,NARCS, ISOU, ISNK,MAXFLO,NUMAUG,NPHASE,
N N C U T , N A C U T , E T I M E , IRETN)
I F ( I R E T N . EQ.O) G O T O 4 0
WRITE(LOUT,33)
STOP
40 CONTINUE
C WRITE SOLUTION STATS TO SCREEN:
W R I T E ( L O U T , 1007)
NODES,NARCS,MAXFLO,NUMAUG,NPHASE,NNCUT,NACUT,ETIME
1007 FORMAT(21H NODES ARCS
42HMAXFLO NUMAUG STAGES NNCUT NACUT ELAPTIM
~/ I6, I7, I14,417,F8.2)
C CREATE OUTPUT REPORT:
W R I T E ( L O U T , 1003)
1003 FORMAT(37H WANT SOLUTION REPORTS (O=YES, 1=NO))
READ(LINP,20I)IYESNO
IF(IYESNO.NE.O)STOP
WRITE(LOUT, 1OI2)LREP
1012 F O R M A T ( / 4 3 H S O L U T I O N R E P O R T F O R P R O B L E M D A T A IN F I L E ,I5)
CALL DNOUT(LREP)
9999 STOP
END
SUBROUTINE GETIME(T)
REAL T
C THE USER INSTALLATION PROVIDES A TIMING ROUTINE HERE, SAY SECOND~
C T H A T R E T U R N S T H E C U R R E N T T I M E IN V A R I A B L E T~ IN S E C O N D S .
C A L L S E C O N D (T)
RETURN
D. Goldfarb , M.D. Grigoriadis, Dinic and network simplex methods for max flow 107
END
SUBROUTINE SECOND(T)
T=O. 0
RETURN
END
SUBROUTINE D N S U B (NODES, N A R C S , I S O U R C , I S I N K , M A X F L O ,
* NUMAUG, NUMSTG, NNCUT, NACUT, ELTIM, IRETN)
C
C~:*~.~***~(~**START DNSUB STANDARD USER XFACE DECLARATION BLOCK~**~.~
C
C U S E R M U S T I N C L U D E T H I S B L O C K IN H I S / H E R CALI_ING P R O G R A M .
C
C THESE DECLARATIONS ACCOUNT FOR THE ENTIRE ARRAY STORAGE USED BY
C THE DNSUB SUBROUTINES, I N C L U D I N G W H A T IS N E C E S S A R Y TO STORE THE
C I N P U T D A T A . IT A M O U N T S T O 6 * N O D E S + 5 * A R C S W O R D S ~ B U T IT M A Y B E
C STATED MORE PRECISELY AS FOLLOWS:
C
C I) F O R S O L V I N G P R O B L E M S WITH UP TO 32,765 NODES AND 2~147,483~647
C ARCS, AND WITH FLOW VALUES OF UP TO 2~147~483~647~ IT S U F F I C E S
C TO DECLARE ARRAYS AS SHOWN UNDER 'STDARRANGEMENT' IN T H E
C TABLE BELOW. THIS ARRANGEMENT IS T H E O N E U S E D IN T H E R E L E A S E
C V E R S I O N O F T H E D N S U B SUBF~OUTINES.
C
C 2) IN O R D E R T O H A N D L E P R O B L E M S W I T H M O R E T H A N 32.,765 N O D E S ~ A L L
C INTEGER*2 DECLARATIONS BELOW MUST BE CHANGED TO INTEGER~4 AND
C T H E DNSI]B S U B R O U T I N E S AND USER CALLING PROGRAMS M U S T BE C O M P I L E D
C AND LINKED. (SEE A L T E R N A T E i BELOWo)
C
C 3) F O R SOLVIIqG O N L Y P R O B L E M S WITH AT MOST 32,765 NODES~ 32,767
C ARCS~ AND WITH FLOWS NOT EXCEEDING E,2,767~ A L L I N T E G E R * 4
C DECLARATIONS BELOW MAY BE CHANGED T O INTEGERS.2, A N D T H E D N S U B
C SUBROUTINES AND USER CALLING PROGRAMS MUST BE COMPILED AND
C LINKED. (SEE A L T E R N A T E 2 BELOW.) IT IS A L S O N E C E S S A R Y TO
C ACTIVATE TIdE S T A T E M E N T D I q I B I G = 3 2 7 6 7 in s u b r o u t i n e d n s u b , and t o
C include ~JmpliciL" I N T E G E R * 2 (i-n)' s t a t e m e n t s in e a c h p r o g r a m
C unit~ THIS ARRANGEMENT, WHICH USES THE LEAST AMOUNT OF MEMORY
C A N D IS TIdE F A S T E S T w h e n e x e c u t e d on 1 6 - B I T P R O C E S S O R S , IS O N L Y
C USEFUL FOR A SET OF VERY SPECIAL APPLICATIONS. ITS general
C t~se is n o t r e c o m m e n d e d ° OTHER ALTERNATES ARE ALSO POSSIBLE.
C
C
C
C, STD ARRANGEMENT ALTERNATE I ALTERNATE 2
C (not r e c o m m e n d e d )
C
C ARRAY LENGTH TYPE EQV'D TYPE TYPE EQV'~D T Y P E TYPE EQV~D TYPE
C ....................
C DNFAPT N 4 4 2
C DNFADJ A 2 4 2
C DNCAP A 4 4 2
C DNBAPT N 4 4 2
C DNBAD,] A 2 DNFROM 2 4 DNFROM 4 2 DNFROM 2
C DNFL.OW A 4 DNTO 2 4 DNTO 4 2 DNTO 2
C DNBTOF A 4. DNGCAF' 4 4 DNGCAP 4 2 DNGCAP 2
C DNPTRF N 4 4 2
C DNPTRB N 4 4 2
C DNLIST N 2 4 2
C DIqFLAB N 4 DNDIST 2 4 DNDIST 4 2 DNDIST 2
C ........................................................................
C
108 D. Goldfarb, M.D. Grigoriadis, Dinic and network simplex methods for max flow
C
C DIMENSION THESE TO AT LEAST MAX NUMBER O F N O D E S + 2:
INTEGER DNLIST (4700) , DNDIST (4700)
INTEGER D N F A P T ( 4 7 0 0 ) ~ D N P T R F ,:4700 ) , D N B A P T ~4700) ,
DNFLAB (4700) , DNPTRB (4700)
C DIMENSION THESE TO AT LEAST MAX NUMBER OF ARCS + ~ :
INTEGER DNFADJ (27000) ,DNFROM(27000> ~DNTO(27000) ~DNBAD3 (27000>
INTEGER DiqCAP<27000> ~DNGCAP(27000) ~DNFLOW(27000) ~DNBTOF~27000)
COMMON /DNO1/DNFAPT/DNO2/DNFADJ/DN03/DNCAP/DN04/DNFROM
COMMON /DN05/DNFLOW/DN06/DNGCAP/DN08/DNPTRF/DN09/DNLIST
COMMON /DN~O/DNBAPT/DNII/DNFLAB/DNI2/DNPTRB
C
C CALLING CONDITIONS:
C USER CALLABLE WITH INPUT DATA AS FOLLOWS.
C INPUT:
C SCALARS (IN C A L L I N G SEQUENCE; ALL INTEGERI4):
C NODES: NUMBER OF NODES (INCLUDING SOURCE AND SINK>
C NARCS: NUMBER OF ARCS
C ISOURC: NODE NUMBER FOR SOURCE
C ISINK: NODE NUMBER FOR SINK
C
C ARRAYS (IN C O M M O N ) :
C DNFAPT: (NODES+I)-LONG INTEGERI4 POINTER ARRAY FOR FORWARD ADJA-
C CENCY LISTS (I.E. T H E F O R W A R D ADJACENCY LIST OF A NODE I
C IS T H E S E T O F A R C S
C {(I,DNFADJ(J)) :J=DNFAPT(I)~.~.~DNFAPT(I+I)-I }
C NOTE: MUST HAVE DNFAPT(NODES+I) = NARCS+I~
C
C DNFADJ : NARCS-LONG INTEGER~2 ARRAY GIVING THE LIST OF NODES IN
C THE FORWARD ADJACENCY LIST DNFADJ(J> F O R E A C H N O D E J~
C AS DESCRIBED ABOVE.
C
C DNCAP: NARCS-LONG INTEGER~4 ARRAY GIVING THE ARC CAPACITIES~ IN
C THE ORDER PRESCRIBED BY DNFAPT<.) AND DNFADJ(.). ALL ARC
C CAPACITIES MUST BE GIVEN ~S POSITIVE INTEGERS.
C
C NOTE: FOR TRANSFORMING UNORDERED ARC LISTS TO THE ABOVE INPUT
C DATA STRUCTURE~USE SUBROUTINE DNFWD BEFORE CALLING DNSUB
C
C OUTPUT :
C
C SCALARS (IN C A L L I N G SEQUENCE):
C MAXFLO: VALUE OF MAXIMUM FLOW (INTEGER~4).
C NUMAUG: NUMBER OF FLOW AUGMENTATIONS (INTEGER~4).
C NUMSTG: NUMBER OF STAGES (LAYERED NETWORKS CREATED; INTEGER~4).
D. Goldfarb , M.D. Grigoriadis, Dinic and network simplex methods for max flow 109
DN00, DNOI, DN02, DN03, ON04, ON05, DN06, DN08. ON09, DNIO, DNII,
DNI2, D N A R C , D N A U G , D N B A D J , D N B A P T , D N B F S , D N B T O F , D N C A P , D N C L E A ,
DNCUT, DNDFS, DNDIST, DNFADJ, DNPUSH, DNFAPT, DNFLAB, DNFLOW,
DNFROM, DNFVA, DNFWD, DNGCAP, DNIBIG, DNLAUG, DNI_FVA, DNLIST,
D. Goldfarb , M.D. Grigoriadis, Dinic and network simplex methods for max flow 111
CALL GETIME(TIMBEG)
IRETN=O
DNIBIG=2147483647
C DNIBIG=32767
DNARC=NARCS
DNNODE=NODES
DNNOP2=DNNODE+2
DNSRCE=ISOURC
DNSINK=ISINK
DO 200 I4=I~DNARC
200 DNFLOW(I4)=O
C ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
C
USING THE FORWARD ADJACENCY ARRAYS DNFAPT(.) AND DNFADJ(.) (IN
COMMON)~ CREATE THE BACKWARD ADJACENCY ARRAYS DNBAPT(.)~ DNBAD3(.)
AND THE BACKWARD TO FORWARD ADJACENCY MAPPING DNBTOF(.). DNLIST(.) IS
USED HERE AS A SCRATCH ARRAY.
NODP12=DNNODE+1
DO 210 I2=I~NODPI2
DNLIST(I2)=O
210 DNBAPT(12)=O
C T E M P O R A R I L Y S T O R E IN B N B A P T ( . ) N U M B E R O F A R C S I N T O E A C H N O D E :
DO 230 I2=I,DNNODE
IBEG4=DNFAPT(I2)
IEND4=DNFAPT(I2+I)-I
DO 220 I4=IBEG4~IEND4
JJDN=DNFADJ(I4)
220 DNBAPT(JJDN)=DNBAPT(JJDN)+I
230 CONTINUE
C CONSTRUCT DNBAPT(.):
IHPI4=DNBAPT(1)
DNBAPT(1)=I
DO 240 I2=I~DNNODE
IHPSV4=IHPI4+DNBAPT(I2)
IHPI4=DNBAPT(I2+I)
240 DNBAPT(I2+I)=IHPSV4
C CONSTRUCT DNBADJ(.) AND DNBTOF(.):
DO 260 I2=I~DNNODE
IBEG4=DNFAPT(I2)
IEND4=DNFAPT(I2+I)-I
DO 250 I4=IBEG4~IEND4
IHEAD2=DNFADJ(I4)
IHPUT4=DNBAPT(IHEAD2)+DNLIST(IHEAD2)
IF(IHPUT4.LE.0)GOTOI900
DNBADO(IHPUT4)=I2
DNBTOF(IHPUT4)=I4
250 DNLIST(IHEAD2)=DNLIST(IHEAD2)+I
260 CONTINUE
C
C ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
C
DNFVA=O
DNAUG=O
112 D. Goldfarb, M.D. Grigoriadis, Dinic and network simplex methods for max flow
DNSTGE=I
C
C STAGE LOOP:
300 CONTINUE
C FORM NEW LAYERED NETWORK W . R . T . CURRENT FEASIBLE FLOW.
CALL DNBFS(LAYMAX)
IF(LAYMAX.ST.O)GOT01500
C COMPUTE A MAXIMAL FLOW IN THIS LAYERED NET:
CALL DNDFS
C UPDATEFLOW VALUE:
DNFVA=DNFVA+DNLFVA
DNAUG=DNAUG+DNLAUG
DNSTGE=DNSTSE+I
C ERASEMARKINGS THAT DEFINE LAYERED NETWORK:
CALL DNCLEA
GOT0300
C i i ~ ~ ~ ~ ~ ~ ~ ~ ~ i ~
C
C CURRENT FLOW IS MAXIMUM:
1500 MAXFLO=DNFVA
NUMAUG=DNAUG
NUMSTS=DNSTGE
CALL DNCLEA
C MARK EXECUTION TIME:
CALL GETIME(TIMEND)
DNELTM=TIMEND-TIMBEG
ELTIM=DNELTM
C
C MARK THE MIN CUT-SET IN DNFAPT<.) AND DNFAD3(.):
CALL DNCUT(NNCUT,NACUT)
C
RETURN
C
1900 IRETN=I
RETURN
END
SUBROUTINE DNBFS~LAYMAX)
C
C
C D I M E N S I O N T H E S E TO AT L E A S T MAX N U M B E R OF N O D E S + 2:
INTEGER DNLIST(4700~DNDIST(4700)
INTEGER DNFAPT(4700)~DNPTRF(4700)~DNBAPT(4700)~
DNFLAB(4700)~DNPTRB(4700)
C DIMENSION THESE TO AT LEAST MAX NUMBER OF ARCS + I :
INTEGER DNFADJ<27000>,DNFROM(27000),DNTO<27000),DNBADJ(27000)
INTEGER DNCAP(27000)~DNGCAP(27000),DNFLOW(27000),DNBTOF<27000)
C
COMMON /DNOI/DNFAPT/DNO2/DNFADJ/DNO3/DNCAP/DNO4/DNFROM
COMMON /DNO5/DNFLOW/DNO6/DNGCAP/DNOS/DNPTRF/DNO9/DNLIST
COMMON /DNIO/DNBAPT/DNll/DNFLAB/DNI2/DNPTRB
C
INTEGER DNNODE~NODPI2,DNSRCE~DNSINK,. I2,. I I ~ K ~ , ~ IHEAD2~
ITAIL2~QHEAD2,QTAIL2~KP2~KSAT2,DNNOP2,LAYMAX,K2DST~K2DPI,MAXD2
INTEGER DNARC, D N F V A , D N A U G ~ D N L F V A , D N L A U G ~ D N S T G E ~ D N I B I G
COMMON /DNOO/DNARC~DNFVA~DNAUG~DNLFVA, DNLAUG,DNSTGE~
DNELTM~DNIBIG~DNNODE,DNSRCE~DNSINK~DNNOP2
EQUIVALENCE (DNFLOW(I>~DNTO(I>), (DNFLAB(1)~DNDIST(1))~
<DNFROM(1),DNBADJ(1)), (DNGCAP(1),DNBTOF(1))
C
C ~ i ~ i ~ ~ ~ ~ ~ i ~ ~ ~ ~ i ~
D. Goldfarb, M.D. Grigoriadis, Dinic and network simplex methods for max flow 113
C
C CALLING CONDITIONS:
C INTERNAL CALL FROM DNSUB ONLY.
C INPUT ARRAYS:
C DNFAPT, DNBAPT~ DNFADJ, DNBADJ~ DNBTOF, DNCAP, DNFLOW
C SCRATCH ARRAYS:
C DNLIST
C OUTPUT:
C IN C A L L I N G S E Q U E N C E <INTEGER*2):
C LAYMAX: 0 (LAYERED NET COMPLETE W I T H S I N K IN L A S T L A Y E R . >
C 1 ( L A S T L A Y E R IS E M P T Y ; C U R R E N T F L O W IN O R I G I N A L
C NETWORK IS M A X I M U M . >
C IN C O M M O N (ARRAYS>:
C DNPTRF, DNPTRB, DNDIST
C
C THIS SUBROUTINE CONSTRUCTS THE LAYERED NETWORK OF THE RESIDUAL
C NETWORK W.R.T. THE CURRENT FLOW. THE RESIDUAL NETWORK IS
C INFERRED, AND THE LAYERED NETWORK IS ONLY RECORDED BY TEMPORARY
C MARKERSON THE ORIGINAL GRAPH. THE SUBROUTINE IMPLEMENTS A
C BREADTH-FIRSTSEARCH ON THE RESIDUAL NETWORK, I . E . NODES ARE
C PROCESSEDAS IN A QUEUE. SUCH A SEARCH PARTITIONS THE NODES INTO
C A SET OF "LAYERS'~ ACCORDING TO THEIR CARDNALITY DISTANCE FROM
C THE s o u r c e . THE DNDIST(.> ARRAY IS USED TO RECORD THESE DISTANCES~
C AND THUS DEFINES THE LAYERS (NOTE: DNDIST(ISOURC)=O).
C
C IN SELECTING ARCS OF THE RESIDUAL NEEWORK THAT ARE DIRECTED FROM
C ONE LAYER TO THE NEXT, WE SHALL MARK THE ARCS IN THE ORIGINAL
C N E T W O R K A S ~ O P E N ~ O R ' C L O S E D ~. A ~ C L O S E D ~ A R C (V,W> IN T H E
C LAYERED NETWORK IS E I T H E R A N A R C I = ( V , W > T H A T IS S A T U R A T E D IN T H E
C ORIGINAL NETWORK, OR AN ARC I=(W,V) OF THE ORIGINAL NETWORK WITH
C Z E R O FLOW. IN T H E F O R M E R C A S E , T H E A B S E N C E OF T H I S A R C F R O M T H E
C LAYERED NETWORK IS M A R K E D B Y N E G A T I N G DNFADJ(I), A N D IN T H E L A T T E R
C CASE, BY NEGATING DNBADJ(I). AN 'OPEN ~ ARC I=(V,W) FOR THE LAYERED
C NETWORK EITHER HAS POSITIVE RESIDUAL CAPACITY, O R A R C (W,V) H A S
C POSITIVE FLOW, IN T H E O R I G I N A L NETWORK. IF A N O D E V H A S N O O P E N
C A R C S IN T H E L A Y E R E D N E T W O R K T H A T A R E IN T H E F O R W A R D A D J A C E N C Y LIST
C O F V IN T H E O R I G I N A L NETWORK, THEN WE SET DNPTRF(V>=O; A N D IF IT H A S
C N O O P E N A R C S T H A T A R E IN T H E B A C K W A R D ADJACENCY L I S T O F V IN T H E
C ORIGINAL NETWORK, WE SET DNPTRB(V)=O.
C
C IN T H I S B F S S E A R C H W E O N L Y U S E O P E N A R C S T H A T L E A D U S T O N E W
C NODES, OR TO NODES THAT HAVE ALREADY BEEN PLACED IN T H E N E X T
C LAYER. INITIALLY, ]'HE Q U E U E C O N T A I N S ONLY THE source. AS THE
C VERTICES ARE POPPED FROM THE QUEUE AND SCANNED~ NEW NODES ARE
C INJECTED INTO THE QUEUE. EVENTUALLY~ E I T H E R T H E S I N K IS R E A C H E D ,
C OR SOME VERTICES ARE NOT REACHABLE WITH OPEN ARCS FROM THE
C CURRENT LAYER. IN T H E F O R M E R C A S E T H E L A Y E R E D N E T W O R K F O R T H E
C C U R R E N T S T A G E IS C O M P L E T E ~ AND THUS A FLOW AUGMENTATION IS
C POSSIBLE. IN TIdE L A T T E R C A S E , T H E C U R R E N T FLOW ON THE ORIGINAL
C NETWORK IS M A X I M U M , AND THE RUN TERMINATES.
C
C THE QUEUE IS M A I N T A I N E D IN T H E LIST DNLIST(.) WITH TWO POINTERS,
C AS SHOWN:
C
C ARRAY ~ NODES TO BE SCANNED
C DNLIST(.): ... ~ I
C
C ~
114 D. Goldfarb , M.D. Grigoriadis, Dinic and network simplex methods for max flow
C QHEAD2 QTAIL2
C ~ ~ i ~ i ~ ~ i ~ ~ i ~ i ~ ~ ~ i ~
C
C INITIALIZE:
DO
12=I,DNNODE I0
DNPTRF(12)=O
DNPTRB(I2>=O
I0 DNDIST(I2)=DNNOP2
DNDIST(DNSRCE)=O
C PUT source INTO QUEUE:
QHEAD2=O
QTAIL2=I
DNLIST(1)=DNSRCE
MAXD2=DNNODE-I
C
C SCAN EACH NODE IN Q U E U E :
C
C
C
100 IF (QHEAD2. EQ. Q T A I L 2 ) G O T 0 2 0 0 0
QHEAD2=QHEAD2+I
C POP N O D E IN F R O N T O F Q U E U E :
K2=DNLIST(QHEAD2)
K2DST=DNDIST(K2)
IF(K2DST.GE.MAXD2)GOTOI00
K2DPI=K2DST+I
S C A N N O D E K2, I.E. S E A R C H O V E R F W D A D J A C E N C Y O F K 2 A N D F O R A R C S
(K2,J2> S U C H T H A T J 2 IS U N S C A N N E D A N D J 2 IS N O T IN T H E Q U E U E A N D
A R C (K2,J2) H A S P O S I T I V E R E S I D U A L C A P A C I T Y IN O R I G I N A L N E T W O R K .
'J2 UNSCANNED' IS C H E C K E D B Y T H E C O N D I T I O N : 'DNDIST(J2)>=DNDIST(K2)'
'J2 N O T IN Q U E U E ' IS C H E C K E D B Y T H E C O N D I T I O N
'DNDIST(J2)=DNDIST(K2)+I F O R A S C A N N E D J 2 ~.
IBEG4=DNFAPT(K2)
IEND4=DNFAPT(K2+I)-I
IF(IBEG4.GT. IEND4)GOT01000
DO 400 14=IBEG4, IEND4
J2=DNFADJ(I4)
IF(DNDIST(J2).LE.K2DST)GOT0300
IF(DNCAP(I4).LE.DNFLOW(I4))GOT0300
C ( I M P L I C I T L Y ) M A R K A R C (K2, J2) A S O P E N IN L A Y E R E D N E T W O R K ; A L S O ,
C S A V E I T S I N D E X IN D N P T R F ( . ) :
DNPTRF(K2)=I4
IF(J2.NE.DNSINK)GOT0200
C J2=SINK:
MAXD2=K2DPI
DNDIST(J2)=MAXD2
GOT0400
C A P P E N D N O D E J 2 T O T H E Q U E U E , IF N O T A L R E A D Y T H E R E :
200 IF<DNDIST<J2).EQ.K2DPI)GOTO40Q
DNDIST(J2)=K2DPI
QTAIL2=QTAIL2+I
DNLIST(QTAIL2)=J2
GOT0400
C (EXPLICITLY) M A R K A R C (K2,J2) A S C L O S E D IN L A Y E R E D N E T W O R K :
300 DNFADJ(14)=-DNFADJ(I4)
400 CONTINUE
C
C. . . . . . . . . . . . . . .
D. Go ldfarb , M.D. Grigoriadis, Dinic and network simplex methods for max flow 115
C
C IF S I N K W A G R E A C H E D , D O N ' T N E E D T O S C A N B A C K W A R D A R C S I N T O ITS L A Y E R :
1000 IF(DNDIST(DNSINK).NE.DNNOP2)GOTOI00
C
C E L S E , C O N T I N U E S C A N O V E R F O R W A R D A R C S O U T O F K 2 IN T H E R E S I D U A L
C NETWORK (WHICH ARE BACKWARD ARCS OF THE ORIGINAL NETWORK WITH
C P O S I T I V E F L O W ) . T H I S C O D E S E G M E N T IS A N A L O G O U S T O T H E O N E A B O V E :
C
IBEG4=DNBAPT(K2)
IEND4=DNBAPT(K2+I)-I
IF(IBEG4.GT.IEND4)GOTOI00
DO 1400 I4=IBEG4, IEND4
J2=DNBADJ(I4)
IF(DNDIST(J2).LE.K2DST)GOTOI300
JJDN=DNBTOF(I4)
IF(DNFLOW(JJDN).LE.0)GOEOI300
DNPTRB(K2)=I4
IF(DNDIST(J2).EQ.K2DPI)GOTOI400
DNDIST(J2)=K2DPI
QTAIL2=QTAIL2+I
DNLIST(QTAIL2)=J2
GOTOI400
1300 DNBADJ(I4)=-DNBADJ(I4)
1400 CONTINUE
GOTOI00
C
2000 LAYER2=LAYER2+I
LAYPI2=LAYER2+I
C H E R E ~ A L L N O D E S IN Q U E U E H A V E B E E N P R O C E S S E D .
C IF T H E S I N K W A S R E A C H E D ~ T H E L A Y E R E D N E T W O R K IS C O M P L E T E :
LAYMAX=O
IF(DNDIST(DNSINK).NE.DNNOP2)RETURN
C E L S E , T H E C U R R E N T F L O W IS M A X I M U M :
LAYMAX=I
RETURN
C
END
SUBROUTINE DNDFS
C
C
C D I M E N S I O N T H E S E T O A T L E A S T M A X N U M B E R O F N O D E S + 2:
INTEGER DNLIST(4700)~DNDIST(4700)
INTEGER
DNFAPT(4700),DNF'TRF(4700),DNBAPT(4700)~
DNFLAB(4700),DNPTRB(4700)
C DIMENSION THESE TO AT LEAST MAX NUMBER OF ARCS + i :
INTEGER DNFADJ(27000)~DNFROM(27000)~DNTO(27000)~DNBADJ(27000)
INTEGER DNCAP(27000),DNGCAP(27000)~DNFLOW(27000),DNBTOF(27000)
C
COMMON /DNOI/DNFAPT/DNO2/DNFADJ/DNO3/DNCAP/DNO4/DNFROM
COMMON /DN05/DNFLOW/DN06/DNGCAP/DNOG/DNPTRF/DNO9/DNLIST
COMMON /DNIO/DNBAPT/DNII/DNFLAB/DNI2/DNPTRB
C
INTEGER DNNODE,NODP12~DNSRCE,DNSINK~ I=~ I I 2 , K 2 , J2~ IHEAD2,
ITAIL2, QHEAD2,QTAIL2, KP2, KSAT2,DNNOP2,LAYMAX,K2DST,K2DPI, MAXD2
INTEGER DNARC,DNFVA,DNAUG,DNLFVA,DNLAUG,DNSTGE,DNIBIG
COMMON /DNOO/DNARC, DNFVA,DNAUG,DNLFVA,DNLAUG,DNSTGE,
DNELTM~DNIBIG,DNNODE,DNSRCE,DNSINK~DNNOP2
EQUIVALENCE (DNFLOW(1),DNTO(1)), (DNFLAB(i),DNDIST(1)),
116 D. Goldfarb, M.D. Grigoriadis, Dinic and network simplex methods for max flow
* (DNFROM(1),DNBADO(1)), (DNGCAP(1),DNBTOF(1))
C
************************************************************************
C
C T H I S S U B R O U T I N E F I N D S A M A X I M A L F L O W IN T H E L A Y E R E D N E T W O R K . IT
C USES A DEPTH-FIRST SEARCH STARTING FROM THE SOURCE AND RECORDS
C THE DFS TREE BY THE PREDECESSOR ARRAY DNLIST(.) AND FLOW LABEL
C A R R A Y D N F L A B ( . ) . L A Y E R E D N E T W O R K A R C S T H A T A R E F O R W A R D IN T H E
C ORIGINAL NETWORK ARE SEARCHED BEFORE BACKWARD ARCS. THE
C F O R W A R D A N D B A C K W A R D A D J A C E N C I E S O F A N O D E K 2 A R E S C A N N E D IN L I F O
C ORDER, STARTING FROM THE LAST ARC THAT WAS VISITED DURING A
C P R E V I O U S S C A N O F K2. T H U S , W I T H T H E A I D O F T H E T W O P O I N T E R L I S T S
C DNPTRF(.) AND DNPTRB(.), THE ADJACENCY LISTS OF THE ORIGINAL
C NETWORK ARE SCANNED ONLY ONCE BY THIS SUBROUTINE. DNPTRF(K2>=O
C IMPLIES THAT NODE K2 HAS NO OUTGOING UNSCANNED ARCS; DNPTRB(K2)=O
C IMPLIES THAT NODE K2 HAS NO INCOMING UNSCANNED ARCS; A ~CLOSED ~
C N O D E IS D E T E C T E D BY T H E C O N D I T I O N D N P T R F ( K 2 ) = D N P T R B ( K 2 ) = O .
C
************************************************************************
C
C CALLING CONDITIONS:
C I N T E R N A L C A L L F R O M D N S U B ONLY.
C INPUT ARRAYS:
C DNPTRB, DNPTR, DNBTOF, DNCAP, DNFLOW, DNBADJ. DNFADJ
C OUTPUT ARRAYS:
C DNPTRF, DNPTRB, DNLIST, DNFLAB.
C***********************************************************************
C
C SUBROUTINES CALLED: DNPUSH
C
C
K2=DNSRCE
DNLFVA=O
DNLAUG=O
DNFLAB(K2)=DNIBIG
C
C . . . . . . . . . . .
C
C S C A N N O D E K2:
C
I00 IF(DNPTRF(K2).EQ.O)GOTOI000
C F I N D A N O P E N A R C F R O M K 2 T O S O M E N O D E J2: S C A N T H E
C F O R W A R D A D J A C E N C Y L I S T O F K2, S T A R T I N G F R O M DNPTRF(K2) AND
C PROCEEDING BACKWARD ON DNFADJ() TOWARD DNFAPT(K2):
14=DNPTRF(K2)
IPT4=DNFAPT(K2)
300 J2=DNFADJ(I4)
I F ( J 2 . GE.O)GOT0600
400 14=14-i
IF(14.GE. IPT4)GOT0300
C N O O P E N A R C S O U T O F K2; M A R K K 2 A S C L O S E D :
DNPTRF(K2)=O
SOTOI000
C A N O P E N A R C F O U N D ; M O V E P O I N T E R D N P T R F < ) T O T H I S ARC;
C E X T E N D D F S T R E E T O N O D E J2:
600 DNPTRF(K2)=I4
DNFLAB(J2>=DNFLAB<K2)
IF<DNCAP(14)-DNFLOW<I4).LT.DNFLAB(J2))
D N F L A B <O2) = D N C A P ( 1 4 ) - D N F L O W (14)
D. Goldfarb , M.D. Grigoriadis, Dinic and network simplex methods for max flow 117
DNLIST(J2)=K2
K2=J2
C IF N O D E K 2 ( F O R M E R L Y J2) IS T H E S I N K , A U G M E N T FLOW; GET NEW K2:
IF(K2.EQ.DNSINK)CALL DNPUSH(K2)
GOTO100
C
C
C
1000 IF(DNPTRB(K2).EQ.0)GOT02000
C SCAN BACKWARD A R C S I N T O K 2 T O F I N D A N O P E N ARC:
I4=DNPTRB(K2)
IPT4=DNBAPT(K2>
1300 J2=DNBADJ(I4)
IF(J2.GE.0)GOTOI600
I4=I4-I
IF(I4.GE. IPT4)GOTOI300
C N O O P E N A R C I N T O K2:
DNPTRB(K2)=O
GOT02000
C A N O P E N A R C F O U N D ; E X T E N D D F S T R E E T O N O D E J2:
1600 DNPTRB(K2)=I4
DNFLAB(J2)=DNFLAB(K2)
JJDN=DNBTOF(I4)
IFL4=DNFLOW(JJDN)
IF(IFL4.LT.DNPLAB(J2))DNFLAB(J2)=IFL4
DNLIST(J2)=-K2
K2=J2
GOTOI00
C
C
C K 2 IS " C L O S E D ' N O D E ; IF IT IS T H E s o u r c e , T H E N W E H A V E A M A X I M A L
C F L O W IN L A Y E R E D N E T W O R K :
2000 IF(K2.EQ.DNSRCE)RETURN
C E L S E , B A C K U P O N E N O D E F R O M K 2 IN D F S T R E E :
KP2=DNLIST(K2)
K2=KP2
IF(K2.LT.O)K2=-K2
IF(KP2.GE.0)SOT02200
I4=DNPTRB(K2)
DNBADJ(I4)=-DNBADJ(I4)
GOTOI00
2200 1 4 = D N P T R F (K2)
D N F A D J (I4) = - D N F A D J (14)
GOTO 100
C
C
END
SUBROUTINE D N P U S H (K'2)
C
C
C DIMENSION T H E S E T O A T L E A S T M A X N U M B E R O F N O D E S + 2:
INTEGER D N L I S T (4700), D N D I S T (4700)
INTEGER D N F A P T (4700) , D N P T R F (4700) , D N B A P T (4700) ,
D N F L A B (4700) , DNF'TRB (470(:))
C DIMENSION T H E S E T O A T L E A S T M A X N U M B E R O F A R C S + I:
INTEGER DNFADJ(27t300) ,DNFROM(27000),DNTO(27000),DNBADJ(27000)
I N T E G E R D N C A P ( 2 7 0 0 0 ) , D N G C A P (27000) ~ D N F L O W ( 2 7 0 0 0 ) , D N B T O F ( 2 7 0 0 0 )
C
COMMON /DNO 1/DNFAPT/DN02/DNFADJ/DN03/DNCAP/DN04/DNFROM
118 D. Goldfarb, M.D. Grigoriadis, Dinic and network simplex methods for max flow
COMMON /DN05/DNFLOW/DN06/DNSCAP/DN08/DNPTRF/DN09/DNLIST
COMMON /DNIO/DNBAPT/DNII/DNFLAB/DNI2/DNPTRB
C
C AUGMENT FLOW ALONG FLOW AUGMENTING P A T H D E F I N E D S U B R O U T I N E D N D F S ~ I.E.
C USING THE PREDECESSOR ARRAY DNLIST(.), START FROM THE SINK AND
C TRAVERSE TO THE SOURCE ARC FLOWS AND FLOW LABELS BY AN AMOUNT EQUAL
C TO DNFLAB(DNSINK>. MARK SATURATED FORWARD ( F R O M S T O T) A R C S ~ A N D
C BACKWARD ARCS HAVING ZERO FLOW, AS CLOSED.
C
C
C CALLING CONDITIONS:
C INTERNAL CALL FROM DNDFS ONLY.
C INPUT ARRAYS:
C DNFLAB,DNLIST~DNPTRB, DNPTRF,DNBTOF,DNCAP~DNFLOW,DNBADJ~DNFADJ
C OUTPUT ARRAYS:
C DNFLAB,DNFLOW,DNBADJ,DNFADJ
C ~ i ~ i ~ ~ * ~ ~ i ~ ~ i ~ ~ * ~ ~ i * ~ i ~
C
KSAT2=O
J2=DNSINK
INCRE4=DNFLAB(J2)
DNLFVA=DNLFVA+INCRE4
DNLAUG=DNLAUG+I
C
i00 K2=J2
J 2 = D N L I S T (K2)
D N F L A B (K2) = D N F L A B (K2) - I N C R E 4
IF (J2. GT. O) G O T 0 2 0 0
C
C DECREASE FLOW O N B A C K W A R D A R C (K2,J2) :
J2=-J2
I 4 = D N P T R B (J2)
I I 4 = D N B T O F (I4)
D N F L O W ( I I4) = D N F L O W ( I I 4 ) - I N C R E 4
IF ( D N F L O W ( I I4) .NE. 0) G O T O I 0 0
C FLOW IS ZERO; M A R K A R C A S ' C L O S E D ' IN L A Y E R E D NETWORK:
D N B A D J (I4) = - D N B A D J (I4)
KSAT2=J2
GOTO 100
C
C INCREASE FLOW ON FORWARD ARC (J2,K2):
200 1 4 = D N P T R F (J 2)
D N F L O W (14) = D N F L O W (I4) + I N C R E 4
IF ( D N C A P ( 14). N E . D N F L O W (I4)) G O T 0 3 0 0
C ARC IS N O W S A T U R A T E D ; M A R K IS A S ' C L O S E D " IN L A Y E R E D NET
D N F A D J (I4) = - D N F A D J ( I4>
KSAT2=J2
300 IF (J2. NE. D N S R C E ) G O T O I 0 0
C
D. Goldfarb, M.D. Grigoriadis, Dinic and network simplex methods for max flow 119
C INITIALIZE:
IRETN=O
NODPI=NODES+I
DO 100 I 2 = I ~ N O D P I
DNFAPT(I2)=O
100 DNLIST(I2)=O
C T E M P O R A R I L Y S T O R E IN D N F A P T ( . ) N U M B E R OF A R C S OUT OF E A C H NODE:
DO 200 I 4 = I ~ N A R C S
,]JDN=DNFROM(I4)
200 DNFAPT(JJDN)=DNFAPT(~JDN)+I
C CONSTRUCT DNFAPT(.):
ITPI4=DNFAPT(1)
DNFAPT(1)=I
DO 300 I 2 = I ~ N O D E S
ITPSV4=ITPI4+DNFAPT(I2)
ITPI4=DNFAPT(I2+I)
300 DNFAPT(I2+I>=ITPSV4
C CONSTRUCT DNFADJ(.) AND DNCAP(.):
DO 400 I 4 = I ~ N A R C S
ITAIL2=DNFROM(14)
ITPUT4=DNFAPT(ITAIL2)+DNLIST(ITAIL2)
IF(ITPUT4.LE.0)GOT0500
DNFADJ(ITPUT4)=DNTO(14)
DNLIST(ITAIL2>=DNLIST(ITAIL2)+I
DNCAP(ITPUT4)=DNGCAP(I4>
400 CONTINUE
RETURN
50¢) IRETN=I
RETURN
END
SUBROUTINE DNCLEA
C
C
C D I M E N S I O N T H E S E TO AT L E A S T MAX N U M B E R OF N O D E S + 2:
INTEGER DNLIST(4700>~DNDIST(4700>
INTEGER DNFAPT(4700),DNPTRF(4700),DNBAPT(4700)~
DNFLAB(4700)~DNPTRB(4700)
C D I M E N S I O N T H E S E TO AT L E A S T MAX N U M B E R OF A R C S + i:
I N T E G E R D N F A D J ( 2 7 0 0 0 ) ~ D N F R O M ( 2 7 0 0 0 ) ~ D N T O ( 2 7 0 0 0 ) ~DNBADJ (27000)
INTEGER DNCAP(27000),DNGCAP(27000),DNFLOW(27000) ~DNBTOF(27000)
C
COMMON /DNOI/DNFAPT/DN02/DNFADO/DNO3/DNCAP/DNO4/DNFROM
COMMON /DN05/DNFLOW/DNO6/DNGCAP/DNO8/DNPTRF/DN09/DNLIST
COMMON /DNIO/DNBAPT/DNI1/DNFLAB/DNI2/DNPTRB
C
INTEGER DNNODE~NODPI2~DNSRCE, DNSINK~I2~II2~K2~J2~IHEAD2~
ITAIL2,QHEAD2,QTAIL2~KP2~KSAT2~DNNOP2~LAYMAX,K2DST~K2DPI,MAXD2
INTEGER DNARC, D N F V A ~ D N A U G , D N L F V A ~ D N L A U G , D N S T G E ~ D N 2 ~ I G
COMMON /DN00/DNARC,DNFVA~DNAUG~DNLFVA~DNLAUG~DNSTGE,
DNELTM~DNIBIG~DNNODE~DNSRCE~DNSINK~DNNOP2
EQUIVALENCE (DNFLOW(1)~DNTO(1)), (DNFLAB(1)~DNDIST(I>)~
(DNFROM(1),DNBADJ(1))~ (DNGCAP(1)~DNBTOF(1))
C
C ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
C CALLING CONDITIONS:
C I N T E R N A L C A L L F R O M D N S U B ONLY.
C INPUT (IN C O M M O N ) :
C SCALARS: DNARC
C ARRAYS: DNFAD~, DNBAD~
C OUTPUT:
D. Goldfarb , M.D. Grigoriadis, Dinic and network simplex methods for max flow 121
C A R R A Y S (IN C O M M O N ) : D N F A D J ~ D N B A D J
C ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
C
C C L E A R M A R K I N G S IN A R R A Y S D N F A D J ( ) A N D D N B A D J ( ) . :
D O 100 I 4 = I ~ D N A R C
IF ( D N B A D J (I4). LT. 0) D N B A D J (14) = - D N B A D J (I4)
IF(DNFADJ(I4).LT.O)DNFADJ(I4)=-DNFADJ(I4)
100 CONTINUE
RETURN
END
SUBROUTINE DNCUT(NNCUT,NACUT)
C
C
C D I M E N S I O N T H E S E T O A T L E A S T M A X N U M B E R O F N O D E S + 2:
INTEGER DNLIST(4700),DNDIST(4700)
INTEGER DNFAPT(4700),DNPTRF(4700),DNBAPT(4700),
DNFLAB(4700),DNPTRB(4700)
C D I M E N S I O N T H E S E T O A T L E A S T M A X N U M B E R O F A R C S + i:
INTEGER DNFADJ(27000),DNFROM(27000),DNTO(27000),DNBADJ(27000)
INTEGER DNCAP(27000),DNGCAP(27000),DNFLOW(27000),DNBTOF(27000)
C
C O M M O N /DNOI/DNFAPT/DN02/DNFADJ/DN03/DNCAP/DN04/DNFROM
C O M M O N /DN05/DNFLOW/DN06/DNGCAP/DN08/DNPTRF/DNO9/DNLIST
C O M M O N /DNIO/DNBAPT/DNll/DNFLAB/DNI2/DNPTRB
C
INTEGER DNNODE,NODPI2, DNSRCE,DNSINK, I2, II2,K2,J2, IHEAD2,
ITAIL2,QHEAD2,QTAIL2,KP2, KSAT2,DNNOP2,LAYMAX,K2DST,K2DPI,MAXD2
INTEGER DNARC,DNFVA, DNAUG, DNLFVA,DNLAUG,DNSTGE,DNIBIG
C O M M O N /DN00/DNARC,DNFVA,DNAUG, DNLFVA,DNLAUG,DNSTGE ,
DNELTM,DNIBIG, DNNODE,DNSRCE,DNSINK,DNNOP2
EQUIVALENCE (DNFLOW(1),DNTO(1)), (DNFLAB(1),DNDIST(1)),
(DNFROM(1),DNBADJ(1)), (DNGCAP(1),DNBTOF(1))
C
C i ~ l i ~ i ~ ~ i ~ ~ ~ ~ ~ ~ ~ ~
C CALLING CONDITIONS:
C ONLY AFTER A SUCCESSFUL RETURN FROM A CALL TO DNSUB.
C INPUT ARRAYS:
C DNFAPT, DNFADJ, DNCAP,DNFLOW, DNDI~T
C OUTPUT ARRAYS:
C DNFAPT,DNFADJ
C P A S S E D IN C A L L I N G S E Q U E N C E :
C NNCUT: NUMBER OF NODES ON source SIDE OF FINAL CUT (INTEGER~4)
C NACUT: N U M B E R O F A R C S IN T H E F I N A L C U T ( I N T E G E R ~ 4 )
C ~ ~ i ~ i ~ i i ~ ! ~ ~ ~ i ~ ~ ~ ~ ~
C
C N E G A T E D N F A P T ( . ) F O R N O D E S O N S I N K S I D E O F CUT:
NNCUT=O
DO 1700 I2=I,DNNODE
IF(DNDIST(I2).NE.DNNOP2)GOTOI650
DNFAPT(12)=-IABS(DNFAPT(12))
GOTOI700
1650 NNCUT=NNCUT+I
1700 CONTINUE
C N E G A T E D N F A D J ( . ) F O R T H O S E S A T U R A T E D A R C S IN M I N CUT:
NACUT=O
DO 1900 I2=I,DNNODE
IF(DNFAPT(I2).LT.0)GOTOI900
C N O D E I2 IS O N s o u r c e S I D E :
IBEG4=IABS(DNFAPT(I2))
IEND4=IABS(DNFAPT(I2+I))-I
122 D. Goldfarb, M.D. Grigoriadis, Dinic and network simplex methods for max flow
DO 1800
I4=IBEG4, IEND4
JJDN=DNFADJ (I4)
IF(DNFAPT(JJDN) ~GT..O)GOT(]I800
C NODE DNFADJ(I4) O N SIIqK S I D E :
IF ( D N F L O W (I4) ~ NE. D N C A P (I4)) G O T O I 8 0 0
I 1 2 = D N F A D J ( 14 )
D N F A D J (I4) = - I A B S ( I I2)
NACUT=NACUT+ I
1800 CONT INUE
1900 CON]" I NUE
RETURN
END
SUBROUTINE DNOUT(IUNREP)
C
C
C DIMENSION THESE TO AT LEAST MAX NUMBER O F N O D E S + 2:
INTEGER DNLIST (4700) ,DNDIST (4700)
INTEGER DNFAPT (4700) ,DNPTRF (4700) ~DNBAPT (4700) ,
* DNI--LAB ( 4 7 0 0 ) , DNPTRB ( 4 7 0 0 )
C DIMENSION THESE TO AT LEAST MAX NUMBER OF ARCS + I :
INTEGER DNFADLI (27~'~00 ) , D N F R O M (2 7 0 0 0 ) ~ D N T O (2 7 0 0 0 ) , D N B A D J ( 2 7 0 0 0 )
INTEGER D N C A P ( 2 7 0 0 0 ) ,D N G C A P ( 2 7 0 0 0 ) , D N F L O W ( 2 7 0 0 0 ) ~ D N B T O F ( 2 7 0 0 0 )
COMMON /DNOI/DNFAPT/DN02/DNFADJ/DN03/DNCAP/DNO4/DNFROM
COMMON /DN05/DNFLOW/DN06/DNGCAP/DN08/DNPTRF/DN09/DNLIST
COMMON /DNIO/DNBAPT/DNII/DNFLAB/DNI2/DNPTRB