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

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

Initializes a new instance of the Population class.
Creates new population of specified size. The specified ancestor becomes first member of the population and is used to create other members with same parameters, which were used for ancestor's creation.
Too small population's size was specified. The /// exception is thrown in the case if is smaller than 2.
public Population ( int size, IChromosome ancestor, IFitnessFunction fitnessFunction, ISelectionMethod selectionMethod ) : System
size int Initial size of population.
ancestor IChromosome Ancestor chromosome to use for population creatioin.
fitnessFunction IFitnessFunction Fitness function to use for calculating /// chromosome's fitness values.
selectionMethod ISelectionMethod Selection algorithm to use for selection /// chromosome's to new generation.
Результат System
        public Population( int size,
                           IChromosome ancestor,
                           IFitnessFunction fitnessFunction,
                           ISelectionMethod selectionMethod )
        {
            if ( size < 2 )
                throw new ArgumentException( "Too small population's size was specified." );

            this.fitnessFunction = fitnessFunction;
            this.selectionMethod = selectionMethod;
            this.size = size;

            // add ancestor to the population
            ancestor.Evaluate( fitnessFunction );
            population.Add( ancestor.Clone( ) );
            // add more chromosomes to the population
            for ( int i = 1; i < size; i++ )
            {
                // create new chromosome
                IChromosome c = ancestor.CreateNew( );
                // calculate it's fitness
                c.Evaluate( fitnessFunction );
                // add it to population
                population.Add( c );
            }
        }