[Avida-SVN] r2929 - in branches/movement/source: actions main

grabow38 at myxo.css.msu.edu grabow38 at myxo.css.msu.edu
Mon Nov 10 07:24:05 PST 2008


Author: grabow38
Date: 2008-11-10 10:24:05 -0500 (Mon, 10 Nov 2008)
New Revision: 2929

Modified:
   branches/movement/source/actions/PopulationActions.cc
   branches/movement/source/main/cDeme.cc
   branches/movement/source/main/cResourceCount.cc
   branches/movement/source/main/cResourceCount.h
Log:
Revised cAbstractCompeteDemes_FollowPath.  Also have temporary fix for resources.

Modified: branches/movement/source/actions/PopulationActions.cc
===================================================================
--- branches/movement/source/actions/PopulationActions.cc	2008-11-09 22:46:09 UTC (rev 2928)
+++ branches/movement/source/actions/PopulationActions.cc	2008-11-10 15:24:05 UTC (rev 2929)
@@ -1731,7 +1731,8 @@
 };
 
 // @ LMG
-// Compete demes based on how many steps the organism took on the path compared to how many steps it took off the path
+// 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) { }
@@ -1740,29 +1741,42 @@
   
     double Fitness(const cDeme& deme) {    
 	
-	  cResourceCount res = deme.GetDemeResourceCount(); 
-	  double current_good_res = 0.0;// Current total good resource in deme                                                                                                            
-	  double initial_good_res = 0.0;// Initial total good resource in deme
-	  double current_poison = 0.0;  // Current total poison in deme
-	  double initial_poison = 0.0;  // Initial total poison in deme
-	  double consumed_good = 0.0;   // Amount of good resource consumed
-	  double consumed_poison = 0.0; // Amount of poison consumed
-	  cString res_name;			    // Name of resource
-	  double fitnessOfDeme = 0.0;   // Fitness of deme
+	  cResourceCount res = deme.GetDemeResourceCount();				// Deme resource count
+	  tArray<double> init_counts = deme.GetDemeInitCellResSum();	// Initial counts of all resources
+	  tArray<double> curr_counts = deme.GetDemeCurrentCellResSum();	// Current counts of all resources
+	  double current_good_res = 0.0;								// Current total good resource in deme                                                                                                            
+	  double initial_good_res = 0.0;								// Initial total good resource in deme
+	  double current_poison = 0.0;									// Current total poison in deme
+	  double initial_poison = 0.0;									// Initial total poison in deme
+	  double consumed_good = 0.0;									// Amount of good resource consumed
+	  double consumed_poison = 0.0;									// Amount of poison consumed
+	  cString res_name;												// Name of resource
+	  double fitnessOfDeme = 0.0;									// Fitness of deme
 	  
-	  for (int i = 0; i < res.GetSize(); i++) {                                                                                                                        
+	  //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);
-		  if ( res_name != "poison" ) {                                                                                                    
-		    current_good_res += sp_res.GetAmount(i);                                                                                                                     
-		    initial_good_res += res.GetInitialResourceValue(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 {
-		    current_poison = sp_res.GetAmount(i);                                                                                                                     
-		    initial_poison = res.GetInitialResourceValue(i);  
+		  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;
       }   
 	  
 	  consumed_good = initial_good_res - current_good_res;
@@ -1772,6 +1786,11 @@
 	  if ( consumed_good > consumed_poison )
 	    fitnessOfDeme = pow( (consumed_good - consumed_poison), 2.0 );
 	  
+	  // Debugging output
+	  // cout << " Consumed Good " << consumed_good 
+	 //      << " Consumed Poison " << consumed_poison
+	 //      << " Fitness " << fitnessOfDeme << endl<< endl;
+	  
       return fitnessOfDeme;
     }
 };

Modified: branches/movement/source/main/cDeme.cc
===================================================================
--- branches/movement/source/main/cDeme.cc	2008-11-09 22:46:09 UTC (rev 2928)
+++ branches/movement/source/main/cDeme.cc	2008-11-10 15:24:05 UTC (rev 2929)
@@ -457,6 +457,7 @@
 {
   tArray<double> cell_res_counts;
   cell_res_counts.Resize(deme_resource_count.GetSize());
+  cell_res_counts.SetAll(0.0);
   deme_res_count_array.Resize(deme_resource_count.GetSize());
   deme_res_count_array.SetAll(0.0);
   
@@ -468,8 +469,13 @@
 //	cout << "Deme res count " << deme_resource_count.GetSize() << endl;
     for (int j = 0; j < deme_resource_count.GetSize(); j++) {
 	  if ( cell_res_counts[j] > 0.0 ) {
+		if ( cell_res_counts[j] < 1.0 ) {
+		  cell_res_counts[j] = 0.0;
+		  deme_resource_count.ResetCell(i, j, 0.0);
+		}
 	    deme_res_count_array[j] += cell_res_counts[j];
-//		cout << "Deme resource array position " << j << "res amount " << deme_res_count_array[j] << " Cell res amt " << endl;
+		//cout << "Deme resource array position " << j << " Res name " << deme_resource_count.GetResName(j)
+		//	 << " res amount " << deme_res_count_array[j] << " Cell res amt " << cell_res_counts[j] << endl;
 	  }
 	}
   }

Modified: branches/movement/source/main/cResourceCount.cc
===================================================================
--- branches/movement/source/main/cResourceCount.cc	2008-11-09 22:46:09 UTC (rev 2928)
+++ branches/movement/source/main/cResourceCount.cc	2008-11-10 15:24:05 UTC (rev 2929)
@@ -416,6 +416,18 @@
   }
 }
 
+// @ LMG
+// Resets
+void cResourceCount::ResetCell(int cell_id, int res_id, double reset_amt)
+{
+  // Process only spatial resources
+  if(geometry[res_id] == nGeometry::GLOBAL) {
+    return; }
+  else {
+    spatial_resource_count[res_id].SetCellAmount(cell_id, reset_amt);
+  }
+}
+
 double cResourceCount::Get(int id) const
 {
   assert(id < resource_count.GetSize());

Modified: branches/movement/source/main/cResourceCount.h
===================================================================
--- branches/movement/source/main/cResourceCount.h	2008-11-09 22:46:09 UTC (rev 2928)
+++ branches/movement/source/main/cResourceCount.h	2008-11-10 15:24:05 UTC (rev 2929)
@@ -101,6 +101,7 @@
   void Modify(const tArray<double>& res_change);
   void Modify(int id, double change);
   void ModifyCell(const tArray<double> & res_change, int cell_id);
+  void ResetCell(int cell_id, int res_id, double reset_amt); // @LMG, resets a particular cell resource amount
   void Set(int id, double new_level);
   double Get(int id) const;
   void ResizeSpatialGrids(int in_x, int in_y);




More information about the Avida-cvs mailing list