Improving the performance of evolutionary algorithms in gridbased puzzles resolution
 139 Downloads
 4 Citations
Abstract
This paper proposes several modifications to existing hybrid evolutionary algorithms in gridbased puzzles, using apriori probabilities of 0/1 occurrence in binary encodings. This calculation of apriori probabilities of bits is possible in gridbased problems (puzzles in this case) due to their special structure, with the solution confined into a grid. The work is focused in two different gridbased puzzles, the Japanese puzzles and the Lightup puzzle, each one having special characteristics in terms of constraints, which must be taken into account for the probabilities of bit calculation. For these puzzles, we show the process of apriori probabilities calculation, and we modify the initialization of the EAs to improve their performance. We also include novel mutation operators based on apriori probabilities, which makes more effective the evolutionary search of the algorithms in the tackled puzzles. The performance of the algorithms with these new initialization and novel mutation operators is compared with the performance without them. We show that the new initialization and operators based on apriori probabilities of bits make the evolutionary search more effective and also improve the scalability of the algorithms.
Keywords
Gridbased puzzles Evolutionary algorithms Apriori probabilities of bits Japanese puzzles Lightup puzzles1 Introduction
Logic puzzles have been studied for years in Computer Science, Mathematics and Artificial Intelligence fields as important problems for testing different types of algorithms [1, 2]. In the last few years, logic puzzles have gained importance, since they are specially wellsuited to test heuristic and metaheuristics approaches [3], which has contributed to the development of this kind of algorithms. Specifically, many metaheuristic approaches to solve logic puzzles are hybrid approaches, where a global search algorithm is combined with a local search procedure to improve the search. Some examples of this can be found in different works in the literature, focused on different gridbased puzzles [3, 4, 5, 6, 7].
A particular case of logic puzzles are gridbased puzzles. These puzzles are really interesting since they have special characteristics inherited from its structure in the form of a grid. Examples of gridbased puzzles are the popular Sudoku, Japanese puzzles [8, 9, 10], the Lightup puzzle [11, 12], Spiral Galaxies [3] etc. The majority of gridbased puzzles admit solution algorithms based on logic reasoning, using the puzzle constraints. These constraints are reinforced by the fact that the solution to the puzzle must be confined into the puzzle grid. Many grid puzzles are known to be NPcomplete [3], and metaheuristic approaches have also been proposed for this kind of puzzles.
In spite of the huge work carried out in solving gridbased puzzles, the fact that the solution of these puzzles is in a grid has not been completely exploited yet to improve the performance of algorithms. Specifically, many gridbased puzzles can be encoded in the form of a binary vector or matrix, and associated with an objective function which is maximum (or minimum) when the puzzle is completely solved, and provides local optimum for incomplete (or infeasible) puzzle solutions. This is, for example, the case of Japanese puzzles [8] or the Lightup puzzle [11], two gridbased logic puzzles which can be encoded in this form. The interesting point, still unexploited, is that in the majority of gridbased puzzles, it is possible to calculate apriori probabilities of bits in the encoding. For example, in a Japanese puzzle, this would be the probability that a given square of the puzzle is black (1 in the encoding). In the Lightup puzzle, the apriori probabilities refer to the probability of a light bulb is in a given square of the puzzle.
This paper explores the use of apriori probabilities in gridbased puzzles (Japanese and Lightup puzzles specifically), to improve the performance of evolutionary computing algorithms when solving them. Details on the calculation of apriori probabilities for these two puzzles are given, and then used to implement new operators or novel initializations in the evolutionary algorithms. Experiments in several instances of the puzzles will show the improvements obtained in the algorithms’ performance with the new proposed operators. The main contributions of this paper are, first, to use apriori probabilities of bits to initialize the evolutionary algorithms, and to construct novel operators based on these apriori probabilities, which are able to improve the evolutionary algorithm’s performance in the resolution of the considered puzzles.
The structure of the rest of the paper is as follows: first, preliminary work on Japanese puzzles is presented. This includes some background, previous approaches and the apriori calculation of probabilities of bits for these puzzles. The same preliminary work on the Lightup puzzle is presented from Sect. 4, also including the calculation of apriori probabilities of bits for this puzzle. Then, the modifications included in the evolutionary algorithms based on apriori probabilities of bits are presented for both types of puzzles in Sects. 6 and 7, respectively. Section 8 shows the performance of the different algorithms modified with the novel operators based on apriori probabilities in both puzzles. Section 9 closes the paper giving some final conclusions and remarks.
2 Background on Japanese puzzles
A Japanese puzzle is a interesting and addictive game, which takes the form of a N × M grid, with numbers situated on the left and the top rows and columns. There are two types of Japanese puzzles, black and white (also known as nonograms) and color puzzles. In black and white Japanese puzzles, the numbers in rows and columns represent how many blocks of cells must be filled in the grid, in the order they appear. If there are two or more numbers, the blocks of cells in the grid must be separated by at least one white square.
2.1 Previous approaches to solve Japanese puzzles
It is possible to classify the algorithms to solve Japanese puzzles into two main groups, objective function guided algorithms and logictype algorithms. The objective function guided approaches include metaheuristics approaches and emergent solutions, such as genetic or evolutionary algorithms.
There have been several attempts of applying evolutionary computation algorithms to solve Japanese puzzles. The first of such attempts can be found in [5], where a solver based on a GA with operators from discrete tomography was presented. Another paper dealing with GA for solving Japanese puzzles can be found in [6]. In that paper, a comparison between a GA and a depth first search algorithm for Japanese puzzles is presented. The performance of a hybrid evolutionary algorithm for Japanese puzzles, and its application in education has been recently explored in [7]. In that work, an EA with a special encoding based on alleles (groups of bits which form a row or column) is proposed. In general, GAs are able to find solutions to small or medium size picturelogic puzzles, basing only on the information provided by the objective function, without considering the local information of the puzzle. Note that objective function guided algorithms usually evaluates full solutions to the puzzle.
The opposite situation appears when a logictype algorithm is used. These algorithms do not evaluate full solutions to the puzzle, but they construct a solution from scratch, using the local information of the puzzle to fix cells to 1 or 0 (black or white). Several logic solvers have been proposed in the literature in the last few years [15, 16]. Recently, a solid approach for Japanese puzzle solving has been proposed in [17]. That paper proposes the combination of relaxations of the problem, which are used to discover the value of pixels of the puzzle. The iteration of these relaxations leads to discover the entire solution of the puzzle. Also, in [18], a powerful solver based on an adhoc algorithm, called logic adhoc, for solving Japanese puzzles has been recently proposed. This algorithm can also be applied to color Japanese puzzles and has been used to generate puzzles in a efficient way [19]. The logic adhoc algorithm works with a set of unknowns (cells which are not yet fixed as being filled or left white), and progresses by fixing cells to be filled or white, by means of a set of logic procedures (see reference [18] for details on this solver). The logic adhoc algorithm exclusively exploits the logic information of the puzzle, so no objective function is needed in this case. There are some difficult puzzles in which the logic information of the puzzle is scarce, so the algorithms such as the algorithm in [17] or the logic adhoc approach in [18] do not work, or they take a lot of time to solve the puzzle.
In order to solve this problem, in [4] a hybrid evolutionary algorithm was proposed, the logic adhoc algorithm in [18] acts as local solver. The evolutionary algorithm encodes the puzzle using a ternary encoding, similar to the one used in the logic adhoc heuristic: 0 for cells in white, 1 for cells in black and 2 for unknown cells. The fitness function is a measure of the degree of puzzle solving when the logic adhoc algorithm is applied. It is easy to see that the idea of this algorithm is quite different to the existing genetic algorithms for Japanese puzzles solving: in this case, each individual of the evolutionary algorithm is a possible initialization of the logic adhoc heuristic, and the evolutionary algorithm tries to find the optimal initialization which solves the puzzle.
This paper proposes several improvements to the hybrid algorithm described above, based on apriori probabilities of bits in the puzzle.
3 Calculation of apriori probabilities of bits in Japanese puzzles

