A heuristic for blocking flow algorithms

A heuristic for blocking flow algorithms

EUROPEAN JOURNAL OF OPERATIONAL RESEARCH ELSEVIER European Journal of Operational Research 89 (1996) 564-569 Theory and Methodology A heuristic for ...

434KB Sizes 6 Downloads 58 Views

EUROPEAN JOURNAL OF OPERATIONAL RESEARCH ELSEVIER

European Journal of Operational Research 89 (1996) 564-569 Theory and Methodology

A heuristic for blocking flow algorithms J e s p e r L a r s s o n Tr~iff DIKU - Department of Computer Science, University of Copenhagen, Universitetsparken1, DK-2100 Copenhagen O, Denmark I

Received July 1994; revised October 1994

Abstract

This note presents a simple heuristic to speed up algorithms for the maximum flow problem that works by repeatedly finding blocking flows in layered (acyclic) networks. The heuristic assigns a capacity to each vertex of the layered network, which will be an upper bound on the amount of flow that can be transported through that vertex to the sink. This information can be utilized when constructing a blocking flow, since no vertex can ever accommodate more flow than its capacity. The static heuristic computes capacities in a layered network once, while a dynamic variant readjusts capacities during construction of the blocking flow. The effects of both static and dynamic heuristics are evaluated by a series of experiments with the wave algorithm of Tarjan. Although neither give theoretical improvement to the efficiency of the algorithm, the practical effects are in most cases worthwhile, and for certain types of networks quite dramatic. Keywords: Combinatorialoptimization;Heuristics; Networkprogramming;Graph algorithms

1. Introduction

Although currently out of fashion, maximum flow algorithms derived from Dinic' scheme of reducing the maximum flow problem to the easier problem of determining blocking flows in a series of layered (acyclic) networks are nevertheless still worth considering, since they are both simple to implement and competitive with algorithms based on the now-common preflow-push scheme of Goldberg and Tarjan [2] (see also Ref. [ 1 ] ) , which often require some tuning in order to perform well. In this note it is shown that the restriction to acyclic networks in addition gives room for heuristic improvement of blocking I Present address: Max-Planck lnstitut f'~ir Informatik, lm Stadtwald, D-66123 Saarbriicken, Germany. Email: [email protected]; [email protected]

flOW algorithms. The improvement is based on propagation of information backwards in the network in a manner which is not possible for algorithms of the Goldberg and Tarjan genus. The heuristic is applicable to the maximum flow algorithms of Karzanov, Shiloach and Vishkin [5], Tarjan [7,6], and others, in short algorithms which solve the problem by finding a sequence of blocking flows in consecutive layered networks, and compute blocking flows by gradually converting a preflow into a blocking flow. The heuristic assigns a capacity to each vertex of the acyclic network, which is an upper bound on the amount of flow that can be transported through that vertex to the sink. Vertex capacities can be utilized to reduce the amount of flow sent to a vertex during the blocking flow computation, thereby making it possible to explore more vertices in fewer operations. A static variant of the heuristic computes capacities once for

0377-2217/96/$15.00 @ 1996 Elsevier Science B.V. All rights reserved SSDI 0377-2217 (94) 00360-2

J.L. Triiff/European Journal of OperationalResearch89 (1996) 564-569 each layered network, while a dynamic variant at certain points adjusts the capacities to provide more accurate upper bounds. The effects of both variants are tested using the wave algorithm of Tarjan [7,6]. Some familiarity with the maximum flow problem will be assumed, see for instance [ 1,4,7].

