X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;ds=sidebyside;f=include%2Ffitness%2Ffitness.h;fp=include%2Ffitness%2Ffitness.h;h=a9750341f32271db145a514c42b5d8691a3ae931;hb=2a8fc81203107eb3495a50fb2666803fda3e0517;hp=0000000000000000000000000000000000000000;hpb=169219566d08e4940d25b66ecdb68e80b90c090d;p=genetic.git diff --git a/include/fitness/fitness.h b/include/fitness/fitness.h new file mode 100644 index 0000000..a975034 --- /dev/null +++ b/include/fitness/fitness.h @@ -0,0 +1,80 @@ +#ifndef __FITNESS_FITNESS_H +#define __FITNESS_FITNESS_H + +#include +#include + +#include "chromosome.h" + +namespace genetic { + /** + * Base Fitness template class. It should be a base class for any custom + * fitness functions. + */ + template < typename _Chromosome, typename _Value = double > + class Fitness { + template friend class Selection; + public: + /** + * Type representing Chromosome Gene + */ + typedef typename _Chromosome::GeneType GeneType; + + /** + * Value type returned by the Fitness function + */ + typedef _Value ValueType; + protected: + /** + * Chromosome on which calculations are made + */ + _Chromosome chromosome; + + /** + * Calculations should be done here... + * + * @return Fitness value of the current Chromosome + */ + virtual _Value do_calculate() = 0; + + public: + /** + * Class constructor + */ + Fitness() {} + + /** + * Copy constructor + */ + Fitness(_Chromosome& _chromosome) + : chromosome(_chromosome) { + } + + /** + * Invokes calculations + * + * @return Fitness value of the current Chromosome + */ + _Value calculate() { + return this->do_calculate(); + } + + /** + * Method used to pass additional arguments needed by the function to + * run correctly. + */ + virtual void parseArguments(std::map) { } + + /** + * Method used to get additional arguments needed by the function to + * run correctly + * + * @return map containing additional arguments, empty if do not use any + */ + virtual std::map getArguments() { + return std::map(); + } + }; +} + +#endif /* __FITNESS_FITNESS_H */