1 #ifndef __ALGORITHM_CONDITION_H
2 #define __ALGORITHM_CONDITION_H
4 #include "chromosome.h"
5 #include "generation.h"
12 * It is used for checking if algorithm should stop.
14 * By default stops algorithm after 1000 of generations.
16 template < typename _Chromosome>
21 * Variable indicating current generation
23 unsigned int currentGeneration = 0;
26 * Variable indicating max number of generations, after which program
29 const unsigned int maxNumberOfGenerations = 1000;
34 * Checks if current generation passes stop condition.
35 * If condition is satisfied, we can check another generation.
37 * @param generation current generation to check
39 * @return true if condition is satisfied and another generation can checked;
40 * false if condition is not satisfied and algorithm should stop.
42 virtual bool check(Generation<_Chromosome>) {
43 /* Initial population is never checked, as method is invoked after
44 * selection, crossover and mutation. It is safe to increment it now.
48 if (currentGeneration < maxNumberOfGenerations) {
57 #endif /* __ALGORITHM_CONDITION_H */