Search code examples
genetic-algorithmgenetic-programming

Choosing parents to crossover in genetic algorithms?


First of all, this is a part of a homework.

I am trying to implement a genetic algorithm. I am confused about selecting parents to crossover.

In my notes (obviously something is wrong) this is what is done as example;

  1. Pc (possibility of crossover) * population size = estimated chromosome count to crossover (if not even, round to one of closest even)
  2. Choose a random number in range [0,1] for every chromosome and if this number is smaller then Pc, choose this chromosome for a crossover pair.

But when second step applied, chosen chromosome count is equals to result found in first step. Which is not always guaranteed because of randomness.

So this does not make any sense. I searched for selecting parents for crossover but all i found is crossover techniques (one-point, cut and slice etc.) and how to crossover between chosen parents (i do not have a problem with these). I just don't know which chromosomesi should choose for crossover. Any suggestions or simple example?


Solution

  • You can implement it like this:

    For every new child you decide if it will result from crossover by random probability. If yes, then you select two parents, eg. through roulette wheel selection or tournament selection. The two parents make a child, then you mutate it with mutation probability and add it to the next generation. If no, then you select only one "parent" clone it, mutate it with probability and add it to the next population.

    Some other observations I noted and that I like to comment. I often read the word "chromosomes" when it should be individual. You hardly ever select chromosomes, but full individuals. A chromosome is just one part of a solution. That may be nitpicking, but a solution is not a chromosome. A solution is an individual that consists of several chromosomes which consist of genes which show their expression in the form of alleles. Often an individual has only one chromosome, but it's still not okay to mix terms.

    Also I noted that you tagged genetic programming which is basically only a special type of a genetic algorithm. In GP you consider trees as a chromosome which can represent mathematical formulas or computer programs. Your question does not seem to be about GP though.