Algorithm 815: FORTRAN Subroutines for Computing Approximate Solutions of Feedback Set Problems using GRASP PAOLA FESTA University of Salerno PANOS M. PARDALOS University of Florida and MAURICIO G. C. RESENDE AT&T Labs Research
We propose FORTRAN subroutines for approximately solving the feedback vertex and arc set problems on directed graphs using a Greedy Randomized Adaptive Search Procedure (GRASP). Implementation and usage of the package is outlined and computational experiments are reported illustrating solution quality as a function of running time. Categories and Subject Descriptors: G.1.6 [Numerical Analysis]: Optimization—Integer programming; G.2.1 [Discrete Mathematics]: Combinatorics—Combinatorial algorithms; G.m [Mathematics of Computing]: Miscellaneous General Terms: Algorithms, Performance Additional Key Words and Phrases: Combinatorial optimization, feedback set problems, graph bipartization, local search, GRASP, FORTRAN subroutines
1. INTRODUCTION Let G = (V , E) be a directed graph with vertex set V and arc set E. A path P in G connecting vertex u to vertex v is a sequence of arcs e1 , . . . , er in E, such The research of Paola Festa was supported in part by the Italian Ministry of Scientific Research (MURST)—Research Project MOST 97. The research of Panos Pardalos was supported in part by DIMACS and by National Science Foundation Grant EIA98-72509. Authors’ addresses: P. Festa, Mathematics and Computer Science Department, University of Salerno, Via S. Allende, 84081 Baronissi (SA), Italy; email:
[email protected]; P. M. Pardalos, Center for Applied Optimization, Industrial and Systems Engineering Department, University of Florida, Gainesville, FL 32611; email:
[email protected]; M. G. C. Resende, Information Sciences Research Center, AT&T Labs Research, Room C241, 180 Park Avenue, Florham Park, NJ 07932; email:
[email protected]. Permission to make digital or hard copies of part or all of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or direct commercial advantage and that copies show this notice on the first page or initial screen of a display along with the full citation. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, to republish, to post on servers, to redistribute to lists, or to use any component of this work in other works requires prior specific permission and/or a fee. Permissions may be requested from Publications Dept, ACM, Inc., 1515 Broadway, New York, NY 10036 USA, fax +1 (212) 869-0481, or
[email protected].
C 2001 ACM 0098-3500/01/1200–0456 $5.00 ACM Transactions on Mathematical Software, Vol. 27, No. 4, December 2001, Pages 456–464.
FORTRAN Subroutines for Feedback Set Problems using GRASP
•
457
that ei = (vi , vi+1 ), i = 1, . . . , r with v1 = u and vr+1 = v. A cycle C in G is a path C = (v1 , . . . , vr ), with v1 = vr . A feedback vertex (arc) set of G is a subset of vertices (arcs) S ⊆ V (S ⊆ E) such that each cycle in G contains at least one vertex (arc) in S. Let w be a function that assigns a nonnegative weight to each vertex (arc) of G. Then the weight of a feedback vertex (arc) set is the sum of the weights of its vertices (arcs), and a minimum feedback vertex (arc) set of a weighted graph (G,w) is a feedback vertex (arc) set of G of minimum weight. This kind of NP-hard problem is also known as the hitting cycle problem, since one must hit every cycle in C. In addition to the minimum feedback vertex (arc) set problem, it also generalizes a number of problems, such as the subset minimum feedback vertex (arc) set problem and the graph bipartization problem, in which one must remove a minimum-weight set of vertices so that the remaining graph is bipartite. A general NP-hardness proof for all feedback set problems restricted to planar graphs has been given in Yannakakis [1978]. These results apply to the planar bipartization problem, and the planar (directed, undirected, or subset) feedback vertex set problems (already proved to be NP-hard [Karp 1972; Garey and Johnson 1979]). Furthermore, it is NP-complete [Garey and Johnson 1979] for planar graphs with no in-degree or out-degree exceeding three, general graphs with no in-degree or out-degree exceeding two, and arc-directed graphs [Karp 1972]. The feedback vertex (arc) set problem has found applications in many fields, including deadlock prevention [Wang et al. 1985], program verification [Shamir 1979], and Bayesian inference [Bar-Yehuda et al. 1998]. For example, in deadlock prevention, consider an operating system which schedules different processes with requests on different resources, which need to be used exclusively, before being released by the process. A directed graph modeling these resource requirements is to have a node i for each process i and a directed arc e(i, j ) denotes process i requests for a resource already allocated to process j . Therefore, if there is a directed cycle in such a graph, a deadlock occurs and every process in the cycle will wait for the requested resource and never release the resources already allocated to it. To break such cycles, one can remove some processes from the graph and put them in a waiting queue. It is clear that the objective is to minimize the number of removed processes. In the past few years there have been intensive efforts on approximation algorithms for these kinds of problems. Even et al. [1998] proposed an algorithm for approximating the feedback vertex set problem in the weighted and directed case. Their approach is an algorithmic adaptation of a theoretical result by Seymour [1995], who proved that the integrality gap in the case of the unweighted feedback vertex set problem can be at most O(log τ ∗ log log τ ∗ ), where τ ∗ is the weight of an optimal fractional feedback set. Even et al. observe that all existence arguments contained in the proof of Seymour’s statement can be made constructive, and thus, with some additional operations, an algorithm for the unweighted feedback vertex set problem having an approximation factor of O(log τ ∗ log log τ ∗ ) can be obtained. Further modifications of the algorithm lead to a polynomial time approximation scheme applicable to the weighted problem. In O(|E| · |V |2 ) time the algorithm finds a feedback vertex set having ACM Transactions on Mathematical Software, Vol. 27, No. 4, December 2001.
458
•
P. Festa et al. Table I. The Distribution makefile drivers subroutines sample input sample output test problems instructions
Makefile driver-gfvs.f gfvs.f sample.dat sample-gfvs.out fsp-data.tar.gz READ.ME
driver-gfas.f gfas.f sample-gfas.out
weight O(min{τ ∗ log τ ∗ log log τ ∗ , τ ∗ log |V | log log |V |}). All of the observations contained in Even et al. improve upon the O(log2 |V |)-approximation algorithm of Leighton and Rao [1988] for this case. A recent survey of feedback set problems can be found in Festa et al. [1999]. Although the approximation algorithms guarantee a solution of a certain quality, for many practical real world cases, heuristic methods can lead to better solutions in a reasonable amount of CPU time. One such heuristic is the greedy randomized adaptive search procedure (GRASP) introduced by Feo and Resende [1989, 1995] and used by Pardalos et al. [1999] to find approximate solutions for large instances of the feedback vertex set problem. GRASP [Feo and Resende 1995] is an iterative sampling method for finding approximate solutions to combinatorial optimization problems. It can be thought of as a multi-start procedure, since GRASP iterations are repeated, each iteration finding an approximate solution to the problem. The best solution found, over all GRASP iterations, is returned by the method as the GRASP solution. Each GRASP iteration is made up of two phases: a construction phase and a local search phase (also known as a local improvement phase). During the construction phase, a feasible solution is iteratively constructed. One element at a time is randomly chosen from a Restricted Candidate List (RCL), whose elements are ranked according to some greedy criterion, and is added to the solution that is being built. The randomness used in the algorithm makes it unlikely that the greedy choice is always selected during construction. Therefore, the construction phase solution is rarely the greedy solution. In the second phase, the neighborhood of the constructed solution is searched for an improved solution. In this paper, we propose gfvs and gfas, two sets of ANSI standard FORTRAN 77 subroutines that apply GRASP, to find approximate solutions of the feedback vertex set and the feedback arc set problems, respectively. The codes are intended to run without modification on UNIX platforms (They should also run on other environments without modification). There are no common blocks in the codes and all arrays and variables are passed as parameters. The distribution consists of ten files which are listed in Table I. The GRASP algorithm for the feedback vertex set problem implemented in gfvs is the procedure proposed by Pardalos et al. [1999]. The GRASP algorithm for the feedback arc set problem implemented in gfas uses the following important property: feedback vertex and feedback arc set problems are reducible to each other. In all reductions, there is a one-to-one correspondence between feasible solutions and their corresponding ACM Transactions on Mathematical Software, Vol. 27, No. 4, December 2001.
FORTRAN Subroutines for Feedback Set Problems using GRASP
•
459
Fig. 1. Procedure to reduce a feedback arc set problem into a feedback vertex set problem.
costs. Therefore, an approximate solution to one problem can be translated into an approximate solution of the corresponding translated problem. To solve feedback arc set problems, an O(|E|) time procedure [Even et al. 1998], is applied to translate the instance of the feedback arc set problem into an equivalent feedback vertex set problem, which can then be solved by gfvs. Given a graph G = (V , E) on which a feedback arc set problem is defined, gfvs is applied to the graph G 0 = (V 0 , E 0 ) defined by the procedure fas2fvs described in Figure 1. For each arc in G there is a corresponding vertex in G 0 . For each pair of arcs in G for which the head of the first arc is the tail of the second, there is an arc in G 0 whose tail is the vertex corresponding to the first arc in G and whose head is the vertex corresponding to the second arc. The paper is organized as follows. In Section 2, we describe the usage of gfvs and gfas, two sets of FORTRAN subroutines distributed with the packages. Computational testing is presented in Section 3. 2. USAGE OF THE SUBROUTINES The subroutines in files gfvs.f and gfas.f compute an approximate solution of the feedback vertex and arc set problems, respectively. The user interface with them is subroutine gmpsg, which must be called from a driver program. In addition to a number of auxiliary arrays, the driver passes the following representation of the input graph: n: Number of nodes in graph, m: Number of arcs in graph, vtx1: Integer array where vtx1(i) is tail of arc i, vtx2: Integer array where vtx2(i) is head of arc i, The following are the array dimensions: maxv: Dimension of number of nodes declared in the drivers, maxe: Dimension of number of arcs declared in the drivers. The sample driver programs for gfvs and gfas included in the distribution (driver-gfvs.f and driver-gfas.f, respectively) are set for problems of dimension |V | ≤ 1000 nodes and |E| ≤ 1000 arcs. The input/output parameters that define FORTRAN input/output devices are set to the standard values in = 5 and iout = 6. These parameters can be set by the user for problems of different dimension or for alternate input or output devices. ACM Transactions on Mathematical Software, Vol. 27, No. 4, December 2001.
460
•
P. Festa et al.
Fig. 2. Input file of feedback set instance.
Fig. 3. Sample output of driver gfvs.f and driver gfas.f for sample instance.
All variables and arrays needed by subroutines gfvs and gfas are defined in the main programs in files driver-gfvs.f and driver-gfas.f, respectively. Subroutines readp and outsol, also provided in the drivers are examples of code that can be used for input and output, respectively. Five parameters that control the execution of the algorithm need to be set before the optimization module is called: alpha, the restricted candidate list parameter, whose value is between 0 and 1, inclusively, (or it can be set to a negative value to indicate that each GRASP iteration uses a different randomly generated alpha value); look4, a stopping parameter that forces GRASP to stop if a cutset of size at least look4 is found, is an integer that must satisfy 0 ≤ look4 ≤ |V | for the feedback vertex set problem or 0 ≤ look4 ≤ |E| for the feedback arc set problem; maxitr, the maximum number of GRASP iterations, is an integer such that maxitr > 0; prttyp, the output option parameter, is an integer that is set to 0 (silent run, gfvs and gfas do not write anything), 1 (gfvs and gfas print out solution improvements), or 2 (gfvs and gfas print out the solution found in each GRASP iteration); and seed, the pseudo random number generator seed, an integer such that 1 ≤ seed ≤ 231 − 1. The default settings for alpha, look4, maxitr, prttyp, and seed are, respectively, −1, 0, 1024, 1, and 270001. ACM Transactions on Mathematical Software, Vol. 27, No. 4, December 2001.
FORTRAN Subroutines for Feedback Set Problems using GRASP
•
461
Table II. Cutset Elements in Incumbent Solution as a Function of GRASP Iteration: FVS Problem nodes 50 50 50 50 50 50 50 50 50 50 100 100 100 100 100 100 100 100 100 100 500 500 500 500 500 500 500 500 500 500 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000
arcs 100 150 200 250 300 500 600 700 800 900 200 300 400 500 600 1000 1100 1200 1300 1400 1000 1500 2000 2500 3000 5000 5500 6000 6500 7000 3000 3500 4000 4500 5000 10000 15000 20000 25000 30000
2 3 10 19 21 28 30 37 39 40 42 10 24 36 43 53 57 72 75 76 79 45 124 180 234 276 370 378 383 391 408 244 319 357 428 469 733 817 860 889 912
8 3 9 17 21 24 29 36 38 40 41 10 23 29 41 49 57 71 73 75 78 43 119 180 229 273 356 374 383 388 394 237 307 354 407 469 726 804 853 881 897
GRASP iteration 32 128 512 3 3 3 9 9 9 15 14 14 19 19 17 23 21 20 29 28 28 36 36 33 38 37 33 38 38 38 40 39 38 9 9 9 21 20 19 29 28 26 41 41 40 48 47 45 56 56 55 71 66 66 72 71 68 73 72 72 75 74 73 42 40 39 114 107 106 180 174 166 229 221 221 266 259 258 354 350 341 360 360 360 377 376 372 381 381 379 388 383 383 233 233 230 301 296 290 354 348 340 407 407 405 456 456 456 714 714 712 804 803 803 849 847 841 881 877 872 897 892 892
2048 3 9 13 17 20 28 33 33 37 38 9 18 26 38 45 55 66 68 71 71 37 105 166 220 257 341 357 371 369 383 224 290 340 400 450 712 798 841 868 892
The driver programs call readp, which reads the input data and returns an error condition, errcnd. If errcnd = 0 is returned by readp, then the drivers call the optimization subroutines which attempt to find a small cutset of the input graph. Subroutines gfvs and gfas return error condition errcnd indicating the status of the optimization. Error condition errcnd can have the following values: errcnd = 1 if a |V | > maxv; errcnd = 2 if a |E| > maxe; errcnd = 3 if an input node is less than 1 or greater than |V |; ACM Transactions on Mathematical Software, Vol. 27, No. 4, December 2001.
462
•
P. Festa et al.
Table III. Cutset Elements in Incumbent Solution as a Function of GRASP Iteration: FAS Problem feedback arc set nodes arcs 50 100 50 150 50 200 50 250 50 300 50 500 50 600 50 700 50 800 50 900 100 200 100 300 100 300 100 400 100 500 100 1000 100 1100 100 1200 100 1300 100 1400 500 1000 500 1500 500 2000 500 2500 500 3000 1000 3000 1000 3500 1000 4000 1000 4500 1000 5000
feedback vertex set nodes arcs 100 202 150 462 200 836 250 1224 300 1729 500 5024 600 7206 700 9782 800 12771 900 16109 200 397 300 908 400 1564 500 2419 600 3641 1000 9997 1100 12133 1200 14482 1300 16822 1400 19609 1000 2034 1500 4570 2000 7999 2500 12446 3000 18034 3000 9233 3500 12254 4000 15997 4500 19945 5000 24739
2 6 36 69 105 141 366 459 562 656 751 16 73 128 209 317 710 816 923 1017 1127 90 365 725 1180 1637 686 1061 1451 1842 2347
8 6 25 68 100 138 355 445 540 654 739 16 63 123 208 305 710 797 901 994 1097 87 347 704 1175 1637 686 1047 1399 1784 2273
GRASP iteration 32 128 6 6 25 23 68 62 90 90 129 128 344 343 440 434 536 531 629 629 735 734 15 14 63 56 119 112 204 199 291 291 702 702 797 797 899 892 992 992 1093 1093 79 79 340 326 704 690 1133 1127 1631 1595 686 686 1026 1021 1369 1369 1784 1779 2273 2238
512 6 21 61 90 128 332 430 517 621 726 14 54 105 194 290 696 785 879 972 1073 75 325 690 1114 1595 677 1012 1362 1759 2238
2048 6 21 57 82 121 321 426 517 621 714 14 49 98 184 278 678 773 878 972 1073 73 311 684 1114 1590 677 1007 1362 1759 2238
errcnd = 4 if look4 < 0 or look4 > |V | for the feedback vertex set problem; errcnd = 4 if look4 < 0 or look4 > |E| for the feedback arc set problem; errcnd = 5 if maxitr < 1; errcnd = 6 if prttyp 6= 0, 1, 2; errcnd = 7 if seed < 1 or seed > 2147483647. As an example, consider an instance with 10 vertices and 22 arcs whose input file is shown in Figure 2. Running the driver programs driver gfvs.f and driver gfas.f, using the default settings, this instance produces the outputs shown in Figure 3. The outputs list each iteration for which an improving solution was found and describe the best solutions found by listing the cutsets. 3. COMPUTATIONAL RESULTS In this section, we illustrate the effectiveness of the subroutines by running the feedback set procedures on a subset of the test problems used in Pardalos et al. [1999]. The experiment was limited to half of the test problems having at least ACM Transactions on Mathematical Software, Vol. 27, No. 4, December 2001.
FORTRAN Subroutines for Feedback Set Problems using GRASP
•
463
Table IV. Running Times (in seconds) for 2048 GRASP Iterations. DNR Indicates did not run nodes 50 50 50 50 50 50 50 50 50 50 100 100 100 100 100 100 100 100 100 100 500 500 500 500 500 500 500 500 500 500 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000
arcs 100 150 200 250 300 500 600 700 800 900 200 300 400 500 600 1000 1100 1200 1300 1400 1000 1500 2000 2500 3000 5000 5500 6000 6500 7000 3000 3500 4000 4500 5000 10000 15000 20000 25000 30000
Time in CPU seconds gfvs gfas 1.6 7.6 7.7 62.7 14.4 201.6 20.0 411.6 24.0 717.7 33.2 4451.4 54.3 8239.6 64.2 14509.6 75.5 26279.9 87.2 43690.8 9.8 42.0 35.9 273.1 46.9 602.1 74.7 1716.2 94.5 3402.4 140.0 21339.7 190.8 31609.1 207.6 47757.9 228.8 66840.8 249.0 86099.1 252.1 911.2 813.9 7472.6 1361.9 25023.4 1912.3 63473.1 2445.0 151323.2 4887.1 DNR 5451.6 DNR 6210.0 DNR 6933.5 DNR 7880.7 DNR 3388.7 36848.8 4529.7 68618.1 5678.6 129305.4 6677.7 204685.0 8518.0 348972.6 27577.1 DNR 47742.6 DNR 75464.6 DNR 104301.6 DNR 137855.7 DNR
50 and at most 1000 vertices with at most 30000 arcs (a total of 40 instances). The GRASP procedures gfvs and gfas were applied to each input graph to find approximate solutions to the feedback vertex set (FVS) and feedback arc set (FAS) problems, respectively. Procedure gfas was tested on all 50 and 100 nodes instances, but only on the smaller instances having 500 and 1000 nodes. The default parameter settings were used, as defined in the driver files of the distribution, that is alpha = −1, look4 = 0, maxitr = 2048, prttyp = 1, and seed = 270001. ACM Transactions on Mathematical Software, Vol. 27, No. 4, December 2001.
464
•
P. Festa et al.
The experiments were done on a Silicon Graphics Challenge computer with twenty 196 MHz MIPS R10000 processors and 6.1 Gb of main memory. The code was compiled on the SGI Fortran compiler f77 using the flags -O3 -r4 -64 -static. Processes were limited to a single processor. CPU times in seconds were computed by calling the system routine etime(). For each problem considered in the experiment, Tables II and III show the size of feedback vertex cutset of the incumbent solution as a function of GRASP iterations. In addition to the size of the input graph, Table III also lists the size of the transformed feedback vertex set problem that is solved to solve the feedback arc set problem. The incumbent solutions at iterations 2, 8, 32, 128, 512, and 2048 are listed. Table IV shows the running times (in seconds) for 2048 iterations using both gfvs and gfas. The table shows that while gfvs can be used on the entire set of test problems, gfas is only indicated for solving sparse instances, since it requires long running times on dense problems. This is expected, since gfas creates an equivalent feedback vertex set problem with as many nodes as the number of arcs of the graph in the original problem. This feedback vertex set problem is solved by a GRASP for feedback vertex set. ACKNOWLEDGMENTS
The authors would like to thank Tianbing Qian for implementing a preliminary version of gfvs. REFERENCES BAR-YEHUDA, R., GEIGER, D., NAOR, J., AND ROTH, R. M. 1998. Approximation algorithms for the vertex feedback set problem with applications to constraint satisfaction and Bayesian inference. SIAM J. Comput. 27, 942–959. EVEN, G., NAOR, S., SCHIEBER, B., AND SUDAN, M. 1998. Approximating minimum feedback sets and multicuts in directed graphs. Algorithmica 20, 151–174. FEO, T. AND RESENDE, M. G. C. 1989. A probabilistic heuristic for a computationally difficult set covering problem. Op. Res. Lett. 8, 67–71. FEO, T. A. AND RESENDE, M. G. C. 1995. Greedy randomized adaptive search procedures. J. Global Opt. 6, 109–133. FESTA, P., PARDALOS, P. M., AND RESENDE, M. G. C. 1999. Feedback set problems. In Handbook of Combinatorial Optimization. Kluwer Academic Publishers, Supplement vol. A, 209–259. GAREY, M. R. AND JOHNSON, D. S. 1979. Computers and intractability—A guide to the theory of NP-completeness. W.H. Freeman and Company. KARP, R. M. 1972. Reducibility among combinatorial problems. In R. E. Miller and J. W. Thatcher Eds., Complexity Of Computer Computations, Plenum Press, 85–103. LEIGHTON, T. AND RAO, S. 1988. An approximate max-flow min-cut theorem for uniform multicommodity flow problems with applications to approximation algorithms. In Proceedings of the 29th Annual Symposium on Foundations of Computer Science, 422–431. PARDALOS, P. M., QIAN, T., AND RESENDE, M. G. C. 1999. A greedy randomized adaptive search procedure for feedback vertex set. J. Comb. Opt. 2, 399–412. SEYMOUR, P. 1995. Packing directed circuits fractionally. Combinatorica 15, 281–288. SHAMIR, A. 1979. A linear time algorithm for finding minimum cutsets in reduced graphs. SIAM J. Comput. 8, 645–655. WANG, C., LLOYD, E., AND SOFFA, M. 1985. Feedback vertex sets and cyclically reducible graphs. JACM 32, 296–313. YANNAKAKIS, M. 1978. Node and edge-deletion NP-complete problems. In Proceedings of the 10-th Annual ACM Symposium on Theory of Computing (1978), 253–264. Received May 1999; accepted August 2001 ACM Transactions on Mathematical Software, Vol. 27, No. 4, December 2001.