+#ifndef __FITNESS_WSTI_H
+#define __FITNESS_WSTI_H
+
+#include <cmath>
+
+#include "../gene.h"
+
+using namespace std;
+
+namespace genetic {
+ /**
+ * Just an example Fitness function based on WSTI version.
+ */
+ template < typename _Chromosome >
+ class WSTI {
+ protected:
+ _Chromosome chromosome;
+
+ float span_start;
+ float span_end;
+
+ double fenotype() {
+ int fen = 0;
+ int rat = 1;
+ for (unsigned int i = 0; i < chromosome.get().size(); i++) {
+ fen = fen + chromosome.get()[i].get() * rat;
+ rat = rat * 2;
+ }
+ return fen;
+ }
+
+ double 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) {
+ this->chromosome = chromosome;
+ this->span_start = start;
+ this->span_end = end;
+ }
+
+ double calculate() {
+ double fenotype = this->calculateFenotype();
+ return (exp(fenotype) * sin(3.1415 * fenotype) + 1) / fenotype;
+ }
+ };
+}
+
+#endif /* __FITNESS_WSTI_H */