public void OffspringPopulationBoundaries() { Algorithm nsga = new Nsga2(); int pop = 10; TestFunctions funcs = TestFunctions.GetTestFunctions(); Population parent = new Population(); parent.NewPopulation(pop); Population p = parent.CreateOffspring(); int mistakes = 0; for (int i = 0; i < p.GetCount(); i++) { for (int j = 0; j < p.Get(i).DecisionVariables.Count; j++) { if (p.Get(i).DecisionVariables[0] < funcs.GetLowerThreshold() || p.Get(i).DecisionVariables[j] > funcs.GetUpperThreshold()) { mistakes++; } } } Assert.AreEqual(mistakes, 0); }
public Population StartEvaluation(int populationCount, int generationCount) { infinite = 10000; Population genom = new Population(); genom.NewPopulation(populationCount); Console.WriteLine("Initial population"); genom.PrintToConsole(); Population newGenom = genom.CreateOffspring(); Console.WriteLine("Initial population after creating offspring pop"); genom.PrintToConsole(); Console.WriteLine("Offspring population"); newGenom.PrintToConsole(); FastNonDominatedSort(genom); RankingsPrintToConsole(); for (int i = 0; i < generationCount; i++) { Population combinedGenom = genom.Concat(newGenom); FastNonDominatedSort(combinedGenom); genom.RemoveAll(); AssignCrowdingDistance(); genom.Copy(SortPopulation(combinedGenom).Selection()); newGenom = genom.CreateOffspring(); } newGenom.PrintToConsole(); this.RankingsPrintToConsole(); //PrintToConsole(genom); // genom.PrintToConsole(); return genom; }