[Avida-SVN] r2312 - development/source/main
beckma24 at myxo.css.msu.edu
beckma24 at myxo.css.msu.edu
Fri Feb 8 08:32:52 PST 2008
Author: beckma24
Date: 2008-02-08 11:32:52 -0500 (Fri, 08 Feb 2008)
New Revision: 2312
Modified:
development/source/main/cAvidaConfig.h
development/source/main/cDeme.cc
development/source/main/cDeme.h
development/source/main/cPhenotype.cc
development/source/main/cPhenotype.h
development/source/main/cPopulation.cc
Log:
Added config option to pass energy from parent to offspring deme
Modified: development/source/main/cAvidaConfig.h
===================================================================
--- development/source/main/cAvidaConfig.h 2008-02-08 04:20:55 UTC (rev 2311)
+++ development/source/main/cAvidaConfig.h 2008-02-08 16:32:52 UTC (rev 2312)
@@ -447,15 +447,15 @@
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(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_PARENT_ENERGY_GIVEN_TO_ORG_AT_BIRTH, double, 0.5, "Fraction of perent's energy given to offspring organism.");
+ CONFIG_ADD_VAR(FRAC_PARENT_ENERGY_GIVEN_TO_DEME_AT_BIRTH, double, 0.5, "Fraction of perent's energy given to offspring deme.");
+ CONFIG_ADD_VAR(FRAC_ENERGY_DECAY_AT_ORG_BIRTH, double, 0.0, "Fraction of energy lost due to decay during organism reproduction.");
+ CONFIG_ADD_VAR(FRAC_ENERGY_DECAY_AT_DEME_BIRTH, double, 0.0, "Fraction of energy lost due to decay during deme reproduction.");
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(FRAC_ENERGY_TRANSFER, double, 0.0, "Fraction of replaced organism's energy take by new resident");
-// 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
CONFIG_ADD_GROUP(SECOND_PASS_GROUP, "Tracking metrics known after the running experiment previously");
CONFIG_ADD_VAR(TRACK_CCLADES, int, 0, "Enable tracking of coalescence clades");
Modified: development/source/main/cDeme.cc
===================================================================
--- development/source/main/cDeme.cc 2008-02-08 04:20:55 UTC (rev 2311)
+++ development/source/main/cDeme.cc 2008-02-08 16:32:52 UTC (rev 2312)
@@ -22,6 +22,8 @@
*/
#include "cDeme.h"
+#include "cOrganism.h"
+#include "cPhenotype.h"
#include "cPopulation.h"
#include "cPopulationCell.h"
#include "cResource.h"
@@ -88,15 +90,37 @@
++_age;
}
-void cDeme::Reset()
+void cDeme::Reset()
{
- birth_count = 0;
- _age = 0;
- //clear cell energy
-
+ birth_count = 0;
+ _age = 0;
deme_resource_count.ReinitializeResources();
}
+void cDeme::Reset(double deme_energy)
+{
+ assert(m_world->GetConfig().ENERGY_ENABLED.Get());
+ assert(org_count>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>(org_count));
+ phenotype.SetMerit(cMerit(cMerit::EnergyToMerit(phenotype.GetStoredEnergy() * phenotype.GetEnergyUsageRatio(), m_world)));
+ }
+ }
+ Reset();
+}
+
+
/*! Replacing this deme's germline has the effect of changing the deme's lineage.
There's still some work to do here; the lineage labels of the Genomes in the germline
are all messed up.
@@ -184,3 +208,19 @@
cDemeCellEvent demeEvent = cDemeCellEvent(x1, y1, x2, y2, delay, duration, width);
cell_events.Push(demeEvent);
}
+
+double cDeme::CalculateTotalEnergy() {
+ assert(m_world->GetConfig().ENERGY_ENABLED.Get());
+
+ double energy_sum = 0.0;
+ 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();
+ energy_sum += phenotype.GetStoredEnergy();
+ }
+ }
+ return energy_sum;
+}
Modified: development/source/main/cDeme.h
===================================================================
--- development/source/main/cDeme.h 2008-02-08 04:20:55 UTC (rev 2311)
+++ development/source/main/cDeme.h 2008-02-08 16:32:52 UTC (rev 2312)
@@ -46,6 +46,7 @@
int birth_count; //!< Number of organisms that have been born into this deme since reset.
int org_count; //!< Number of organisms are currently in this deme.
int _age; //!< Age of this deme, in updates.
+ double total_org_energy; //! total amount of energy in organisms in this deme
cGermline _germline; //!< The germline for this deme, if used.
@@ -57,7 +58,7 @@
tArray<cDemeCellEvent> cell_events;
public:
- cDeme() : width(0), birth_count(0), org_count(0), _age(0), deme_resource_count(0) { ; }
+ cDeme() : width(0), birth_count(0), org_count(0), _age(0), total_org_energy(0.0), deme_resource_count(0) { ; }
~cDeme() { ; }
void Setup(const tArray<int>& in_cells, int in_width = -1, cWorld* world = NULL);
@@ -72,6 +73,7 @@
int GetHeight() const { return cell_ids.GetSize() / width; }
void Reset();
+ void Reset(double deme_energy); //! used to pass energy to offspring deme
int GetBirthCount() const { return birth_count; }
void IncBirthCount() { birth_count++; }
@@ -110,6 +112,8 @@
int GetRelativeCellID(int absolute_cell_id) { return absolute_cell_id % GetSize(); } //!< assumes all demes are the same size
void SetCellEvent(int x1, int y1, int x2, int y2, int delay, int duration);
+
+ double CalculateTotalEnergy();
};
#endif
Modified: development/source/main/cPhenotype.cc
===================================================================
--- development/source/main/cPhenotype.cc 2008-02-08 04:20:55 UTC (rev 2311)
+++ development/source/main/cPhenotype.cc 2008-02-08 16:32:52 UTC (rev 2312)
@@ -1393,8 +1393,8 @@
assert(m_world->GetConfig().ENERGY_ENABLED.Get() > 0);
// energy model config variables
double energy_given_at_birth = m_world->GetConfig().ENERGY_GIVEN_AT_BIRTH.Get();
- double frac_parent_energy_given_at_birth = m_world->GetConfig().FRAC_PARENT_ENERGY_GIVEN_AT_BIRTH.Get();
- double frac_energy_decay_at_birth = m_world->GetConfig().FRAC_ENERGY_DECAY_AT_BIRTH.Get();
+ double frac_parent_energy_given_at_birth = m_world->GetConfig().FRAC_PARENT_ENERGY_GIVEN_TO_ORG_AT_BIRTH.Get();
+ double frac_energy_decay_at_birth = m_world->GetConfig().FRAC_ENERGY_DECAY_AT_ORG_BIRTH.Get();
double energy_cap = (double) m_world->GetConfig().ENERGY_CAP.Get();
// apply energy if APPLY_ENERGY_METHOD is set to "on divide" (0)
Modified: development/source/main/cPhenotype.h
===================================================================
--- development/source/main/cPhenotype.h 2008-02-08 04:20:55 UTC (rev 2311)
+++ development/source/main/cPhenotype.h 2008-02-08 16:32:52 UTC (rev 2312)
@@ -83,7 +83,6 @@
template <class T> class tList;
class cTaskContext;
class cTaskState;
-//class cWorld;
class cPhenotype
{
Modified: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc 2008-02-08 04:20:55 UTC (rev 2311)
+++ development/source/main/cPopulation.cc 2008-02-08 16:32:52 UTC (rev 2312)
@@ -1066,6 +1066,8 @@
1: 'full_deme' - ...demes that have been filled up.
2: 'corners' - ...demes with upper left and lower right corners filled.
3: 'deme-age' - ...demes who have reached their maximum age
+4: 'birth-count' ...demes that have had a certain number of births.
+
*/
void cPopulation::ReplicateDemes(int rep_trigger)
@@ -1149,6 +1151,15 @@
// Stats tracking; pre-replication hook.
m_world->GetStats().DemePreReplication(source_deme, target_deme);
+ // used to pass energy to offspring demes (set to zero if energy model is not enabled)
+ double source_deme_energy(0.0), deme_energy_decay(0.0), parent_deme_energy(0.0), offspring_deme_energy(0.0);
+ if(m_world->GetConfig().ENERGY_ENABLED.Get()) {
+ source_deme_energy = source_deme.CalculateTotalEnergy();
+ deme_energy_decay = 1.0 - m_world->GetConfig().FRAC_ENERGY_DECAY_AT_DEME_BIRTH.Get();
+ parent_deme_energy = source_deme_energy * deme_energy_decay * (1.0 - m_world->GetConfig().FRAC_PARENT_ENERGY_GIVEN_TO_DEME_AT_BIRTH.Get());
+ offspring_deme_energy = source_deme_energy * deme_energy_decay * m_world->GetConfig().FRAC_PARENT_ENERGY_GIVEN_TO_DEME_AT_BIRTH.Get();
+ }
+
// Are we using germlines? If so, we need to mutate the germline to get the
// genome that we're going to seed the target with.
if(m_world->GetConfig().DEMES_USE_GERMLINE.Get()) {
@@ -1199,8 +1210,13 @@
}
// 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()) {
+ source_deme.Reset(parent_deme_energy);
+ target_deme.Reset(offspring_deme_energy);
+ } else {
+ source_deme.Reset();
+ target_deme.Reset();
+ }
// All done; do our post-replication stats tracking.
m_world->GetStats().DemePostReplication(source_deme, target_deme);
More information about the Avida-cvs
mailing list