Search code examples
selectiongenetic-algorithmparents

Genetic Algorithm new generation exponentially increasing


I'm programming Genetic Algorithm in C++ and after searching all kind of ways of doing GA'a operators (selection, crossover, mutation) I came up with a doubt. Let's say I have an initial population of 500. My selection will consist in getting the top 20% (based on best fitness). So I get 100 individuals to mate. When I do the crossover I'll get 2 children where both together have 50% of surviving. So far so good. I start the mutation, and everything's ok.. Now when I start choosing the Next generation, I see that I have a big number of children (in this case, 4950 if you wanna know). Now the thing is, every time I run GA, if I send all the children to the next generation, the number of individuals per generation will increase exponentially. So there must be a way of choosing the children to fulfill a new generation without getting out of this range of the initial population.

What I'm asking here is if there is anyway of choosing the children to fill the new generations OR should I choose somehow (and maybe reduce) the parents to mate so I don't get so many children in the end.

Thanks :)


Solution

  • Generally for a GA, you choose your mating algorithm such that the population size remains fixed. So for you example with a population size of 500, you'll choose 250 pairs of fit individuals to mate and have 2 offspring per pair, or choose 500 pairs and have 1 offspring.

    In your example it sounds like you want to consider just the top 20% (100) individuals as 'fit' each generation, so they're the only ones who will produce any children. An alternative is to just weight your random choice of parent pairs so that more fit individuals are more likely to be chosen (and thus will end up with more mates).