2. • We are given an n by n checkboard in which
every field can have a different colour from a
set of four colours.
• Goal is to achieve a checkboard in a way that there
are no neighbours with the same colour (not diagonal)
1 2 3 4 5 6 7 8 9 10
1
2
3
4
5
6
7
8
9
10
1 2 3 4 5 6 7 8 9 10
1
2
3
4
5
6
7
8
9
10
3. The size of a population populationSize = 4
The size of the matrix we'll be using as a solution matrixSize = 4
Build a data structure to contain the initial population population =
zeros( matrixSize, matrixSize, populationSize );
• The checkboard contain 4 colors which shows by number 0 to 3.
it is a node-edge problem so the maximum fitness can easily be computed
optimalFitness = 2 * ( ( matrixSize - 1 ) * matrixSize )=2*3*4=24;
Performance
Initialize:
for( i = 1:populationSize )
population( :, :, i ) = fix( 4 * rand( matrixSize, matrixSize ) );
end
10. Number of chromosome which bestindividual is memorized to do
crossovers a3 = fix (populationSize*rand(1))+1;
Number of chromosome which bestindividual is memorized after crossovers
a4 = fix (populationSize*rand(1))+1;
a3 = 4
a4 = 4
Generation = 1