K _{ i }: number of conditions in a given row.

K _{ j }: number of conditions in a given column.

c _{ ik }: kth condition of row i, i = 1, ..., N.

c _{ jk }: kth condition of column j, j = 1, ..., M.
Note that these calculations are based on the number of combinations with repetitions, where n _{ i } is the number of elements from which you can choose and r _{ i } is the number to be chosen. Next, we also need to obtain the total number of feasible cell blocks distributions in row i and column j, considering that the cell (i, j) is fixed to be black. For the row case, this number will be equal to the sum of possible cell blocks distribution with each condition c _{ ik } situated over the cell (i, j) in all possible positions (moving the condition m cells from the leftmost position).
First, we obtain the total number of cell blocks distributions in the row (RT_{ i }) and in the column (CT_{ j }). Note that, though in the example we show all distributions of the row and column, we only need its total number, not the specific distributions (Eqs. 3, 5). In all these distributions, we emphasize the (i, j) cell, in such a way that we can see the number of distributions in the row i with the (i, j) cell fixed to black, i.e, the value of R _{ ij } (Eq. 7). Similarly, for the column j, we can see the distributions corresponding to C _{ ij } (Eq. 12). Finally, through of these values obtained in the example, and Eq. (17) we can obtain the (i, j) apriori probability which is equal to 0.2.
As a final remark for this subsection, note that a given cell (i, j) in which p _{ ij } = 1 or p _{ ij } = 0, can be directly set to black or white (1 or 0), so we can use the calculation of apriori probabilities of bits as the preprocessing step of the logic adhoc algorithm.
4 Background on the Lightup puzzle
4.1 Previous approaches to solve the Lightup puzzle
Contrary to Japanese puzzles, there are not many works devoted to solve the Lightup puzzle. The most important works on algorithms to solve this puzzle are [12, 20]. In [12] a hybrid Hopfield networkgenetic algorithm is introduced, whereas in [20] banks of Hopfield networks are used to solve specific instances of the puzzle. Specifically, in this paper the approach presented in [12] is considered, and will be improved using the apriori probabilities of bits defined later. The algorithm in [12] proposes to separate the solution of Lightup puzzle in two steps. First, part of the puzzle’s constraints are solved by using a binary Hopfield neural network. However, this neural network is not able to cope with the black squares constraints of the puzzle, which must be tackled using a GA. The next subsections give the most important details of this algorithm.
4.1.1 Binary Hopfield network for Lightup puzzle constraints
4.1.2 Complete hybrid genetic algorithm
5 Calculation of apriori probabilities of bits in the Lightup puzzle
Let us consider a given square in a Lightup puzzle after the preprocessing step described in Sect. 4, called x _{ ij }. This square can be classified in several states, depending on its characteristics: it can be a black one with numbers, x _{ ij } = 0 to 4 (constraint square, we refer to this value as C _{ ij } in the case of constraint squares), a black square without numbers (black square), encoded as x _{ ij } = 5. Also, it could be an unknown square, with value x _{ ij } = 6 (referring to white squares which may contain a light bulb or not, i.e. they are unknown in the process of puzzle solution), it could be a light bulb square (squares with a light bulb in them) x _{ ij } = 7 and finally it could be a lit square (white squares that are lit, without containing a light bulb) x _{ ij } = 8.
If we consider a square x _{ ij } which is not a constraint square, we can evaluate the number of combinations with x _{ ij } fixed to be light bulb or lit one, similarly that in the previous case. For that, we take into account the unknown squares in the same row i and column j which can illuminate the square x _{ ij }. We call h _{ i } and h _{ j } to the number of these squares. The number of combinations with the variable x _{ ij } fixed to light bulb is 1, considering that this square is the light bulb which illuminates the rest of squares. When we fix it to be a lit square, the following cases can be possible: one light bulb is in the same row, one light bulb is in the same column, and both cases at the same time, being the total number of combinations h _{ i } + h _{ j } + h _{ i } ·h _{ j }.
For the calculation of Eq. (28), we divide the neighborhood in three cases given in Fig. 9b, the two blacksquares conditions and the rest of squares which might illuminate x _{ ij }, as shown in the figure. Note that although the constraint squares have a common neighbor, we consider both conditions independent for simplify the calculation. With this decomposition, we can calculate the combinations with x _{ ij } = 7 (light bulb square) in each case. In the case with C _{(i1)j } = 3 there are two combinations, the result of evaluating Eq. (26) with nn = 3 and nd = 1 (three unknown squares and one light bulb square in its neighborhood, respectively). With C _{ i(j1)} = 1, the calculation is similar, but nn = 3 and nd = 0 this time. For the combinations with x _{ ij } = 8 (lit square) we carry out the same calculations than before, using Eq. (27). The rest of squares form h _{ i } and h _{ j } as it is shown in the figure. The final value of the apriori probability for the considered square x _{ ij } in Fig. 9 results: \(p(x_{ij}=7)=\frac{2 \cdot 1}{2 \cdot 1+1 \cdot 2 \cdot (2+3+2 \cdot 3)}=\frac{1}{12}=0.083.\)
6 Improving the hybrid evolutionary algorithms for Japanese puzzles
If this rule is not fulfilled, we consider that the gene should be set to 0.
The DGM operator works as follows: if it has been decided that a given gene in the population should be set to 1, all the genes which are 0s are mutated with probability q _{ i }. In the same way, if it has been decided that the gene should be set to 0, all the genes set to 1 are mutated with probability (1 − q _{ i }). Note that genes set to 2 are not modified by the DGM mutation operator. This procedure significantly improves the search capacity of the evolutionary algorithm, as will be shown in the experimental section.
7 Improving the hybrid Hopfield genetic algorithm for the Lightup puzzle
First, the initialization of the genetic population based on the apriori probability of bits in the Lightup puzzle is quite intuitive. It consists of, instead of initializing the population in a random way, using the probabilities p _{ ij } to evaluate the initial value (1 or 0) of the genes in the genetic algorithm (squares of the puzzle). For example, if a given square in the grid has apriori probability p _{ ij } = 0.8, this means that the corresponding gene in the genetic algorithm will be a 1 (will contain a lightbulb) with a probability 80%. Thus, this probability will be used to generate the value of this gene in the entire population of the genetic algorithm.
The second improvement in the hybrid algorithm for the Lightup is focused on the initialization of the Hopfield network. Recall that the implemented version of the binary Hopfield network depends on a vector of neurons updating, called φ. The performance of the Hopfield networks depend much on this updating order. The idea is to use the apriori probabilities of a puzzle to construct this updating order φ. This process is simple, the neurons in the Hopfield network (equivalent to each white square in the Lightup grid), are sorted by apriori probability value, in such a way that the neurons with largest p _{ ij } are updated before that the neurons with a low apriori probability. Small changes in this updating order are introduced in order to help the Hopfield network to find different solutions to the puzzle, and thus encourage variability in the population of the genetic algorithm.
8 Experiments and results
In this section we show several experiments to test the different new operators (based on apriori probabilities of bits) proposed in this paper. The experiments and results are presented separately for the Japanese puzzle and the Lightup puzzle. Note that, since the constraints of both problems (and also the approaches to tackle them) are completely different, it is expected that the improvements obtained in both puzzles are also different. In fact, a direct comparison of the results in both puzzles is not possible. However, we will try to show how the proposed new operators are able to improve the algorithms in both cases, and how these operators can be adapted to the peculiarities of each puzzle.
8.1 Experiments in Japanese puzzles
In order to test the performance of the modified hybrid evolutionarylogic algorithm, we have tackled several Japanese puzzles from [13]. This web site offers more than 200 Japanese puzzles, sorted by difficulty. A classification of the difficulty with stars is used, in such a way that the easiest puzzles are given 1 star, and the most difficult puzzles 9 stars. We have applied our algorithm to tackle all the puzzles of 8 and 9 stars offered in the page (16 puzzles). All these puzzles are 10 × 10 puzzles, in which the difficulty is in that no initial black nor white cell can be fixed at the beginning of a logictype algorithm (preprocessing stage).
Performance of the evolutionary algorithm (EA) proposed in the different Japanese puzzles tackled (in percentage of convergence to the puzzle solution, over 50 runs)
Instance in [13]  Proposed EA  EA in [7]  EA no DGM  EA no init. 