2. Blocking flows in acydic networks Aflow network N = (G, s, t,c) is a directed graph, G = (V,E), with two distinguished vertices s, t E V called source and sink respectively, in which each edge (v, w) E E has a non-negative, real-valued capacity c(v, w). As usual, n and m denote the number of vertices and edges of G, respectively. Aflow f on a network is a non-negative, real-valued function on the edges of G which satisfies (i) a capacity constraint: for all edges (v, w) E E, f ( v , w) <~c(v, w), and (it) a conservation constraint: for all vertices v E V \ {s,t}, I N ( f , v ) = O U T ( f , v ) , where I N ( f , v ) = ~-'~(u,v)EEf(U,V) is the total flow into, and O U T ( f , v ) = ~~(v,w)EEf(V,W) is the total flow out of vertex v. The value of a flow is O U T ( f , s) (= I N ( f , t ) ) . The maximum flow problem is to find a flow f of maximum value. A flow f is said to saturate the edge (v, w) E E if f ( v , w ) = c ( v , w ) . A flow on an acyclic network (a network for which G is acyclic) is a blocking flow if all paths from s to t contain at least one saturated edge. In contrast to a maximum flow, the value of a blocking flow is not unique. A layered network is a special acyclic network, in which the vertices can be partitioned into a sequence of layers (Li), such that s E Lo, and if (v, w) is an edge, then v E Li and w E Li+l. By a theorem of Dinic, a maximum flow can be found by combining at most n blocking flows on successive layered networks.

3. Vertex capacities in acyclic networks Let A = (G, s, t, c) be an acyclic network on which a blocking flow is to be computed. It is obvious that vertices from which t is not reachable can be eliminated from the network, since by the flow conservation constraint they cannot carry any flow. Such vertices

565

are called dead vertices. By a scan of the network in reverse topological order, dead vertices can be eliminated in O(m) time. More information is however present in the network, and can be propagated backwards in the same fashion. This is captured by assigning to each vertex v E V a non-negative, real-valued capacity p ( v ) . The capacity of v shall be an upper bound on the amount of flow that can be transported from v to t. For each vertex the capacity must satisfy: (i) p ( t ) = oo, and (it) p(v) = ~ ( v , w ) ~ E m i n { c ( v , w ) , p ( w ) } for v E V \ {t}. The capacities thus assigned are reminiscent of throughput as used in the "three Indians" algorithm

[3]. Proposition 1. For each vertex v E V, the capacity p ( v ) is an upper bound on the amount of flow that can be transported from v to t. That is, for any flow f on A it holds that IN(f, v) = O U T ( f , v) <<.p ( v ) . Proof. Induction on the size of A in reverse topological order. For the sink t there is nothing to prove, since the outflow is undefined, and I N ( f , t ) < p ( t ) = oo. Now assume for vertex v that the proposition holds for all vertices w after v in topological order. Since f is a flow, f ( v , w ) <~ c ( v , w ) , and, by the induction hypothesis, f ( v , w ) <~ I N ( f , w ) --- O U T ( f , w ) <<. p ( w ) . Therefore f ( v , w) <~min{c(v, w ) , p ( w ) } and hence OUT(f, v) <~ ~(v,w)~emin{c(v, w ) , p ( w ) } =

p(v).

[]

It should be noted that the capacity cannot in general be reduced further without excluding legal flows. The proof immediately gives an O ( m ) algorithm for computing vertex capacities.

4. Tarjan's wave algorithm and vertex capacities It remains to show how to exploit the vertex capacities when constructing a blocking flow. This is done using a specific blocking flow algorithm, namely Tarjan's wave algorithm [6,7]. For the sake of completeness a brief description of the algorithm is included. On an acyclic (layered) network, the wave algorithm maintains a preflow, which is gradually converted into a blocking flow. A preflow f is a

566

J.L. Traff/European Journal of Operational Research 89 (1996) 564-569

