I'm writing a genetic algorithm to minimize a function. I have two questions, one in regards to selection and the other with regards to crossover and what to do when it doesn't happen.
Here's an outline of what I'm doing:
while (number of new population < current population) # Evaluate all fitnesses and give them a rank. Choose individual based on rank (wheel roulette) to get first parent. # Do it again to get second parent, ensuring parent1 =/= parent2 # Elitism (do only once): choose the fittest individual and immediately copy to new generation Multi-point crossover: 50% chance if (crossover happened) do single point mutation on child (0.75%) else pick random individual to be copied into new population. end
And all of this is under another
while loop which tracks fitness progression and number of iterations, which I didn't include. So, my questions:
- As you can see, two parents are chosen randomly in each iteration until the new population is filled up. So, the two same parents may mate more than once and surely several fit parents will mate many more times than once. Is this in any way bad?
- In the obitko tutorial, it says if crossover doesn't happen, then child is exact copy of parents. I don't even understand what that means, so, as you can see, I just picked a random parent (uniformly; no fitness considered) and copied to new population. This seems weird to me. Whether I actually do this or not, my results really don't change that much. What's the proper way to handle the case when crossover doesn't happen?