222  100  100  100  100 
223  100  64  96  98 
224  100  54  100  100 
225  100  70  98  98 
226  100  100  100  100 
227  100  100  100  100 
228  100  92  94  100 
229  100  34  100  100 
230  100  14  96  92 
231  100  96  96  100 
232  98  14  72  92 
233  94  0  64  92 
237  100  78  96  100 
236  96  4  54  94 
235  100  0  96  96 
234  96  12  86  98 
Average  99.00  52.00  90.50  97.50 
Comparison of the average number of generations to the convergence for the different Japanese puzzles tackled
Instance in [13]  # Variables  Proposed EA  EA no DGM  EA no init.  EA in [7] 

222  94  2.34  4.22  4.26  14.64 
223  99  4.90  6.95  7.45  20.55 
224  82  2.34  2.84  2.76  24.61 
225  100  2.28  3.75  4.18  18.97 
226  93  2.14  2.94  2.4  12.38 
227  89  2.5  2.88  2.36  3.68 
228  98  5.36  9.78  9.46  13.98 
229  85  2.46  2.96  4.12  21.17 
230  89  8.87  11.49  15.34  19.00 
231  93  2.02  3.66  5.36  13.04 
232  98  11.32  17.36  22.23  35.42 
233  95  11.56  12.55  18.11  N/A 
237  100  4.14  5.82  7.56  25.92 
236  96  10.02  11.875  22.21  50.53 
235  94  5.87  11.70  8.54  N/A 
234  94  11.45  15.11  17.22  16.80 
Average  –  5.60  7.87  9.60  18.17 
8.2 Experiments in the Lightup puzzle
Results obtained (probability of convergence to the puzzle’s optimal solution) in several Lightup instances from [23], with and without including the new operators based on apriori probabilities of bits in the evolutionary search; WOP stands for “Without any operator”, WPH stands for “With probabilities of bits in the Hopfield network”, WPI stands for “With probabilities in the initialization” and finally WP stands for the algorithm with all operators included
Instance  Size  Fitness evaluations  WOP  WPH  WPI  WP 

