I am encoding the interval [x:y] to binary codes like 10101111, so for population, it is like [[1,0,1,1],[0,1,0,1]]
.
I defined the fitness function directly using the value of the function (sin(x)^2
).
For selection, i am using tournament selection and for crossover, only simple exchange part of the chromosome like this: 1(10)0
and 0(01)1
-> 1(01)0
and 0(10)1
.
For mutation, using Bit inversion.
The algorithm kind of works, it can generate the global minimum sometimes, and sometimes local ones. but I don't see the function of crossover in this problem, because the feature of the 'x' is being broken every time (i think), I don't know why, and if it is even right way to code the crossover or maybe the encoding part.