/// <summary> /// One-point recombination (crossover). /// </summary> /// /// <param name="pair">Pair chromosome to crossover with.</param> /// public void RecombinationOnePoint( GEPChromosome pair ) { // check for correct pair if ( ( pair.length == length ) ) { // crossover point int crossOverPoint = rand.Next( length - 1 ) + 1; // length of chromosome to be crossed int crossOverLength = length - crossOverPoint; // swap parts of chromosomes Recombine( genes, pair.genes, crossOverPoint, crossOverLength ); } }
/// <summary> /// Two point recombination (crossover). /// </summary> /// /// <param name="pair">Pair chromosome to crossover with.</param> /// public void RecombinationTwoPoint( GEPChromosome pair ) { // check for correct pair if ( ( pair.length == length ) ) { // crossover point int crossOverPoint = rand.Next( length - 1 ) + 1; // length of chromosome to be crossed int crossOverLength = length - crossOverPoint; // if crossover length already equals to 1, then it becomes // usual one point crossover. otherwise crossover length // also randomly chosen if ( crossOverLength != 1 ) { crossOverLength = rand.Next( crossOverLength - 1 ) + 1; } // swap parts of chromosomes Recombine( genes, pair.genes, crossOverPoint, crossOverLength ); } }
/// <summary> /// Initializes a new instance of the <see cref="GEPChromosome"/> class. /// </summary> /// /// <param name="source">Source GEP chromosome to clone from.</param> /// protected GEPChromosome( GEPChromosome source ) { headLength = source.headLength; length = source.length; fitness = source.fitness; // allocate genes array genes = new IGPGene[length]; // copy genes for ( int i = 0; i < length; i++ ) genes[i] = source.genes[i].Clone( ); }