Genetic Algorithm to Solve Sliding Tile 8-Puzzle Problem

The research tackled the classical problem in artificial intelligence as 8-puzzle problem with genetic algorithm. The research present the fundamental of genetic algorithm with sliding tile 8-puzzle problem. Starting from current state for state space search into a goal state by depending on the tile’s move (tiles out of place) in the current and compare with the solution of the problem (goal)


Introduction
The 8 puzzle is a game invented by Sam Loyd in 1870s [12].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.Rich [8].
The sliding tile puzzle is also called the n-puzzle, which features n tiles numbered from 1 to n and one blank tile in a square grid.The npuzzle is known in various forms, the most famous being the 8-puzzle and 15-puzzle.A puzzle start with a jumbled arrangement of these tiles.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 Qian [6].The objective of the 8-puzzle is to rearrange a given initial configuration of eight squared tiles on a 3x3 board into a specified goal configuration by successively sliding tiles into the orthogonally adjacent empty square (the blank square).While it would seem easy to find any solution to this problem, we are only interested in obtaining optimal solutions with the fewest moves.There exist 9! possible tile permutations on a 3x3 board, and every second permutation is solvable, there is a total of 9!/2= 181440 solvable problem instances Reinefeld [7].
A genetic algorithm is a search technique used in computing to find exact or approximate solutions to optimization and search problems.Genetic algorithms are a particular class of evolutionary algorithms (also known as evolutionary computation) that use techniques inspired by evolutionary biology such as inheritance, mutation, selection, and crossover also called recombination.
Genetic algorithms are implemented as a computer simulation in which a population of abstract representations called chromosome or the genotype or the genome of candidate solutions called individuals, creatures, or phenotypes to an optimization problem evolves toward better solutions.
The evolution usually starts from a population of randomly generated individuals and happens in generations.In each generation, the fitness of every individual in the population is evaluated, multiple individuals are stochastically selected from the current population based on their fitness, and modified recombined and possibly randomly mutated to form a new population.The new population is then used in the next iteration of the algorithm Mitchell [5].
Commonly, the algorithm terminates when either a maximum number of generations has been produced, or a satisfactory fitness level has been reached for the population.If the algorithm has terminated due to a maximum number of generations, a satisfactory solution may or may not have been reached Qian [6], [10], [11].
The research aims to present the fundamental of heuristic genetic algorithm with sliding tile 8-puzzle problem.Starting from current state for state space search into a goal state by depending on the tile's move (tiles out of place) in the current and compare with the solution of the problem (goal), without blank's move not as classical methods

1-2 Methodology of Genetic Algorithm
A genetic algorithm operates through a simple cycle of stages Konar [3].
i. Creation of a "population" of strings.ii.Evaluation of each string.iii.Selection of best strings.iv.Genetic manipulation to create new population of string.

Flowchart for proposed genetic algorithm with 8-puzzle problem
Below figure (2) Flowchart for proposed genetic algorithm with 8-puzzle problem ١٤٩

2-1 Create the Individuals and Population
Initially many individual solutions are randomly generated to form an initial population size depends on the nature of the problem, covering possible solutions (the search space) Mitchell [5].
In this research, the population size was equal the number of tiles out of place therefore, this is depended on the number of generations.The length of each Individuals varies from one to another with a lower bound of 2 and an upper bound of 24 in 8-puzzles.Also in this research, uses a 9 bits to represent the chromosome.
for example if tile in the index 3 and tile in the index 4 is out of place, then tile in the index 3 has 2 tile's moves (left, down) and tile in the index 4 has 3 tile's moves (right, up, down) therefore the population size must be 5 chromosome.are shown next: The problem : The chromosome

2-2 Selection
During each successive process, a proportion of the existing population is selected generation.Individual solutions are selected through a fitness-based process.The fitness of each solution and preferentially select the best solutions Gen et.al [1].
In this research, used tournament selection method that is one of many methods of selection in genetic algorithms which runs a tournament among a few individuals chosen at random.from the population and selects the winner (the one with the best fitness) for crossover.Below the steps of tournament selection procedure see Mitchell [5] : 1-Choose two individuals at random from population.2-Choose a random r between 0 and 1.
3-Choose k is parameter, for example 0.75 If r < k then the fitter of the two individuals is selected to be parent.
Otherwise the less fit individual is selected.4-The two are then returned to the original population and can be selected again.% then the fitter of the two individuals is selected to be parent.
Else small; % Otherwise the less fit individual is selected.End The two are then returned to the original population and can be selected again.

