Solving The N-Queens Problem Using Genetic Algorithm:: Chromosome Design
Solving The N-Queens Problem Using Genetic Algorithm:: Chromosome Design
𝐹𝑖𝑡𝑛𝑒𝑠𝑠 𝑓𝑢𝑛𝑐𝑡𝑖𝑜𝑛 = 𝐹1 + 𝐹2 + 𝐹3 + 𝐹4 + 𝐹5
where:
[5 2 4 3 5] fitness function = 7
[4 3 5 1 4] fitness function = 6
[2 1 3 2 4] fitness function = 6
[5 2 3 4 1] fitness function = 5
Then we need to compute the probability of being chosen from the
fitness function. This will be needed for the next selection step. First,
we need to add all fitness functions which will be equal as the
following:
7 + 6 + 6 + 5 = 24
In the next step, we randomly choose the two pairs to reproduce based
on probabilities which we counted on the previous step. In other words,
a certain number of chromosomes will survive into the next generator
using a selection operator. Here selected chromosomes to act as parents
that are combined using crossover operator to make children. In
addition to this, we pick a crossover point per pair.
Here we took randomly following chromosomes based on their
probabilities:
[4 3 5 1 4]
[5 2 4 3 5]
[4 3 5 1 4]
[2 1 3 2 4]
We can notice that we did not take the chromosome [5 2 3 4 1] because
its probability of being chosen is the least among chromosomes.
[4 3 5 1 4]
[5 2 4 3 5]
[4 3 5 1 4]
[2 1 3 2 4]
Here we go to the next step because our fitness value is not equal to
𝐹𝑚𝑎𝑥 which is the maximum number fitness value in the chromosome
that satisfies the condition of the solution of the 5-Queen problem.
𝐹𝑚𝑎𝑥 is equal to 10.
In the crossover, selected chromosomes act as parents that are
combined using crossover operator to make children. In other words, it
combines the genetic information of two parents to generate new
offspring.
Here we can see that children generated from the first pair ([4 3 5 1 4]
and [5 2 4 3 5]) are the following:
[4 3 4 3 5]
[5 2 5 1 4]
From the second pair ([4 3 5 1 4] and [2 1 3 2 4]) the children are the
following:
[4 3 5 2 4]
[2 1 3 1 4]
The next step is mutation. In the mutation process, we alter one or more
gene values in chromosomes which we found after crossover. So it
randomly changes a few genes and the mutation probability is low. So
in our example, our mutation will look like the following:
[4 3 4 3 5] → [4 3 1 3 5]
[5 2 5 1 4] → [5 2 3 1 4]
[4 3 5 2 4] → [4 3 5 2 4]
[2 1 3 1 4] → [2 1 3 5 4]
So until this, the genetic algorithm to solve the 5-Queen algorithm will
look like the following:
In the next step, we need to update the generation. New chromosomes
will update the population but the population number will not change.
So the chromosomes
[4 3 1 3 5]
[5 2 3 1 4]
[4 3 5 2 4]
[2 1 3 5 4]
Steps 3–7 are repeated until chromosome (solution) will satisfy the
following:
Final state
And the corresponding score which equals none other than Fmax.
References:
*******************************************************