[Avida-SVN] r1811 - branches/energy/source/main
beckma24 at myxo.css.msu.edu
beckma24 at myxo.css.msu.edu
Tue Jul 17 06:13:30 PDT 2007
Author: beckma24
Date: 2007-07-17 09:13:30 -0400 (Tue, 17 Jul 2007)
New Revision: 1811
Modified:
branches/energy/source/main/cAvidaConfig.h
branches/energy/source/main/cPopulation.cc
branches/energy/source/main/cPopulationCell.cc
branches/energy/source/main/cPopulationCell.h
Log:
Added cell-level energy, but the organisms can't use it yet.
Modified: branches/energy/source/main/cAvidaConfig.h
===================================================================
--- branches/energy/source/main/cAvidaConfig.h 2007-07-17 12:20:06 UTC (rev 1810)
+++ branches/energy/source/main/cAvidaConfig.h 2007-07-17 13:13:30 UTC (rev 1811)
@@ -226,7 +226,7 @@
CONFIG_ADD_VAR(DIVIDE_METHOD, int, 1, "0 = Divide leaves state of mother untouched.\n1 = Divide resets state of mother\n (after the divide, we have 2 children)\n2 = Divide resets state of current thread only\n (does not touch possible parasite threads)");
CONFIG_ADD_VAR(INJECT_METHOD, int, 0, "0 = Leaves the parasite thread state untouched.\n1 = Resets the calling thread state on inject");
CONFIG_ADD_VAR(GENERATION_INC_METHOD, int, 1, "0 = Only the generation of the child is\n increased on divide.\n1 = Both the generation of the mother and child are\n increased on divide (good with DIVIDE_METHOD 1).");
- CONFIG_ADD_VAR(RESET_INPUTS_ON_DIVIDE, int, 0, "Reset environment inputs of parent upon successful divide.");
+ CONFIG_ADD_VAR(RESET_INPUTS_ON_DIVIDE, int, 0, "Reset environment inputs of parent upon successful divide.");
CONFIG_ADD_GROUP(RECOMBINATION_GROUP, "Sexual Recombination and Modularity");
CONFIG_ADD_VAR(RECOMBINATION_PROB, double, 1.0, "probability of recombination in div-sex");
@@ -342,14 +342,15 @@
CONFIG_ADD_VAR(ANALYZE_OPTION_2, cString, "", "String variable accessible from analysis scripts");
CONFIG_ADD_GROUP(ENERGY_GROUP, "Energy Settings");
- CONFIG_ADD_VAR(ENERGY_ENABLED, bool, 0, "Enable Energy Model. 0/1 (off/on)");
- CONFIG_ADD_VAR(ENERGY_GIVEN_ON_INJECT, int, 0, "Energy given to organism upon injection.");
- CONFIG_ADD_VAR(ENERGY_GIVEN_AT_BIRTH, int, 0, "Energy given to offspring upon birth.");
+ CONFIG_ADD_VAR(ENERGY_ENABLED, int, 0, "Enable Energy Model. 0 = off\n1 = Organism-level energy enabled\n2 = Cell-level energy enabled\n3 = Organism & Cell-level energy enabled");
+ CONFIG_ADD_VAR(ENERGY_GIVEN_TO_ORG_ON_INJECT, int, 0, "Energy given to organism upon injection.");
+ CONFIG_ADD_VAR(ENERGY_GIVEN_TO_ORG_AT_BIRTH, int, 0, "Energy given to offspring upon birth.");
CONFIG_ADD_VAR(FRAC_PARENT_ENERGY_GIVEN_AT_BIRTH, double, 0.5, "Fraction of perent's energy given to offspring.");
- CONFIG_ADD_VAR(FRAC_ENERGY_DECAY_AT_BIRTH, double, 0.0, "Fraction of energy lost due to decay during reproduction.");
+ CONFIG_ADD_VAR(FRAC_ORG_ENERGY_DECAY_AT_BIRTH, double, 0.0, "Fraction of energy lost due to decay during reproduction.");
+ CONFIG_ADD_VAR(INITIAL_CELL_ENERGY, double, 0.0, "Amount of energy given to each cell in group (deme).");
CONFIG_ADD_VAR(NUM_INST_EXC_BEFORE_0_ENERGY, int, 0, "Number of instructions executed before energy is exhausted.");
CONFIG_ADD_VAR(ENERGY_CAP, int, -1, "Maximum amount of energy that can be stored in an organism. -1 means the cap is set to Max Int"); // TODO - is this done?
- CONFIG_ADD_VAR(APPLY_ENERGY_METHOD, int, 0, "When should rewarded energy be applied to current energy?\n0 = on divide\n1 = on completion of task\n2 = on sleep");
+ CONFIG_ADD_VAR(ENERGY_METABOLISM_PROCESS, int, 0, "When should rewarded energy be applied to current energy?\n0 = on divide\n1 = on completion of task\n2 = on sleep");
CONFIG_ADD_VAR(ENERGY_VERBOSE, bool, 0, "Print energy and merit values. 0/1 (off/on)");
CONFIG_ADD_VAR(LOG_SLEEP_TIMES, bool, 0, "Log sleep start and end times. 0/1 (off/on)\nWARNING: may use lots of memory.");
// CONFIG_ADD_VAR(FIX_METABOLIC_RATE, bool, 0, "When activated the metabolic rate of all orgiansims are equal. 0/1 (off/on)"); // TODO - check for correctness
Modified: branches/energy/source/main/cPopulation.cc
===================================================================
--- branches/energy/source/main/cPopulation.cc 2007-07-17 12:20:06 UTC (rev 1810)
+++ branches/energy/source/main/cPopulation.cc 2007-07-17 13:13:30 UTC (rev 1811)
@@ -130,6 +130,12 @@
reaper_queue.Push(&(cell_array[i]));
}
}
+ // set energy level in all cells
+ if(m_world->GetConfig().ENERGY_ENABLED.Get() == 2 || m_world->GetConfig().ENERGY_ENABLED.Get() == 3) {
+ for(int i=0; i<num_cells; ++i) {
+ cell_array[i].SetLocalEnergy(m_world->GetConfig().INITIAL_CELL_ENERGY.Get());
+ }
+ }
// What are the sizes of the demes that we're creating?
const int deme_size_x = world_x;
@@ -1002,6 +1008,13 @@
for (int deme_id = 0; deme_id < num_demes; deme_id++) {
deme_array[deme_id].Reset();
}
+
+ if(m_world->GetConfig().ENERGY_ENABLED.Get() == 2 || m_world->GetConfig().ENERGY_ENABLED.Get() == 3) {
+ // reset energy level in all cells
+ for (int i=0; i<cell_array.GetSize(); i++) {
+ cell_array[i].SetLocalEnergy(m_world->GetConfig().INITIAL_CELL_ENERGY.Get());
+ }
+ }
}
@@ -1021,12 +1034,12 @@
const int num_demes = GetNumDemes();
// Loop through all candidate demes...
- for (int deme_id = 0; deme_id < num_demes; deme_id++) {
- cDeme & source_deme = deme_array[deme_id];
-
+ for (int deme_id = 0; deme_id < num_demes; deme_id++) {
+ cDeme & source_deme = deme_array[deme_id];
+
// Doesn't make sense to try and replicate a deme that *has no organisms*.
if(source_deme.IsEmpty()) continue;
-
+
// Test this deme to determine if it should be replicated. If not,
// continue on to the next deme.
switch (rep_trigger) {
@@ -1043,46 +1056,46 @@
case 2: {
// Replicate all demes with the corners filled in.
// The first and last IDs represent the two corners.
- const int id1 = source_deme.GetCellID(0);
- const int id2 = source_deme.GetCellID(source_deme.GetSize() - 1);
- if(cell_array[id1].IsOccupied() == false ||
+ const int id1 = source_deme.GetCellID(0);
+ const int id2 = source_deme.GetCellID(source_deme.GetSize() - 1);
+ if(cell_array[id1].IsOccupied() == false ||
cell_array[id2].IsOccupied() == false) continue;
- break;
+ break;
}
- case 3: {
+ case 3: {
// Replicate old demes.
if(source_deme.GetAge() < m_world->GetConfig().MAX_DEME_AGE.Get()) continue;
break;
}
- default: {
- cerr << "ERROR: Invalid replication trigger " << rep_trigger
- << " in cPopulation::ReplicateDemes()" << endl;
+ default: {
+ cerr << "ERROR: Invalid replication trigger " << rep_trigger
+ << " in cPopulation::ReplicateDemes()" << endl;
assert(false);
}
}
- // -- If we made it this far, we should replicate this deme --
- cRandom& random = m_world->GetRandom();
-
- // Choose a random target deme to replicate to, and kill all the organisms
- // in that deme.
- int target_id = deme_id;
- while(target_id == deme_id) {
- target_id = random.GetUInt(num_demes);
- }
- cDeme& target_deme = deme_array[target_id];
- for (int i=0; i<target_deme.GetSize(); i++) {
- KillOrganism(cell_array[target_deme.GetCellID(i)]);
- }
-
- // 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
- // option DEMES_USE_GERMLINE is set.
- if(m_world->GetConfig().DEMES_USE_GERMLINE.Get()) {
- // Get the latest germ from the source deme.
- cGermline& source_germline = source_deme.GetGermline();
- cGenome& source_germ = source_germline.GetLatest();
+ // -- If we made it this far, we should replicate this deme --
+ cRandom& random = m_world->GetRandom();
+
+ // Choose a random target deme to replicate to, and kill all the organisms
+ // in that deme.
+ int target_id = deme_id;
+ while(target_id == deme_id) {
+ target_id = random.GetUInt(num_demes);
+ }
+ cDeme& target_deme = deme_array[target_id];
+ for (int i=0; i<target_deme.GetSize(); i++) {
+ KillOrganism(cell_array[target_deme.GetCellID(i)]);
+ }
+
+ // 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
+ // option DEMES_USE_GERMLINE is set.
+ if(m_world->GetConfig().DEMES_USE_GERMLINE.Get()) {
+ // Get the latest germ from the source deme.
+ cGermline& source_germline = source_deme.GetGermline();
+ cGenome& source_germ = source_germline.GetLatest();
// Now create the next germ by manually mutating the source.
// @refactor (strategy pattern)
@@ -1097,10 +1110,10 @@
}
}
- // Here we're adding the next_germ to the germline(s). Note the
+ // Here we're adding the next_germ to the germline(s). Note the
// config option to determine if we should update the source_germline
// as well.
- target_deme.ReplaceGermline(source_germline);
+ target_deme.ReplaceGermline(source_germline);
cGermline& target_germline = target_deme.GetGermline();
target_germline.Add(next_germ);
if(m_world->GetConfig().GERMLINE_REPLACES_SOURCE.Get()) {
@@ -1108,11 +1121,11 @@
}
// Kill all the organisms in the source deme.
- for (int i=0; i<source_deme.GetSize(); i++) {
- KillOrganism(cell_array[source_deme.GetCellID(i)]);
- }
+ for (int i=0; i<source_deme.GetSize(); i++) {
+ KillOrganism(cell_array[source_deme.GetCellID(i)]);
+ }
- // Lineage label is wrong here; fix.
+ // Lineage label is wrong here; fix.
if(m_world->GetConfig().GERMLINE_RANDOM_PLACEMENT.Get()) {
InjectGenome(source_deme.GetCellID(m_world->GetRandom().GetInt(0, source_deme.GetSize()-1)),
source_germline.GetLatest(), 0);
@@ -1122,46 +1135,55 @@
InjectGenome(source_deme.GetCellID(source_deme.GetSize()/2), source_germline.GetLatest(), 0);
InjectGenome(target_deme.GetCellID(target_deme.GetSize()/2), target_germline.GetLatest(), 0);
}
-
- // Note: not rotating the clones.
- } else {
- // Not using germline; choose a random organism from this deme.
- int cell1_id = -1;
- while (cell1_id == -1 || cell_array[cell1_id].IsOccupied() == false) {
- cell1_id = source_deme.GetCellID(random.GetUInt(source_deme.GetSize()));
- }
-
- cOrganism* seed = cell_array[cell1_id].GetOrganism();
-
- // And do the replication into the central cell of the target deme...
- const int cell2_id = target_deme.GetCellID(target_deme.GetWidth()/2, target_deme.GetHeight()/2);
- InjectClone(cell2_id, *seed);
- // Kill all the organisms in the source deme.
- seed = 0; // Note that we're killing the organism that seed points to.
- for (int i=0; i<source_deme.GetSize(); i++) {
- KillOrganism(cell_array[source_deme.GetCellID(i)]);
- }
-
- // Inject the target offspring back into the source ID.
- const int cell3_id = source_deme.GetCellID(source_deme.GetWidth()/2, source_deme.GetHeight()/2);
- InjectClone(cell3_id, *cell_array[cell2_id].GetOrganism());
+ // Note: not rotating the clones.
+ } else {
+ // Not using germline; choose a random organism from this deme.
+ int cell1_id = -1;
+ while (cell1_id == -1 || cell_array[cell1_id].IsOccupied() == false) {
+ cell1_id = source_deme.GetCellID(random.GetUInt(source_deme.GetSize()));
+ }
- // Rotate both injected cells to face northwest.
+ cOrganism* seed = cell_array[cell1_id].GetOrganism();
+
+ // And do the replication into the central cell of the target deme...
+ const int cell2_id = target_deme.GetCellID(target_deme.GetWidth()/2, target_deme.GetHeight()/2);
+ InjectClone(cell2_id, *seed);
+
+ // Kill all the organisms in the source deme.
+ seed = 0; // Note that we're killing the organism that seed points to.
+ for (int i=0; i<source_deme.GetSize(); i++) {
+ KillOrganism(cell_array[source_deme.GetCellID(i)]);
+ }
+
+ // Inject the target offspring back into the source ID.
+ const int cell3_id = source_deme.GetCellID(source_deme.GetWidth()/2, source_deme.GetHeight()/2);
+ InjectClone(cell3_id, *cell_array[cell2_id].GetOrganism());
+
+ // Rotate both injected cells to face northwest.
int offset=target_deme.GetCellID(0);
- cell_array[cell2_id].Rotate(cell_array[GridNeighbor(cell2_id-offset,
+ cell_array[cell2_id].Rotate(cell_array[GridNeighbor(cell2_id-offset,
target_deme.GetWidth(),
target_deme.GetHeight(), -1, -1)+offset]);
offset = source_deme.GetCellID(0);
- cell_array[cell3_id].Rotate(cell_array[GridNeighbor(cell3_id-offset,
+ cell_array[cell3_id].Rotate(cell_array[GridNeighbor(cell3_id-offset,
source_deme.GetWidth(),
source_deme.GetHeight(), -1, -1)+offset]);
- }
-
- // And reset both demes, in case they have any cleanup work to do.
- source_deme.Reset();
- target_deme.Reset();
- }
+ }
+
+ // And reset both demes, in case they have any cleanup work to do.
+ source_deme.Reset();
+ target_deme.Reset();
+ if(m_world->GetConfig().ENERGY_ENABLED.Get() == 2 || m_world->GetConfig().ENERGY_ENABLED.Get() == 3) {
+ // reset energy level in source and distination demes
+ for (int i=0; i<source_deme.GetSize(); i++) {
+ cell_array[source_deme.GetCellID(i)].SetLocalEnergy(m_world->GetConfig().INITIAL_CELL_ENERGY.Get());
+ }
+ for (int i=0; i<target_deme.GetSize(); i++) {
+ cell_array[target_deme.GetCellID(i)].SetLocalEnergy(m_world->GetConfig().INITIAL_CELL_ENERGY.Get());
+ }
+ }
+ }
}
// Loop through all demes to determine if any are ready to be divided. All
Modified: branches/energy/source/main/cPopulationCell.cc
===================================================================
--- branches/energy/source/main/cPopulationCell.cc 2007-07-17 12:20:06 UTC (rev 1810)
+++ branches/energy/source/main/cPopulationCell.cc 2007-07-17 13:13:30 UTC (rev 1811)
@@ -40,6 +40,7 @@
, organism(NULL)
, mutation_rates(NULL)
, organism_count(0)
+ , local_energy(0.0)
{
}
@@ -50,6 +51,7 @@
, cell_id(in_cell.cell_id)
, deme_id(in_cell.deme_id)
, organism_count(in_cell.organism_count)
+ , local_energy(0.0)
{
mutation_rates = new cMutationRates(*in_cell.mutation_rates);
tConstListIterator<cPopulationCell> conn_it(in_cell.connection_list);
Modified: branches/energy/source/main/cPopulationCell.h
===================================================================
--- branches/energy/source/main/cPopulationCell.h 2007-07-17 12:20:06 UTC (rev 1810)
+++ branches/energy/source/main/cPopulationCell.h 2007-07-17 13:13:30 UTC (rev 1811)
@@ -56,6 +56,7 @@
int cell_id; // Unique id for position of cell in population.
int deme_id; // ID of the deme that this cell is part of.
int organism_count; // Total number of orgs to ever inhabit this cell.
+ double local_energy;
//location in population
int m_x; //!< The x-coordinate of the position of this cell in the environment.
@@ -93,6 +94,10 @@
bool IsOccupied() const { return organism != NULL; }
+ void SetLocalEnergy(const double energy) { local_energy = energy; }
+ double GetLocalEnergy() const { return local_energy; }
+ void ReduceLocalEnergy(const double energy) { local_energy -= energy; }
+
bool OK();
};
More information about the Avida-cvs
mailing list