Bigger values for testing results.
[genetic.git] / include / condition / generationLimitCondition.h
1 #ifndef __CONDITION_GENERATION_LIMIT_H
2 #define __CONDITION_GENERATION_LIMIT_H
3
4 #include "chromosome.h"
5 #include "generation.h"
6
7 #include "condition.h"
8
9 using namespace std;
10
11 namespace genetic {
12     /**
13      * Condition class. It is used for checking if algorithm should stop after
14      * iteration.
15      */
16     template < typename _Chromosome>
17     class GenerationLimitCondition : public Condition<_Chromosome> {
18     public:
19     protected:
20         /**
21          * Variable indicating current generation
22          */
23         unsigned int currentGeneration = 0;
24
25         /**
26          * Variable indicating max number of generations, after which program
27          * will be stopped
28          */
29         const unsigned int maxNumberOfGenerations = 0;
30
31         /**
32          * Checks if the given limit of generations has occured
33          *
34          * @return true if limit is not reached and another iteration of
35          *      calculations should be started, false otherwise
36          */
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.
40              */
41             currentGeneration++;
42
43             if (currentGeneration < maxNumberOfGenerations) {
44                 return true;
45             }
46
47             return false;
48         }
49     public:
50         /**
51          * Class constructor. Initializes required variables.
52          *
53          * @param limit number of generations after which algorithm should stop
54          */
55         GenerationLimitCondition(unsigned int limit)
56             : maxNumberOfGenerations(limit) {
57         }
58     };
59 }
60
61 #endif /* __CONDITION_GENERATION_LIMIT_H */