[Avida-SVN] r1937 - in branches/energy/source: actions cpu main
beckma24 at myxo.css.msu.edu
beckma24 at myxo.css.msu.edu
Wed Aug 15 09:40:34 PDT 2007
Author: beckma24
Date: 2007-08-15 12:40:34 -0400 (Wed, 15 Aug 2007)
New Revision: 1937
Modified:
branches/energy/source/actions/PopulationActions.cc
branches/energy/source/cpu/cHardwareCPU.cc
branches/energy/source/cpu/cHardwareCPU.h
branches/energy/source/main/cPopulation.cc
Log:
WARNING: InjectDeme injects on organism over the initial ancestor. Changed InjectDeme for-loop so that th orginal ancestor does not get overwritten when energy model is used.
Modified: branches/energy/source/actions/PopulationActions.cc
===================================================================
--- branches/energy/source/actions/PopulationActions.cc 2007-08-15 16:37:32 UTC (rev 1936)
+++ branches/energy/source/actions/PopulationActions.cc 2007-08-15 16:40:34 UTC (rev 1937)
@@ -473,32 +473,42 @@
class cActionInjectDemes : public cAction
{
private:
- cString m_filename;
- double m_merit;
- int m_lineage_label;
- double m_neutral_metric;
+ cString m_filename;
+ double m_merit;
+ int m_lineage_label;
+ double m_neutral_metric;
public:
- cActionInjectDemes(cWorld* world, const cString& args) : cAction(world, args), m_merit(-1), m_lineage_label(0), m_neutral_metric(0)
- {
- cString largs(args);
- if (!largs.GetSize()) m_filename = "START_CREATURE"; else m_filename = largs.PopWord();
- if (largs.GetSize()) m_merit = largs.PopWord().AsDouble();
- if (largs.GetSize()) m_lineage_label = largs.PopWord().AsInt();
- if (largs.GetSize()) m_neutral_metric = largs.PopWord().AsDouble();
- if (m_filename == "START_CREATURE") m_filename = m_world->GetConfig().START_CREATURE.Get();
- }
-
- static const cString GetDescription() { return "Arguments: [string fname=\"START_CREATURE\"] [double merit=-1] [int lineage_label=0] [double neutral_metric=0]"; }
-
- void Process(cAvidaContext& ctx)
- {
- cGenome genome = cGenomeUtil::LoadGenome(m_filename, m_world->GetHardwareManager().GetInstSet());
- for(int i=0; i<m_world->GetPopulation().GetNumDemes(); ++i) {
- m_world->GetPopulation().Inject(genome,
- m_world->GetPopulation().GetDeme(i).GetCellID(0),
- m_merit, m_lineage_label, m_neutral_metric);
- }
- }
+ cActionInjectDemes(cWorld* world, const cString& args) : cAction(world, args), m_merit(-1), m_lineage_label(0), m_neutral_metric(0)
+ {
+ cString largs(args);
+ if (!largs.GetSize()) m_filename = "START_CREATURE"; else m_filename = largs.PopWord();
+ if (largs.GetSize()) m_merit = largs.PopWord().AsDouble();
+ if (largs.GetSize()) m_lineage_label = largs.PopWord().AsInt();
+ if (largs.GetSize()) m_neutral_metric = largs.PopWord().AsDouble();
+ if (m_filename == "START_CREATURE") m_filename = m_world->GetConfig().START_CREATURE.Get();
+ }
+
+ static const cString GetDescription() { return "Arguments: [string fname=\"START_CREATURE\"] [double merit=-1] [int lineage_label=0] [double neutral_metric=0]"; }
+
+ void Process(cAvidaContext& ctx)
+ {
+ cGenome genome = cGenomeUtil::LoadGenome(m_filename, m_world->GetHardwareManager().GetInstSet());
+ if(m_world->GetConfig().ENERGY_ENABLED.Get() == 1) {
+ for(int i=1; i<m_world->GetPopulation().GetNumDemes(); ++i) { // first org has already been injected
+ m_world->GetPopulation().Inject(genome,
+ m_world->GetPopulation().GetDeme(i).GetCellID(0),
+ m_merit, m_lineage_label, m_neutral_metric);
+ }
+ } else {
+ for(int i=0; i<m_world->GetPopulation().GetNumDemes(); ++i) {
+ // WARNING: initial ancestor has already be injected into the population
+ // calling this will overwrite it.
+ m_world->GetPopulation().Inject(genome,
+ m_world->GetPopulation().GetDeme(i).GetCellID(0),
+ m_merit, m_lineage_label, m_neutral_metric);
+ }
+ }
+ }
};
Modified: branches/energy/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/energy/source/cpu/cHardwareCPU.cc 2007-08-15 16:37:32 UTC (rev 1936)
+++ branches/energy/source/cpu/cHardwareCPU.cc 2007-08-15 16:40:34 UTC (rev 1937)
@@ -218,8 +218,8 @@
tInstLibEntry<tMethod>("rotate-l", &cHardwareCPU::Inst_RotateL),
tInstLibEntry<tMethod>("rotate-r", &cHardwareCPU::Inst_RotateR),
- tInstLibEntry<tMethod>("rotate-oneL", &cHardwareCPU::Inst_RotateOneL),
- tInstLibEntry<tMethod>("rotate-oneR", &cHardwareCPU::Inst_RotateOneR),
+ tInstLibEntry<tMethod>("rotate-left-one", &cHardwareCPU::Inst_RotateLeftOne),
+ tInstLibEntry<tMethod>("rotate-right-one", &cHardwareCPU::Inst_RotateRightOne),
tInstLibEntry<tMethod>("rotate-label", &cHardwareCPU::Inst_RotateLabel),
@@ -3669,18 +3669,14 @@
return true;
}
-bool cHardwareCPU::Inst_RotateOneL(cAvidaContext& ctx)
+bool cHardwareCPU::Inst_RotateLeftOne(cAvidaContext& ctx)
{
- // If this organism has no neighbors, ignore rotate.
- if (organism->GetNeighborhoodSize() == 0) return false;
organism->Rotate(-1);
return true;
}
-bool cHardwareCPU::Inst_RotateOneR(cAvidaContext& ctx)
+bool cHardwareCPU::Inst_RotateRightOne(cAvidaContext& ctx)
{
- // If this organism has no neighbors, ignore rotate.
- if (organism->GetNeighborhoodSize() == 0) return false;
organism->Rotate(1);
return true;
}
Modified: branches/energy/source/cpu/cHardwareCPU.h
===================================================================
--- branches/energy/source/cpu/cHardwareCPU.h 2007-08-15 16:37:32 UTC (rev 1936)
+++ branches/energy/source/cpu/cHardwareCPU.h 2007-08-15 16:40:34 UTC (rev 1937)
@@ -443,8 +443,8 @@
bool Inst_RotateL(cAvidaContext& ctx);
bool Inst_RotateR(cAvidaContext& ctx);
- bool Inst_RotateOneL(cAvidaContext& ctx);
- bool Inst_RotateOneR(cAvidaContext& ctx);
+ bool Inst_RotateLeftOne(cAvidaContext& ctx);
+ bool Inst_RotateRightOne(cAvidaContext& ctx);
bool Inst_RotateLabel(cAvidaContext& ctx);
bool Inst_SetCopyMut(cAvidaContext& ctx);
bool Inst_ModCopyMut(cAvidaContext& ctx);
Modified: branches/energy/source/main/cPopulation.cc
===================================================================
--- branches/energy/source/main/cPopulation.cc 2007-08-15 16:37:32 UTC (rev 1936)
+++ branches/energy/source/main/cPopulation.cc 2007-08-15 16:40:34 UTC (rev 1937)
@@ -446,8 +446,12 @@
}
// Update the contents of the target cell.
+ std::cerr<<"cPop::ActivateOrg1: "<<in_organism->GetPhenotype().GetStoredEnergy()<<" "<<target_cell.GetDemeID()<<std::endl;
KillOrganism(target_cell);
+ std::cerr<<"cPop::ActivateOrg2: "<<in_organism->GetPhenotype().GetStoredEnergy()<<" "<<target_cell.GetDemeID()<<std::endl;
target_cell.InsertOrganism(*in_organism);
+ std::cerr<<"cPop::ActivateOrg3: "<<in_organism->GetPhenotype().GetStoredEnergy()<<" "<<target_cell.GetDemeID()<<std::endl;
+
// Setup the inputs in the target cell.
environment.SetupInputs(ctx, target_cell.input_array);
@@ -1120,6 +1124,11 @@
KillOrganism(cell_array[target_deme.GetCellID(i)]);
}
+ // And reset both demes, in case they have any cleanup work to do.
+/* source_deme.Reset();
+ target_deme.Reset();
+*/
+
// Ok, there are two potential places where the seed for the target deme can
// come from. First, it could be a random organism in the source deme.
// Second, it could be an offspring of the source deme's germline, if the config
@@ -2725,8 +2734,6 @@
phenotype.SetupInject(new_genotype->GetGenome()); //TODO sets merit to lenght of genotype
if(m_world->GetConfig().ENERGY_ENABLED.Get() == 1) {
- double initial_energy = min(m_world->GetConfig().ENERGY_GIVEN_ON_INJECT.Get(), m_world->GetConfig().ENERGY_CAP.Get());
- phenotype.SetEnergy(initial_energy);
phenotype.SetMerit(cMerit(cMerit::EnergyToMerit(phenotype.GetStoredEnergy(), m_world)));
} else {
phenotype.SetMerit( cMerit(new_genotype->GetTestMerit(ctx)) );
More information about the Avida-cvs
mailing list