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 s. The fitness score requires absolutely no complex math—just count the total number of s in the string!
- Survival of the Fittest: Strings with more s 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 at a specific position, crossover can never bring it back! You will be instructed to mutate a specific bit (flipping a back to a ) 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 chromosomes.
| Data Point | Chromosome (Binary String) |
|---|---|
| P1 | 101100 |
| P2 | 011011 |
| P3 | 110001 |
| P4 | 001110 |
Step 2: Fitness Evaluation & Selection
First, we calculate the fitness function by counting the 1s. Then, we use Fitness-Proportionate Selection (sorting in descending order) to pair the strongest parents together.
1. Evaluate Fitness
| ID | Chromosomes | Fitness |
|---|---|---|
| P1 | 101100 | 3 |
| P2 | 011011 | 4 |
| P3 | 110001 | 3 |
| P4 | 001110 | 3 |
2. Sort & Select (Descending)
| Rank | Chromosomes | Fitness |
|---|---|---|
| New #1 (P2) | 011011 | 4 |
| New #2 (P1) | 101100 | 3 |
| New #3 (P3) | 110001 | 3 |
| New #4 (P4) | 001110 | 3 |
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
| C1 | 011100 |
| C2 | 101011 |
| C3 | 110110 |
| C4 | 001001 |
2. Apply Mutation
| C1 | 011100 |
| C2 | 101011 |
| C3 (mutated) | 111110 |
| C4 | 001001 |
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 ID | New Chromosome | Genetics Status | Final Fitness |
|---|---|---|---|
| C1 | 011100 | Crossover | 3 |
| C2 | 101011 | Crossover | 4 |
| C3 | 111110 | Mutated | 5 |
| C4 | 001001 | Crossover | 2 |
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!