I am trying to implement genetic algorithm for maximizing a function of n variables such that each variable is in the range [-n, n].
In order to make crossover less complex, while generating initial population, I am only generating numbers from 0 to 2n and then while evaluating fitness I subtract n from each of them. Since n may be small, I have decided to use bit strings instead of integer arrays for representing chromosomes.
Now the problem is with generation of illegal values (greater than 2n) during crossover and mutation. One way would be to replace the illegal value with a legal value during both crossover and mutation. But this will be a little complicated and might also affect performance.
So I am wondering if I can leave the checking and replacing at the time of crossover and mutation and instead do it at after both are done.So I after I have the new generation, I will iterate through the chromosomes of each individual and replace illegal strings and calculate fitness. Also, is it possible to get away without replacing the illegal bit-strings?