[Avida-SVN] r2657 - in development/source: cpu main
beckma24 at myxo.css.msu.edu
beckma24 at myxo.css.msu.edu
Thu Jun 19 18:56:27 PDT 2008
Author: beckma24
Date: 2008-06-19 21:56:27 -0400 (Thu, 19 Jun 2008)
New Revision: 2657
Modified:
development/source/cpu/cHardwareCPU.cc
development/source/main/cDeme.cc
Log:
There is a problem with the order in which a deme is initialized. Organisms are injected into a deme before the deme is reset, aka the environment provided by the deme can change after an organism is injected, but before the organism executes. This presents a problem when the environment contains energy resources.
Modified: development/source/cpu/cHardwareCPU.cc
===================================================================
--- development/source/cpu/cHardwareCPU.cc 2008-06-19 19:11:53 UTC (rev 2656)
+++ development/source/cpu/cHardwareCPU.cc 2008-06-20 01:56:27 UTC (rev 2657)
@@ -5932,7 +5932,7 @@
cPopulationCell& mycell = pop.GetCell(cellid);
cDeme &deme = pop.GetDeme(pop.GetCell(cellid).GetDemeID());
- cResourceCount deme_resource_count = deme.GetDemeResourceCount();
+// const cResourceCount& deme_resource_count = deme.GetDemeResourceCount();
int fromcellID, destcellID;
int cell_data;
Modified: development/source/main/cDeme.cc
===================================================================
--- development/source/main/cDeme.cc 2008-06-19 19:11:53 UTC (rev 2656)
+++ development/source/main/cDeme.cc 2008-06-20 01:56:27 UTC (rev 2657)
@@ -274,8 +274,23 @@
(*movement_pred_list[i]).Reset();
}
- if(resetResources)
+ if(resetResources) {
deme_resource_count.ReinitializeResources(additional_resource);
+ if(m_world->GetConfig().ENERGY_ENABLED.Get() == 1) {
+ cPopulation& pop = m_world->GetPopulation();
+ for (int i=0; i<GetSize(); i++) {
+ int cellid = GetCellID(i);
+ cPopulationCell& cell = m_world->GetPopulation().GetCell(cellid);
+ if(cell.IsOccupied()) {
+ cOrganism* organism = cell.GetOrganism();
+ cPhenotype& phenotype = organism->GetPhenotype();
+ phenotype.SetEnergy(cell.UptakeCellEnergy(1.0));
+ phenotype.SetMerit(cMerit(cMerit::EnergyToMerit(phenotype.GetStoredEnergy() * phenotype.GetEnergyUsageRatio(), m_world)));
+ pop.UpdateMerit(cell.GetID(), (phenotype.GetMerit()).GetDouble());
+ }
+ }
+ }
+ }
}
More information about the Avida-cvs
mailing list