Advertisement

Evolutionary Intelligence

, 2:169 | Cite as

Improving the performance of evolutionary algorithms in grid-based puzzles resolution

  • E. G. Ortiz-García
  • S. Salcedo-Sanz
  • Á. M. Pérez-Bellido
  • L. Carro-Calvo
  • A. Portilla-Figueras
  • X. Yao
Special Issue

Abstract

This paper proposes several modifications to existing hybrid evolutionary algorithms in grid-based puzzles, using a-priori probabilities of 0/1 occurrence in binary encodings. This calculation of a-priori probabilities of bits is possible in grid-based problems (puzzles in this case) due to their special structure, with the solution confined into a grid. The work is focused in two different grid-based puzzles, the Japanese puzzles and the Light-up 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 a-priori probabilities calculation, and we modify the initialization of the EAs to improve their performance. We also include novel mutation operators based on a-priori 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 a-priori probabilities of bits make the evolutionary search more effective and also improve the scalability of the algorithms.

Keywords

Grid-based puzzles Evolutionary algorithms A-priori probabilities of bits Japanese puzzles Light-up puzzles 

1 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 well-suited 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 grid-based puzzles [3, 4, 5, 6, 7].

A particular case of logic puzzles are grid-based puzzles. These puzzles are really interesting since they have special characteristics inherited from its structure in the form of a grid. Examples of grid-based puzzles are the popular Sudoku, Japanese puzzles [8, 9, 10], the Light-up puzzle [11, 12], Spiral Galaxies [3] etc. The majority of grid-based 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 NP-complete [3], and metaheuristic approaches have also been proposed for this kind of puzzles.

In spite of the huge work carried out in solving grid-based 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 grid-based 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 Light-up puzzle [11], two grid-based logic puzzles which can be encoded in this form. The interesting point, still unexploited, is that in the majority of grid-based puzzles, it is possible to calculate a-priori 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 Light-up puzzle, the a-priori probabilities refer to the probability of a light bulb is in a given square of the puzzle.

This paper explores the use of a-priori probabilities in grid-based puzzles (Japanese and Light-up puzzles specifically), to improve the performance of evolutionary computing algorithms when solving them. Details on the calculation of a-priori 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 a-priori probabilities of bits to initialize the evolutionary algorithms, and to construct novel operators based on these a-priori 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 a-priori calculation of probabilities of bits for these puzzles. The same preliminary work on the Light-up puzzle is presented from Sect. 4, also including the calculation of a-priori probabilities of bits for this puzzle. Then, the modifications included in the evolutionary algorithms based on a-priori 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 a-priori 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.

For example, Fig. 1b shows the solution to the Japanese puzzle displayed in Fig. 1a. Note that in the first row a 6 cells block must be filled, whereas in the second row two blocks of 3 cells each must be filled, with at least one white square between them. Columns in the puzzle follow the same rules. When all constraints in rows and columns are fulfilled, the puzzle is solved, and a nice picture can be seen, in this case a famous picture of Popeye. See [8, 9, 10, 11, 12, 13, 14] for more examples on Japanese puzzles.
Fig. 1

Example of a Japanese puzzle; a grid with conditions; b solution

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 logic-type 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 picture-logic 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 logic-type 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 ad-hoc algorithm, called logic ad-hoc, 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 ad-hoc 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 ad-hoc 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 ad-hoc 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 ad-hoc 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 ad-hoc 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 ad-hoc 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 ad-hoc heuristic, and the evolutionary algorithm tries to find the optimal initialization which solves the puzzle.

