2b175751fb66d15510ae3380d36d28b7c0a8102c
[genetic.git] / include / condition / condition.h
1 #ifndef __CONDITION_CONDITION_H
2 #define __CONDITION_CONDITION_H
3
4 #include "chromosome.h"
5 #include "generation.h"
6
7 using namespace std;
8
9 namespace genetic {
10     /**
11      * Base Condition class.
12      * It is used for checking if algorithm should stop.
13      */
14     template < typename _Chromosome>
15     class Condition {
16     protected:
17         /**
18          * Check calculations for current generation if it passes stop condition
19          * If condition is satisfied, we can check another generation.
20          * All the custom Condition checks should be invoked in this method.
21          *
22          * @param generation reference of current generation to check
23          *
24          * @return true if condition is satisfied and another generation can checked;
25          *      false if condition is not satisfied and algorithm should stop.
26          */
27         virtual bool do_check(const Generation<_Chromosome>&) = 0;
28
29     public:
30         /**
31          * Checks if current generation passes stop condition.
32          * If condition is satisfied, we can check another generation.
33          *
34          * @param generation reference of current generation to check
35          *
36          * @return true if condition is satisfied and another generation can checked;
37          *      false if condition is not satisfied and algorithm should stop.
38          */
39         bool check(const Generation<_Chromosome>& generation) {
40             return do_check(generation);
41         }
42     };
43 }
44
45 #endif /* __CONDITION_CONDITION_H */