protected void TransposeRoot( )
{
// select source point (may be any point in the head of the chromosome)
int sourcePoint = rand.Next( headLength );
// scan downsrteam the head searching for function gene
while ( ( genes[sourcePoint].GeneType != GPGeneType.Function ) && ( sourcePoint < headLength ) )
{
sourcePoint++;
}
// return (do nothing) if function gene was not found
if ( sourcePoint == headLength )
return;
// calculate maxim source length
int maxSourceLength = headLength - sourcePoint;
// select randomly transposon length
int transposonLength = rand.Next( 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( );
}
// shift the head
for ( int i = headLength - 1; i >= transposonLength; i-- )
{
genes[i] = genes[i - transposonLength];
}
// put new root
for ( int i = 0; i < transposonLength; i++ )
{
genes[i] = genesCopy[i];
}
}