non-negative, real-valued function on the edges of G which satisfies the capacity constraint but may violate the conservation constraint by allowing I N ( f , v ) t> O U T ( f , v). The excess of a vertex v E V \ {s, t} is defined to be e(v) = I N ( f , v) - O U T ( f , v), and vertices for which e(v) > 0 are called overflowing. By definition the sink is never overflowing, i.e. e(t) = O. The wave algorithm starts by saturating all edges out of s, thus making the vertices adjacent to s overflowing, and maintains the invariant that all paths from s to t contains at least one saturated edge. Hence, when the algorithm terminates the preflow has become a blocking flow. Vertices can be either blocked or unblocked, and initially all vertices except for s are unblocked. The algorithm alternates between forward (topological order) and backward (reverse topological order) scans - the compound operation is called a wave - of the network until no overflowing vertices remain. During a forward scan a push operation is applied to all overflowing, unblocked vertices. During a backward scan a return operation is applied to all overflowing, blocked vertices. The push operation applied to vertex v repeatedly selects a non-saturated edge (v, w) for which w is unblocked, increases the flow on (v,w) by min{c(v, w) - f ( v , w ) , e ( v ) } , and increases e(w) and decreases e(v) by the same amount, until either no non-saturated edges out of v remain or e(v) = O. If the push operations terminates with all edges out of v saturated, then v becomes blocked. The return operation applied to a vertex v repeatedly selects an edge (u, v) along which flow was previously pushed into v, decreases the flow on (u,v) by m i n { f ( u , v ) , e ( v ) } , and increases e(u) and decreases e(v) by the same amount, until e(v) = O. Tarjan [ 7] establishes the following theorem: Theorem 1. Let k be the number of waves required to find a blockingflow. Then k < n, and the number of operations required is O(m + kn). In the worst case the wave algorithm needs O(n 2) operations to find a blocking flow. The advantage of Tarjan's algorithm over that of Karzanov is that the space requirement is only O(m) instead of O(n2). It is obvious how to exploit vertex capacities in

the wave algorithm. The push operation is modified such that the amount of flow pushed along an edge (v, w) is min{c(v, w) - f ( v , w ) , p ( w ) - e ( w ) , e(v) }, i.e. no more flow than allowed by the capacity of the end vertex w minus the excess already present at w is pushed. This is the static (weak) variant of the heuristic, which is tested as algorithm C in the next section. A stronger version of the heuristic is obtained by dynamically readjusting the vertex capacities. Capacity condition (ii) is modified to reflect that a preflow f may have reduced the capacity of vertex v, either by consuming the capacity of edges out of v or by leaving v overflowing: (ii) p ( v ) = [)-~Cv,w)~Emin{c(v,w) -- f ( V , W ) ,

p(w)}] forv E V \ {t}. By the same argument as in Proposition 1, it can easily be shown that p ( v ) = 0 if vertex v is blocked. The backward scan is modified to satisfy the new condition (ii) after the scan has been completed. The flow return operation is modified to be applicable also to vertices v which are not blocked, but for which e (v) ~> p ( v ) . For such vertices flow is returned backwards until e(v) = p ( v ) , and p ( v ) is set toO. If e(v) < p ( v ) , p ( v ) is set to p ( v ) - e(v). Unfortunately, the complexity of the dynamic variant of the heuristic compromises the complexity of the blocking flow algorithm, since O(m) edges may have to be checked in each backward scan. Proposition 2, Let k be the number of waves required to find a blocking flow. The number of operations for the dynamic heuristic is O( km ). If readjusting is done only on k' = O(n2/m) of the backward scans, the worst-case complexity of the algorithm with the dynamic heuristic remains O(n2). And even when readjusting is performed on each backward scan, the worst case is, never (or almost never) attained. First, during the backward scan, it is only necessary to consider an unblocked vertex v when its capacity has actually decreased. In particular vertices with zero capacity never have to be scanned again. Second, edges which have been saturated do not have to be considered in the backward scan. Finally, the backward scan only have to be continued as far back as there are overflowing vertices, since only the over-

J.L. Trtlff/European Journal of Operational Research 89 (1996) 564-569

flowing, unblocked vertices make use of the capacities during the forward scan. The dynamic variant of the heuristic implemented as outlined above is tested as algorithm D in the next section. Another way of looking at the dynamic heuristic is that it attempts to gather information at each vertex in one wave, which the unmodified algorithm would have needed several waves to obtain. Assume that all paths from some vertex u to t pass through w, and that excess flow at u during some forward scan is pushed to w, eventually blocking vertex w. The dynamic heuristic propagates this information backwards to u by the first backward wave, making p ( u ) = 0. Thus u can be ignored in all subsequent waves. Without the heuristic, only one path from u to w could have been removed per wave. This is illustrated in Fig. 1. In this example both the number of operations and the number of waves are reduced by the dynamic heuristic. The static heuristic is only able to reduce the number of waves by one, by reducing the capacities of all the u to w paths to 1. Recalling that a blocking flow is not unique, the following holds: Proposition 3. If the wave algorithm and the algo-

