Commits

Jay Barra committed 48c5626

adding more functions for demonstration

  • Participants
  • Parent commits 3c33037

Comments (0)

Files changed (2)

 //-------------------------------------------------
 float fitness(struct Firefly& f)
 {
-    f.current_fitness =  -1 * pow(f.current_pos.x - .5, 2) + 4 * f.current_pos.x;
-    if (f.current_fitness > f.best_fitness) {
-        f.best_fitness = f.current_fitness;
-        f.best_pos.x   = f.current_pos.x;
-        f.best_pos.y   = f.current_pos.y; 
-    }
+  float x = f.current_pos.x;
+  float y = f.current_pos.y
+    
+  f.current_fitness =  -1 * pow(x - .5, 2) + 4 * x;
+
+  //f.current_fitness =  -1 * pow(x - 0.5, 3) + x - pow(y, 2) - (x * y);
+  if (f.current_fitness > f.best_fitness) {
+    f.best_fitness = f.current_fitness;
+    f.best_pos.x   = x;
+    f.best_pos.y   = y; 
+  }
 
-    return f.current_fitness;
+  return f.current_fitness;
 }
 //-------------------------------------------------
 float randFloat(float a, float b)
 //-------------------------------------------------
 float fitness(struct Particle& f, bool bSetBest)
 {
-    f.current_fitness =  -1 * pow(f.current_pos.x - 0.5, 3) + f.current_pos.x;
-    
+    float x = f.current_pos.x;
+    float y = f.current_pos.y;
+
+    f.current_fitness =  -1 * pow(x - 0.5, 3) + x;
+    //f.current_fitness =  -1 * pow(x - 0.5, 3) + x - pow(y, 2) - (x * y);
+
     if (f.current_fitness > f.best_fitness || bSetBest == true) {
       f.best_fitness = f.current_fitness;
-      f.best_pos.x   = f.current_pos.x;
-      f.best_pos.y   = f.current_pos.y;
+      f.best_pos.x   = x;
+      f.best_pos.y   = y;
     }
     return f.current_fitness;
 }