Remove some not used namespace declarations.
[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 namespace genetic {
10     /**
11      * Condition class. It is used for checking if algorithm should stop after
12      * iteration.
13      */
14     template < typename _Chromosome>
15     class GenerationLimitCondition : public Condition<_Chromosome> {
16     protected:
17         /**
18          * Variable indicating current generation
19          */
20         unsigned int currentGeneration = 0;
21
22         /**
23          * Variable indicating max number of generations, after which program
24          * will be stopped
25          */
26         const unsigned int maxNumberOfGenerations = 0;
27
28         /**
29          * Checks if the given limit of generations has occured
30          *
31          * @return true if limit is not reached and another iteration of
32          *      calculations should be started, false otherwise
33          */
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.
37              */
38             currentGeneration++;
39
40             if (currentGeneration < maxNumberOfGenerations) {
41                 return true;
42             }
43
44             return false;
45         }
46     public:
47         /**
48          * Class constructor. Initializes required variables.
49          *
50          * @param limit number of generations after which algorithm should stop
51          */
52         GenerationLimitCondition(const unsigned int limit)
53             : maxNumberOfGenerations(limit) {
54         }
55     };
56 }
57
58 #endif /* __CONDITION_GENERATION_LIMIT_H */