TD 06 Solution
TD 06 Solution
Exercise 1:
The aim is to determine the maximum of the function f(x)=x on the interval x ∈ [0,24]. We
seek to obtain an optimal maximum by applying genetic algorithms.
Starting from the two initial solutions, 03 and 17, apply the different operators of the genetic
algorithm over four generations:
- It1: 3pos crossing; mutation (3rd bit)
- It2: 2pos and 3 pos crossing; mutation (last 2 bits)
- It3: 1pos crossing; mutation (3rd bit)
- It4: 2pos crossing; mutation (first bit)
Exercise 2:
Calculate the maximum of the function f(x) = (1-x)2/(1+x) set to the interval x ∈ [0, 31]. The
objective is to use genetic algorithms to find the optimal maximum.
1. Give the size in bits of an individual. Justify your answer.
2. Starting with both solutions 12 and 5. Apply the different operators of Genetic
algorithm for four generations:
a) Crossing (3rd point in the first iteration, 4th point in the second iteration, 2nd
point in the 3rd iteration, and 3rd point in the 4th iteration)
b) Mutation (1st bit in the first iteration, and 3rd bit in the second iteration, 4th bit
in the third iteration, and 3rd bit in the fourth iteration)
c) Selection (justify your selection for each iteration).
Choose the optimal solution from all the solutions generated in the different iterations. Justify
your choice.
Solution
Exercise 01 :
The size is 5 bits, because the maximum in the range [0-24] can be represented in 5 bits
(11000).
It 1:
Selection:
3 => 00011 ;
17 => 10001
Crossing:
00001
10011
Mutation :
00101 => 5
10111 => 23
f(3) = 3
f(17)= 17
f(5) = 5
f(23) = 23
It 2:
We select 17 and 23 because the solutions checked the criteria (17 and 23 belongs to the range
[0-24]); and its maximizes the function f(x)).
Selection:
17 => 10001
23 => 10111
Crossing:
10101
10011
Mutation:
10110 => 22
10000 => 16
f(17) = 17
f(23)= 23
f(22) = 22
f(16) = 16
It 3:
We select 22 and 23 because the solutions checked the criteria (22 and 23 belongs to the range
[0-24]); and its maximizes the function f(x)).
Selection:
22 => 10110
23=> 10111
Crossing:
10110
10111
Mutation:
10010 => 18
10011 => 19
f(19) = 19
f(18)= 18
f(22) = 22
f(23) = 23
It 4:
We select 22 and 23 because the solutions checked the criteria (22 and 23 belongs to the range
[0-24]); and it maximizes the function f(x)).
Selection:
22 => 10110
23=> 10111
Crossing:
10110
10111
Mutation:
00110=> 6
00111=> 7
f(6) = 6
f(7)= 7
f(22) = 22
f(23) = 23
The optimal solution is 23 because according to the objective function, f(23) = 23 is the value
maximum of all values tested on f(x).
Exercise 2:
1. The size is 5 bits, because the maximum in the range [0-31] can be represented 5 in bit
(11111)
2. It 1:
Selection:
01100 => 12
00101 => 05
Crossing:
01101
00100
Mutation :
11101 => 29
10100=> 20
F(12)= 9.3 F(5)= 2.66 F(29)= 26.13 F(20)=17.19
We select 29 and 20 because the solutions checked the criteria (29 and 20 belongs to the range
[0-31]); and it maximizes the function f(x)).
It2:
Selection:
11101 => 29
10100 => 20
Crossing:
11100
10101
Mutation :
11000 => 24
10001 => 17
We select 29 and 24 because the solutions checked the criteria (29 and 24 belongs to the range
[0-31]); and it maximizes the function f(x)).
It3:
Selection:
11101 => 29
11000 => 24
Crossing:
11101
11000
Mutation:
11111 => 31
11010 => 26
We select 29 and 31 because the solutions checked the criteria (29 and 31 belongs to the range
[0-31]); and it maximizes the function f(x)).
We select 29 and 31 because the solutions checked the criteria (29 and 31 belongs to the range
[0-31]); and it maximizes the function f(x)).
The optimal solution is 31 because according to the objective function, f(31) = 28.25 is
the value maximum of all values tested on f(x).