Ejemplo n.º 1
0
 /// <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( );
     }
 }
Ejemplo n.º 2
0
        /// <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);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Crossover operator.
        /// </summary>
        ///
        /// <param name="pair">Pair chromosome to crossover with.</param>
        ///
        /// <remarks><para>The method performs one-point or two-point crossover selecting
        /// them randomly with equal probability.</para></remarks>
        ///
        public override void Crossover(IChromosome pair)
        {
            GEPChromosome p = (GEPChromosome)pair;

            // check for correct chromosome
            if (p != null)
            {
                // choose recombination method
                if (rand.Next(2) == 0)
                {
                    RecombinationOnePoint(p);
                }
                else
                {
                    RecombinationTwoPoint(p);
                }
            }
        }
Ejemplo n.º 4
0
        /// <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);
            }
        }