Intelligent Systems II · TEE · mocks
Q5(a) Genetic algorithm [10]
Re-examination · 31 Jan 2026
100-mark timed practice using the actual Re-exam 2026 paper. Q1 compulsory; any four of Q2–Q7. Worked solutions are below the questions.
Implement a GA to maximise LaTeX:
f(x)=2x^3-3x^2+8x for x in [0,50]. Take 4-bit representations of 12, 20, 17, 13. Crossover after the second bit and mutate by flipping any one bit. Produce two offspring and comment on fitness. [10 marks]
Answer
The printed data are inconsistent. 20 and 17 do not fit into four bits, and covering 0–50 needs six bits. We use six-bit encoding to preserve the supplied parent values and the stated range.
Given
Printed parents: [12, 20, 17, 13]. Worked variant: [12, 20, 17, 13] with 6 bits. For the unspecified selection step, select the two highest-fitness candidates. For the unspecified mutation location, flip the last bit of each child. Crossover is after bit 2.
To find
Two valid children under the declared assumptions and their fitness.
Formula and why it applies
Encoding must respect the candidate range. Crossover swaps tails; mutation flips the chosen bit. Fitness is evaluated after mutation.
f(x)=2x^3-3x^2+8xSolution
Step 1. Encode and evaluate the declared parent population
| x | Binary | Fitness substitution |
|---|---|---|
| 12 | 001100 | 2(12³) − 3(12²) + 8(12) = 3120 |
| 20 | 010100 | 2(20³) − 3(20²) + 8(20) = 14960 |
| 17 | 010001 | 2(17³) − 3(17²) + 8(17) = 9095 |
| 13 | 001101 | 2(13³) − 3(13²) + 8(13) = 3991 |
Step 2. Select the two fittest under the stated assumption
[20, 17] with fitness [14960, 9095].
Step 3. Cut after bit 2 and exchange tails
| Parent 1 | Parent 2 | Child 1 | Child 2 |
|---|---|---|---|
| 01 | 0100 | 01 | 0001 | 010001 | 010100 |
Step 4. Flip the last bit of each child
| Before | After | Decoded x |
|---|---|---|
| 010001 | 010000 | 16 |
| 010100 | 010101 | 21 |
Step 5. Evaluate both children
| x | Fitness calculation |
|---|---|
| 16 | 2(4096) − 3(256) + 8(16) = 7552 |
| 21 | 2(9261) − 3(441) + 8(21) = 17367 |
Step 6. Compare with the selected parents
Best parent score = 14960; best child score = 17367. Parent average = 12027.5; child average = 12459.5. Both the best score and the average score increased in this worked variant. An individual child can still be worse than a parent; GA does not guarantee improvement after every random operator.
The printed wording about “two offspring” is not an explicit requirement for two complete generations. The M2 examples separately work two full generations because your class update asks for iteration 2.
Evaluate the polynomial without skipping the powers
Calculate x²=x×x, then x³=x²×x. Multiply each by its coefficient and combine with the written signs. A bit-string repair in the worked answer is an explicitly stated response to inconsistent printed givens; it is not a new instruction in the original paper.
x=12
x^2=12\times12=144\qquad x^3=144\times12=17282x^3=3456\quad 3x^2=432\quad 8x=96f(12)=3456-432+96=3120x=20
x^2=20\times20=400\qquad x^3=400\times20=80002x^3=16000\quad 3x^2=1200\quad 8x=160f(20)=16000-1200+160=14960x=17
x^2=17\times17=289\qquad x^3=289\times17=49132x^3=9826\quad 3x^2=867\quad 8x=136f(17)=9826-867+136=9095x=13
x^2=13\times13=169\qquad x^3=169\times13=21972x^3=4394\quad 3x^2=507\quad 8x=104f(13)=4394-507+104=3991x=16
x^2=16\times16=256\qquad x^3=256\times16=40962x^3=8192\quad 3x^2=768\quad 8x=128f(16)=8192-768+128=7552x=21
x^2=21\times21=441\qquad x^3=441\times21=92612x^3=18522\quad 3x^2=1323\quad 8x=168f(21)=18522-1323+168=17367