[Avida-SVN] r1941 - branches/energy/source/main

beckma24 at myxo.css.msu.edu beckma24 at myxo.css.msu.edu
Wed Aug 15 12:56:33 PDT 2007


Author: beckma24
Date: 2007-08-15 15:56:33 -0400 (Wed, 15 Aug 2007)
New Revision: 1941

Modified:
   branches/energy/source/main/cDeme.cc
   branches/energy/source/main/cDeme.h
   branches/energy/source/main/cPopulation.cc
   branches/energy/source/main/cPopulationCell.cc
   branches/energy/source/main/cPopulationCell.h
Log:
Removed notion of cell-level energy.  Energy is either in the organism or in a resourceCount.

Modified: branches/energy/source/main/cDeme.cc
===================================================================
--- branches/energy/source/main/cDeme.cc	2007-08-15 17:57:46 UTC (rev 1940)
+++ branches/energy/source/main/cDeme.cc	2007-08-15 19:56:33 UTC (rev 1941)
@@ -22,6 +22,7 @@
  */
 
 #include "cDeme.h"
+#include "cPopulationCell.h"
 #include "cResource.h"
 
 
@@ -64,6 +65,8 @@
 {
   birth_count = 0; 
   _age = 0;
+  //clear cell energy
+  
   deme_resource_count.ReinitializeResources();
 }
 
@@ -110,18 +113,31 @@
   double total_energy = 0.0;
   int relative_cell_id = GetRelativeCellID(absolute_cell_id);
   tArray<double> cell_resources = deme_resource_count.GetCellResources(relative_cell_id);
-  tArray<double> modified_cell_resource(cell_resources.GetSize());
-  modified_cell_resource.SetAll(0.0);
-  
+
   // sum all energy resources
   for(int i = 0; i < energy_res_ids.GetSize(); i++) {
     if(cell_resources[energy_res_ids[i]] > 0.0) {
       total_energy += cell_resources[energy_res_ids[i]];
-      modified_cell_resource[energy_res_ids[i]] = -1.0 * cell_resources[energy_res_ids[i]];      
+      cell_resources[energy_res_ids[i]] *= -1.0;
     }
   }
-  
   // set energy resources to zero
-  deme_resource_count.ModifyCell(modified_cell_resource, relative_cell_id);
+  deme_resource_count.ModifyCell(cell_resources, relative_cell_id);
   return total_energy;
 }
+
+void cDeme::GiveBackCellEnergy(int absolute_cell_id, double value) {
+  assert(cell_ids[0] <= absolute_cell_id);
+  assert(absolute_cell_id <= cell_ids[cell_ids.GetSize()-1]);
+
+  int relative_cell_id = GetRelativeCellID(absolute_cell_id);
+  tArray<double> cell_resources = deme_resource_count.GetCellResources(relative_cell_id);
+
+  double amount_per_resource = value / energy_res_ids.GetSize();
+  
+  // put back energy resources evenly
+  for(int i = 0; i < energy_res_ids.GetSize(); i++) {
+    cell_resources[energy_res_ids[i]] += amount_per_resource;
+  }
+  deme_resource_count.ModifyCell(cell_resources, relative_cell_id);
+}

Modified: branches/energy/source/main/cDeme.h
===================================================================
--- branches/energy/source/main/cDeme.h	2007-08-15 17:57:46 UTC (rev 1940)
+++ branches/energy/source/main/cDeme.h	2007-08-15 19:56:33 UTC (rev 1941)
@@ -95,6 +95,7 @@
   void ResizeSpatialGrids(const int in_x, const int in_y) { deme_resource_count.ResizeSpatialGrids(in_x, in_y); }
   void ModifyDemeResCount(const tArray<double> & res_change, const int absolute_cell_id);
   double GetAndClearCellEnergy(int absolute_cell_id);
+  void GiveBackCellEnergy(int absolute_cell_id, double value);
   void SetupDemeRes(int id, cResource * res, int verbosity);
   void UpdateDemeRes() { deme_resource_count.GetResources(); }
   void Update(double time_step) { deme_resource_count.Update(time_step); }

