コード例 #1
0
        /// <summary>
        /// We compare to see if it is worth changing the position of the food
        /// </summary>
        private Vector <double> CompareToFoodLastPosition(Vector <double> centerOfFoodCoordinates)
        {
            if (FoodLastPosition != null)
            {
                if (FitnessFunction.Invoke(FoodLastPosition.ToArray()) > FitnessFunction.Invoke(centerOfFoodCoordinates.ToArray()))
                {
                    centerOfFoodCoordinates = FoodLastPosition;
                }
            }

            FoodLastPosition = centerOfFoodCoordinates;
            return(centerOfFoodCoordinates);
        }
コード例 #2
0
        /// <summary>
        /// Evolve the the population to the next generation.
        /// </summary>
        public void Evolve()
        {
            foreach (T chromosome in _population)
            {
                chromosome.FitnessValue = _fitnessFunction.Invoke(chromosome);
            }

            GetFittestChromsome();

            IList <T> selection = _selection.ApplySelection(_population).Select(x => x.Clone()).ToArray();

            foreach (IEvolveFunction function in _eveolveFunctions)
            {
                function.Execute(selection, this._population);
            }

            EnsureSurvival();

            foreach (T chromosome in _population)
            {
                chromosome.OnEvolved();
            }

            this.CurrentGeneration++;
        }
コード例 #3
0
        /// <summary>
        /// Calculation of fitness for a given krill
        /// </summary>
        public double Evaluate(FitnessFunction fitnessFunction)
        {
            Fitness = fitnessFunction.Invoke(Coordinates.ToArray());

            if (Fitness > BestFitness)
            {
                BestFitness     = Fitness;
                BestCoordinates = Coordinates;
            }

            return(Fitness);
        }
コード例 #4
0
        /// <summary>
        /// Evaluates the Chromosome by invoking the specified delegate method.
        /// The fitness function should return a higher
        /// value for those chromosomes that are deemed fitter.
        /// </summary>
        /// <param name="fitnessFunctionDelegate"></param>
        /// <returns></returns>
        public double Evaluate(FitnessFunction fitnessFunctionDelegate)
        {
            if (fitnessFunctionDelegate == null)
            {
                throw new ArgumentNullException("nameof (fitnessFunctionDelegate)");
            }

            var fitness = fitnessFunctionDelegate.Invoke(this);

            if (fitness < 0 || fitness > 1.0)
            {
                throw new EvaluationException("The fitness value must be within the range 0.0 to 1.0.");
            }

            Fitness = fitness;
            return(fitness);
        }
コード例 #5
0
        /// <summary>
        /// EQUATION 13
        /// </summary>
        private Vector <double> Beta_i_food(Krill krill, int currentIteration, Vector <double> vf_position)
        {
            Vector <double> result = Vector <double> .Build.Dense(krill.Coordinates.Count);

            var K_food = FitnessFunction.Invoke(vf_position.ToArray());

            if (K_food > krill.Fitness)
            {
                double          C_food   = EffectiveFoodCoefficient(currentIteration);
                double          K_i_food = K_i_j(krill.Fitness, K_food);
                Vector <double> X_i_food = X_i_j(krill.Coordinates, vf_position);

                result = X_i_food.Multiply(K_i_food * C_food);
            }

            return(result);
        }
コード例 #6
0
 public double Evaluate(FitnessFunction fitnessFunction)
 {
     Fitness = fitnessFunction.Invoke(this, Dimensions);
     return(Fitness);
 }