Accord.Genetic.GEPChromosome.TransposeIS C# (CSharp) Method

TransposeIS() protected method

Transposition of IS elements (insertion sequence).

The method performs transposition of IS elements by copying randomly selected region of genes into chromosome's head (into randomly selected position). First gene of the chromosome's head is not affected - can not be selected as target point.

protected TransposeIS ( ) : void
return void
        protected void TransposeIS()
        {
            var rand = Generator.Random;

            // select source point (may be any point of the chromosome)
            int sourcePoint = rand.Next(length);

            // calculate maxim source length
            int maxSourceLength = length - sourcePoint;

            // select target insertion point in the head (except first position)
            int targetPoint = rand.Next(headLength - 1) + 1;

            // calculate maximum target length
            int maxTargetLength = headLength - targetPoint;

            // select randomly transposed length
            int transposonLength = rand.Next(Math.Min(maxTargetLength, maxSourceLength)) + 1;
            
            // genes copy
            IGPGene[] genesCopy = new IGPGene[transposonLength];

            // copy genes from source point
            for (int i = sourcePoint, j = 0; j < transposonLength; i++, j++)
            {
                genesCopy[j] = genes[i].Clone();
            }

            // copy genes to target point
            for (int i = targetPoint, j = 0; j < transposonLength; i++, j++)
            {
                genes[i] = genesCopy[j];
            }
        }