public void RandomInitialize()
 {
     // Generate Initial Population
     for (int idx = 0; idx < this.InitialPopulationSize; ++idx)
     {
         IndividualBase individual = problem.CreateRandomSolution();
         IndividualEvaluator.Execute(individual, problem);
         AddIndividual(individual);
     }
 }
        protected override void EvaluateObjectiveValues()
        {
            // Create Temporary Individuals
            List <IndividualBase> temporaryList = new List <IndividualBase>();

            for (int iCount = 0; iCount < 200; ++iCount)
            {
                IndividualBase i = Problem.CreateRandomSolution();
                IndividualEvaluator.Execute(i, Problem);
                temporaryList.Add(i);
            }
            double maxValueFound   = temporaryList.Max(I => I.GetFitnessForObjective(Problem.MonoObjectiveGoal));
            double adaptedMaxValue = Math.Abs(maxValueFound) * 2;

            Problem.MonoObjectiveGoal.BigValueForMaximization = adaptedMaxValue;
        }
        private Population_MonoObjective_AG RunGeneration(Population_MonoObjective_AG currentGeneration, SelectionMethodBase selectionMethod, CrossoverMethodBase crossoverMethod, /*IReinsertionMethod reinsertionMethod, */ ReinsertionMethodBase reinsertionMethod)
        {
            Population_MonoObjective_AG recentlyBorn = new Population_MonoObjective_AG(Problem, InitialPopulationSize);

            int expectedChildCount = ((InitialPopulationSize * reinsertionMethod.OffspringPercentage) / 100);

            while (recentlyBorn.IndividualCount < expectedChildCount)
            {
                IndividualBase parent1 = null, parent2 = null, child1 = null, child2 = null;
                selectionMethod.Execute(currentGeneration, out parent1, out parent2);
                crossoverMethod.Execute(parent1, parent2, out child1, out child2);
                recentlyBorn.AddIndividual(child1);
                recentlyBorn.AddIndividual(child2);
            }

            int mutatedChildCount = ((recentlyBorn.IndividualCount * mutationPct) / 100);

            for (int idx = 0; idx < mutatedChildCount; ++idx)
            {
                IndividualBase randomIndividual = recentlyBorn.GetRandomIndividual();
                Problem.MutateIndividual(randomIndividual);
            }

            IndividualBase individual = null;

            for (int idx = 0; idx < recentlyBorn.IndividualCount; ++idx)
            {
                individual = recentlyBorn.Content[idx];
                Problem.ValidateIndividual(individual);
                IndividualEvaluator.Execute(individual, Problem);
            }

            Population_MonoObjective_AG newGeneration = reinsertionMethod.Execute(currentGeneration, recentlyBorn);

            return(newGeneration);
        }