Permutation chromosome.

Permutation chromosome is based on short array chromosome, but has two features:

all genes are unique within chromosome, i.e. there are no two genes with the same value; maximum value of each gene is equal to chromosome length minus 1.
상속: ShortArrayChromosome
예제 #1
0
        /// <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 void Crossover(IChromosome pair)
        {
            PermutationChromosome p = (PermutationChromosome)pair;

            // check for correct pair
            if ((p != null) && (p.length == length))
            {
                ushort[] child1 = new ushort[length];
                ushort[] child2 = new ushort[length];

                // create two children
                CreateChildUsingCrossover(this.val, p.val, child1);
                CreateChildUsingCrossover(p.val, this.val, child2);

                // replace parents with children
                this.val = child1;
                p.val    = child2;
            }
        }
예제 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PermutationChromosome"/> 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 PermutationChromosome(PermutationChromosome source) : base(source)
 {
 }
예제 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PermutationChromosome"/> 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 PermutationChromosome(PermutationChromosome source) : base(source) { }