AForge.Genetic.Population.Crossover C# (CSharp) Метод

Crossover() публичный Метод

Do crossover in the population.
The method walks through the population and performs crossover operator taking each two chromosomes in the order of their presence in the population. The total amount of paired chromosomes is determined by crossover rate.
public Crossover ( ) : void
Результат void
        public virtual void Crossover( )
        {
            // crossover
            for ( int i = 1; i < size; i += 2 )
            {
                // generate next random number and check if we need to do crossover
                if ( rand.NextDouble( ) <= crossoverRate )
                {
                    // clone both ancestors
                    IChromosome c1 = population[i - 1].Clone( );
                    IChromosome c2 = population[i].Clone( );

                    // do crossover
                    c1.Crossover( c2 );

                    // calculate fitness of these two offsprings
                    c1.Evaluate( fitnessFunction );
                    c2.Evaluate( fitnessFunction );

                    // add two new offsprings to the population
                    population.Add( c1 );
                    population.Add( c2 );
                }
            }
        }