/// <summary> /// Crossover operator. /// </summary> /// /// <param name="pair">Pair chromosome to crossover with.</param> /// /// <remarks><para>The method performs crossover between two chromosomes interchanging /// range of genes (array elements) between these chromosomes.</para></remarks> /// public override void Crossover(AForge.Genetic.IChromosome pair) { ModelItemArrayChromosome p = (ModelItemArrayChromosome)pair; // check for correct pair if ((p != null) && (p.Mic.Length == Mic.Length)) { // crossover point int crossOverPoint = rand.Next(Mic.Length - 1) + 1; // length of chromosome to be crossed int crossOverLength = Mic.Length - crossOverPoint; // temporary array uint[] temp1 = new uint[crossOverLength]; uint[] temp2 = new uint[crossOverLength]; ObjectItem[] temp3 = new ObjectItem[crossOverLength]; // copy part of first (this) chromosome to temp Array.Copy(start, crossOverPoint, temp1, 0, crossOverLength); Array.Copy(end, crossOverPoint, temp2, 0, crossOverLength); Array.Copy(Micp, crossOverPoint, temp3, 0, crossOverLength); // copy part of second (pair) chromosome to the first Array.Copy(p.start, crossOverPoint, start, crossOverPoint, crossOverLength); Array.Copy(p.end, crossOverPoint, end, crossOverPoint, crossOverLength); Array.Copy(p.Micp, crossOverPoint, Micp, crossOverPoint, crossOverLength); // copy temp to the second Array.Copy(temp1, 0, p.start, crossOverPoint, crossOverLength); Array.Copy(temp2, 0, p.end, crossOverPoint, crossOverLength); Array.Copy(temp3, 0, p.Micp, crossOverPoint, crossOverLength); } }
/// <summary> /// Initializes a new instance of the <see cref="ShortArrayChromosome"/> class. /// </summary> /// /// <param name="source">Source chromosome to copy.</param> /// /// <remarks><para>This is a copy constructor, which creates the exact copy /// of specified chromosome.</para></remarks> /// protected ModelItemArrayChromosome(ModelItemArrayChromosome source) { // copy all properties length = source.length; Mic = source.Mic; Micp = (ObjectItem[])source.Micp.Clone(); minValues = source.minValues; sItems = source.sItems; start = (uint[])source.start.Clone(); end = (uint[])source.end.Clone(); durations = source.durations; oDurations = source.oDurations; si = source.si; fitness = source.fitness; }