Modified: branches/energy/source/main/cPopulation.cc
===================================================================
--- branches/energy/source/main/cPopulation.cc	2007-08-15 17:57:46 UTC (rev 1940)
+++ branches/energy/source/main/cPopulation.cc	2007-08-15 19:56:33 UTC (rev 1941)
@@ -1197,8 +1197,8 @@
         source_deme.Reset();
         target_deme.Reset();
 
-        InjectGenome(source_deme.GetCellID(source_deme.GetSize()/2),seed_genome,seed_lineage); // source deme
-        InjectGenome(target_deme.GetCellID(target_deme.GetSize()/2),seed_genome,seed_lineage); // destination deme
+        InjectGenome(source_deme.GetCellID(source_deme.GetSize()/2), seed_genome, seed_lineage); // source deme
+        InjectGenome(target_deme.GetCellID(target_deme.GetSize()/2), seed_genome, seed_lineage); // destination deme
         
       } else {
         cOrganism* seed = cell_array[cell1_id].GetOrganism();

Modified: branches/energy/source/main/cPopulationCell.cc
===================================================================
--- branches/energy/source/main/cPopulationCell.cc	2007-08-15 17:57:46 UTC (rev 1940)
+++ branches/energy/source/main/cPopulationCell.cc	2007-08-15 19:56:33 UTC (rev 1941)
@@ -205,24 +205,20 @@
   // For the moment, the cell doesn't keep track of much...
   cOrganism * out_organism = organism;
   if(m_world->GetConfig().ENERGY_ENABLED.Get() == 1 && m_world->GetConfig().FRAC_ENERGY_TRANSFER.Get() > 0.0) {
-    IncreaseCellEnergy(organism->GetPhenotype().GetStoredEnergy() * m_world->GetConfig().FRAC_ENERGY_TRANSFER.Get()); // put remaining energy back into cell
+    m_world->GetPopulation().GetDeme(deme_id).GiveBackCellEnergy(cell_id, organism->GetPhenotype().GetStoredEnergy() * m_world->GetConfig().FRAC_ENERGY_TRANSFER.Get());
   }
   organism = NULL;
   return out_organism;
 }
 
-void cPopulationCell::UpdateCellEnergy() {
-  // ONLY DEME-LEVEL SPACIAL RESOURCES ARE IMPLEMENTED
-  cell_energy += m_world->GetPopulation().GetDeme(deme_id).GetAndClearCellEnergy(cell_id);
-}
-
 double cPopulationCell::UptakeCellEnergy(double frac_to_uptake) {
   assert(0.0 <= frac_to_uptake);
   assert(frac_to_uptake <= 1.0);
 
-  UpdateCellEnergy();
+  double cell_energy = m_world->GetPopulation().GetDeme(deme_id).GetAndClearCellEnergy(cell_id);  
   double uptakeAmount = cell_energy * frac_to_uptake;
   cell_energy -= uptakeAmount;
+  m_world->GetPopulation().GetDeme(deme_id).GiveBackCellEnergy(cell_id, cell_energy);
   return uptakeAmount;
 }
 

Modified: branches/energy/source/main/cPopulationCell.h
===================================================================
--- branches/energy/source/main/cPopulationCell.h	2007-08-15 17:57:46 UTC (rev 1940)
+++ branches/energy/source/main/cPopulationCell.h	2007-08-15 19:56:33 UTC (rev 1941)
@@ -61,13 +61,9 @@
   int m_x; //!< The x-coordinate of the position of this cell in the environment.
   int m_y; //!< The y-coordinate of the position of this cell in the environment.
 
-  double cell_energy; //!< energy stored in the cell
-
   void InsertOrganism(cOrganism & new_org);
   cOrganism* RemoveOrganism();
 
-  void UpdateCellEnergy();
-
 public:
   cPopulationCell();
   cPopulationCell(const cPopulationCell& in_cell);
@@ -98,8 +94,6 @@
 
   bool IsOccupied() const { return organism != NULL; }
 
-//  void SetCellEnergy(const double in_energy) { cell_energy = in_energy; }
-  void IncreaseCellEnergy(const double in_energy) { cell_energy += in_energy; }
   double UptakeCellEnergy(double frac_to_uptake);
 
   bool OK();




More information about the Avida-cvs mailing list