« Back to home

Maximisation Scenario Breakdown

Posted on

Understanding an optimisation problem helps thinking about how best to approach solving it. This post follows the process of analysing a maximisation scenario and implementing a genetic algorithm to solve it. Chromosomes in the scenario are encoded with the structure:

ch = {x0, x1, x2, x3, x4, x5, x6, x7}

where x0-7 can be any digit between zero and nine

Fitness is calculated using the formula:

  • f (ch) = (x0+x1) - (x2+x3) + (x4+x5) - (x6+x7)

I: Calculate fitnesses and sort a sample population…

ch2 = {8, 7, 1, 2, 6, 6, 0, 1}

  • f (ch2) = (8+7) - (1+2) + (6+6) - (0+1) = 23

ch1 = {6, 5, 4, 1, 3, 5, 3, 2}

  • f (ch1) = (6+5) - (4+1) + (3+5) - (3+2) = 9

ch3 = {2, 3, 9, 2, 1, 2, 8, 5}

  • f (ch3) = (2+3) - (9+2) + (1+2) - (8+5) = -16

ch4 = {4, 1, 8, 5, 2, 0, 9, 4}

  • f (ch4) = (4+1) - (8+5) + (2+0) - (9+4) = -19

II: Apply crossovers…

Single point crossover (at the middle) on the best two chromosomes…

Parent 1: ch2 = {8, 7, 1, 2, 6, 6, 0, 1}

Parent 2: ch1 = {6, 5, 4, 1, 3, 5, 3, 2}

  • Child 1: {8, 7, 1, 2, 3, 5, 3, 2}
  • Child 2: {6, 5, 4, 1, 6, 6, 0, 1}

Two point crossover (after x1 and after x5) to cross the 2nd and 3rd best…

Parent 1: ch1 = {6, 5, 4, 1, 3, 5, 3, 2}

Parent 2: ch3 = {2, 3, 9, 2, 1, 2, 8, 5}

  • Child 3: {6, 5, 9, 2, 1, 2, 3, 2}
  • Child 4: {2, 3, 4, 1, 3, 5, 8, 5}

Uniform crossover (0.5 probability) to cross the 1st and 3rd best…

Parent 1: ch2 = {8, 7, 1, 2, 6, 6, 0, 1}

Parent 2: ch3 = {2, 3, 9, 2, 1, 2, 8, 5}

  • Child 5: {2, 7, 9, 2, 6, 2, 8, 1}
  • Child 6: {8, 3, 1, 2, 1, 6, 0, 5}

III: Evaluate new offspring…

of1 = {8, 7, 1, 2, 3, 5, 3, 2}

  • f (of1) = (8+7) - (1+2) + (3+5) - (3+2) = 15

of2 = {6, 5, 4, 1, 6, 6, 0, 1}

  • f (of2) = (6+5) - (4+1) + (6+6) - (0+1) = 17

of3 = {6, 5, 9, 2, 1, 2, 3, 2}

  • f (of3) = (6+5) - (9+2) + (1+2) - (3+2) = -2

of4 = {2, 3, 4, 1, 3, 5, 8, 5}

  • f (of4) = (2+3) - (4+1) + (3+5) - (8+5) = -5

of5 = {2, 7, 9, 2, 6, 2, 8, 1}

  • f (of5) = (2+7) - (9+2) + (6+2) - (8+1) = -3

of6 = {8, 3, 1, 2, 1, 6, 0, 5}

  • f (of6) = (8+3) - (1+2) + (1+6) - (0+5) = 10

The offspring have a mean fitness of five (rounded from 5.33) which is a signifigant improvement on negative one (rounded from 0.75) of their parents. However the maximum chromosome of both generations ( f [ch2]=23 got six greater than the second best ( f [of2]=17).


IV: Chromosome with the maximum fitness…

op = {9, 9, 0, 0, 9, 9, 0, 0}

  • f (op) = (9+9) - (0+0) + (9+9) - (0+0) = 36

V: Reaching the optimal solution…

The initial population would be able to crossover to the solution if each gene in op were present, however they are missing:

x0=9, x1=9, x3=0, x4=0, x5=9, x6=9 and x8=0

Due to this, using crossover alone would not reach the optimal solution no matter how many generations or large a population. A stochastic type of exploration like the mutation modification would work.


For Natural Computing (IS53052A)