An Evolutionary Annealing Approach to Graph Coloring Dimitris A. Fotakis1 , Spiridon D. Likothanassis1 , and Stamatis K. Stefanakos2 1
Computer Engineering & Informatics Department, University of Patras, 26500 Greece {fotakis, likothan}@cti.gr 2 Department of Computer Science, ETH Zurich, CH-8092, Zurich, Switzerland
[email protected]
Abstract. This paper presents a new heuristic algorithm for the graph coloring problem based on a combination of genetic algorithms and simulated annealing. Our algorithm exploits a novel crossover operator for graph coloring. Moreover, we investigate various ways in which simulated annealing can be used to enhance the performance of an evolutionary algorithm. Experiments performed on various collections of instances have justified the potential of this approach. We also discuss some possible enhancements and directions for further research.
1
Introduction
In this work, we consider one of the most extensively studied NP-hard problems, the graph coloring problem (GCP). In the GCP, one wishes to color the vertices of a given graph with a minimum number of colors, such that no two adjacent vertices receive the same color. A coloring which uses k colors is called a kcoloring and can be regarded as the partition of the vertices of the graph to distinct color classes. The minimum number of colors (or the minimum color classes) needed to color a specific graph G, is called the chromatic number χ(G). Given a specific coloring, if two adjacent vertices have the same color we say that these vertices are in conflict and call the connecting edge between them, a conflicting edge. For an excellent bibliographic survey on the GCP, see [1]. Given the NP-hardness of the GCP, it is natural to use heuristic methods in order to tackle it. The simplest heuristics work on a given permutation of the vertices and color each one sequentially, with the minimal possible color. Other heuristics, like RLF [2] and Dsatur [3], try to generate the permutation of the vertices dynamically, as they proceed with the coloring. In the case where a better solution is needed, more time-consuming methods have to be applied. Simulated Annealing (SA) [4] and Tabu Search (TS) [5] have been applied successfully to the GCP [6,7,8,9]. The basic idea behind TS and SA is to allow some uphill moves during the search process, hoping that the algorithm will be able to escape local minima. E.J.W. Boers et al. (Eds.) EvoWorkshop 2001, LNCS 2037, pp. 120–129, 2001. c Springer-Verlag Berlin Heidelberg 2001
An Evolutionary Annealing Approach to Graph Coloring
121
The first extensive study of the application of Genetic Algorithms (GAs) [10] to the GCP was made by Fleurent and Ferland [11]1 . Their work showed that GAs that use standard crossover operators are not able to compete on the GCP with heuristic algorithms based on TS and SA. On the other hand by maintaining a population of possible solutions and using a meaningful problemspecific crossover, together with a powerful local search method they were able to improve on the solutions obtained by local search, both in terms of solution quality and time. Since then, considerable work has been done in applying hybrid algorithms (i.e. algorithms combining two heuristics in order to improve the efficiency of both elements of the algorithm) to the GCP. Most of the proposed algorithms [13,14,15] use either TS or a simple steepest descent algorithm as the local search ingredient and utilize a specialized crossover in order to get the best results. To the best of our knowledge, Simulated Annealing has never been used in a hybrid Genetic Algorithm for the GCP. A hybrid scheme like that seems very promising: by maintaining a population of solutions we can investigate a large part of the search space and move within promising areas of it by the use of suitable genetic operators. On the other hand SA gives us the opportunity to exploit (improve) quickly any good solutions that we might come up with and also serves as a fine mutation operator in order to move to new solutions and therefore keep the population diversity in high levels. In this paper we present a new hybrid genetic algorithm for the GCP which uses simulated annealing in order to enhance the search process and also a new crossover specialized for the graph coloring problem called Maximum Independent Set Crossover (MISC). In the next section we present the generic form of our evolutionary annealing algorithm. In section 3 we present the GCP-specific details of our implementation. Then, we present the results we obtained on various test instances (section 4). Finally, in the last section we give some conclusions and ideas for future work.
2
The Generic Evolutionary Annealing Algorithm
In this section we present the Evolutionary Annealing (EVA) algorithm. We do not concentrate on any problem specific details but only present the building blocks of the algorithm in their generic form. We will deal with the GCP-specific details and the genetic operators in the next section. The basic idea behind EVA is to maintain a population of solutions and to evolve them using genetic operators such as mutation and crossover. Using simulated annealing we can enhance the search process by two ways: first, we use simulated annealing to exploit quickly any good solutions that we might come upon with. This is achieved by starting the annealing process at low temperatures. On the other hand, when the process is stuck, we can use simulated annealing in order to generate different solutions using the existing ones; this is achieved by starting the cooling process from high temperatures and thus allowing many uphill moves. The main EVA procedure is given below: 1
There exists also the earlier work of Davis [12], but he did not consider the combination of GAs with local search.
122
D.A. Fotakis, S.D. Likothanassis, and S.K. Stefanakos
The main EVA algorithm % pop size: population size % p mut: mutation probability % off size: number of offsprings generated by crossover Initialize the population P with pop size solutions Repeat Repeat P = evolve(P , off size, p mut) Until term cond GA = TRUE Choose a solution s ∈ P snew = anneal(s) Add snew to the population and delete s Until term cond EVA = TRUE Return the best solution found. The procedure evolve implements a one-generation evolution process which is repeated in order to obtain a complete evolution process. The model used here is a variation of the (µ + λ) evolutionary algorithm. In our case, the offsprings are generated only by crossover and are included in the enlarged population, while the solutions that are selected for mutation are replaced directly (without competition) by the new ones. The exact procedure is presented here: Algorithm evolve(P, off size, p mut) % P : Population of pop size solutions % f (): cost function Evaluate the population P Repeat Choose two solutions s1 , s2 ∈ P sc = crossover(s1 , s2 ) sc = anneal(sc ) Compute f (sc ) Add sc to P Until iterations = off size ∀s ∈ P with probability p mut1 s = mutate(s) s = anneal(s) with probability p mut2 s = anneal(s) Discard the worst solutions from P until there are pop size solutions left Return the new population The basic idea behind simulated annealing is that the search process can escape local minima if we allow some uphill moves. Starting with an initial solution s = s0 we choose at random a neighbor of s. If that move improves the cost function we perform it; otherwise we move to that solution with probability
An Evolutionary Annealing Approach to Graph Coloring
123
p = e−∆/t , where ∆ is the deterioration in the cost function. The parameter t, which is called temperature, is used in order to control the acceptance ratio: In the beginning, the temperature is set to a high value, and therefore a move to a worse is solution is often; as the search goes on, the temperature is reduced by a factor a and thus the probability of a downhill move decreases. The initial temperature together with the factor a and the number of trials performed in each iteration is called the cooling schedule. The procedure anneal which is presented below, implements a full annealing cycle. Algorithm anneal(s0 ) % s0 : initial solution % f (): cost function % N (s): the neighbors of s % We consider a minimization problem Compute an initial temperature t0 depending on f (s0 ) Let t0 = tf · t0 + tp where tf , tp are user-defined parameters Repeat Repeat Compute the size of the neighborhood N = |N (s0 )| Let nrep= N · Sf , where Sf is a user-defined parameter Randomly choose s ∈ N (s0 ) ∆ = f (s) − f (s0 ) If ∆ < 0 Let s0 = s Else With probability e−∆/t0 put s0 = s Until iterations = nrep Let t0 = a · t0 Until term cond SA = TRUE Return s0 Our implementation is similar to a typical SA algorithm with the exception that the neighborhood size is re-computed for every solution and therefore varies from time to time (in most implementations that we are aware of, the neighborhood size is computed once and remains the same during the whole optimization cycle). This feature makes a difference if we choose a neighborhood that reduces its size over the optimization process. As we shall see in the next section, that is the case in our implementation for the GCP. The annealing procedure turns out to be a very important feature of our algorithm, as it is used after every crossover or mutation. The parameters that need to be defined by the user for the anneal procedure are namely tf , tp , sf , a. These parameters are used so that we shall be able to control better the cooling schedule of the annealing process. An interesting characteristic of our implementation is that the user is able to define different values for these parameters, according to which component of the algorithm calls the procedure anneal. For example, we are able to define a different cooling schedule for the annealing process that takes place in the ini-
124
D.A. Fotakis, S.D. Likothanassis, and S.K. Stefanakos
tialization phase instead of the one performed after each crossover. This is very crucial for the efficiency of the algorithm, since it facilitates the full exploitation of the “cooling” process: In one extreme, we may use annealing as a random walk in the search space by using very high temperatures and therefore increase the diversity of the population when it becomes too low. It is well known that maintaining the diversity of the population in high levels is very important in GAs, because otherwise the crossover is not able to produce different solutions and that leads to premature convergence. On the other hand, we can see annealing as a greedy local search (using zero temperatures), which could be handy when we are dealing with good solutions (e.g. with 1 or 2 conflicts) that we want to improve.
3
GCP-Specific Details of Our Implementation
In order to find a proper coloring of a given graph G(V, E), one usually starts out by trying to color the graph with a large enough number of colors k. Upon succeeding, the number of colors is reduced by one and a new attempt is made. Our evolutionary annealing algorithm (EVA) seeks out proper k-colorings and stops when it finds one. Initialization. The first generation of solutions is created by a modified RLF algorithm, which uses at maximum k colors and assigns randomly those vertices that cannot be colored, within that range. Before the solutions are entered into the population, they are improved for a number of iterations by simulated annealing. Search space and cost function. A solution (i.e. a not necessarily proper k-coloring) is a partition of the vertices of the graph in k color classes: s = {C1 , C2 , . . . , Ck }. In order to evaluate such a solution we just count the number of conflicting edges. Thus, the cost function in both the anneal and evolve processes is f (s) = | {(u, v) ∈ E | u ∈ Ci and v ∈ Ci , 1 ≤ i ≤ k} |. Obviously, in order to find a proper k-coloring we need to minimize f () and seek for a zero-cost solution. Neighborhood operator. A solution s2 is a neighbor of s1 if the two solutions differ in a single location of a vertex v in the coloring classes, and additionally v is in conflict with another vertex. In order to obtain such a neighbor from a given solution s, we first choose at random a conflicting edge and then choose with equal probability one of its adjacent vertices. Finally, we move that vertex to another color class. It is obvious that this neighborhood is not symmetric because a valid coloring would have no neighbors; apparently that is not a problem, for if we ever find a legal coloring there is no point in continuing any further with the search process. Another thing to be noted here is that not all the solutions have the same neighborhood size. As we have mentioned earlier, in order to speed up
An Evolutionary Annealing Approach to Graph Coloring
125
the search process, our annealing algorithm recomputes the neighborhood size for every solution considered, thus spending more time (making more trials) when starting off with a solution that has many conflicts. Crossover operator. The crossover operator used in our implementation is called Maximum Independent Set Crossover (MISC), as it is based on the notion of maximizing the independent sets that already appear in the parent solutions, in a way similar to the RLF algorithm. Our crossover works on two parent solutions s1 = { C11 , . . . , Ck1 }, s2 = { C12 , . . . , Ck2 } and produces an offspring solution s = { C1 , . . . , Ck } as follows: In each step the chromatic class Ci of the offspring solution is constructed by setting Ci = Ijm , where Ijm is the largest independent subset of a chromatic class of the solutions sm , m = 1, 2 (we check all the classes in order to find the largest independent subset). We consider two sets V, U : V contains the uncolored vertices, while U contains at step the vertices that can’t be colored at that moment i.e. the vertices that are in conflict with the color class Ci that is being constructed. Initially V contains all the vertices of the graph and U = ∅. After setting Ci = Ijm we delete all the vertices of Ci from V and add to U all the vertices that are adjacent to a member of Ci . The vertices of V − U are then added to Ci and are deleted from V . Finally we set U = ∅, delete the vertices of Ci from the solutions s1 , s2 and repeat the process until V = ∅. The offspring is then improved for a number of iterations by the anneal procedure. Mutation operator. The mutation operator used tries to give to each conflicting vertex v a feasible color. If that’s not possible (meaning that its adjacent vertices have been already assigned to all k color classes), we then assign color i ∈ [1, k] with probability proportional to p(i) = d(v) − φ(v, i), where d(v) is the degree of the vertex v and φ(v, i) is the number of the vertices adjacent to v that own the color i. As in the crossover operator, the outcome of the mutation is then improved by the anneal procedure. We hope that this mutation, will move the conflicts to another part of the graph when the search is stuck and thus in the long term we will be able to improve the solution.
4
Experimental Results
In this section we present the results we were able to obtain using the EVA algorithm on various test instances and compare them with other algorithms. We performed experiments on the following instances: – Three random graphs (G125, 0.5 , G250, 0.5 , G500, 0.5 ) with unknown chromatic number, which we generated using the random graph generators of LEDA [16]. – Twelve Leighton graphs with 450 vertices and chromatic numbers 5,15 and 25, which were taken from the 2nd DIMACS challenge benchmarks [17]. – Two application graphs, school and school nsh, also used in [18].
126
D.A. Fotakis, S.D. Likothanassis, and S.K. Stefanakos
We are interested in these particular instances because they have been largely studied in the literature and thus constitute a good reference for comparisons. Besides that, some of the Leighton graphs have proved to be very difficult. The application graphs, which were generated from class scheduling problems, are used in order to find out the performance and therefore the usefulness of EVA on such problems. In order to evaluate the algorithm’s performance we use the criterion of the quality of the best solution found, that is the number of colors k used. For the Leighton and the application graphs we check whether the algorithm is able to solve the instance optimally. If optimum cannot be found, we increase the number of colors used, until we find a feasible coloring. For the three random graphs, due to the fact that their chromatic number is unknown, we perform multiple runs for various values of k and measure the ratio of successful runs (meaning these that come up with a legal coloring). Table 1. Results for random graphs per 5 runs. Instance G125,0.5
G250,0.5
G500,0.5
k succ (fail) avg. t (sec) 16 (5) 17 4 (1) 512.49 18 5 115.51 19 5 13.26 27 (5) 28 1 (4) 50864 29 2 (3) 7867.23 30 5 2746.69 50 (5) 51 1 (4) 140043 52 3 (2) 67560 53 5 36136
We compare our results with those given for three well known algorithms: – DCNS. The algorithm of C. Morgenestern [8], based on Simulated Annealing. It features a distributed implementation with various child-processes coloring in parallel a population of possible solutions. – PGC. This algorithm of G. Lewandowski and A. Condon [18] , is a parallel implementation based on DCNS and Johnson’s XRLF [7]. – FF. This is a hybrid GA-TS algorithm by Fleurent and Ferland [11]. Their given results do not base on one method only: For the most difficult instances they first partially color the graph with an Independent Set Extraction method based on XRLF and then color the remainder graph with their algorithm. In table 1 we present the results obtained by EVA on the three random graphs. In table 2 we give the best results that were obtained for all the instances and the parameters we used. Our algorithm is able to solve all but two Leighton
An Evolutionary Annealing Approach to Graph Coloring
127
Table 2. Best results obtained by EVA and parameters used. Instance le450 5a le450 5b le450 5c le450 5d le450 15a le450 15b le450 15c le450 15d le450 25a le450 25b le450 25c le450 25d G125,0.5 G250,0.5 G500,0.5 school school nsh
k 5 5 5 5 15 15 15 15 25 25 27 27 17 28 51 14 14
|P | offsize pmut1 8 2 0.5 8 2 0.5 1 1 10 3 0.2 8 3 0.2 10 3 0.2 14 4 0.2 1 1 8 3 0.2 1 0 0.2 6 2 0.2 14 2 0.1 15 2 0.1 8 3 0.3 8 3 0.3
pmut2 0.7 0.7 0.5 0.1 0.2 0.2 0.1 0.1 0.2 0.1 0.1 0.5 0.3
t (sec) 366 146 3 3.2 4010 481 73392 38755 2 2.1 224 18.07 411 50864 140043 12 29
graphs optimally. Let us note that four Leighton graphs (le450 5c, le450 5d, le450 25a, le450 25b) are easily solved in the initialization phase by the RLF algorithm. For the two graphs that were not solved optimally (le450 25c, le450 25d), the small execution times required to solve them with 27 colors, suggest that they should be solved with 26 colors, given sufficient running times. That was not the case though, as we were not able to find legal colorings with 26 colors for very large running times. The two scheduling graphs constitute no problem as they are solved easily in very small running times. As is noted in [18], where more experiments with such graphs were conducted, several applications, like register allocation and scheduling, provide graphs which are easy to color. Our algorithm beats their parallel implementation (using 32 processors) in terms of running time and thus we believe that EVA is well suited for solving problems arising from such applications. We present the comparative results in table 3. Only Morgenstern’s algorithm is able to solve all Leighton graphs optimally. Fleurent and Ferland manage to color the two harder Leighton instances using one color less than our algorithm. For the smaller random graphs, EVA gives similar results with the other algorithms and is only out-beaten on the G500,0.5 graph. In order to find a 51-coloring of G500,0.5 we spent nearly 40 hours of computation time, while DCNS finds 49colorings in half the time. Let us note here, that the three algorithms used for comparative purposes are among the best presented in the literature and each one uses a different technique in order to scale up well with the problem instance. Our algorithm does not use a distributed or parallel implementation, nor a pre-coloring technique that reduces the size of the instance, as the one used in FF.
128
D.A. Fotakis, S.D. Likothanassis, and S.K. Stefanakos
Table 3. Comparative results (”-” means that the algorithm was not tested on that instance). Instance χ(G) DCNS PGC FF EVA le450 5a 5 5 5 5 le450 5b 5 5 5 5 le450 5c 5 5 5 5 le450 5d 5 5 5 5 le450 15a 15 15 15 15 le450 15b 15 15 15 15 le450 15c 15 15 16 15 15 le450 15d 15 15 16 15 15 le450 25a 25 25 25 25 le450 25b 25 25 25 25 le450 25c 25 25 27 26 27 le450 25d 25 25 27 26 27 G125,0.5 17 17 17 G250,0.5 28 29 28 G500,0.5 49 52 49 51 school 14 14 14 school nsh 14 14 14
Note that we do not take into consideration the running times of the algorithms; the only criterion used for the comparison is the number of colors needed to legally color a given graph. Comparing the execution times of the four algorithms is a difficult task, as each algorithm is run on a different machine. Our experiments carried over in a SUN Sparc 10 workstation, that was also accessible to other users.
5
Conclusions and Future Work
In this paper, we introduced a new hybrid algorithm for graph coloring combining a genetic algorithm and simulated annealing. Our algorithm maintains a population of possible solutions in order to investigate a large part of the search space and uses simulated annealing to improve quickly the best solutions found and produce new solutions in different parts of the search space. We also presented a new crossover for graph coloring, called Maximum Independent Set Crossover which builds the color classes of the offspring by expanding the color classes of the parents in an RLF fashion. We conducted experiments on three classes of instances: random graphs, Leighton graphs, and application graphs. The experiments showed that our algorithm gives excellent results in terms of solution quality and speed for small graphs, but is not able to scale up its performance well as the instance size increases. This can be partly overcome by a parallel or distributed implementation which is not difficult due to the nature of our algorithm. Also, pre-coloring techniques can be used for large instances as presented in [11].
An Evolutionary Annealing Approach to Graph Coloring
129
It is our opinion that the combination of genetic algorithms and simulated annealing is a very promising technique that we have slightly investigated in this work and a lot remain to be done.
References 1. P.M Pardalos, T. Mavridou, and J. Xue. The graph coloring problem: A bibliographic survey. In D.-Z. Du and P.M. Pardalos, editors, Handbook of Combinatorial Optimization, Vol. 2, pages 331–395. Kluwer Academic Publishers, 1998. 2. F.T. Leighton. A graph colouring algorithm for large scheduling problems. Journal of Research of the National Bureau of Standards, 84(6):489–503, 1979. 3. D. Br´elaz. New methods to color the vertices of a graph. Communications of the ACM, 22(4):251–256, April 1979. 4. E. Aarts and J. Korst. Simulated Annealing and Boltzmann Machines: A Stochastic Approach to Combinatorial and Neural Computing. Interscience series in discrete mathematics and optimization. John Wiley & Sons, New York, 1989. 5. F. Glover. Future paths for integer programming and links to artificial intelligence. Computers and Operations Research, 13:533–549, 1986. 6. M. Chams, A. Hertz, and D. de Werra. Some experiments with simulated annealing for coloring graphs. European Journal of Operational Research, 32(2):260–266, 1987. 7. D.S. Johnson, C.R. Aragon, L.A. McGeoch, and C. Schevon. Optimization by simulated annealing: An experimental evaluation; part II, graph coloring and number partitioning. Operations Research, 39(3):378–406, May-June 1991. 8. C.A. Morgenstern. Distributed coloration neighborhood search. In [17], pages 335–357. American Mathematical Society, 1996. 9. A. Hertz and D. de Werra. Using tabu search techniques for graph coloring. Computing, 39(4):345–351, 1987. 10. Z. Michalewicz. Genetic Algorithms + Data Structures = Evolution Programs. Springer-Verlag, NY, 1992. 11. C. Fleurent and J.A. Ferland. Genetic and hybrid algorithms for graph coloring. Annals of Operations Research, pages 437–461, 1995. 12. L. Davis. Order-based genetic algorithms and the graph coloring problem. In Handbook of Genetic Algorithms. Van Nostrand Reinhold, 1991. 13. D. Costa, A. Hertz, and O. Dubuis. Embedding a sequential procedure within an evolutionary algorithm for coloring problems. Journal of Heuristics, 1:105–128, 1995. 14. P. Galinier and J.K. Hao. Hybrid evolutionary algorithms for graph coloring. Journal of Combinatorial Optimization, 1998. 15. R. Dorne and J.K. Hao. A new genetic local search algorithm for graph coloring, 1998. 16. K. Mehlhorn and S. Naher. LEDA: A platform for combinatorial and geometric computing. Cambridge University Press, 1999. 17. D.S. Johnson and M.A. Trick, editors. Cliques, Coloring, and Satisfiability: Second DIMACS Implementation Challenge, volume 26 of DIMACS Series in Discrete Mathematics and Theoretical Computer Science. American Mathematical Society, 1996. contains many articles on cliques and coloring. 18. G. Lewandowski and A. Condon. Experiments with parallel graph coloring heuristics and applications of graph coloring. In [17], pages 309–334. American Mathematical Society, 1996.