-
-
Notifications
You must be signed in to change notification settings - Fork 335
terminations
A termination decide when a genetic algorithm should be stopped. GeneticSharp use the GenerationNumberTermination
with just one generation as default termination. This mean that the GA will run just one generation when you call the Start method, after this you can increment the expected generation number of the termination and call the method Resume how many times you want.
There are cases where you want to call the Start method in just wait until some condition be reached, this why termination exist.
If you have some special condition to terminate your GA you can implement the ITermination
interface or extend the TerminationBase
class, but for most of cases you just need to use some of the availables terminations.
var ga = new GeneticAlgorithm(population, fitness, selection, crossover, mutation);
ga.Termination = new GenerationNumberTermination(100);
To use a specific termination, you need to set it on GeneticAlgorithm's Termination property.
ga.termination = new GenerationNumberTermination(100);
The genetic algorithm will be terminate when reach the generation number 100.
ga.termination = new TimeEvolvingTermination(TimeSpan.FromMinutes(5));
The genetic algorithm will be terminate when the evolving exceed the 5 minutes specified.
ga.termination = new FitnessStagnationTermination(100);
The genetic algorithm will be terminate when the best chromosome's fitness has no change in the last 100 generations.
ga.termination = new FitnessThresholdTermination(0.85);
The genetic algorithm will be terminate when the best chromosome reach the expected fitness 0.85.
ga.termination = new AndTermination(
new GenerationNumberTermination(100),
new TimeEvolvingTermination(TimeSpan.FromMinutes(2)));
The genetic algorithm will be terminate when the generation number is greater or equal than 100 and time evolving is greater or equal than 2 minutes.
ga.termination = new OrTermination(
new GenerationNumberTermination(100),
new TimeEvolvingTermination(TimeSpan.FromMinutes(2)));
The genetic algorithm will be terminate when the generation number is greater or equal than 100 or time evolving is greater or equal than 2 minutes.