X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=src%2Ffitness%2Fwsti.h;fp=src%2Ffitness%2Fwsti.h;h=fa303b0eb97fd13d706e8206ec8c609ca47e86e9;hb=12625bb2d19ee89abacc2456bff57dc22aa3a526;hp=b93439f204466028c6d6ba021a15d47ae2bcae7f;hpb=1014b8296cc38f408212d385f036cc78e9c66cce;p=genetic.git diff --git a/src/fitness/wsti.h b/src/fitness/wsti.h index b93439f..fa303b0 100644 --- a/src/fitness/wsti.h +++ b/src/fitness/wsti.h @@ -5,43 +5,46 @@ #include "../gene.h" +#include "fitness.h" + using namespace std; namespace genetic { /** * Just an example Fitness function based on WSTI version. */ - template < typename _Chromosome > - class WSTI { + template + class WSTI : public Fitness<_Chromosome, _Value> { protected: - _Chromosome chromosome; - float span_start; float span_end; - double fenotype() { + _Value fenotype() { int _fenotype = 0; int ratio = 1; - for (unsigned int i = 0; i < chromosome.get().size(); i++) { - _fenotype = _fenotype + chromosome.get()[i].get() * ratio; + for (unsigned int i = 0; i < this->chromosome.get().size(); i++) { + _fenotype = _fenotype + this->chromosome.get()[i].get() * ratio; ratio = ratio * 2; } return _fenotype; } - double calculateFenotype() { + _Value calculateFenotype() { const unsigned int power2N = 1 << this->chromosome.get().size(); return span_start + (span_end - span_start) * this->fenotype() / power2N; } - public: - WSTI(_Chromosome& _chromosome, float start, float end) - : chromosome(_chromosome.get()), span_start(start), span_end(end) { - } - double calculate() { - double fenotype = this->calculateFenotype(); + _Value do_calculate() { + _Value fenotype = this->calculateFenotype(); return (exp(fenotype) * sin(3.1415 * fenotype) + 1) / fenotype; } + public: + WSTI(float start, float end) + : span_start(start), span_end(end) { + } + WSTI(_Chromosome& _chromosome, float start, float end) + : Fitness<_Chromosome>(_chromosome), span_start(start), span_end(end) { + } }; }