Ant Colony Optimization for the Graph Coloring Problem Alexandru-Andrei JancΔ, Mihail-Cosmin PiΕ£-Rada University POLITEHNICA of Bucharest Faculty of Automatic Control and Computers, Computer Science Department alexandru.janca@cti.pub.ro, cosmin.pit@gmail.com Abstract ACO is a well known meta heuristic in which a colony of artificial ants cooperates for solving a combinatorial optimization problem. This approach is suitable for the graph coloring problem and provides good practical results. The starting point of this paper is an algorithm that brought mentionable improvements in comparison with the algorithm that first suggested this sort of approach on the graph coloring problem. The statistical view imposed by ACO allowed us to tamper with various parameters and attempt various heuristics. This argument is backed up by the nature of the problem itself, since no trivial solution is known for graph coloring. Based on our analysis of the current model for apriori information, we have introduced a new measure of such information, removed an existing one and altered the persistence of the way each ant chooses its next move. Keywords: graph coloring, ant colony optimization, heuristics 1. Introduction The graph coloring problem is an important problem and has wide applications in contemporary problems with exponential complexity. The graph coloring problem has many possible applications including the time-tabling problem, the register allocation problem, the digital circuit testing problem, the map coloring problem etc. Being a NPcomplete problem many combinatorial problems can be formulated in terms of a graph coloring. For example the well known game Sudoku ([7]) can be reduced pretty easily to a graph with 81 vertices that needs to be colored with 9 colors. A proper coloring of a graph G = (V, E) is a function f: V → C where C is a set of colors, that assigns a color to every vertex from, G such that any two adjacent nodes have different colors. The graph coloring problem refers to a minimal proper coloring. In this case the number of used colors is called the chromatic number of the graph. ([3], [4]) Figure 1. Example of a minimal proper coloring ACO is a heuristic technique that imitates the behavior of a colony of ants and their ability to collectively solve problems. For example, it has been observed that a colony of ants is able to find the shortest path to a food source by marking their trails with a chemical substance called pheromone. The ants are looking for pheromone trails and prefer to follow the trails with higher levels of pheromone. Some pheromone evaporates over the time and this makes the ants to take in consideration only the paths intensively used. ([2], [6]) 2. Previous Work The graph coloring problem is a difficult problem and being very hard to find an optimal solution makes it the subject of many research papers. Several approaches were suggested such as genetic algorithms, heuristic algorithms (Welsh-Powell, Chaitin), meta heuristics (Tabu Search, ACO), mixed algorithms etc. From those approaches ACO solves the graphs coloring problem near optimally. In [3] the authors propose a multi-agent solution based on the idea of parallel search. The ants move around the nodes and change the colors according to a local criterion. In each iteration every ant moves from the current position to an adjacent node with the maxim number of violations. To escape from the local minimum trap the moves and the color assignment have associated some probabilities giving the algorithm a random behavior. The idea is very simple and easy to implement and in many cases performs better than other complex algorithms but still there is place for further improvements. [4] also proposes an interesting algorithm based on DSATUR heuristic that makes some computations based on the number of different colors assigned to the neighbors. The authors threat the problem as a K-Coloring problem, placing k ants of different colors in every vertex. At every step the colors are updated trying to solve at least one randomly chosen conflict. The task is to have in the end in every vertex only ants of the same color. The behavior seems to be somehow dependent of the density of the graph and probably isn’t too easy to compare the performances with other more general algorithms. Bui et. al. describe an hybrid ACO algorithm [5] in which the ants don’t have the pheromone laying capability. The algorithm starts from a proper k-coloring, where k is an upper bound, obtained with the XRLF algorithm. Then a colony of ants is randomly distributed over the vertices of the graph and a series of cycles of local colorings begin. At the end of each cycle if a proper coloring is obtained then the number of colors is decreased otherwise this number is increased arguing that there is no proper coloring with the current set of colors. This algorithm borrowed the tabu list idea from the TABU search meta heuristic preventing ants from getting stuck into a loop of conflict reduction. The algorithm was tested on a series of 119 DIMACS graphs and it seems to have a good behavior. 3. Foundation of our approach Ant colony optimization was first linked with another NP-complete problem, the travel salesman problem by Dorigo and Giambardella [6]. Costa and Hertz were the first to suggest an ACO-based approach on the graph coloring problem [2]. In order to briefly present their solution, followed by a more detailed presentation of an improved method described by Dowsland and Thompson [1], we review the core of ACO method – the probability distribution by which each ant makes the decision of moving from its current state to another one. Adapting the generic definition to the problem at hand, the option of coloring the vertex i using the color k is selected with the following probability: π½ πΌ πππ πππ πππ = {∑π∈π π πΌ π π½ ππ ππ , ππ π ∈ π (1) 0 , ππ‘βπππ€ππ π W is defined as the set of uncolored vertices that can be colored using the current color k. The set of uncolored vertices that cannot be colored using the current color k is also taken into consideration. Let B denote this last set. Costa and Hertz provide three options for representing the apriori knowledge an ant has regarding its choices. This apriori information is encapsulated in πππ , as stated below: πππ = |π| − ππππ (π) πππ = ππππ΅ (π) πππ = ππππ΅∪π (π) (2) The pheromone trail also provides its contribution in the choice of coloring a vertex. The important trails are those associated with the vertices that have already been colored using the current color k. πππ = ∑π∈π π‘ππ π |ππ | , where ππ is the set of vertices colored using the k color. Finally, parameters α and β are used to represent the influence of the trail-based information and the heuristic function respectively when the ant chooses the next vertex to color. The algorithm ANTCOL, as named by Costa and Hertz, is the starting point for Dowsland and Thompson's experiments, as well as for our own improvements. It is therefore mandatory to have a glance at the main procedure: init πππ (trail matrix) cycles=0 while cycles < ncycles and converge_limit_notreached init i (trail update matrix) for ant=1, nants X = V (initialize the set of uncolored vertices) k = 0 while π ≠ ∅ k = k + 1 πΆπ ≠ ∅ (initialize the set of colored vertices with color k) F = X Select π ∈ πΉ with probability 1/|F| COLOUR_VERTEX(i, k) While πΉ ≠ ∅ Select π ∈ πΉ with probability πππ COLOUR_VERTEX(i, k) End_while End_while πΏππ = πΏππ + 1⁄π ∀π, π βΆ πΆπ = πΆπ , π ≠ π End_for (update trail update matrix) π‘ππ = π‘ππ + πΏππ ∀π, π = 1, |π|, π ≠ π (update trail matrix) Next cycle Procedure COLOUR_VERTEX(i, k) X = X \ {i} Ck = Ck ∪ {i} F = F \ (N(i)∪{i}) (where N(i) denotes the set of i’s neighbors in F) Dowsland and Thompson modified this algorithm starting with the assumption that the chromatic number r (the minimum number of colors that can be used for coloring a certain graph) is known for every given input graph [1]. The above presented procedure would stop after r colors have been used, thus leaving some vertices uncolored in the final solution provided by each ant. Thus, there is need for an evaluation function that would offer a measure of comparison between solution. They proposed a simple evaluation function: 1 π(π ) = π’(π ) (3) where u(s) is the number of vertices left uncolored in the solution. This approach cannot be applied when the chromatic number is unknown, which is of course the practical test case. The solution is to initialize r as being the number of vertices and updating it after each cycle as Q*-1, where Q* is the minimum number of colors found in that cycle. Trails must also reflect the way the evaluation function distinguishes between solutions. If the vertex i remains uncolored in the solution s, then πππ is multiplied by f(s). A comparison between this method and the original ANTCOL algorithm was extensively performed on time-tabling graphs rather than just random graphs. In the case of random graphs, the tests used for comparison were generated in the same manner Costa and Hertz originally provided their results: graphs with 100 and 300 vertices, 100 and 200 respectively maximum cycles and variable number of ants [1, 2]. Dowsland and Thompson matched their generated data set to their algorithm as well as the ANTCOL procedure. Their algorithm obtained an average of 34.5 colors used for the 300 vertices graph, while ANTCOL had an average of 35.3 colors. Similar improvements were also observed for the 500 vertices graphs set: 53.2 average versus 54.8 obtained by ANTCOL. These algorithms may be tackled in various ways. Our attempts have altered the behavior of the pheromone trail, the data structures used and the probability distribution used to select the vertice to be colored next. 4. Our approach A key part of ACO is the way each ant makes its next choice at each step in its way towards the solution. In our case, which node is next to be colored using the current color class k. This depends on the strength of the pheromone trail and a form of probabilistic reasoning that each ant takes into consideration at each step (referred by us as apriori information). We have analyzed the representations used in the approach described below and interpret them in respect to the graph coloring problem, as of course required. As the way the trail is updated we found the current solution to be quite satisfactory, we consider rather debatable the model proposed for the ants' apriori information, i.e. πππ . It is clear that its purpose is to provide a measure of the advantage gained by coloring vertex i using color k, since the probability increases alongside this parameter. Three heuristics are given and the first two seem to be consistent with the measure's purpose. Thus, if πππ = ππππ΅ (π) is large, we can state it is helpful to choose i as the next colored vertex, since it has many neighbors that could not have been colored with k anyway. This minimizes the number of the uncolored vertices affected by this coloring. The same can be said regarding the second heuristic: a small number of uncolored vertices will not be able to use the color k anymore, since i has a small number of neighbors in the list of current candidates that can be colored using k. However, we found no reasonable justification for including the third measure. So we first decided to discard the use of this measure. Baring in mind that we need to maximize ππππ΅ (π) and minimize ππππ (π), a suitable measure that encapsulates both desires it to maximize ππππ΅ (π) − ππππ (π) . Thus we bring forward our own measure, πππ = π ππππ΅ (π)− ππππ (π) (we used the exp function since ππππ΅ (π) − ππππ (π) could yield a negative value). Finally, we take a look at the way the measure to be used is randomly selected. The ANTCOL approach makes such a choice for each coloring, so every time an ant must choose between candidates it will randomly select one of the measures available. The question arises : should the measure be bounded at a higher level? We decide to experiment with choosing the measure once for each color class k , as well as for each time an ant computes the entire solution. We therefore increase the level (amount of time or number of choices in which the same measure is used in computing choice probability distribution) of commitment of ants to the same strategy. To conclude, three modifications have resulted: removing the third measure, introducing our own measure and increasing the level of commitment. Since each of them operates at a different level, we can combined them in various manners (altering the available measures and level of commitment) and obtain a different behavior. In our experiment we have decided to the following alternatives: using all measures including our own, using just the first 2 proposed measures, using just our own measure and replacing the third proposed measure with our own. For each such alternative, each possible level of commitment is used. 5. Results We have implemented the ANTCOL procedure, as our experiments and attempts are be based on this core algorithm. A simple testing environment allows us to generate various random graphs, varying the number of vertices and its load (number of edges). The implementations and testing environment are linked by the flexible way in which we can toggle parameters such as ant number, trail and visibility influence, convergence limits, number of tests performed etc. Also, one can configure the availability of each of the four measures and the level of commitment to a measure. We have generated a set of random 100 vertices graphs. All graphs have a rather similar load and each vertex a number of neighbors in the range 20-40. Each of the alternatives previously described has been tested against this set by multiples runs. We have computed the minimum number of colors obtained for each graph by each approach, the average number of colors for each graph obtained during all runs of the same approach and the average number of colors used on the entire data set. Such result data being available can provide a extensive number of useful statistics and various methods of evaluating performance and accuracy. Below we present a very relevant excerpt of our results: No. ππππ΅ (π) ππππ (π) π ππππ΅ (π)− ππππ (π) ππππ΅∪π (π) Commit level Data set Avg. minimum k 1 Yes Yes No Yes Coloring 15.883 2 Yes Yes No Yes Color class 15.783 3 Yes Yes No Yes Solution 15.85 4 Yes Yes Yes Yes Coloring 15.2 5 Yes Yes Yes Yes Color class 15.38 6 Yes Yes Yes Yes Solution 15.43 7 Yes Yes Yes No Coloring 15.15 8 Yes Yes Yes No Color class 15.01 9 Yes Yes Yes No Solution 15.21 10 Yes Yes No No Coloring 15.66 11 Yes Yes No No Color class 15.68 12 Yes Yes No No Solution 15.58 13 No No Yes No Coloring 14.08 14 No No Yes No Color class 14.03 15 No No Yes No Solution 14.03 Table 1. Results When eliminating random selection of the measure used by making only one such measure available, our own actually, we obtained the best results, finding a better coloring for almost all graph in the data set. 6. Conclusions The chart presented below underlines the improvements made by the new heuristic. Our new function is clearly outperforming all the other methods and not only it provides the best results itself (13, 14, 15), but also in combination with the other heuristics the results are clearly better. It is also worth mentioning that ππππ΅∪π (π) is producing poor results and they are easily reflected by the comparison between 1, 2, 3 where all the three original heuristics are used and 10, 11, 12 in which the suspected worse heuristic was excluded. Not only the original algorithm is working better without the last heuristic but also our new approximation is improving it. The usage of different commitment levels is debatable due to their close results in all mixed cases. However it can be exploitable on particular kind of graphs or in combination with a proper set of heuristics. Our work demonstrates that there is still place for more improvements and a better understanding on how the heuristic behavior is influencing the general solution combined with new ideas could lead to better results. Figure 2. Chart of results obtained using various measures and commitment levels Every color is related to a particular set of measures. References [1] – Dowsland K.A., Thompson J.M., An improved ant colony optimization heuristic for graph coloring, 2007 [2] – Costa D., Hertz A., Ants can colour graphs, J. Oper. Res. Soc. 48 (1997) 295–305. [3] – Comellas F., Ozon J., An ant algorithm for the graph coloring problem, s.n, s.l., s.a. [4] – Hertz A., Zufferey N., A New Ant Algorithm for Graph Coloring, s.n, s.l., s.a. [5] – Bui T.N, Nguyen T.H., Patel C.M., Phan K.T., An Ant-Based Algorithm for Coloring Graphs, s.n, s.l., s.a. [6] – Dorigo M., Giambardella L.M., Ant colonies for the traveling salesman problem , s.n., s.l., 1996 [7] – Delahaye, Jean-Paul, “The Science Behind Sudoku”, Scientific American magazine, June 2006.