Applying the Intelligence of Ant and Tabu Search to Solve The 8-puzzle Problem

The research tackled artificial intelligent methods to solve one of the optimization problems by using artificial ant by applying ant colony optimization algorithm and also tabu search algorithm to find the solution of sliding tile 8-puzzel problem. In ant colony algorithm generated many possible solutions depending on finding the difference tiles in initial state from the goal and moving accordingly in the current state of the problem. In Tabu search, many possible solutions have been generated according to the replacement relation between different tiles in initial state to find the optimal solution from many solutions. In this research, the experimental show is very speed to obtain the goal. The source code is written in MATLAB language to simulate these two algorithms.


Introduction
The 8-puzzle is a square tray in which are placed 8 square tiles.The remaining ninth square is uncovered.Each tile has a number on it.A tile that is adjacent to be the blank space can be slid into that space.A game consists of a starting position and a specified goal position [12].A player can slide an adjacent tile into a position occupied by the blank tile.The goal of this game is to move the tiles so as to reach the goal state where all numbers are placed in an increasing order from left to right and from top to bottom [10].The objective of the 8-puzzle is to rearrange a given initial configuration of eight squared tiles on a 3×3 board into a specified goal configuration by successively sliding tiles into the orthogonally adjacent empty square( the blank square) [11and 13].The research aims to solve the 8-puzzle problem by ant colony optimization algorithm and tabu search algorithm through proposed algorithm .This algorithm solves the problem by depending on the different tails.
In this paper, besides this introductory section, ant colony optimization and tabu search are described in sections 2 and section 3. Section 4 presents the Pseudo -code of algorithms.Practically, Representation is explained in section 5. Finally, section 6 concludes this paper.

Ant Colony Optimization
Ant algorithms were first proposed by Dorigo and co-authors [6] as some system of cooperating agents (a multi-agent system) for various optimization problems.Ant algorithms were inspired by the observation of real ant colonies.While walking from the nest to food sources and vice versa, ants deposit on the ground a substance called pheromone, forming in this way a pheromone trail.The role of this trail is to guide ants toward the source of food (or to the nest).It has been shown that the quantity of pheromone left by an ant depends on the amount of food found, it is also obvious that the more the ants which reach the source of food, the stronger the pheromone left [3,4,5,6 and 9].
Ant colony optimization algorithm makes use of simple agents called ants which iteratively construct candidate solutions to a combinatorial optimization problem [4].The ant's solution construction is guided by (artificial) pheromone trail and problem dependent heuristic information.Ant colony optimization algorithm can be applied to any combinatorial optimization problem by defining solution components which the ants use to iteratively construct candidate solutions and on which they may deposit a pheromone.Partial problem solutions are seen as states: Each ant moves from a state i to another state j corresponding to a more complete partial solution.At each step, each ant k computes a set of feasible expansion to its current state and moves to one of these state according to a probability distribution [ 3and 7].

2-1 Pheromone Update
Real ants deposit a substance called pheromone while moving from one point to another point.Artificial ants perform this action by adding a value called trace on the trail levels of moves chosen by them [2,3 and 14].
In this paper, each movement (direction) in the sliding tile 8-puzzelis is given an initial pheromone value denoted by fer equal to 1.The size of the colony of ant is the number of differences between current solution and goal denoted by n.The pheromone update denoted by ∆fer ,then the update rule is as follows: fer new = fer old + Δfer …(1) ∆fer= n/ 9, nine is the number of squares with blank in problem.
…(2) The heuristic information indicates the desirability of assigning the i to the location j.There are several methods to estimate the desirability depending on the problem.In 2011, Alkallak and Sha'ban [2] do not include the heuristic information because the ants movement in some deterministic way and they visit all edges in the search space depending on the constraints of the problem.Also, in this paper, the proposed algorithm is used without heuristic information.
Ant colony optimization algorithm is similar to other metaheuristic.It can be terminated in several manners, repeating the algorithm for a maximized number of iterations or running for a stipulated time [3 and 14].In this paper, termination manner belongs to the solution of the problem obtained

