[Avida-SVN] r2942 - branches/movement/source/actions

grabow38 at myxo.css.msu.edu grabow38 at myxo.css.msu.edu
Fri Nov 14 11:15:49 PST 2008


Author: grabow38
Date: 2008-11-14 14:15:49 -0500 (Fri, 14 Nov 2008)
New Revision: 2942

Modified:
   branches/movement/source/actions/PopulationActions.cc
Log:
Revised cAbstractCompeteDemes_FollowPath fitness function in movement branch.

Modified: branches/movement/source/actions/PopulationActions.cc
===================================================================
--- branches/movement/source/actions/PopulationActions.cc	2008-11-14 14:09:08 UTC (rev 2941)
+++ branches/movement/source/actions/PopulationActions.cc	2008-11-14 19:15:49 UTC (rev 2942)
@@ -1735,13 +1735,13 @@
 // Compete demes based on how many steps the organism took on the path compared to how many steps it took off the path,
 // calculated as the square of the difference of "good" resources consumed and "poison" consumed.
 class cAbstractCompeteDemes_FollowPath : public cAbstractCompeteDemes {
-  public:
-    cAbstractCompeteDemes_FollowPath(cWorld* world, const cString& args) : cAbstractCompeteDemes(world, args) { }
-
-    static const cString GetDescription() { return "No Arguments"; }
+public:
+  cAbstractCompeteDemes_FollowPath(cWorld* world, const cString& args) : cAbstractCompeteDemes(world, args) { }
   
-    double Fitness(const cDeme& deme) {    
-	
+  static const cString GetDescription() { return "No Arguments"; }
+  
+  double Fitness(const cDeme& deme) {    
+    
 	  cResourceCount res = deme.GetDemeResourceCount();				// Deme resource count
 	  tArray<double> init_counts = deme.GetDemeInitCellResSum();	// Initial counts of all resources
     tArray<double> curr_counts;
@@ -1755,31 +1755,20 @@
 	  cString res_name;												// Name of resource
 	  double fitnessOfDeme = 0.0;									// Fitness of deme
 	  
-	  // cout << "Deme " << deme.GetID() << ": " << endl;
-	  
 	  for (int i = 0; i < curr_counts.GetSize(); i++) {                                                                                                                        
 	    if ( (res.GetResourcesGeometry())[i] != nGeometry::GLOBAL) {                                                                                                   
 	      cSpatialResCount sp_res = res.GetSpatialResource(i);  
-		  res_name = res.GetResName(i);
-		  //cout << "Resource Name " << res_name << endl;
-		  if ( res_name != "poison" ) { 																
-		    initial_good_res += init_counts[i];
-			current_good_res += curr_counts[i];  
-			//cout << "Init good at " <<  i << "  " << init_counts[i]
-			//     << " Curr good at " <<  i << "  " << curr_counts[i] << endl;
-		  }
-		  else {                                                                                                           
-		    initial_poison += init_counts[i];  
-			current_poison += curr_counts[i];  
-			//cout << "Init poison at " <<  i << "  " << init_counts[i]
-			//     << " Curr poison at " <<  i << "  " << curr_counts[i] << endl;
-		  }
-	    } 
-		
-		//cout << "Totals so far: " << endl
-		//	 << "Initial good " << initial_good_res << " Current good " << current_good_res
-		//	 << " Initial poison " << initial_poison << " Current poison " << current_poison << endl;
-      }   
+        res_name = res.GetResName(i);
+        if ( res_name != "poison" ) { 																
+          initial_good_res += init_counts[i];
+          current_good_res += curr_counts[i];  
+        }
+        else {                                                                                                           
+          initial_poison += init_counts[i];  
+          current_poison += curr_counts[i];  
+        }
+      } 
+    }   
 	  
 	  consumed_good = initial_good_res - current_good_res;
 	  consumed_poison = initial_poison - current_poison;
@@ -1787,14 +1776,11 @@
 	  // If consumed more good resources than poison, fitness is square of difference, otherwise fitness = 0.0
 	  if ( consumed_good > consumed_poison )
 	    fitnessOfDeme = pow( (consumed_good - consumed_poison), 2.0 );
+    else if ( consumed_good > 0 )
+      fitnessOfDeme = consumed_good;
 	  
-	  // Debugging output
-	  // cout << " Consumed Good " << consumed_good 
-	  //      << " Consumed Poison " << consumed_poison
-	  //      << " Fitness " << fitnessOfDeme << endl<< endl;
-	  
-      return fitnessOfDeme;
-    }
+    return fitnessOfDeme;
+  }
 };
 
 




More information about the Avida-cvs mailing list