Added example fitness function template.
[genetic.git] / src / fitness / wsti.h
index 068590d94c815868b0d2bf6c04401932a47ef566..b93439f204466028c6d6ba021a15d47ae2bcae7f 100644 (file)
@@ -20,13 +20,13 @@ namespace genetic {
         float span_end;
 
         double fenotype() {
-            int fen = 0;
-            int rat = 1;
+            int _fenotype = 0;
+            int ratio = 1;
             for (unsigned int i = 0; i < chromosome.get().size(); i++) {
-                fen = fen + chromosome.get()[i].get() * rat;
-                rat = rat * 2;
+                _fenotype = _fenotype + chromosome.get()[i].get() * ratio;
+                ratio = ratio * 2;
             }
-            return fen;
+            return _fenotype;
         }
 
         double calculateFenotype() {
@@ -34,10 +34,8 @@ namespace genetic {
             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;
+        WSTI(_Chromosome& _chromosome, float start, float end)
+            : chromosome(_chromosome.get()), span_start(start), span_end(end) {
         }
 
         double calculate() {