GA: A Full Worked Example
Source: Unit 5 §6
- Minimise .
- Subject to .
- Crossover rate 0.5, mutation rate 0.1, population 10 chromosomes.
- One generation, worked end to end.
Step 1: initialisation and evaluation
Ten values of are drawn, and is computed for each.
Step 2: selection, with normalisation
Sort ascending, then normalise the costs between 0.1 and 0.9:
Here , , and .
- Normalise every cost into [0.1, 0.9] with the formula above.
- Divide each normalised cost by the sum of all of them to get a probability.
- Flip the probabilities, so the lowest-cost chromosome ends up with the highest selection probability.
- Spin the roulette wheel 10 times to fill the mating pool. A random draw of 0.6777 falls in the interval [0.6508, 0.7458], which selects the 5th chromosome, .
is the 7th entry in the initial list above, but the 5th once step 1 sorts the population by cost: the ascending order runs 0.5605 (), 0.7796, −0.5914, 0.1572, then 0.0991 at . The ordinal refers to the sorted population. Say which ordering you are counting in and the discrepancy disappears.
Feeding cost straight into a roulette wheel would give the worst chromosomes the biggest arcs. Step 3 is not decoration; it is what converts a cost into a fitness. Any minimisation GA needs an equivalent flip.
Step 3: directional crossover
A crossover rate of 0.5 over 10 chromosomes means 5 crossovers; a mutation rate of 0.1 means 1 mutation.
- Take , , and a random .
- .
- .
Every new offspring must lie within . If it does not, the parent is not replaced. Skipping this check is how a real-coded GA quietly starts evaluating points outside its own domain.
Step 4: mutation
Randomly select an offspring - say the third - and replace it with a new random number drawn from .
Step 5: termination
Stop after a set number of generations, or on another criterion. Otherwise loop back to the evaluation in step 1 and run the next generation.