The chromosome represents a Gene Expression, which is used for different tasks of Genetic Expression Programming (GEP).

This type of chromosome represents combination of ideas taken from Genetic Algorithms (GA), where chromosomes are linear structures of fixed length, and Genetic Programming (GP), where chromosomes are expression trees. The GEP chromosome is also a fixed length linear structure, but with some additional features which make it possible to generate valid expression tree from any GEP chromosome.

The theory of Gene Expression Programming is well described in the next paper: Ferreira, C., 2001. Gene Expression Programming: A New Adaptive Algorithm for Solving Problems. Complex Systems, Vol. 13, issue 2: 87-129. A copy of the paper may be obtained on the gene expression programming web site.

Inheritance: ChromosomeBase
Exemplo 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();
     }
 }
Exemplo 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);
            }
        }
Exemplo 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);
                }
            }
        }
Exemplo 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);
            }
        }
Exemplo n.º 5
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();
 }
Exemplo n.º 6
0
        /// <summary>
        /// Two point recombination (crossover).
        /// </summary>
        /// 
        /// <param name="pair">Pair chromosome to crossover with.</param>
        /// 
        public void RecombinationTwoPoint(GEPChromosome pair)
        {
            var rand = Generator.Random;

            // 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);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// One-point recombination (crossover).
        /// </summary>
        /// 
        /// <param name="pair">Pair chromosome to crossover with.</param>
        /// 
        public void RecombinationOnePoint(GEPChromosome pair)
        {
            var rand = Generator.Random;

            // 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);
            }
        }