1  10 × 10  10,000  100  100  100  100 
2  10 × 10  10,000  100  100  100  100 
3  10 × 10  10,000  71  70.5  72.5  72.5 
4  10 × 10  10,000  92  92.5  89  93.5 
5  14 × 14  40,000  96.5  96.5  94.5  98 
6  14 × 14  40,000  35.5  46  42  56.5 
7  14 × 14  40,000  92  95  97  97 
8  14 × 14  40,000  99.5  100  100  100 
9  14 × 14  40,000  100  100  100  100 
10  14 × 14  40,000  14.5  13.5  8  17 
11  14 × 14  40,000  100  100  100  100 
12  14 × 14  40,000  90  95  94  96 
Average  –  –  82.5833  84.08  83.08  85.87 
Comparison of the average number of generations to the convergence for the different Lightup puzzles tackled
Instances  # Variables  WOP  WP 

1  28  2.75  4.15 
2  6  1  1 
3  74  27.67  35.02 
4  47  12.47  13.09 
5  121  53.53  52.96 
6  71  55.25  44.62 
7  77  13.00  13.105 
8  68  9.63  9.59 
9  84  12.25  13.36 
10  133  76.5  105.00 
11  36  2.155  2.175 
12  95  31.64  29.27 
Average  –  24.82  26.94 
9 Conclusions
In the majority of problems tackled with evolutionary computation techniques it is not possible to have a first idea of the probability that a given gene in an individual has a given value. This means that, if we use a binary encoding for a problem, in a general we are not able to calculate the probability of a given gene is 1. If we could have such an information we could construct more effective operators that improve the genetic search. In this paper we have shown that it is possible to calculate the apriori probabilities of bits for some kind of puzzles, specifically gridbased puzzles, i.e. puzzles in which the solution is confined into a grid. Specifically, we have focused the work on two popular gridbased puzzles: the Japanese puzzle (also known as nonogram) and the Lightup puzzle. We have also shown how to construct new operators which improve the performance of existing hybrid genetic algorithms to solve these puzzles. We have also shown this performance by solving several hard puzzles obtained from the Internet, and comparing the new algorithms obtained with the previous versions, without apriori probabilities knowledge. This study can be extrapolated to any problem (not only puzzle resolution nor binary encoding) in which the calculation of apriori probabilities of the gene values can be carried out.
Notes
Acknowledgments
This work has been partially supported by Universidad de Alcalá, Comunidad de Madrid and Ministerio de Educación of Spain under grants number CCG08UAH/AMB3993 and TEC200607010. E. G. OrtizGarcía is supported by Universidad de Alcalá, under the University F.P.I. grants program. Á. M. PérezBellido is supported with a doctoral fellowship by the European Social Fund and Junta de Comunidades de Castilla la Mancha, in the frame of the Operating Programme ESF 20072013.
References
 1.Khoo A, Zubek R (2002) Applying inexpensive AI techniques to computer games. IEEE Intell Syst 17(4):48–53CrossRefGoogle Scholar
 2.Lucas SS, Kendall G (2006) Evolutionary computation and games. IEEE Comput Intell Mag 1(1):10–18CrossRefGoogle Scholar
 3.Kendall G, Parkes A, Spoerer K (2008) A Survey of NPComplete Puzzles. Int Comput Games Assoc J 31(1):13–34Google Scholar
 4.OrtizGarcía E, SalcedoSanz S, PérezBellido AM, PortillaFigueras A, Yao X (2008) Solving very difficult Japanese puzzles with a hybrid evolutionarylogic algorithm. Lect Notes Comput Sci 5361:360–369CrossRefGoogle Scholar
 5.Batenburg B, Kosters W (2004) A discrete tomography approach to Japanese puzzles. In: Proceedings of the BelgianDutch conference on artificial intelligence, pp 243–250Google Scholar
 6.Wiggers W (2004) A comparison of a genetic algorithm and a depth first search algorithm applied to Japanese nonograms. In: Proceedings of the 1st Twente Student conference on IT, pp 1–6Google Scholar
 7.SalcedoSanz S, PortillaFigueras J, Pérez.Bellido A, OrtizGarcía E, Yao X (2007) Teaching advanced features of evolutionary algorithms using Japanese puzzles. IEEE Trans Edu 50(2):151–155CrossRefGoogle Scholar
 8.Conceptis Puzzles Inc (2009) http://www.conceptispuzzles.com
 9.Ueda N, Nagao T (1996) NPcompleteness results for nonograms via parsimonious reductions. Internal Report, University of Tokyo, Computer Science DepartmentGoogle Scholar
 10.Benton J, Snow R, Wallach N (2006) A combinatorial problem associated with nonograms. Linear Algebra Appl 412(1):30–38MATHCrossRefMathSciNetGoogle Scholar
 11.Nikoli puzzles (2009) http://www.nikoli.co.jp/en/puzzles/light_up/
 12.OrtizGarcía EG, SalcedoSanz S, PérezBellido ÁM, PortillaFigueras A (2007) A Hybrid Hopfield NetworkGenetic Algorithm Approach for the Lightup Puzzle. In: Proceedings of the IEEE conference on evolutionary computation, pp 1403–1407Google Scholar
 13.Benchmark puzzles (2009) http://www.homepages.cwi.nl/∼aeb/games/jpuzzlegraded/index.html
 14.Dorant M (2007) A begginer’s guide to solving picture forming logic puzzles, http://www.conceptispuzzles.com/index.aspx?uri=info/article/79
 15.Duncan G (1999) Puzzle solving. B.Sc. degree final project Report, University of York, Computer Science DepartmentGoogle Scholar
 16.Simpson S (2006) http://www.comp.lancs.ac.uk/computing/users/ss/nonogram/index.html
 17.Batenburg KJ, Kosters WA (2009) Solving nonograms by combining relaxations. Pattern Recognition (in press)Google Scholar
 18.SalcedoSanz S, OrtizGarcía E, Pérez.Bellido A, PortillaFigueras J, Yao X (2007) Solving Japanese puzzles with heuristics. In: IEEE symposium on computational intelligence and games, Honolulu (USA), AprilGoogle Scholar
 19.OrtizGarcía E, SalcedoSanz S, LeivaMurillo JM, Pérez.Bellido A, PortillaFigueras J (2007) Automated generation and visualization of picturelogic puzzles. Comput Graph 31:750–760CrossRefGoogle Scholar
 20.SalcedoSanz S, OrtizGarcía EG, PrezBellido AM, PortillaFigueras JA (2008) Using a bank of binary Hopfield networks as constraints solver in hybrid algorithms. Neurocomputing 71:1061–1068Google Scholar
 21.Hopfield JJ (1982) Neurons and physical systems with emergent collective computational abilities. Proc Natl Acad Sci USA 79:2554–2558CrossRefMathSciNetGoogle Scholar
 22.Shrivastava Y, Dasgupta S, Reddy SM (1992) Guaranteed convergence in a class of Hopfield networks. IEEE Trans Neural Netw 3:951–961CrossRefGoogle Scholar
 23.Lightup puzzle page (2009) http://www.puzzleLightup.com/