2-3 Crossover
The next step is to generate a second generation population of solutions from the genetic operators.Crossover (also called recombination).For each new solution to be produced, a pair of "parent" solutions is selected from selected previously.By producing a "offspring" solution.The process continues until a new population of size is generated.The Crossover operator used to generate the next population and have many crossover techniques Goldberg [2].
In this research, in Crossover operation used the ordered chromosomes method.A crossover point is selected on the parents.Since the chromosome is an ordered list, a direct swap would introduce duplicates and remove necessary candidates from the list.Instead, the chromosome up to the crossover point is retained for each parent.The information after the crossover point is ordered as it is ordered in the other parent as represented by:

2-4 Mutation
The mutation is a genetic operator used to maintain genetic diversity from one generation of a population of chromosome to the next.A common method of implementing the mutation operator involve generating a random variable for each bit in a sequence.The purpose of mutation in genetic algorithms is to allow the algorithm to avoid local minima by preventing the population of chromosomes from becoming too similar to each other Koza [4].
In this research, used the order changing method for mutation operator.As represented by :

2-5 Fitness Function
The fitness function depends on the nature of the problem.It computed for every chromosome by depending on the objective function the chromosome Schmidt et.al [9].
We express in this research, the proposed fitness function is calculated by:

2-6 Termination
This generational process is repeated until a termination condition has been terminating.many runs were performed, stop criterion was used like classical measures to accept (reach) the solution and depends on the nature of the problem Goldberg [2].
In this research, classical measures used to reach the goal depend on the number of generation.

The Steps of Proposed Heuristic Genetic Algorithm
Below the illustrated steps of the proposed heuristic genetic algorithm for solving the 8-puzzle problem : Step 1: Create an initial state matrix of the problem as 3x3 grid filled numbers 1-8 and a blank, the length of chromosome represented by: Similarly, the goal state of the problem could be represented : Step 2: Create the initial generation (population) randomly, population size is the number of misplaced tiles (tiles out of place) in initial state, As below in the table (1).Represented the number and direction of tile's move Where R: Right, L: Left, U: Up, D: Down The initial state is some arbitrary arrangement of the tiles.An initial state and goal state are shown next : Initial state Goal state For above example, in the initial state the population size is 5 depend on the tile's moves, when the tile in the index 3 has 2 tile's moves, and the tile in the index 6 has 3 tile's moves are shown next : Index of tile The number of tile's move The direction of tile's move

3-2 Conclusion
The sliding tile puzzle is a typical problem for modeling algorithms involving heuristics.The proposed heuristic genetic algorithm for solving the 8-puzzle is feasible plan, because heuristic rules can be used as fitness function to evaluate the individuals that have evolved in each stage.It founds the feasible solution for a state space search that will enable us to find a series of moves that transform a start puzzle into a goal puzzle.The proposed heuristic genetic algorithm has the ability to find a global solution in a large space.The algorithm performs significantly bettor than the traditional search methods.The dynamic of population size was equal the number of tiles out of place therefore, this is depended on the number of generations in evolutionary computed have been reached to the goal and reduce the region of the space considered.

Step 3 :
let it =1 ; the it is a variable of initialize the iteration number of generation Step 4: Compute fitness value (fitness function) for each chromosome in the generation for proposed heuristic genetic algorithm with 8puzzle problem is given as: F = n : represent the tile's value i : index of tile and Compute the probability of fitness function by : Prob i = F i / Step 5: Compare the fitness function for each chromosome with fitness function of the goal, and also compare the tile's value of chromosome with tile's value of the goal.If the two conditions are satisfied, then record the generation's index and chromosome index.Else go to the next chromosome.Step 6: The next generation are produced by executing Selection, Crossover and Mutation operations respectively.(a): Tournament Selection operator to select the fitter parents.(b): Execute the crossover operator consists of combining parts of individuals to create new individuals as following: Begin Initialize Let Probability select pc = 0.7 ; where (0.5 < pc < 0.8) Let point = randint (length of chromosome); determine the crossover point Let ra = size of population Let k =1 ; k is a counter While k < = ra -Let p1 , p2 pairs of individuals choose d randomly from the population.-Let r a random number ; where (0 < r < 1).IF r > pc (if true then crossover operator is executed)The first part of chromosom about (child 1) is the same as of chromosom in p1 before crossover point Also the first part of chromosom about (child 2) is the same as of chromosom in p2 before crossover point End

3-1 Running the Proposed Heuristic Genetic Algorithm for Solving the 8-Puzzle Problem :
(3)ow two runs of the program in this research.Number of different tiles is 2. therefore length of initial generation is 5. Below table(2)shows the execution of proposed algorithm and the figure(3)shows the number of solution with number of generation for run 1:

of generation No.of solution Run 2:
(4)hows the execution of proposed algorithm and the figure(4)shows the number of solution with number of generation for run 2 :