Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GeneticAlgorithm"/> class containing
        /// a random population using the specified <see cref="GeneticAlgorithmNS.GeneticSettings"/>.
        /// </summary>
        /// <param name="geneticSettings">The settings that the algorithm should use.</param>
        public GeneticAlgorithm(GeneticSettings geneticSettings)
        {
            // Start timer
            RunTimeStopWatch = new Stopwatch();
            // Set up variables
            GenerationCount      = 0;
            this.GeneticSettings = geneticSettings;
            TopKAgents           = new TopKAgents(geneticSettings.TopKAgentsCount);
            // Make random start population
            MakeRandomPopulation(geneticSettings);

            IsRunning = true;
            IsPaused  = false;
        }
Exemplo n.º 2
0
 // Invokes the calculate fitness method on the current population and
 private void CalculateFitness()
 {
     CurrentPopulation.CalculateFitness(GeneticSettings.FitnessCalculator);
     CurrentAverageFitnessPopulation = CurrentPopulation.AverageFitness;
     TopKAgents.Update(CurrentPopulation.Agents);
 }