7.
In case of 8 queen problem answer the following questions
a. What could be the initial population?
Like beam search GA begins with a set of k randomly generated states called
Population. Or the process with a set of individuals which is called a population.Each
individual is a solution to the problem you want to solve.
In case of 8 queen problem we have the following initial population with 4
individuals:
b. How the 8 queen problem will be modeled GA problem so that GA
can be applied on it?
The GA is implemented for solving 8-queen problem in order
to find all 92 correct solutions. The algorithm starts by initial solution.
Each chromosome is represented by one dimension array with
size equal to 8 and this the idea which reduce the space
search.
Each position refer to row in 8*8 board and the value
containing in the position is represent the Column number for example;
2 5 3 7 6 4 1 0
Where number 2 refer to the Column 2 and the array position
which equal 0 refer to the raw so the queen location is [0,2].
Algorithm: Genetic Algorithm:
Input: Initial random solutions.
Output: All possible solutions for eight queens problem.
Step1
Generate 92 random solutions.
This was done by initializing 92 chromosome (with length of
8) , This is the initial population for GA.
Step2
Evaluate the fitness of each chromosome (solution).
Step3
Rank the chromosomes dep-ending on their fitness’s values
Step4
apply the crossover and mutation on each pair of
chromosomes to generate new solutions.
Step5
Repeat the steps 2,3,4 until rich to the stop condition.
The fitness is calculated be founding the numbers of crossover between the queens
and stop condition.
c. What will be the effect of the crossover and mutation?
Crossover: Once parents having high fitness are selected, crossover essentially marks
the recombining of genetic materials / chromosomes to produce a healthy offspring
In Crossover the offspring themselves are created by crossing over the parent strings
at the crossover point. For example the first child of the first pair gets the first three
digits from the first parent and the remaining digits from the second parent, whereas
the second child gets the first three digits from the second parent and the rest from
the first parent. When two parent states are quite different the crossover operation
can produce a state that is a long way from either parent state. It is often the case
that the population is quite diverse early in the process, so crossover frequently
takes large steps in the state space early in the search process and smaller steps later
on when most individuals are quite similar.
Mutation:
Mutation may or may not occur. In case mutation occurs, it forces a random value of
child to change , thereby shifting the algorithm in either a positive or
negative route.The amount of mutation can greatly affect your results and should be
tweaked based on your domain and the problem you are trying to solve.
In mutation each location is subject to random mutation with a small independent
probability. One digit was mutated in the first, third, and fourth offspring. In the 8
queen problem this corresponds to choosing a queen at random and moving it to a
random square in its column.
d. What will be the fitness function in case of 8 queen problem?
Fitness function: instead of − h as before, use the number of non attacking pairs of
queens. There are 28 pairs of different queens, smaller column first, all together, so
solutions have fitness 28. (Basically, fitness function is 28 − h.)
For example, fitness of the state below is 27 (queens in columns 4 and 7 attack each
other)