As was mentioned before, the encoding used in the evolutionary algorithm is a ternary encoding, with values 0 for white cells, 1 for white cells and 2 for unknowns (the encoding of this evolutionary algorithm is the initialization of the logic ad-hoc algorithm [18]). The logic ad-hoc is then run for each individual in order to obtain the fitness value associated to it. In this case the fitness function is defined as:
$$ g({\mathbf x})= \sum_{i=1}^N \sum_{j=1}^M \left(I_{\{x_{ij}=1\}}+I_{\{x_{ij}=0\}}\right), $$
(1)
$$ I_{\{x_{ij}=k\}}= \left\{ \begin{array}{ll} 1 & if\,\,x_{\rm ij}=k\\ 0 & \hbox{otherwise} \end{array} \right. $$
(2)
which is equivalent to maximize the number of cells fixed to 0 and 1, or minimizing the number of unknown cells. The logic ad-hoc algorithm also provides a penalty term in case that the fixed cells by the evolutionary algorithm are incompatible with the puzzle’s constraints. The complete evolutionary algorithm uses a set of traditional operators: a roulette wheel selection, where the probability of survival of individuals is proportional to its fitness value; a two-points crossover, in which, given two individuals, two points are selected on them and the parts of individuals between these two points are swapped from one individual to the other; and finally a swapping mutation between two cells with different values is implemented. Details on this approach can be seen in [4].

This paper proposes several improvements to the hybrid algorithm described above, based on a-priori probabilities of bits in the puzzle.

3 Calculation of a-priori probabilities of bits in Japanese puzzles

Let us consider a Japanese puzzle, with N rows and M columns, where we also have the following known parameters:
  • 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.

We look for the calculation of the a-priori probability that a given cell will be 1 in the puzzle. To carry out this, we first calculate the total number of feasible cell blocks distributions, in each row or column of the puzzle, given the initial puzzle’s parameters shown above. For a given row, this number can be written as:
$$ \hbox{RT}_i = \left(\begin{array}{l}{r_i+n_i-1} \\ {r_i}\end{array}\right) $$
(3)
where n i K i + 1 is the number of cell blocks plus one, and
$$ r_i = M - {\sum_{k=1}^{K_i} c_{ik}} - K_i + 1, $$
(4)
is the total number of white cells situated between each two cell blocks.
In the same way, for a given column, this number is:
$$ CT_j = \left(\begin{array}{l} {r_j+n_j-1}\\ {r_j} \end{array}\right) ,$$
(5)
with n j K j + 1, and
$$ r_j = N - {\sum_{k=1}^{K_j} c_{jk}} - K_j + 1, $$
(6)

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 (ij) 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 (ij) in all possible positions (moving the condition m cells from the left-most position).

For each condition c ik and each m, we can divide the row in two segments. Each segment can be seen as an equivalent row with a group of conditions to place. The first segment contains those conditions previous to the condition c ik , i.e. c ir with r = {1, ..., k − 1}, and the second one contains those conditions next to the condition c ik . Thus, we can calculate the feasible cell blocks distributions in each segment, using Eq. (3). The product of these values and its sum is the number of possible cells blocks distributions wanted:
$$ R_{ij} = \sum_{k=1}^{K_i} \sum_{m=1}^{c_{ik}} \left(\begin{array}{l} (L1)_{ijkm} - (s1)_{ik} + k -1 \\ (L1)_{ijkm}- (s1)_{ik} \end{array}\right) \left(\begin{array}{l} (L2)_{ijkm}-(s2)_{ik} + K_i-k \\ (L2)_{ijkm}-(s2)_{ik} \end{array} \right) $$
(7)
where
$$ (L1)_{ijkm} = j - c_{ik} + m - 2, $$
(8)
is the length of the first segment given a condition c ik and its relative position m,
$$ (L2)_{ijkm} = M - j - m, $$
(9)
is the length of the second segment given a condition c ik and its relative position m,
$$ (s1)_{ik} = k - 2 + \sum_{r=1}^{k-1}{c_{ir}} $$
(10)
is the sum of conditions and fixed white squares in the first segment and
$$ (s2)_{ik} = K_i - k - 1 + \sum_{r=k+1}^{K_i}{c_{ir}} $$
(11)
is the sum of conditions and fixed white squares in the second segment.
Similarly, for a column, the equivalent equations are:
$$ C_{ij} = \sum_{k=1}^{K_j} \sum_{m=1}^{c_{jk}} \left(\begin{array}{l} (L1)_{ijkm} - (s1)_{jk} +k -1\\ (L1)_{ijkm}- (s1)_{jk} \end{array}\right) \left(\begin{array}{l} (L2)_{ijkm}-(s2)_{jk}+ K_j-k \\ (L2)_{ijkm}-(s2)_{jk} \end{array} \right) $$
(12)
$$ (L1)_{ijkm} = i - c_{jk} + m - 2 $$
(13)
$$ (L2)_{ijkm} = N - i - m $$
(14)
$$ (s1)_{jk} = k - 2 + \sum_{r=1}^{k-1}{c_{jr}} $$
(15)
$$ (s2)_{jk} = K_j - k -1 + \sum_{r=k+1}^{K_j}{c_{jr}} $$
(16)
Finally, the a-priori probability that the cell (ij) in the Japanese puzzle is a 1, can be calculated by means of the following expression:
$$ p_{ij} = \frac{R_{ij} C_{ij}}{R_{ij} \cdot C_{ij} + (\hbox{RT}_i - R_{ij})(\hbox{CT}_j- C_{ij})} $$
(17)
A small example can clarify the concepts used in the calculation above: Fig. 2 shows an example of the calculation using one row and one column of a Japanese puzzle. In the depicted row, there are two conditions of size 2, and in the column there are two conditions of size 2 and 1, respectively. The grid length of the row and column is 6 and 5, respectively. The a-priori probability p ij is calculated for the cell situated in the intersection of the row and column considered.
Fig. 2

Example of the a-priori probability calculation in a cell of a Japanese puzzle, given the conditions in the corresponding row and column

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 (ij) cell, in such a way that we can see the number of distributions in the row i with the (ij) 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 (ij) a-priori probability which is equal to 0.2.

As a final remark for this subsection, note that a given cell (ij) 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 a-priori probabilities of bits as the preprocessing step of the logic ad-hoc algorithm.

4 Background on the Light-up puzzle

The Light-up is a logical-type puzzle which consists of an N × M grid, with black and white squares in it. The objective is to place light bulbs on the grid, in such a way that every white square is lit. Squares are illuminated (lit) by a light bulb if they are in the same row or column, and if there is not a black square between them. Also, no light bulb can illuminate another light bulb. In addition, some of the black squares have numbers in them. The number in a black square indicates how many light bulbs share an edge with that square. Note that a black square without a number in it, only divides the row or column in which it is situated, and no constraints on the number of light bulbs are included. Figure 3a shows an example of the Light-up grid, and Fig. 3b a solution for the puzzle.
Fig. 3

Example of a Light-up puzzle and its encoding; a puzzle and grid; b Light-up solution

The Light-up puzzle can be encoded as a binary string, using a preprocessing to fix light bulbs or white squares. For example, if there is a black square with a 0 condition in it, it means that the squares beside this condition must be white squares, without light bulb in them. In a similar way, black squares with a 4 condition fix 4 light bulbs in the puzzle. In addition, the fact of fixing squares to contain or not light bulbs can affect other squares in the puzzle. This preprocessing is applied at the beginning of the algorithm, then the squares which have not been fixed in this process are encoded in the corresponding algorithm. As an example, Fig. 4 shows the preprocessing procedure and the final encoding of the puzzle: Figure 4a shows the puzzle, Fig. 4b shows the first step of the preprocessing algorithm, where two white squares are fixed (“X” in the figure). Figure 4c shows the second step of the preprocessing, where two light bulbs and the corresponding lit squares (in grey in the figure) are fixed as a consequence of the previous step. Figure 4d shows the unknown squares after the preprocessing procedure, Fig. 4e shows the encoding of these squares, and finally Fig. 4f shows the final solution to the Light-up puzzle considered.
Fig. 4

Example of the preprocessing carried out in a Light-up puzzle and the corresponding puzzle encoding after it; a initial Light-up puzzle; b first step of the preprocessing procedure; c second step of the preprocessing procedure; d squares after the preprocessing procedure; e encoding of the not fixed squares in the puzzle; f final solution of the puzzle

4.1 Previous approaches to solve the Light-up puzzle

Contrary to Japanese puzzles, there are not many works devoted to solve the Light-up puzzle. The most important works on algorithms to solve this puzzle are [12, 20]. In [12] a hybrid Hopfield network-genetic 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 a-priori probabilities of bits defined later. The algorithm in [12] proposes to separate the solution of Light-up 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 Light-up puzzle constraints

Binary HNNs [21], are a special class of neural networks frequently used for solving combinatorial optimization problems [22]. Specifically, the binary HNN used to solve part of the constraints of the Light-up puzzle is a sequential binary HNN, in which the total input to a given neuron i can be defined as:
$$ u_i(t+1)=\sum_{j} w_{ij}x_j(t)-I_j. $$
(18)
where u(t) is the total input of neuron i at time t and x(t) is the output of the neuron at time t. The element w ij is the symmetric interconnection weight from neuron j to neuron i, and I i is the offset bias of neuron i.
Each neuron computes its output at the following time from its input, taking into account that x i at any time is a two-state threshold neuron:
$$ x_i(t+1)=\left\{\begin{array}{ll} 1 & \hbox{if}\,\,u_i(t+1) \leq 0 \\ 0 & \hbox{if}\,\,u_i(t+1) > 0 \end{array} \right. $$
(19)
The application of this Hopfield network to the Light-up puzzle is straight-forward, just by defining weights w ij  = 1 if squares i and j can be lit at once, or w ij  = 0 in the case that they cannot be lit at the same time. The bias term can be removed from the equation, and another improvement can be done by defining a random updating order of neurons, defined by a permutation φ:
$$ u_{\varphi(i)}(t+1)=\sum_{j=1} w_{\varphi(i)j}x_j(t). $$
(20)
and
$$ x_{\varphi(i)}(t+1)=\left\{ \begin{array}{ll} 1 & \hbox{if}\,\,u_{\varphi(i)}(t+1) \leq 0\\ 0 & \hbox{if}\,\,u_{\varphi(i)}(t+1) > 0 \end{array}\right. $$
(21)
This binary Hopfield network is able to obtain repaired solutions which fulfil the rule that no light bulb must lit another light bulb, in the Light-up puzzle. As an example, consider the Light-up puzzle example given in Fig. 5. In this figure a possible (infeasible) solution for a small Light-up puzzle is shown. Note that, in this solution, light bulbs in squares 1 and 2 lit each other, which breaks a puzzle’s rule.
Fig. 5

Possible solution for a small instance of a Light-up puzzle (infeasible solution)

The first cycle (updating of all the neurons in the network), produces the partially repaired solution given in Fig. 6. The light bulb in square 1 has been removed in this case. The second cycle produces the solution given by Fig. 7. This solution is feasible in terms of the light bulbs rule, but it does not fulfil the black square rule, so it is a suboptimal solution. The Hopfield network cannot cope with the black squares rule. Thus, a GA must be used together with the network in order to completely solve the problem.
Fig. 6

Partially repaired solution for the Light-up puzzle (first cycle of the repairing heuristic)

Fig. 7

Feasible solution (suboptimal due to puzzle’s constraints in black squares are not fulfilled)

4.1.2 Complete hybrid genetic algorithm

The final solution to the Light-up puzzle is obtained by means of hybridizing a genetic algorithm (GA) with the Hopfield networks previously defined. The encoding of the problem in the GA is shown in Fig. 3c. The objective function of the GA is detailed in [19], and takes into account the number of lights bulb situated beside black square conditions, and the number of squares that are not lit in the puzzle. Specifically, the function to be minimized by the GA in the example of Fig. 3c is:
$$ \begin{aligned} f(x) = | x_{12}+x_{21}+x_{32}+x_{23}-3|+|x_{14}+x_{23}+x_{34}-2|+|x_{41}+x_{32}+x_{43}-1|+\Phi(X), \end{aligned} $$
(22)
where Φ stands for a function which counts the number of squares not lit in the problem’s grid.
Figure 8 shows an example of how the hybrid algorithm works. After the crossover and mutation operators, the individuals in the population can be unfeasible. The HNN repairs the individuals, and the GA works always with feasible solutions (no light bulb illuminates another light bulb). Note however, that the constraint about the number of squares illuminated must be managed by the GA.
Fig. 8

Scheme of the hybrid Hopfield network-genetic algorithm used in this paper

5 Calculation of a-priori probabilities of bits in the Light-up puzzle

Let us consider a given square in a Light-up 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.

Now let us define the variables nn and nd, which stand for the number of unknown and light bulb variables around a given x ij , i.e,
$$ nn_{ij} = I\{x_{(i-1)j}=6\} + I\{x_{(i+1)j}=6\} + I\{x_{i(j-1)}=6\} + I\{x_{i(j+1)}=6\} $$
(23)
$$ nd_{ij} = I\{x_{(i-1)j}=7\} + I\{x_{(i+1)j}=7\} + I\{x_{i(j-1)}=7\} + I\{x_{i(j+1)}=7\} $$
(24)
with
$$ I_{\{x_{ij}=k\}}=\left\{ \begin{array}{ll} 1 & \hbox{if}\,\,x_{ij}=k \\ 0 & \hbox{otherwise}\\ \end{array} \right. $$
(25)
Using these nn and nd variables, we can calculate, given a constraint square x ij , how many combinations using the neighbor unknown squares there are if we suppose one of them to be light bulb or lit. Note that the neighbor squares are the variables which define nn and nd. These two functions are defined as:
$$ f_{ij} = \left\{ \begin{array}{ll} \left(\begin{array}{l} nn_{ij} - 1 \\ {C_{ij}-nd_{ij}-1} \end{array} \right) & \hbox{if}\,\,x_{ij}=C_{ij}\\ 1 & \hbox{otherwise} \end{array} \right. $$
(26)
$$ g_{ij}=\left\{ \begin{array}{ll} \left(\begin{array}{l} {nn_{ij} - 1 } \\ {C_{ij}-nd_{ij}} \end{array}\right) & \hbox{if}\,\,x_{ij}=C_{ij}\\ 1 & \hbox{otherwise} \\ \end{array} \right. $$
(27)
where f ij provides the number of combinations when we fix one neighbor square to be a light bulb square and g ij provides the number of combinations when we fix it to be a lit square. Note that functions f ij and g ij make sense only with constraint squares, and these functions are 1 other case, in consistency with Eqs. (29) and (30), shown later.

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 .

The calculation of a-priori probabilities of bits in the Light-up puzzle is equivalent to the calculation of the probability p(x ij  = 7), i.e, the probability of a given square to be a light bulb square. We need to evaluate the number of combinations with x ij fixed to be light bulb and fixed to be a lit square, in the following way:
$$ p(x_{ij}=7)=\frac{\hbox{NL}_{ij}}{\hbox{NL}_{ij}+\hbox{NT}_{ij}} $$
(28)
where NL ij is the total number of combinations with x ij fixed to be light bulb:
$$ \hbox{NL}_{ij} = f_{(i-1)j} \cdot f_{(i+1)j} \cdot f_{i(j-1)} \cdot f_{i(j+1)} \cdot 1 $$
(29)
and NT ij fixed to be a lit square:
$$ \hbox{NT}_{ij}= g_{(i-1)j} \cdot g_{(i+1)j} \cdot g_{i(j-1)} \cdot g_{i(j+1)} \cdot (h_i + h_j + h_i \cdot h_j) $$
(30)
In order to clarify the previous results we show a small example, in Fig. 9. Figure 9a shows part of a Light-up puzzle in which we will calculate the probability of x ij to be a light bulb square, i.e, Eq. (28). This square has two neighbor that are constraint squares, the condition C (i-1)j  = 3 and the condition C i(j-1) = 1. Both of them have themselves fixed neighbor squares, in one case, a light bulb square and in the other case a lit square.
Fig. 9

Example of the calculation of the a-priori probabilities for the Light-up puzzle

For the calculation of Eq. (28), we divide the neighborhood in three cases given in Fig. 9b, the two black-squares 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 (i-1)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(j-1) = 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 a-priori 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

In this paper we introduce several improvements in the hybrid evolutionary algorithm described in Sect. 1, using the a-priori probabilities of bits calculated in the previous section. First, this probabilities can be used to initialize the evolutionary algorithm. For this, an initial threshold for the number of cells which will be 0 or 1 in the puzzle (the rest will be unknown cells, i.e. fixed to 2) is fixed. In fact, this threshold has been fixed to be around the 10% of the puzzle’s cells. Thus, for each puzzle’s cell and with a probability of 0.1, it is decided if that cell is fixed to 0 or 1, or not. If the answer is yes, we use the a-priori probability p ij , calculated using Eq. (17), to decide if we fix the cell to 1 or 0. Note that the proposed initialization using the a-priori probabilities of bits obtains initial individuals quite different from an initialization using an uniform distribution (random initialization). To illustrate this point, Fig. 10 shows an example of two different initialization probabilities. Figure 10a shows the puzzle solution, Fig. 10b the initialization using a-priori probabilities and Fig. 10c initialization using an uniform distribution. Note that the initialization given by the a-priori probabilities is much more similar than the one that would be obtained with the uniform distribution (random initialization).
Fig. 10

Example of the initialization with a-priori probabilities in Japanese puzzles. In grey scale, the different probabilities of bits (white stands for a value of 0 and black stands for a value of 1, grey color squares stand for other probabilities, closer to 0 or 1 depending on their intensity); a puzzle solution; b initialization using a-priori probabilities; c initialization with a uniform distribution

In addition to the traditional operators used in the evolutionary algorithm, a novel mutation operator which uses the a-priori probabilities obtained in Sect. 3, is also introduced. It has been called Diversity-Guided Mutation (DGM, hereafter). The idea of the DGM operator is a mutation in which both the population diversity and the a-priori probability of each cell in the puzzle are taken into account. The DGM operator is focussed in each gene of the population (a given cell (mn) in the puzzle), in such a way that only individuals in which this gene is different from 2 are used. We define then a probability for gene i, called q i , which is the probability that the gene i in an individual is set to 1. Note that this q i is different for each stage of the evolutionary algorithm (depends on the current population) and can be calculated as:
$$ q_i=\sum_j \frac{I_{\{g_{ij}=1\}}} {I_{\{g_{ij}=1\}}+I_{\{g_{ij}=0\}}} $$
(31)
where g ij stands for the ith gene in the jth individual of the population.
$$ I_{\{x_j=k\}}= \left\{ \begin{array}{ll} 1 & \hbox{if}\,\,x_j=k\\ 0 & \hbox{otherwise} \end{array} \right. $$
(32)
The criterion to decide if a given gene in the population should be set to 1 is the following:
$$ q_i \cdot p_{mn} \geq (1-q_i) \cdot (1-p_{mn}) $$
(33)
which can be easily rewritten with basic operations as:
$$ q_i+p_{mn} \geq 1 $$
(34)

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 Light-up puzzle

The hybrid Hopfield network genetic algorithm for the Light-up puzzle, described in [19], can be improved by using the a-priori probabilities of bits calculated in Sect. 5. We propose two improvements, one in the initialization of the genetic population and the other one in the initialization of the Hopfield network. Note that we also tested several operators similar to the DGM operator proposed for Japanese puzzles above, but without success in this case (Fig. 11)
Fig. 11

Outline of the proposed EA including the DGM operator for solving Japanese puzzles

.

First, the initialization of the genetic population based on the a-priori probability of bits in the Light-up 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 a-priori probability p ij  = 0.8, this means that the corresponding gene in the genetic algorithm will be a 1 (will contain a light-bulb) 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 Light-up 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 a-priori 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 Light-up grid), are sorted by a-priori probability value, in such a way that the neurons with largest p ij are updated before that the neurons with a low a-priori 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 a-priori probabilities of bits) proposed in this paper. The experiments and results are presented separately for the Japanese puzzle and the Light-up 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 evolutionary-logic 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 logic-type algorithm (preprocessing stage).

We compare the performance of the modified hybrid evolutionary-logic algorithm against the GA in [7]. The parameters of the algorithms are the following: population of 30 individuals in both algorithms, maximum of 50 generations, 2 fitness function evaluations for generation, so a total of 3,000 function evaluations. A comparison in terms of convergence percentage to the optimal puzzles’ solution is carried out (over 50 runs of the algorithms). The results of these experiments can be seen in Table 1. It is easy to see how the proposed hybrid evolutionary-logic algorithm obtains the best results, outperforming the GA in [7] in all the puzzles tackled. The percentage of convergence of the proposed algorithm is over 94% in all the puzzles tested, and reaches the 100% in 12 out of 16 puzzles. The results of the algorithm only implementing the DGM operator (without special initialization) and only with the special initialization (without DGM operator) are also displayed in Table 1 (columns 3 and 4 of the table, respectively). Note that the performance of the algorithm in these cases is worse than the complete algorithm, as expected, but better than the GA in [7]. These data show that the proposed DGM operator is an important feature of the algorithm, which improves significantly its performance. The inclusion of the initialization has influence in improving the algorithm’s performance, but less than the DGM operator.
Table 1

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

Another interesting point is the speed of convergence of the algorithms, measured in number of generations to the convergence (considering only runs in which the algorithms obtained the solution to the puzzle). These results are summarized in Table 2. It is straightforward that the proposed algorithm obtains the solution within a quite small number of generations, 10 in the majority of puzzles. This speed of convergence gets worse when either the DGM or the initialization with a-priori probabilities is not considered, as can be seen in the table. Note that the EA for comparison [7] takes much more generations to obtain the solution to the puzzles.
Table 2

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 Light-up puzzle

Experiments in the Light-up puzzle are carried out in several puzzles obtained from the web site [23]. In this site several Light-up puzzle of different sizes can be freely downloaded. We have focused the experiments in puzzles of size 10 (4 instances) and 14 × 14 (8 instances). Table 3 shows the results obtained with the hybrid Hopfield-genetic algorithm with and without considering a-priori probabilities in Hopfield and initialization procedures. The values in the table indicate the number of maximum fitness evaluations (we stop the algorithm when the solution to the puzzle is obtained), set to 10,000 evaluations in the easiest puzzles (10 × 10), and to 40,000 in the hardest ones (14 × 14), and the percentage of convergence to the optimal solution after launching 200 times the algorithm for each instance. Note that the inclusion of the operators based on a-priori probabilities of bits equals or improves the percentage of convergence of the algorithm in all cases. A detailed analysis of the results based on the different performance of the proposed approach including the new operators can be carried out. Note that the application of the a-priori probabilities operators only in the Hopfield network (WPH in the table) improves the performance of the algorithm, if we compare against the original one (WOP in the table). It is interesting that the application of the EA initialization using a-priori probabilities (WPI) improves the original algorithm, but the improvement is smaller than in the previous case. However, when both new operators are included in the algorithm (column WP), the performance of the resulting algorithm is better than the previous cases, and of course much better than the original algorithm.
Table 3

Results obtained (probability of convergence to the puzzle’s optimal solution) in several Light-up instances from [23], with and without including the new operators based on a-priori 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

Table 4 shows the results in terms of speed of convergence of the proposed EA with and without a-priori probabilities (considering only runs in which the solution to the puzzle was obtained). This table also shows the real number of variables of each instance once a pre-processing step to eliminate trivial constraints is applied. It is easy to see that in these puzzles, the a-priori probabilities improve the performance in terms of quality of solutions obtained (Table 3), but the speed of convergence is almost equal in this case (there are very small differences in the average number of generations to convergence when considering a-priori probabilities).
Table 4

Comparison of the average number of generations to the convergence for the different Light-up 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

Also, the inclusion of these operators based on a-priori probabilities of bits makes that the algorithm works in larger instances, which suggests that the approach with a-priori probabilities is more scalable. As an example, the hybrid Hopfield network-genetic algorithm is not able to converge in very large Light-up puzzles, for example 25 × 25, however, the algorithm including the new operators is able to converge in these very large instances. Figure 12 shows the solution found by the algorithm in one of these 25 × 25 instances.
Fig. 12

Solution of a 25 × 25 Light-up instance obtained with the Hopfield-genetic algorithm including the new operators based on a-priori probabilities of bits

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 a-priori probabilities of bits for some kind of puzzles, specifically grid-based puzzles, i.e. puzzles in which the solution is confined into a grid. Specifically, we have focused the work on two popular grid-based puzzles: the Japanese puzzle (also known as nonogram) and the Light-up 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 a-priori probabilities knowledge. This study can be extrapolated to any problem (not only puzzle resolution nor binary encoding) in which the calculation of a-priori 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 CCG08-UAH/AMB-3993 and TEC2006-07010. E. G. Ortiz-García is supported by Universidad de Alcalá, under the University F.P.I. grants program. Á. M. Pérez-Bellido 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 2007-2013.

References

  1. 1.
    Khoo A, Zubek R (2002) Applying inexpensive AI techniques to computer games. IEEE Intell Syst 17(4):48–53CrossRefGoogle Scholar
  2. 2.
    Lucas SS, Kendall G (2006) Evolutionary computation and games. IEEE Comput Intell Mag 1(1):10–18CrossRefGoogle Scholar
  3. 3.
    Kendall G, Parkes A, Spoerer K (2008) A Survey of NP-Complete Puzzles. Int Comput Games Assoc J 31(1):13–34Google Scholar
  4. 4.
    Ortiz-García E, Salcedo-Sanz S, Pérez-Bellido AM, Portilla-Figueras A, Yao X (2008) Solving very difficult Japanese puzzles with a hybrid evolutionary-logic algorithm. Lect Notes Comput Sci 5361:360–369CrossRefGoogle Scholar
  5. 5.
    Batenburg B, Kosters W (2004) A discrete tomography approach to Japanese puzzles. In: Proceedings of the Belgian-Dutch conference on artificial intelligence, pp 243–250Google Scholar
  6. 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. 7.
    Salcedo-Sanz S, Portilla-Figueras J, Pérez.Bellido A, Ortiz-García E, Yao X (2007) Teaching advanced features of evolutionary algorithms using Japanese puzzles. IEEE Trans Edu 50(2):151–155CrossRefGoogle Scholar
  8. 8.
    Conceptis Puzzles Inc (2009) http://www.conceptispuzzles.com
  9. 9.
    Ueda N, Nagao T (1996) NP-completeness results for nonograms via parsimonious reductions. Internal Report, University of Tokyo, Computer Science DepartmentGoogle Scholar
  10. 10.
    Benton J, Snow R, Wallach N (2006) A combinatorial problem associated with nonograms. Linear Algebra Appl 412(1):30–38MATHCrossRefMathSciNetGoogle Scholar
  11. 11.
  12. 12.
    Ortiz-García EG, Salcedo-Sanz S, Pérez-Bellido ÁM, Portilla-Figueras A (2007) A Hybrid Hopfield Network-Genetic Algorithm Approach for the Light-up Puzzle. In: Proceedings of the IEEE conference on evolutionary computation, pp 1403–1407Google Scholar
  13. 13.
  14. 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. 15.
    Duncan G (1999) Puzzle solving. B.Sc. degree final project Report, University of York, Computer Science DepartmentGoogle Scholar
  16. 16.
  17. 17.
    Batenburg KJ, Kosters WA (2009) Solving nonograms by combining relaxations. Pattern Recognition (in press)Google Scholar
  18. 18.
    Salcedo-Sanz S, Ortiz-García E, Pérez.Bellido A, Portilla-Figueras J, Yao X (2007) Solving Japanese puzzles with heuristics. In: IEEE symposium on computational intelligence and games, Honolulu (USA), AprilGoogle Scholar
  19. 19.
    Ortiz-García E, Salcedo-Sanz S, Leiva-Murillo JM, Pérez.Bellido A, Portilla-Figueras J (2007) Automated generation and visualization of picture-logic puzzles. Comput Graph 31:750–760CrossRefGoogle Scholar
  20. 20.
    Salcedo-Sanz S, Ortiz-García EG, Prez-Bellido AM, Portilla-Figueras JA (2008) Using a bank of binary Hopfield networks as constraints solver in hybrid algorithms. Neurocomputing 71:1061–1068Google Scholar
  21. 21.
    Hopfield JJ (1982) Neurons and physical systems with emergent collective computational abilities. Proc Natl Acad Sci USA 79:2554–2558CrossRefMathSciNetGoogle Scholar
  22. 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. 23.
    Light-up puzzle page (2009) http://www.puzzle-Light-up.com/

Copyright information

© Springer-Verlag 2009

Authors and Affiliations

  • E. G. Ortiz-García
    • 1
  • S. Salcedo-Sanz
    • 1
  • Á. M. Pérez-Bellido
    • 1
  • L. Carro-Calvo
    • 1
  • A. Portilla-Figueras
    • 1
  • X. Yao
    • 2
    • 3
  1. 1.Department of Signal Theory and CommunicationsUniversidad de Alcalá, Escuela Politécnica SuperiorMadridSpain
  2. 2.The Centre for Research in Computational Intelligence and Applications (CERCIA), School of Computer ScienceThe University of BirminghamBirminghamUK
  3. 3.Nature Inspired Computation and Applications Laboratory (NICAL)University of Science and Technology of ChinaHefeiPeople’s Republic of China

Personalised recommendations