X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=include%2Fcondition%2Fcondition.h;fp=include%2Fcondition%2Fcondition.h;h=3562129a1666999eaad86ea0249029a80012c569;hb=2a8fc81203107eb3495a50fb2666803fda3e0517;hp=0000000000000000000000000000000000000000;hpb=169219566d08e4940d25b66ecdb68e80b90c090d;p=genetic.git diff --git a/include/condition/condition.h b/include/condition/condition.h new file mode 100644 index 0000000..3562129 --- /dev/null +++ b/include/condition/condition.h @@ -0,0 +1,45 @@ +#ifndef __CONDITION_CONDITION_H +#define __CONDITION_CONDITION_H + +#include "chromosome.h" +#include "generation.h" + +using namespace std; + +namespace genetic { + /** + * Base Condition class. + * It is used for checking if algorithm should stop. + */ + template < typename _Chromosome> + class Condition { + protected: + /** + * Check calculations for current generation if it passes stop condition + * If condition is satisfied, we can check another generation. + * All the custom Condition checks should be invoked in this method. + * + * @param generation current generation to check + * + * @return true if condition is satisfied and another generation can checked; + * false if condition is not satisfied and algorithm should stop. + */ + virtual bool do_check(Generation<_Chromosome>) = 0; + + public: + /** + * Checks if current generation passes stop condition. + * If condition is satisfied, we can check another generation. + * + * @param generation current generation to check + * + * @return true if condition is satisfied and another generation can checked; + * false if condition is not satisfied and algorithm should stop. + */ + bool check(Generation<_Chromosome> generation) { + return do_check(generation); + } + }; +} + +#endif /* __CONDITION_CONDITION_H */