// Starts and executes algorithm public void Run(int maxRepeat = 9999, double minFitness = 0.999) { if (_prototype == null) { return; } Initialize(); _currentArchiveSize = _populationSize; // Current generation int currentGeneration = 0; int repeat = 0; double lastBestFit = 0.0; for (; ;) { var best = Result; if (currentGeneration > 0) { var status = string.Format("\rFitness: {0:F6}\t Generation: {1}", best.Fitness, currentGeneration); Console.Write(status); // algorithm has reached criteria? if (best.Fitness > minFitness) { FinalizePopulation(); break; } double difference = Math.Abs(best.Fitness - lastBestFit); if (difference <= 0.0000001) { ++repeat; } else { repeat = 0; } if (repeat > (maxRepeat / 100)) { ++_crossoverProbability; } } CreateParentPopulation(); CreateOffspringPopulation(); MutateOffspringPopulation(); UpdateArchivePopulation(); Configuration.Seed(); ++currentGeneration; } }
// Starts and executes algorithm public void Run(int maxRepeat = 9999, double minFitness = 0.999) { if (_prototype == null) { return; } // clear best chromosome group from previous execution ClearBest(); Initialize(_chromosomes); // Current generation int currentGeneration = 0; int repeat = 0; double lastBestFit = 0.0; for (; ;) { var best = Result; var status = string.Format("\rFitness: {0:F6}\t Generation: {1}", best.Fitness, currentGeneration++); Console.Write(status); // algorithm has reached criteria? if (best.Fitness > minFitness) { break; } var difference = Math.Abs(best.Fitness - lastBestFit); if (difference <= 0.0000001) { ++repeat; } else { repeat = 0; } if (repeat > (maxRepeat / 100)) { ReplaceByGeneration = _replaceByGeneration * 3; ++_crossoverProbability; } Replacement(_chromosomes); Configuration.Seed(); lastBestFit = best.Fitness; } }
// Starts and executes algorithm public void Run(int maxRepeat = 9999, double minFitness = 0.999) { if (_prototype == null) { return; } var population = new List <T>(); Initialize(population); // Current generation int currentGeneration = 0; int repeat = 0; double lastBestFit = 0.0; for (; ;) { var best = Result; if (currentGeneration > 0) { var status = string.Format("\rFitness: {0:F6}\t Generation: {1}", best.Fitness, currentGeneration); Console.Write(status); // algorithm has reached criteria? if (best.Fitness > minFitness) { break; } double difference = Math.Abs(best.Fitness - lastBestFit); if (difference <= 0.0000001) { ++repeat; } else { repeat = 0; } if (repeat > (maxRepeat / 100)) { ++_crossoverProbability; } } /******************* crossover *****************/ var offspring = Replacement(population); /******************* mutation *****************/ foreach (var child in offspring) { child.Mutation(_mutationSize, _mutationProbability); } var totalChromosome = new List <T>(population); totalChromosome.AddRange(offspring); /******************* non-dominated sorting *****************/ var front = NonDominatedSorting(totalChromosome); /******************* selection *****************/ population = Selection(front, totalChromosome); _populationSize = population.Count; /******************* comparison *****************/ if (currentGeneration == 0) { _chromosomes = population.ToArray(); } else { totalChromosome = new List <T>(population); totalChromosome.AddRange(_chromosomes); var newBestFront = NonDominatedSorting(totalChromosome); _chromosomes = Selection(newBestFront, totalChromosome).ToArray(); lastBestFit = best.Fitness; } Configuration.Seed(); ++currentGeneration; } }