/// <summary> /// Clone the chromosome. /// </summary> /// /// <returns>Return's clone of the chromosome.</returns> /// /// <remarks><para>The method clones the chromosome returning the exact copy of it.</para> /// </remarks> /// public override Chromosome ImplementationClone() { PermutationChromosome permutationChromosome = new PermutationChromosome(); permutationChromosome.Length = Length; permutationChromosome.Positions = Positions.ToArray(); return(permutationChromosome); }
/// <summary> /// Crossover operator. /// </summary> /// /// <param name="pair">Pair chromosome to crossover with.</param> /// /// <remarks><para>The method performs crossover between two chromosomes – interchanging /// some parts between these chromosomes.</para></remarks> /// public override Tuple <Chromosome, Chromosome> Crossover(Chromosome pair) { PermutationChromosome p = (PermutationChromosome)pair; if (p == null) { throw new ArgumentNullException("pair"); } if (p.Length != Length) { throw new ArgumentException("The parents must have the same length", "pair"); } ushort[] child1 = new ushort[Length]; ushort[] child2 = new ushort[Length]; // create two children CreateChildUsingCrossover(this.Positions, p.Positions, child1); CreateChildUsingCrossover(p.Positions, this.Positions, child2); return(new Tuple <Chromosome, Chromosome>(new PermutationChromosome(child1), new PermutationChromosome(child2))); }