Fitness() public method

Compute and return fitness for the given parameters.
public Fitness ( double parameters ) : double
parameters double Candidate solution.
return double
コード例 #1
0
        /// <summary>
        /// Compute the fitness measure by passing the
        /// given parameters to the wrapped problem, and if
        /// candidate solution is an improvement then log
        /// the results.
        /// </summary>
        /// <param name="parameters">Candidate solution.</param>
        /// <param name="fitnessLimit">Preemptive Fitness Limit</param>
        /// <param name="newFeasible">Feasibility of old candidate solution.</param>
        /// <param name="oldFeasible">Feasibility of new candidate solution.</param>
        /// <returns>Fitness value.</returns>
        public override double Fitness(double[] parameters, double fitnessLimit, bool oldFeasible, bool newFeasible)
        {
            double fitness = Problem.Fitness(parameters, fitnessLimit, oldFeasible, newFeasible);

            // Log solutions. If feasibiilty is required then only log feasible solutions.
            if (!OnlyFeasible || newFeasible)
            {
                // Log solutions with better fitness and feasibility.
                if (Tools.BetterFeasibleFitness(oldFeasible, newFeasible, fitnessLimit, fitness))
                {
                    // Ensure log does not exceed desired capacity.
                    if (Log.Count >= Capacity)
                    {
                        // Assume log is sorted in ascending (worsening) order.
                        // Remove worst from the log.
                        Log.RemoveAt(Log.Count - 1);
                    }

                    Solution candidateSolution = new Solution(parameters, fitness, newFeasible);

                    // Add new solution to the log.
                    Log.Add(candidateSolution);

                    // Sort log according to fitness.
                    // This could be implemented more efficiently
                    // but it is not crucial for runtime performance
                    // so this simple implementation is sufficient.
                    Log.Sort(new Solution.FitnessComparer());
                }
            }

            return(fitness);
        }
コード例 #2
0
        /// <summary>
        /// Compute fitness of wrapped problem and print the result.
        /// </summary>
        public override double Fitness(double[] parameters, double fitnessLimit, bool oldFeasible, bool newFeasible)
        {
            double fitness = Problem.Fitness(parameters, fitnessLimit);

            Tools.PrintSolution(parameters, fitness, fitnessLimit, oldFeasible, newFeasible, FormatAsArray);

            return(fitness);
        }