Short array chromosome.

Short array chromosome represents array of unsigned short values. Array length is in the range of [2, 65536].

Наследование: ChromosomeBase
Пример #1
0
 /// <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 ShortArrayChromosome(ShortArrayChromosome source)
 {
     // copy all properties
     length   = source.length;
     maxValue = source.maxValue;
     val      = (ushort[])source.val.Clone();
     fitness  = source.fitness;
 }
Пример #2
0
        /// <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(IChromosome pair)
        {
            ShortArrayChromosome p = (ShortArrayChromosome)pair;

            // check for correct pair
            if ((p != null) && (p.length == length))
            {
                // crossover point
                int crossOverPoint = Generator.Random.Next(length - 1) + 1;
                // length of chromosome to be crossed
                int crossOverLength = length - crossOverPoint;
                // temporary array
                ushort[] temp = new ushort[crossOverLength];

                // copy part of first (this) chromosome to temp
                Array.Copy(val, crossOverPoint, temp, 0, crossOverLength);
                // copy part of second (pair) chromosome to the first
                Array.Copy(p.val, crossOverPoint, val, crossOverPoint, crossOverLength);
                // copy temp to the second
                Array.Copy(temp, 0, p.val, crossOverPoint, crossOverLength);
            }
        }
Пример #3
0
 /// <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 ShortArrayChromosome(ShortArrayChromosome source)
 {
     // copy all properties
     length = source.length;
     maxValue = source.maxValue;
     val = (ushort[])source.val.Clone();
     fitness = source.fitness;
 }