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:
Some parents having several offspring is common; I'd even say this is the default practice (and consider biological evolution, where precisely this is one of the main ingredients).
"If crossover doesn't happen, then child is exact copy of parents"
That is a bit confusing. Crossover (well explained in your link) means taking some genes from one parent and some from the other. This is called sexual reproduction and requires two (or more?) parents.
But asexual reproduction is also possible. In this case, you simply take one parent and mutate its genome in the new individual. This is almost what you were attempting, but you are missing the important mutation step (note mutations can be very aggressive or very conservative!)
Note that asexual reproduction requires mutation after copying the genome to create diversity, while in sexual reproduction this is an optional step.
It is fine to use either type of reproduction, or a mix of them. By the way: in some problems genes might not always have the same size. Sexual reproduction is problematic in this case. If you are interested in this problem, take a look at the NEAT algorithm, a popular neuroevolution algorithm designed to address this (wiki and paper).
Finally, elitism (copying the best-performing individuals to the next generation) is common, but it may be problematic. Genetic algorithms often stall in sub-optimal solutions (called local maxima, where any changes decrease fitness). Elitism can contribute to this problem. Of course, the opposite problem is too much diversity being similar to random search, so you need to find the right balance.