1 #ifndef __CONDITION_GENERATION_LIMIT_H
2 #define __CONDITION_GENERATION_LIMIT_H
4 #include "chromosome.h"
5 #include "generation.h"
13 * Condition class. It is used for checking if algorithm should stop after
16 template < typename _Chromosome>
17 class GenerationLimit : public Condition<_Chromosome> {
21 * Variable indicating current generation
23 unsigned int currentGeneration = 0;
26 * Variable indicating max number of generations, after which program
29 unsigned int maxNumberOfGenerations = 0;
32 * Checks if the given limit of generations has occured
34 * @return true if limit is not reached and another iteration of
35 * calculations should be started, false otherwise
37 bool do_check(Generation<_Chromosome>) {
38 /* Initial population is never checked, as method is invoked after
39 * selection, crossover and mutation. It is safe to increment it now.
43 if (currentGeneration < maxNumberOfGenerations) {
51 * Class constructor. Initializes required variables.
53 * @param limit number of generations after which algorithm should stop
55 GenerationLimit(unsigned int limit)
56 : maxNumberOfGenerations(limit) {
61 #endif /* __CONDITION_GENERATION_LIMIT_H */