1 #ifndef __CONDITION_GENERATION_LIMIT_H
2 #define __CONDITION_GENERATION_LIMIT_H
4 #include "chromosome.h"
5 #include "generation.h"
11 * Condition class. It is used for checking if algorithm should stop after
14 template < typename _Chromosome>
15 class GenerationLimitCondition : public Condition<_Chromosome> {
18 * Variable indicating current generation
20 unsigned int currentGeneration = 0;
23 * Variable indicating max number of generations, after which program
26 const unsigned int maxNumberOfGenerations = 0;
29 * Checks if the given limit of generations has occured
31 * @return true if limit is not reached and another iteration of
32 * calculations should be started, false otherwise
34 bool do_check(const Generation<_Chromosome> &) {
35 /* Initial population is never checked, as method is invoked after
36 * selection, crossover and mutation. It is safe to increment it now.
40 if (currentGeneration < maxNumberOfGenerations) {
48 * Class constructor. Initializes required variables.
50 * @param limit number of generations after which algorithm should stop
52 GenerationLimitCondition(const unsigned int limit)
53 : maxNumberOfGenerations(limit) {
58 #endif /* __CONDITION_GENERATION_LIMIT_H */