Esempio n. 1
0
        /// <summary>
        /// This method needs to be called at the end of the <see cref="Evolve"/>
        /// method.
        /// </summary>
        protected virtual void UpdateState()
        {
            // Update the best individual with the best fitness
            BestIndividual = _population.OrderByDescending(c => c, _problem.FitnessComparer).First();

            // Update generation counter
            CurrentGeneration++;

            // Update evolution time
            var startDateTime = DateTime.Now;

            EvolutionTime += DateTime.Now - startDateTime;

            var oldState = _currentState;

            _currentState = new GeneticAlgorithmState <T>()
            {
                BestIndividual = BestIndividual,
                Generation     = CurrentGeneration,
                Evaluations    = _problem.FitnessFunctionEvaluations,
                ElapsedTime    = EvolutionTime
            };

            RaiseStateChanged(oldState, _currentState);

            UpdateStateAwareComponents();
        }
Esempio n. 2
0
 private void RaiseStateChanged(
     IGeneticAlgorithmState <T> oldState, IGeneticAlgorithmState <T> newState)
 {
     if (StateChanged != null)
     {
         StateChanged(this, new GeneticAlgorithmStateChangedEventArgs <T>(oldState, newState));
     }
 }
 public GeneticAlgorithmStateChangedEventArgs(
     IGeneticAlgorithmState oldState, IGeneticAlgorithmState newState)
 {
     OldState = oldState;
     NewState = newState;
 }