2-2 Pheromone Evaporate
Pheromones evaporate over time, preventing levels becoming unbounded, and allowing the ant colony to "forget" old information.We implemented this by reducing the amount of pheromone on each edge once per cycle, The pheromone evaporation is denoted by p. where 0<p<1 [8].
In this research, the evaporation rate is 0.2, pheromone information is updated (Pheromone Evaporate).The update rule is as follows: fer new = ( 1-p)* fer old …(3)

Tabu Search
Tabu search is based on the neighborhood search with local-optima avoidance, but in a rather deterministic way.The key idea of tabu search is to allow climbing movements when no improving movement (neighboring solution) exists.However, some movements have to be forbidden in order to avoid cycling.So, the tabu search starts from an initial solution s, may be, randomly generated in S and movements repeatedly from a solution to a neighboring one.At each step of the procedure, a set (subset) of the neighboring solutions of the current solution s is considered and the movement that improves most the objective function value f is chosen.If there are no improving movements, tabu search chooses one that at least degrades the objective function, a movement is performed to the best neighbor s′.
In order to avoid returning to the local optimal solution just visited, the reverse movement must be forbidden (prohibited).This is done by storing this movement (or an attribute of the move) into a memory (or more precisely short-term-memory) managed like a circular list T and called a tabu list.The tabu list keeps information on the last movements which have been done during the search process (the parameter is called a tabu list size).Thus, a movement from s to s′ is considered as tabu if it (or its attribute) is contained in the list T. This way of proceeding hinders the algorithm from returning to a solution reached in the last steps.However, it might be worth returning after a while to a solution visited previously to search in another direction.Consequently, an aspiration criterion is introduced to permit the tabu status to be dropped under certain favorable circumstances.Typically, a tabu movement from s to s′ is permitted where the best solution is found so far [1 and 9].

Pseudo -code of Algorithms
In this research, we solved 8-puzzle problem by two algorithms as ant colony and tabu search.In 2010, Sha'ban et al proposed a table which contains the number of tile's move for index of tile and direction of tile's move.Also, in this research, we used this table to generate the number of tile's movement for the index of tile and direction of tile's movement.Below this table (1) [13].

Index of tile
The number of tile's move The direction of tile's move Where: R: Right L: Left U: Up D: Down

4-1 Pseudo -code of Ant Colony Algorithm
Below are steps to solve the problem by ant colony algorithm: 1-Input the initial state of problem 8-puzzel 2-Input the goal of the problem 3-Find the numbers of tail difference between the goal and initial state =d and denoted to the number of ants.4-Initialize the matrix of pheromone trails in Fig. (1)by the creation of the matrix called fer which consists of 9 row and 4 column for each row describes in general how the different tail from the goal must be moved to which direct (R,L,U,D) by: a-Put 1 according to which direction the next movement of the tail b-Put 0 if the tail does not need to moving therefore, for general problem of the matrix should be as follows:

