Intelligent Systems II · M2 · papers

Q5(b) Genetic algorithm [10]

Final examination · 24 Nov 2025

Longer past-paper questions on Fuzzy, GA and PSO. Original TEE marks retained; not the M2 paper pattern.

Implement a GA to maximise f(x)=2x^3-5x^2+7xLaTeX: f(x)=2x^3-5x^2+7x for x in [0,15]. Take 4-bit representations of 13, 22, 18, 23. 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. 22, 18 and 23 are outside 0–15 and cannot fit into four bits. Increasing the bit count would encode the numbers but would still violate the stated range. There is no single exact solution satisfying all printed conditions.

The complete worked variant below explicitly changes the invalid parents to their last four bits (values modulo 16), producing [13,6,2,7]. This is one declared repair, not a silent interpretation of the printed question. If the instructor clarifies different corrected data, follow those data.

Given

Printed parents: [13, 22, 18, 23]. Worked variant: [13, 6, 2, 7] with 4 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-5x^2+7xLaTeX: f(x)=2x^3-5x^2+7x

Solution

Step 1. Encode and evaluate the declared parent population
xBinaryFitness substitution
1311012(13³) − 5(13²) + 7(13) = 3640
601102(6³) − 5(6²) + 7(6) = 294
200102(2³) − 5(2²) + 7(2) = 10
701112(7³) − 5(7²) + 7(7) = 490
Step 2. Select the two fittest under the stated assumption

[13, 7] with fitness [3640, 490].

Step 3. Cut after bit 2 and exchange tails
Parent 1Parent 2Child 1Child 2
11 | 0101 | 1111110101
Step 4. Flip the last bit of each child
BeforeAfterDecoded x
1111111014
010101004
Step 5. Evaluate both children
xFitness calculation
142(2744) − 5(196) + 7(14) = 4606
42(64) − 5(16) + 7(4) = 76
Step 6. Compare with the selected parents

Best parent score = 3640; best child score = 4606. Parent average = 2065; child average = 2341. 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.

Final answer. Under these declared repairs and operator choices, children are [14, 4] with fitness [4606, 76]. These are not unique answers to the inconsistent and under-specified original question.

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=13

x^2=13\times13=169\qquad x^3=169\times13=2197LaTeX: x^2=13\times13=169\qquad x^3=169\times13=2197
2x^3=4394\quad 5x^2=845\quad 7x=91LaTeX: 2x^3=4394\quad 5x^2=845\quad 7x=91
f(13)=4394-845+91=3640LaTeX: f(13)=4394-845+91=3640

x=6

x^2=6\times6=36\qquad x^3=36\times6=216LaTeX: x^2=6\times6=36\qquad x^3=36\times6=216
2x^3=432\quad 5x^2=180\quad 7x=42LaTeX: 2x^3=432\quad 5x^2=180\quad 7x=42
f(6)=432-180+42=294LaTeX: f(6)=432-180+42=294

x=2

x^2=2\times2=4\qquad x^3=4\times2=8LaTeX: x^2=2\times2=4\qquad x^3=4\times2=8
2x^3=16\quad 5x^2=20\quad 7x=14LaTeX: 2x^3=16\quad 5x^2=20\quad 7x=14
f(2)=16-20+14=10LaTeX: f(2)=16-20+14=10

x=7

x^2=7\times7=49\qquad x^3=49\times7=343LaTeX: x^2=7\times7=49\qquad x^3=49\times7=343
2x^3=686\quad 5x^2=245\quad 7x=49LaTeX: 2x^3=686\quad 5x^2=245\quad 7x=49
f(7)=686-245+49=490LaTeX: f(7)=686-245+49=490

x=15

x^2=15\times15=225\qquad x^3=225\times15=3375LaTeX: x^2=15\times15=225\qquad x^3=225\times15=3375
2x^3=6750\quad 5x^2=1125\quad 7x=105LaTeX: 2x^3=6750\quad 5x^2=1125\quad 7x=105
f(15)=6750-1125+105=5730LaTeX: f(15)=6750-1125+105=5730

x=5

x^2=5\times5=25\qquad x^3=25\times5=125LaTeX: x^2=5\times5=25\qquad x^3=25\times5=125
2x^3=250\quad 5x^2=125\quad 7x=35LaTeX: 2x^3=250\quad 5x^2=125\quad 7x=35
f(5)=250-125+35=160LaTeX: f(5)=250-125+35=160

x=14

x^2=14\times14=196\qquad x^3=196\times14=2744LaTeX: x^2=14\times14=196\qquad x^3=196\times14=2744
2x^3=5488\quad 5x^2=980\quad 7x=98LaTeX: 2x^3=5488\quad 5x^2=980\quad 7x=98
f(14)=5488-980+98=4606LaTeX: f(14)=5488-980+98=4606

x=4

x^2=4\times4=16\qquad x^3=16\times4=64LaTeX: x^2=4\times4=16\qquad x^3=16\times4=64
2x^3=128\quad 5x^2=80\quad 7x=28LaTeX: 2x^3=128\quad 5x^2=80\quad 7x=28
f(4)=128-80+28=76LaTeX: f(4)=128-80+28=76

“Modulo 16” means keep the remainder after dividing by 16: 22=1×16+6, so its remainder is 6; 18=1×16+2; 23=1×16+7. This is only the declared repair used here, not an unspoken general encoding rule.