| |||||
| |||||
A very simple example illustrates the mechanics of the algorithm. Figure 11.3 shows the function
for 0 ≤ x < 16. Let the population consist of four units A, B, C, and D with solutions x encoded in 4-bit strings. (A simple function and small population were chosen to provide a clear example. Normal functions are not so simple and populations are larger.)
Units are initialized with random values for the first generation.
Generation 1
unit | x | bits | J | fi |
A | 1 |
0001 | 28 |
0.1854 |
B | 9 |
1001 | 60 |
0.3973 |
C | 15 |
1111 | 0 |
0 |
D |
6 | 0110 |
63 | 0.4742 |
After random selection weighted by fitness, the population is A, B, D, D. Unit C with fitness 0 has died and unit D, with the highest fitness, is selected twice.
New Population
unit | |
---|---|
A |
0001 |
B | 1001 |
D |
0110 |
D | 0110 |
A mates to D and B mates to D, both with crossover after the 3rd bit.
Mating results
unit | |
---|---|
a |
0000 |
b | 1000 |
c |
0111 |
d | 0111 |
Mutation flips the 3rd bit in a.
Mutation results
unit | |
---|---|
a |
0010 |
b | 1000 |
c |
0111 |
d | 0111 |
The resulting population after one generation is
Generation 2
unit | x | bits | ||
---|---|---|---|---|
J | fi | |||
a | 2 |
0010 | 39 |
0.1696 |
b | 8 |
1000 | 63 |
0.2739 |
c | 7 |
0111 | 64 |
0.2782 |
d | 7 |
0111 | 64 |
0.2782 |
Units c and d have already reached the maximum of the function at x = 7 and the average score has increased from 37.75 to 57.75.