rithm with the dynamic heuristic compute the same blocking flow, then the number of waves required by the latter is no greater than the number of waves required by the former.

5. Experimental evaluation of the heuristic In this section an experimental evaluation of the heuristic when applied to the wave algorithm is presented. The results obtained indicate that the heuristic does not increase running time, and often leads to worthwhile improvements. For certain types of networks the effects are considerable. Four variants of the algorithm have been tested. Algorithm A is the basic wave algorithm. In algorithm B elimination of dead vertices is performed for each layered network constructed. Algorithm C is the wave algorithm with the static heuristic, i.e. capacities computed once for each layered network. Finally, algorithm D is the wave algorithm with the dynamic heuristic, where vertex capacities are readjusted on each backward scan. Two types of test graphs have been used. The first

567

2i s •

U



t

Fig. I. Layered flow network. Assume that the number of e d g e s on each dotted path from u to w is l, and that the degree of vertex u is d(u). The wave algorithm needs 2 + 2d(u)l operations and d(u) waves to find a blocking flow. With the dynamic heuristic the number of operations is 2 + l + d(u)l and only one wave is needed. The static heuristic only reduces the number of operations and waves to 2 + l + 2 ( d ( u ) - 1)l and d(u) - 1.

type is random graphs, where each vertex within a specified interval of degrees is given a random number of random edges. The second type are (almost) layered networks with some extra edges between layer 0 vertices. For both types, edge weights have been chosen randomly from the integer interval [ 1,105]. The algorithms have been implemented on a transputer which runs at about 10 MIPS, but running times columns "t" below - are included only for the comparison between the four algorithms. Also listed are the number of waves ("W"), the number of overflowing vertices encountered during forward waves ("Ver"), and the number of dead vertices eliminated after construction of a layered network ("Elim"). Eliminated vertices are listed only for variant B since the number is only marginally larger for variants C and D. For variant D the number of times vertex capacities have been reduced is also shown ("Decr"). The figures given are for the whole maximum flow computation,

568

J.L. Trdff/European Journal of Operational Research 89 (1996) 564-569

Table 1 Results for random graphs. A

B

C

D

N

t

W

Ver

t

W

Ver

Elim

t

W

Ver

t

W

Ver

Decr

100 200 200a 500 1000 2000 4000

1.6 3.0 2.8 2.4 5.2 13.0 70.6

9 10 14 57 271 455 1618

568 1243 1055 2410 7577 10517 40215

1.6 3.0 3.8 2.1 1.9 2.7 5.8

9 8 26 10 40 20 29

434 609 845 146 579 250 245

67 220 257 1023 2591 5136 13942

1.6 3.0 2.8 2.2 1.9 2.7 5.7

4 4 4 6 27 13 23

215 322 225 109 474 172 186

1.7 3.2 3.1 2.3 2.0 3.0 6.1

4 4 4 5 8 5 9

215 322 225 104 242 136 142

82 113 147 233 164 153 79

a The number of layered networks constructed changed: 3 for A, C, and D, and 4 for B. This is due to the fact that blocking flows are not unique. Table 2 Results for layered graphs. For the second graph 32, 128 the reduction in running time by the dynamic heuristic is very dramatic. A

C

D

w, l

t

w

Ver

t

W

Ver

Elim

t

W

Vet

Decr

32, 32 32, 64 32, 128 32, 128 64, 32 64,64

4.1 6.1 22.4 160.4 4.8 21.7

214 110 330 3171 67 321

4696 11472 21340 19332 10064 18245

4.2 7.0 26.1 192.8 5.4 23.7

181 97 323 3393 49 302

