[Avida-SVN] r2972 - in development/source: cpu main
beckma24 at myxo.css.msu.edu
beckma24 at myxo.css.msu.edu
Tue Nov 25 10:02:08 PST 2008
Author: beckma24
Date: 2008-11-25 13:02:08 -0500 (Tue, 25 Nov 2008)
New Revision: 2972
Modified:
development/source/cpu/cHardwareCPU.cc
development/source/cpu/cHardwareCPU.h
development/source/main/cDeme.cc
development/source/main/cPopulation.cc
Log:
Added repro_deme inst, and moved code that applies energy from parent deme to organisms in offspring deme
Modified: development/source/cpu/cHardwareCPU.cc
===================================================================
--- development/source/cpu/cHardwareCPU.cc 2008-11-25 16:56:46 UTC (rev 2971)
+++ development/source/cpu/cHardwareCPU.cc 2008-11-25 18:02:08 UTC (rev 2972)
@@ -331,6 +331,7 @@
tInstLibEntry<tMethod>("h-divide0.001", &cHardwareCPU::Inst_HeadDivide0_001, nInstFlag::STALL),
// High-level instructions
+ tInstLibEntry<tMethod>("repro_deme", &cHardwareCPU::Inst_ReproDeme, nInstFlag::STALL),
tInstLibEntry<tMethod>("repro", &cHardwareCPU::Inst_Repro, nInstFlag::STALL),
tInstLibEntry<tMethod>("repro-sex", &cHardwareCPU::Inst_ReproSex, nInstFlag::STALL),
tInstLibEntry<tMethod>("repro-A", &cHardwareCPU::Inst_Repro, nInstFlag::STALL),
@@ -2646,6 +2647,20 @@
}
}
+
+// Inst_ReproDeme replicates a deme using cPopulation::ReplicateDeme.
+// It is similar to Inst_SpawnDeme, but the implementation of Inst_SpawnDeme doesn't contain many new deme-level replication features
+bool cHardwareCPU::Inst_ReproDeme(cAvidaContext& ctx) {
+
+ cDeme* sourceDeme = m_organism->GetOrgInterface().GetDeme();
+ if(sourceDeme == NULL)
+ return false; // in test CPU
+
+ // this function will become to depend on a predicate, but I am still thinking of how to do this (BEB)
+ m_world->GetPopulation().ReplicateDeme(*sourceDeme);
+ return true;
+}
+
bool cHardwareCPU::Inst_Repro(cAvidaContext& ctx)
{
// check if repro can replace an existing organism
Modified: development/source/cpu/cHardwareCPU.h
===================================================================
--- development/source/cpu/cHardwareCPU.h 2008-11-25 16:56:46 UTC (rev 2971)
+++ development/source/cpu/cHardwareCPU.h 2008-11-25 18:02:08 UTC (rev 2972)
@@ -429,6 +429,7 @@
bool Inst_InjectRand(cAvidaContext& ctx);
bool Inst_InjectThread(cAvidaContext& ctx);
bool Inst_Transposon(cAvidaContext& ctx);
+ bool Inst_ReproDeme(cAvidaContext& ctx);
bool Inst_Repro(cAvidaContext& ctx);
bool Inst_ReproSex(cAvidaContext& ctx);
bool Inst_TaskPutRepro(cAvidaContext& ctx);
Modified: development/source/main/cDeme.cc
===================================================================
--- development/source/main/cDeme.cc 2008-11-25 16:56:46 UTC (rev 2971)
+++ development/source/main/cDeme.cc 2008-11-25 18:02:08 UTC (rev 2972)
@@ -230,27 +230,9 @@
// Handle energy model
if (m_world->GetConfig().ENERGY_ENABLED.Get())
{
- assert(cur_org_count>0);
-
total_energy_testament = 0.0;
- if(m_world->GetConfig().ENERGY_PASSED_ON_DEME_REPLICATION_METHOD.Get() == 0) {
- total_org_energy = deme_energy;
- if(total_org_energy < 0.0)
- total_org_energy = 0.0;
-
- // split deme energy evenly between organisms in deme
- 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(phenotype.GetStoredEnergy() + total_org_energy/static_cast<double>(cur_org_count));
- phenotype.SetMerit(cMerit(cMerit::EnergyToMerit(phenotype.GetStoredEnergy() * phenotype.GetEnergyUsageRatio(), m_world)));
- }
- }
- } else if(m_world->GetConfig().ENERGY_PASSED_ON_DEME_REPLICATION_METHOD.Get() == 1) {
+ if(m_world->GetConfig().ENERGY_PASSED_ON_DEME_REPLICATION_METHOD.Get() == 1) {
// split deme energy evenly between cell in deme
additional_resource = deme_energy; // spacial resource handles resource division
}
Modified: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc 2008-11-25 16:56:46 UTC (rev 2971)
+++ development/source/main/cPopulation.cc 2008-11-25 18:02:08 UTC (rev 2972)
@@ -1528,6 +1528,41 @@
target_successfully_seeded = SeedDeme(source_deme, target_deme);
}
+
+ // split energy from parent deme evenly among orgs in child deme
+ if(m_world->GetConfig().ENERGY_ENABLED.Get() == 1 && m_world->GetConfig().ENERGY_PASSED_ON_DEME_REPLICATION_METHOD.Get() == 0) {
+ assert(source_deme.GetOrgCount() > 0 && target_deme.GetOrgCount() > 0);
+ if(offspring_deme_energy < 0.0)
+ offspring_deme_energy = 0.0;
+ if(parent_deme_energy < 0.0)
+ parent_deme_energy = 0.0;
+
+ // split deme energy evenly between organisms in source deme
+ for (int i=0; i < source_deme.GetSize(); i++) {
+ int cellid = source_deme.GetCellID(i);
+ cPopulationCell& cell = m_world->GetPopulation().GetCell(cellid);
+ if(cell.IsOccupied()) {
+ cOrganism* organism = cell.GetOrganism();
+ cPhenotype& phenotype = organism->GetPhenotype();
+ phenotype.SetEnergy(phenotype.GetStoredEnergy() + parent_deme_energy/static_cast<double>(source_deme.GetOrgCount()));
+ phenotype.SetMerit(cMerit(cMerit::EnergyToMerit(phenotype.GetStoredEnergy() * phenotype.GetEnergyUsageRatio(), m_world)));
+ }
+ }
+
+ // split deme energy evenly between organisms in target deme
+ for (int i=0; i < target_deme.GetSize(); i++) {
+ int cellid = target_deme.GetCellID(i);
+ cPopulationCell& cell = m_world->GetPopulation().GetCell(cellid);
+ if(cell.IsOccupied()) {
+ cOrganism* organism = cell.GetOrganism();
+ cPhenotype& phenotype = organism->GetPhenotype();
+ phenotype.SetEnergy(phenotype.GetStoredEnergy() + offspring_deme_energy/static_cast<double>(target_deme.GetOrgCount()));
+ phenotype.SetMerit(cMerit(cMerit::EnergyToMerit(phenotype.GetStoredEnergy() * phenotype.GetEnergyUsageRatio(), m_world)));
+ }
+ }
+ }
+
+
// The source's merit must be transferred to the target, and then the source has
// to rotate its heritable merit to its current merit.
if (target_successfully_seeded) target_deme.UpdateDemeMerit(source_deme);
More information about the Avida-cvs
mailing list