5-1 Practical Representation of Tabu search Method
Below results illustrate that the approach can be applied for solving 8_puzzle problem by tabu search algorithm .In our experiment, input the used initial state and the goal state as array which consist of 1 row and 9 column : Apply the steps of Tabu search algorithm: 1-Initial state : 1 4 3 7 0 6 8 5 2  Goal state: 1 4 0 7 6 5 3 8 2 Iteration (1): 2-To generate the neighbor solution by the creation many solutions by using Move operation.The move operation in the 8_puzzel is making swap between any different tail with others of the current solutions ,so we obtain R solutions as in table (2) In the above example, the number of different tails n=5 The tails (3, 5,6,7 and 8) The number of neighbor solution =10 as in Fig.
(  After sorting the solution according to the different tail, there are many solutions which have it has minimum difference, therefore select the one of them, select the solution s which moves from tail 3 to tail 5 with f(s)=4 tail difference.

35 s= [ 1 4 0 7 3 6 8 5 2 ]
The (short term memory) or tabu list must be as follows: Iteration (2):  After sorting the solution according to difference of tail, there are many solutions with minimum difference, therefore select one of them as example, select the solution s which moves from tail 5 to tail 6 with f(s)=3 tail difference.
67 s=[1 4 0 7 6 8 3 5 2 ] The tabu list must be as follows: At iteration (4), we obtain the best solution S * which has zero different tail one neighbor solution table (4) : The tabu list must be as follows:

5-2 Practical Representation of Ant Colony Method
The results below illustrate that the approach can be applied for solving 8_puzzle problem by Ant colony method.It is implemented to simulate the ants behavior .In our experiment ,the inputs used are initial state and the goal state as an array consists of 1 row and 9 column : e.g: 1-Initial state : 2 8 3 1 6 4 7 0 5 Goal state: 1 2 3 8 0 4 7 6 5 Initialize the matrix of pheromone trails by using Fig.
(1) 2-Find the differences of tails between initial state and the goal state for example n=5 , where n is the number of difference tails in columns (1,2,4,5and 8) in array.5), here we have 15 possible solutions, we have 15 Ant 4-Table (5) describes the solutions( paths) for each ant, the direction, and number of different tail between the path and the goal state ,as well as the pheromone update ∆fer last column.5-Update the pheromone value by equ-1,(see Fig. -4).6-Update the matrix of pheromone evaporation by equ-3 where p=0.2,(seeFig.The optimal solution was obtained when tail 1 moves to Down:

Conclusions
The 8-puzzle problem can be solved by many general heuristics algorithms in artificial intelligence ,so in this paper, it is solved by two heuristics algorithms for combinatorial optimization problems , tabu search and simulating the behavior of real ants through mathematical formulations by using ant colony algorithm.To solve the 8-puzzle problem in the beginning,we must find the number of different tails between the initial state and the goal state, this is considered similarly in the two algorithms of this paper.The difference between the used tabu and ant colony algorithms is the way the trial solutions are generated .In ant colony algorithm trial solutions are constructed incrementally, based on created solutions from all possible moves for the different tail to the suitable direction i.e to the(Right, Left, Up, Down),and consider each result of solution is a path of ant and then apply the steps of ant colony algorithm.On the other hand, in tabu search the trial solutions are use move (swap) operation, with relationships between the different tails that were obtained from the beginning of solution.The relationships are used to construct the neighborhoods and then choose the solution that has minimum number of different tails, then continue with the steps of tabu algorithm ,this is considered efficient and creative good solution.
Tabu search and ant colony optimization perform better than any local optimization method and yield a solution close to global optimum.Despite the classical method (manual method) can give the exact solution, it takes a large space and need more computations.The two algorithms perform significantly better than the traditional search methods.This is dependent on the number of different tail as shown in table (6) .
In tabu search the number of neighborhood obtained by using the rule: But in ACO algorithm the number of ant path obtained by depending on the different tail move for any suitable direction .Table (7 )explains some features used by tabu search and ant colony algorithms in this paper to solve 8-puzzel problem .

Fig.( 1 )
Fig.(1) Matrix of Initializing the Pheromone Trails5-Generate all possible solutions by taking for each different tail of all the possible movements by using Table(1).6-Consider each solution as a result for the previous step which is a path built by Ant 7-Apply the steps of ant algorithm a-Find the ∆fer of pheromone for each path built by ant formulated as in (equa.-2): ∆fer= 9/n , where 9 is the number of all tail in problem 8-puzzel ,where n is the number of different tails in each solution from the goal b-Update the pheromone by using (equa.-1)fernew = fer old + Δfer, now the new pheromone is created.c-Calculate the evaporation according to (equa.-3)fer new = ( 1-p)* fer old , in this paper ,it is assumed that p=0.2Where 0<p<1 d-The path of ant which has higher pheromone is the best solution e-Compare the new solution with the goal f-Compare the numbers of tail difference between the goal and initial state

Fig.( 3 )
Fig.(3) number of neighbor solution of iteration(2) number of possible solutions depends on tail moves for all misplaced tiles in initial state .See table(

Pseudo -Code of Tabu Search Algorithm
Record tabu for the current move in tabu list, i.e. update the tabu list by changing the contents of tabu list as follows: -If solution is not tabu, add solution to tabu list by changing the position of tail to 3 in the next iteration the tabu tenure decrees by one.End whileStep 6: the solution s* as the same of the goal state End

Table ( 2
(1)enerate neighbor solution to create many solutions by using Move operation by iteration(1)

Table ( 3
(2)enerate neighbor solution to create many solutions by using Move operation by iteration(2)

Table ( 6 ) :Explain the
number of solutions that can be obtained by the algorithm used in this paper

Table ( 7
):Explain some features that used by tabu search and Ant colony algorithms