Intelligent Systems II · M2 · read

Two generations including roulette selection

3. Genetic algorithms

Candidate → fitness → encoding → selection → crossover → mutation → two complete generations.

Maximise f(x)=x(15-x)+1LaTeX: f(x)=x(15-x)+1 over unsigned 4-bit integers using the supplied GA settings. Perform two complete generations and compare the population fitness. [3 marks · Practice; complete two-generation solution]

Given

Initial ordered population: [2, 5, 9, 12]. Use 4 bits, crossover after bit 2, pair mating-pool slots 1–2 and 3–4. Flip bit 4 of children [2, 4] in every generation. Replace the whole population with the four children; no elitism.

GenerationSelection instruction
1Random draws [0.1, 0.4, 0.65, 0.9]
2Random draws [0.2, 0.4, 0.6, 0.95]

To find

Both generations: evaluation, selection, crossover, mutation, decoding and comparison.

Formula and why it applies

Encoding represents x; it does not change the objective. Crossover exchanges tails. Mutation flips specified bits. Fitness must be recomputed after mutation. Use exactly the supplied selection rule; replacing the weakest by the strongest is not a universal GA step.

Solution

Step 1. Generation 1: evaluate and encode the current population
IndividualxBinaryObjective calculation
1200102 × (15 − 2) + 1 = 27
2501015 × (15 − 5) + 1 = 51
3910019 × (15 − 9) + 1 = 55
412110012 × (15 − 12) + 1 = 37
Step 2. Generation 1: calculate roulette intervals

Fitness weights are nonnegative. The nonnegative objective itself is the fitness in this maximisation example.

\sum F=27+51+55+37\approx170LaTeX: \sum F=27+51+55+37\approx170
IndividualProbability: weight ÷ totalCumulative: old boundary + probability
127 ÷ 170 ≈ 0.1588235290 + 0.158823529 ≈ 0.158823529
251 ÷ 170 ≈ 0.30.158823529 + 0.3 ≈ 0.458823529
355 ÷ 170 ≈ 0.3235294120.458823529 + 0.323529412 ≈ 0.782352941
437 ÷ 170 ≈ 0.2176470590.782352941 + 0.217647059 ≈ 1
Step 3. Generation 1: use the supplied random draws
Random drawInterval containing itSelected individualSelected x
0.10 ≤ 0.1 < 0.15882352912
0.40.158823529 ≤ 0.4 < 0.45882352925
0.650.458823529 ≤ 0.65 < 0.78235294139
0.90.782352941 ≤ 0.9 < 1412

Intervals are left-closed and right-open, except that a draw of exactly 1 selects the last interval. No draw here is on a boundary. Draws select parents with replacement: selecting a parent once does not remove it. Calculations use unrounded weights; the table displays rounded numbers.

Step 4. Generation 1: crossover after bit 2

Keep each prefix and exchange the suffixes. Bit positions are counted from the left starting at 1.

Pool slots pairedParent AParent BChild AChild B
1 & 200 | 1001 | 0100010110
3 & 410 | 0111 | 0010001101
Step 5. Generation 1: mutate only the specified bits
ChildBefore mutationInstructionAfter mutation
10001No mutation0001
20110Flip bit 40111
31000No mutation1000
41101Flip bit 41100
Step 6. Generation 1: decode and evaluate every child
ChromosomeDecode using place valuesObjective
00010 + 0 + 0 + 1 = 11(15−1)+1 = 15
01110 + 4 + 2 + 1 = 77(15−7)+1 = 57
10008 + 0 + 0 + 0 = 88(15−8)+1 = 57
11008 + 4 + 0 + 0 = 1212(15−12)+1 = 37
Step 7. Generation 1: compare and form the next population

Add the objective scores in each population, then divide by its number of individuals.

\overline f_{old}=\frac{27+51+55+37}{4}=\frac{170}{4}=42.5LaTeX: \overline f_{old}=\frac{27+51+55+37}{4}=\frac{170}{4}=42.5
\overline f_{new}=\frac{15+57+57+37}{4}=\frac{166}{4}=41.5LaTeX: \overline f_{new}=\frac{15+57+57+37}{4}=\frac{166}{4}=41.5

Best objective: 55 → 57. Higher is better. The next population is [1, 7, 8, 12]. No elitism is imposed, so the best previous individual is not automatically protected.

Step 8. Generation 2: evaluate and encode the current population
IndividualxBinaryObjective calculation
1100011 × (15 − 1) + 1 = 15
2701117 × (15 − 7) + 1 = 57
3810008 × (15 − 8) + 1 = 57
412110012 × (15 − 12) + 1 = 37
Step 9. Generation 2: calculate roulette intervals

Fitness weights are nonnegative. The nonnegative objective itself is the fitness in this maximisation example.

\sum F=15+57+57+37\approx166LaTeX: \sum F=15+57+57+37\approx166
IndividualProbability: weight ÷ totalCumulative: old boundary + probability
115 ÷ 166 ≈ 0.0903614460 + 0.090361446 ≈ 0.090361446
257 ÷ 166 ≈ 0.3433734940.090361446 + 0.343373494 ≈ 0.43373494
357 ÷ 166 ≈ 0.3433734940.43373494 + 0.343373494 ≈ 0.777108434
437 ÷ 166 ≈ 0.2228915660.777108434 + 0.222891566 ≈ 1
Step 10. Generation 2: use the supplied random draws
Random drawInterval containing itSelected individualSelected x
0.20.090361446 ≤ 0.2 < 0.4337349427
0.40.090361446 ≤ 0.4 < 0.4337349427
0.60.43373494 ≤ 0.6 < 0.77710843438
0.950.777108434 ≤ 0.95 < 1412

Intervals are left-closed and right-open, except that a draw of exactly 1 selects the last interval. No draw here is on a boundary. Draws select parents with replacement: selecting a parent once does not remove it. Calculations use unrounded weights; the table displays rounded numbers.

Step 11. Generation 2: crossover after bit 2

Keep each prefix and exchange the suffixes. Bit positions are counted from the left starting at 1.

Pool slots pairedParent AParent BChild AChild B
1 & 201 | 1101 | 1101110111
3 & 410 | 0011 | 0010001100
Step 12. Generation 2: mutate only the specified bits
ChildBefore mutationInstructionAfter mutation
10111No mutation0111
20111Flip bit 40110
31000No mutation1000
41100Flip bit 41101
Step 13. Generation 2: decode and evaluate every child
ChromosomeDecode using place valuesObjective
01110 + 4 + 2 + 1 = 77(15−7)+1 = 57
01100 + 4 + 2 + 0 = 66(15−6)+1 = 55
10008 + 0 + 0 + 0 = 88(15−8)+1 = 57
11018 + 4 + 0 + 1 = 1313(15−13)+1 = 27
Step 14. Generation 2: compare and form the next population

Add the objective scores in each population, then divide by its number of individuals.

\overline f_{old}=\frac{15+57+57+37}{4}=\frac{166}{4}=41.5LaTeX: \overline f_{old}=\frac{15+57+57+37}{4}=\frac{166}{4}=41.5
\overline f_{new}=\frac{57+55+57+27}{4}=\frac{196}{4}=49LaTeX: \overline f_{new}=\frac{57+55+57+27}{4}=\frac{196}{4}=49

Best objective: 57 → 57. Higher is better. The next population is [7, 6, 8, 13]. No elitism is imposed, so the best previous individual is not automatically protected.

Final answer. After two generations the ordered population is [7, 6, 8, 13]. Best final objective = 57 at x = [7, 8].