4104 9539 18738 17255 8460 15931

179 167 153 201 362 457

2.1 4.4 8.3 8.6 4.2 8.0

5 5 4 11 5 4

2568 5988 9358 5389 5055 5845

996 1983 3950 4156 1870 3752

i,e. they show the cumulative effects over a (small) number o f layered networks. For the random graphs it is between 2 and 5, for the layered graphs always 2. Only a sample o f the test material is shown. Table 1 shows the results for random networks N with different parameters. The number o f vertices are 100, 200, 500, 1000, 2000 and 4000. The 100 vertex network is complete. Vertex degrees for the other networks have been chosen from the intervals 1-199, 20-50, 8-12, 8-12, and 4 - 8 , respectively. The results show that elimination o f dead vertices is essential ( B ) . The static heuristic gives no reduction in terms o f running time, but the number o f waves and vertices is reduced somewhat ( C ) . The dynamic heuristic again gives no improvement in running time, but the number o f waves and vertices is again reduced, this time quite considerably. For random graphs, there do not seem to be any gain by either variant o f the heuristic, unless one is concerned about the number o f waves (see concluding remarks), which is reduced quite significantly.

The results shown in Table 2 for the layered graphs are more dramatic. Since the difference between variant B and C were minimal, only the figures for variant C are given. The layered graphs are characterized by the number o f vertices in each layer ( w i d t h ) , and the number o f layers (length). The degree for each vertex has in all cases been chosen randomly in the interval 5-10. While the static heuristic gives no improvement in running time (and only modest reductions in number o f waves and vertices), the dynamic variant gives considerable reductions in running times and dramatic reductions in number o f waves. This is perhaps not so surprising, since the situation o f Fig. 1 is likely to occur frequently in this type o f network.

6. Concluding remarks It has been shown how to assign capacities to the vertices in an acyclic flow network and how to utilize

J.L. Triiff/European Journal of Operational Research 89 (1996) 564-569

capacities to reduce the number of operations needed by a standard blocking flow algorithm. An experimental evaluation of both a static and a dynamic heuristic based on vertex capacities indicates that both can be implemented with no increase in running time. For graphs which possess some orderly structure (layered graphs), the effect of the dynamic heuristic is considerable. The motivation for considering the heuristic came from work on a distributed implementation of the more complicated blocking flow algorithm of Shiloach and Vishkin [ 5,8 ]. This algorithm works in "pulses" where in each pulse both push and return operations are performed on the set of overflowing vertices. In the distributed implementation each pulse entails a global synchronization operation. Reducing the number of pulses, even at the cost of some small increase in running time, was one way of getting better performance of the distributed implementation.

569

References [ 1] Ahuja, R.K., Magnanti, T.L., and Odin, J.B., Network Flows, Prentice-Hall, Englewood Cliffs, NJ, 1993. [2] Goldberg, A.V., and Tarjan, R.E., "A new approach to the maximum-fiow problem", Journal of the ACM 35/4 (1988) 921-940. [3] Malhotra, V.M., Kumar, M.P., and Maheshwari, S.N., "An O( IV[3) algorithms for finding maximum flows in networks", Information Processing Letters 7/6 (1978) 277-278. [4] Papadimilriou, C.H., and Steiglitz, K., Combinatorial Optimization: Algorithms and Complexity, Prentice-Hall, Englewood Cliffs, NJ, 1982. [5l Shiloach, Y., and Vishkin, U., "An O(n 2 log n) parallel MAXFLOW algorithm", Journal of Algorithms 3 (1982) 128-146. [6] Tarjan, R.E., "A simple version of Karzanov's blocking flow algorithm", Operations Research Letters 2 (1984) 265-268. [ 71 Tarjan, R.E., Data Structures and Network Algorithms, Society of Industrial and Applied Mathematics (SIAM), 1983. [8] TAft, J.L., "Distributed, synchronized implementation of an algorithm for the maximum flow problem", Proceedings of the 23rd International Conference on Parallel Processing (ICPP'94), pp. IIl-110-114, 1994.