Exemple #1
0
        /// <summary>
        /// Fitness function to evaluate the current genetic algorithm. We decode the weights, run the resulting program, and score the output.
        /// </summary>
        /// <param name="weights">Array of double (genes), where each value cooresponds to a Brainfuck program command.</param>
        /// <returns>double, indicating the score</returns>
        private static double fitnessFunction(double[] weights)
        {
            // Get the selected fitness type.
            IFitness myFitness = GetFitnessMethod();

            // Get the fitness score.
            double fitness = myFitness.GetFitness(weights);

            // Is this a new best fitness?
            if (fitness > _bestStatus.Fitness)
            {
                _bestStatus.Fitness        = fitness;
                _bestStatus.TrueFitness    = myFitness.Fitness;
                _bestStatus.Output         = myFitness.Output;
                _bestStatus.LastChangeDate = DateTime.Now;
                _bestStatus.Program        = myFitness.Program;
                _bestStatus.Ticks          = myFitness.Ticks;
            }

            return(fitness);
        }
Exemple #2
0
 public override Int32 CompareTo([NotNull] IFitness <Double> other)
 => Fitness.CompareTo(other.GetFitness());