Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Solving 15-Puzzle Problem: #SD20IF007

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

!

"
"* +

#SD20IF007
Solving 15-Puzzle Problem
Each food source in the ABC algorithm has a vector of directions for sliding actions
labeled with ‘1’, ‘2’, ‘3’, and ‘4’ representing a move of the blank one place left, right, up,
down, respectively. The standard ABC algorithm has been developed to solve continuous
optimization problems. For combinatorial problems, it is necessary to convert the real
numbers to integers. In this regard, Eq. (1) has been updated to generate integer numbers. A
food source example is shown in Figure 2. The initial population of candidate solutions
(foods) is generally generated randomly in the standard ABC algorithm. But some of the
randomly generated candidate solutions may include infeasible actions for the puzzle
problem like the movements that are opposite each other are likely to be generated back-to-
back. For example, a down movement after an up movement means that no action will be
taken. The initial population might be generated by preventing back-to-back opposite
movements to overcome this problem. However, the same problem might come up in the
new food sources that will be produced from the old food sources. In this case, it may not
be sufficient to produce a feasible initial population. Furthermore, initialization with
feasible solutions requires more time. This process may reduce the search capability of the
algorithm and may increase the time to find an optimal solution [Karaboga and Akay,
2011].
candidate solutions (foods) is generally generated randomly in the standard ABC
algorithm. But some of the randomly generated candidate solutions may include
infeasible actions for the puzzle problem like the movements that are opposite each
other are likely to be generated back-to-back. For example, a down movement after an
up movement means that no action will be taken. The initial population might be
generated by preventing back-to-back opposite movements to overcome this problem.
However, the same problem might come up in the new food sources that will be
produced from the old food sources. In this case, it may not be sufficient to produce a
feasible initial population. Furthermore, initialization with feasible solutions requires
more time. This process may reduce the search capability of the algorithm and may
increase the time to find an optimal solution [Karaboga and Akay, 2011].

Figure 2: Example of the food source in the ABC algorithm

It is obvious that generation candidate solutions considering the constraints will


add an additional cost to the algorithm. Therefore, candidate solutions were generated
without considering the constraints in the study. The movements that do not comply
with the constraints in the food sources have been ignored and removed from the food
source. Thus, a constrained optimization problem has been replaced by an
unconstrained optimization problem ignoring the constraint with movements.
Examples of possible constraints for movements in candidate solutions are shown in
Figure 3.

Figure 3: Constraints. a) back-to-back opposite moves, b) moves that exceed the


boundary of the puzzle, c) moves that exceed the boundary of the puzzle between
back-to-back opposite moves

The heuristic function based on MD used in the study has been enhanced by linear
conflict (LC). The linear conflict heuristic was the first described in [Hansson et al.
1992]. Two tiles ti and tj are in a linear conflict if they are in the same row or column,
their goal positions are both in that row or column, both tiles are different positions than
they should be. MD and LC calculations are shown in Eqs. (6) and (7), respectively.
For tiles with conflict, the cost of linear conflict heuristics will be at least 2 more than
MD. The objective function used as the sum of the MD and LC is shown in Eq. (8).

𝑀 𝐷 = |𝑥+ − 𝑥 , | + |𝑦+ − 𝑦 , | (6)

𝐿𝐶 = 1, 𝑙𝑖𝑛𝑒𝑎𝑟𝑐𝑜𝑛𝑓𝑙𝑖𝑐𝑡𝑒𝑥𝑖𝑠𝑡𝑠
(7)
L
0, 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
)-+

𝑓!= P 𝑀𝐷(𝑡! ) + 2 ×𝐿𝐶(𝑡! ) (8)


!*+

where N represents the size of the puzzle and ti is the i. tile. In the row or column
conflict, extra movement is required for the movement of the tiles and this cost is added
to the MD.

2.3 Pattern Database


A pattern is the partial specification of an N-puzzle and a method [Culberson and
Schaeffer, 1998] based on dividing the N-puzzle into subsets and solving each subset
separately, ignoring the other tiles. This database has been referred to as the fringe.
Studies [Korf and Felner, 2002], [Felner and Adler, 2005], [Culberson and Schaeffer,
1998] show that it is more effective to solve the puzzle by dividing it into subsets
instead of solving the entire puzzle.

Figure 4: The fringe pattern for the 15-puzzle

Figure 4 shows a 15-puzzle divided into two subsets. As can be seen in the figure,
the tiles of <t1, t2, t3, t4, t5, t9, t13> are placed where they should be, and the locations
of the other tiles are ignored. Then the rest tiles are located. In the study, a pattern
database has been used as in the figure to increase the ABC algorithm’s effectiveness
in solving the puzzle.
The efficiency of the ABC algorithm's search strategy has been increased by
including an iterative deepening search approach. The iterative deepening search,
which is of the uninformed search strategies, is a method with an increasing depth limit
until a solution is found. In the study, the steps in the ABC algorithm to approach the
solution iteratively have been updated with inspiration from the iterative deepening
search. The algorithm firstly tries to find a solution by generating food resources
642 Tuncer A.: 15-Puzzle Problem Solving with the Artificial Bee Colony Algorithm...

according to the predetermined number of moves within a depth of 1. Only if it does


not find the goal state, the algorithm then initializes the food sources and starts
searching within a depth of 2. The value of depth is incremented iteratively until the
predefined depth value. The initial state of the puzzle at each depth is the best state
obtained at the previous depth. Thus, the algorithm starts a little closer to the solution
at each depth and the time to reach the solution is shortened. This approach improves
the heuristic search with the strength of iterative deepening.

3 Experiments

