Genetic Algorithm One-Max: A Solved Numerical Example

Scenario: Binary String Optimisation — One-Max Problem

The Objective: Evolve a population of 4 binary chromosomes of length 6 toward the global optimum of all 1s using fitness-proportionate selection, single-point crossover, and bit-flip mutation.

Core Mechanics
  • The "Hello World" of GAs: The objective is embarrassingly simple: breed a chromosome of pure 11s. The fitness score requires absolutely no complex math—just count the total number of 11s in the string!
  • Survival of the Fittest: Strings with more 11s are prioritized to become parents. On an exam or trace table, you simply rank the population by their fitness scores, pair up the winners, and leave the losers behind.
  • Targeted Crossover: Just like the Knapsack problem, you will be given an exact crossover point. Slice both parent strings at that specified index and swap their tails to combine their winning bits into a strictly better child.
  • Mutation (The Rescue Operation): If your entire population accidentally loses the 11 at a specific position, crossover can never bring it back! You will be instructed to mutate a specific bit (flipping a 00 back to a 11) to rescue that lost genetic material.

Step 1: The Initial Population

The One-Max problem aims to maximize the number of 1s in a binary string. We begin with a randomly generated population of N=4N=4 chromosomes.

Data PointChromosome (Binary String)
P1101100
P2011011
P3110001
P4001110
Evolution Rules SetupFitness Criteria: Count 1s
Crossover Rules:Cross New #1 & New #2 after bit 3Cross New #3 & New #4 after bit 3
Mutation Rules:Mutate Child C3 at bit 3

Step 2: Fitness Evaluation & Selection

First, we calculate the fitness function f(x)f(x) by counting the 1s. Then, we use Fitness-Proportionate Selection (sorting in descending order) to pair the strongest parents together.

1. Evaluate Fitness

IDChromosomesFitness f(x)f(x)
P11011003
P20110114
P31100013
P40011103

2. Sort & Select (Descending)

RankChromosomesFitness f(x)f(x)
New #1 (P2)0110114
New #2 (P1)1011003
New #3 (P3)1100013
New #4 (P4)0011103

Step 3: Genetic Operations (Crossover & Mutation)

Parents swap genetic material based on the crossover rules. Then, target bits mutate (flip) to introduce new genetic diversity.

1. Apply Crossover

Child IDChromosome
C1
011100
C2
101011
C3
110110
C4
001001

2. Apply Mutation

Child IDChromosome
C1011100
C2101011
C3 (mutated)111110
C4001001

Step 4: Final Generation Evaluation

We evaluate the fitness of the new children. If the stopping criteria is not met, this new generation becomes the parent pool for the next iteration.

Child IDNew ChromosomeGenetics StatusFinal Fitness f(x)f(x)
C1011100Crossover3
C2101011Crossover4
C3111110Mutated5
C4001001Crossover2

Final Takeaway

Look closely at Child C3 in Step 4! While crossover alone only yielded a fitness of 4, the mutation rule flipped its 3rd bit from a 0 to a 1, bumping its final fitness up to 5. This perfectly demonstrates a crucial exam concept: mutation isn't just random noise, it is the exact mechanism that introduces new genetic material to prevent a population from stagnating!