crossover.py

crossOnes(p1, p2, chrom)

Take two individuals (p1 and p2 ) and a chromosome number (chrom). Crossover the chrom th chromosome of p1 and p2. Return two new individuals that are the same as p1 and p2 , but with the chrom th chromosome replaced with one of the children from the crossover

injectionco(p1, p2, chrom)

Take two individuals (p1 and p2 ) and a chromosome number (chrom). Crossover the chrom th chromosome of p1 and p2 as follows:

  1. Select distinct points A < B between 0 and len(p1.chromosomes[chrom])
  2. Make an empty child chromosome of length len(p1.chromosomes[chrom])
  3. Copy over the genes of p1 from A to (but not including) B into the corresponding genes of the child
  4. Fill in the rest of the genes of the child with the genes from p2, in the order in which they appear in p2, making sure not to include alleles that already exist in the child

Return a new individual that are the same as p1 , but with the chrom th chromosome replaced with the child from the crossover

Table Of Contents

Previous topic

selection.py

Next topic

mutaion.py

This Page