In the study, the ABC algorithm was applied by combining the advantages of
Manhattan distance and linear conflict heuristics, and pattern database. The algorithm
was run on 25 randomly generated solvable instances of the 15-Puzzle. The parameters
of the ABC algorithm are as follows: the number of foods is 80, the limit number is
100, and the max cycle is 100 for each depth. The food length is determined
dynamically, different at each depth. As the goal is approached more at each depth, the
food length, which is initially determined as large, is gradually reduced. In this study,
food length is taken as an initial value of 30. Although a fixed-length value for food
length has been determined, this value becomes less in terms of the total number of
movements when consecutive undesirable moves in the sources are ignored.
Table 1 summarizes the results, averaged over 10 independent runs varying the
initial states of the puzzles. In the table, the best, mean, and worst number of moves
obtained using the ABC algorithm are given. In addition, the number of moves in the
solution of each instance with the IDA* has been also added to the table. However,
with IDA*, it is seen that the number of moves in solutions is less. The reason for this
is that the approach has a deterministic feature. The number of moves in the meta-
heuristic algorithm is greater than IDA* but the difference is negligible. Heuristic
algorithms are expected to produce acceptable results in a reasonable time, rather than
always the optimum results by nature. Considering the number of moves in the
experimental results, it is clearly seen that the ABC algorithm produces acceptable
results.
In Figure 5, the convergence graphic of the ABC algorithm running based on
iterative deepening is given for the first instance in the Table 1. Convergence graphs
also for the other instances occur similarly. As can be seen from the figure, there are
two distinct convergences. The first convergence graphic shows the convergence in the
solution of the first subset of the puzzle divided into two subsets, and the other graphic
shows the convergence in the solution of the second. It is seen from the graphic; the
first subset of the puzzle was solved at the 3rd depth and the second at the 2nd depth.
Tuncer A.: 15-Puzzle Problem Solving with the Artificial Bee Colony Algorithm... 643
Number of moves
No Initial state ABC
IDA*
Best Mean Worst
1 1 5 2 7 10 14 11 6 15 12 9 3 13 0 8 4 34 37 42 45
2 5 6 10 7 1 3 11 8 13 4 15 9 14 0 2 12 38 43 47 51
3 1 11 6 2 10 13 15 5 3 12 0 4 9 7 14 8 40 46 54 62
4 6 5 2 7 13 0 10 12 4 1 3 14 9 11 15 8 44 49 59 68
5 4 3 10 7 6 0 1 2 12 15 5 14 9 13 8 11 44 52 60 68
6 4 10 3 2 1 0 7 8 9 6 13 15 14 12 11 5 44 51 58 69
7 3 4 11 2 9 1 14 15 7 6 0 8 5 13 12 10 44 51 60 72
8 3 10 2 5 15 6 13 4 0 11 1 7 9 12 8 14 46 52 68 79
9 9 4 0 3 14 7 5 12 15 2 13 6 10 1 8 11 46 54 66 79
10 7 1 12 10 6 11 15 4 0 2 5 14 3 13 8 9 48 59 71 85
11 1 13 5 7 14 9 10 12 11 8 2 15 6 0 4 3 48 62 78 88
12 13 9 5 12 10 2 4 11 3 8 0 7 1 14 6 15 48 64 77 86
13 2 13 6 1 14 5 11 0 12 4 8 10 9 3 15 7 50 66 77 89
14 11 3 12 9 2 8 10 14 0 7 15 13 1 6 5 4 50 68 78 92
15 7 6 15 12 14 1 13 3 0 9 8 4 2 11 5 10 50 68 81 94
16 5 8 13 15 14 0 1 7 4 6 10 2 11 9 12 3 52 59 77 92
17 12 2 5 11 10 0 1 6 3 14 8 9 7 4 13 15 52 62 78 91
18 13 3 2 8 12 0 5 1 11 6 9 15 4 14 7 10 52 63 76 89
19 7 13 1 4 9 12 8 5 15 14 0 6 11 2 3 10 52 59 78 91
20 8 11 12 10 2 0 15 1 14 6 4 3 7 9 5 13 54 61 81 93
21 6 8 12 13 7 2 5 14 9 3 1 15 11 0 10 4 54 65 77 94
22 9 12 2 5 11 1 10 14 0 4 3 8 6 15 7 13 54 67 80 92
23 10 12 11 7 8 9 14 5 3 13 4 1 6 0 2 15 56 69 80 96
24 3 10 14 5 1 12 11 8 15 7 9 6 2 0 13 4 56 71 81 95
25 9 3 12 5 4 14 6 11 8 7 15 13 10 0 2 1 56 71 81 92

Table 1: Solutions for 25 randomly generated 15-Puzzle instances using ABC


algorithm

Figure 5: Convergence graphic for ABC algorithm based on iterative deepening and
pattern database
4 Conclusion
A new approach based on the meta-heuristic method using the ABC
algorithm with a solving of the 15-puzzle problem has been proposed in the
study. The efficiency of the Manhattan distance heuristic was improved by
combining it with the linear conflict function. The pattern database method
was implemented for reaching the solution faster. Besides, the efficiency of
the ABC algorithm's search strategy was increased by including an iterative
deepening search approach. It is clear that the ABC algorithm produces
acceptable results given the number of moves in the experimental results,
which proves that the ABC algorithm is an effective method for solving the
15-puzzle problem. It is obvious that the problem cannot be solved with
traditional algorithms as the dimensions of the N-puzzle grow. In this
respect, meta-heuristic algorithms such as the ABC algorithm can be used
effectively in the solution of the N-puzzle problem.

You might also like