[Avida-SVN] r2390 - in development/source: main tools
dknoester at myxo.css.msu.edu
dknoester at myxo.css.msu.edu
Thu Feb 28 06:24:32 PST 2008
Author: dknoester
Date: 2008-02-28 09:24:31 -0500 (Thu, 28 Feb 2008)
New Revision: 2390
Modified:
development/source/main/cDeme.cc
development/source/main/cDeme.h
development/source/main/cEnvironment.cc
development/source/main/cPopulation.cc
development/source/main/cReactionProcess.h
development/source/main/cStats.cc
development/source/main/cStats.h
development/source/tools/cMerit.h
Log:
First of three(?) commits for deme-level merit. This one adds the demefrac process attribute, plumbing in the demes, and stat tracking.
Modified: development/source/main/cDeme.cc
===================================================================
--- development/source/main/cDeme.cc 2008-02-28 03:47:13 UTC (rev 2389)
+++ development/source/main/cDeme.cc 2008-02-28 14:24:31 UTC (rev 2390)
@@ -125,21 +125,26 @@
/*! 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.
-
- at todo Fix lineage labels in germlines.
*/
void cDeme::ReplaceGermline(const cGermline& germline) {
_germline = germline;
}
+/*! If this method is called, this is the "parent" deme. As with individuals,
+we need to rotate the heritable merit to the current merit.
+*/
+void cDeme::UpdateDemeMerit() {
+ _current_merit = _next_merit;
+ _next_merit = 0;
+}
+
+
/*! Update this deme's merit from the given source.
-
- at todo We have a little bit of work to do here yet, as the deme merit isn't yet
-tied into the scheduler. Crash.
*/
void cDeme::UpdateDemeMerit(cDeme& source) {
- assert(false);
+ _current_merit = source.GetHeritableDemeMerit();
+ _next_merit = 0;
}
Modified: development/source/main/cDeme.h
===================================================================
--- development/source/main/cDeme.h 2008-02-28 03:47:13 UTC (rev 2389)
+++ development/source/main/cDeme.h 2008-02-28 14:24:31 UTC (rev 2390)
@@ -26,6 +26,7 @@
#include "cDemeCellEvent.h"
#include "cGermline.h"
+#include "cMerit.h"
#include "tArray.h"
#include "cResourceCount.h"
#include "cStringList.h"
@@ -57,6 +58,9 @@
tArray<cDemeCellEvent> cell_events;
+ cMerit _current_merit; //!< Deme merit applied to all organisms living in this deme.
+ cMerit _next_merit; //!< Deme merit that will be inherited upon deme replication.
+
public:
cDeme() : width(0), birth_count(0), org_count(0), _age(0), total_org_energy(0.0), deme_resource_count(0) { ; }
~cDeme() { ; }
@@ -90,8 +94,16 @@
//! Replaces this deme's germline.
void ReplaceGermline(const cGermline& germline);
- //! Update this deme's merit from the given source.
+ //! Update this deme's merit by rotating the heritable merit to the current merit.
+ void UpdateDemeMerit();
+ //! Update this deme's merit from the given source; merit will be applied to organisms now.
void UpdateDemeMerit(cDeme& source);
+ //! Update the heritable merit; will be applied to this deme and it's offspring upon replication.
+ void UpdateHeritableDemeMerit(double value) { _next_merit += value; }
+ //! Retrieve this deme's current merit; to be applied to organisms living in this deme now.
+ const cMerit& GetDemeMerit() const { return _current_merit; }
+ //! Retrieve this deme's heritable merit.
+ const cMerit& GetHeritableDemeMerit() const { return _next_merit; }
// -= Update support =-
//! Called once, at the end of every update.
Modified: development/source/main/cEnvironment.cc
===================================================================
--- development/source/main/cEnvironment.cc 2008-02-28 03:47:13 UTC (rev 2389)
+++ development/source/main/cEnvironment.cc 2008-02-28 14:24:31 UTC (rev 2390)
@@ -207,6 +207,11 @@
return false;
new_process->SetSterile(var_value.AsInt());
}
+ else if (var_name == "demefrac") {
+ if (!AssertInputDouble(var_value, "demefrac", var_type))
+ return false;
+ new_process->SetDemeFraction(var_value.AsDouble());
+ }
else if (var_name == "detect") {
cResource* test_resource = resource_lib.GetResource(var_value);
if (!AssertInputValid(test_resource, "product", var_type, var_value)) {
Modified: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc 2008-02-28 03:47:13 UTC (rev 2389)
+++ development/source/main/cPopulation.cc 2008-02-28 14:24:31 UTC (rev 2390)
@@ -122,7 +122,6 @@
// Not yet supported:
assert(m_world->GetConfig().DEMES_REPLICATE_SIZE.Get()==1);
- assert(m_world->GetConfig().DEMES_HAVE_MERIT.Get()==0);
#ifdef DEBUG
const int birth_method = m_world->GetConfig().BIRTH_METHOD.Get();
@@ -490,7 +489,7 @@
m_world->GetClassificationManager().AdjustGenotype(*in_genotype);
// Initialize the time-slice for this new organism.
- schedule->Adjust(target_cell.GetID(), in_organism->GetPhenotype().GetMerit(),target_cell.GetDemeID());
+ schedule->Adjust(target_cell.GetID(), in_organism->GetPhenotype().GetMerit(), target_cell.GetDemeID());
// Special handling for certain birth methods.
if (m_world->GetConfig().BIRTH_METHOD.Get() == POSITION_CHILD_FULL_SOUP_ELDEST) {
@@ -1214,6 +1213,7 @@
// If we're using deme merit, the source's merit must be transferred to the target.
if(m_world->GetConfig().DEMES_HAVE_MERIT.Get()) {
target_deme.UpdateDemeMerit(source_deme);
+ source_deme.UpdateDemeMerit();
}
bool source_deme_resource_reset(true), target_deme_resource_reset(true);
Modified: development/source/main/cReactionProcess.h
===================================================================
--- development/source/main/cReactionProcess.h 2008-02-28 03:47:13 UTC (rev 2389)
+++ development/source/main/cReactionProcess.h 2008-02-28 14:24:31 UTC (rev 2390)
@@ -53,7 +53,8 @@
cResource* product; // Output resource.
double conversion; // Conversion factor.
bool lethal; // Lethality of reaction
- bool sterilize; //! Whether performance of this reaction sterilizes the organism.
+ bool sterilize; //!< Whether performance of this reaction sterilizes the organism.
+ double deme_fraction; //!< Fraction of process reward that is applied to the organism's deme.
cString match_string; // Bit string to match if this is a match string reaction
int inst_id; // Instruction to be triggered if reaction successful.
bool depletable; // Does completing consume resource?
@@ -81,6 +82,7 @@
, conversion(1.0)
, lethal(0)
, sterilize(false)
+ , deme_fraction(0.0)
, inst_id(-1)
, depletable(true)
, detect(NULL)
@@ -102,6 +104,7 @@
bool GetDepletable() const { return depletable; }
bool GetLethal() const { return lethal; }
bool GetSterilize() const { return sterilize; }
+ double GetDemeFraction() const { return deme_fraction; }
cResource* GetDetect() const { return detect; }
double GetDetectionThreshold() const { return detection_threshold; }
double GetDetectionError() const { return detection_error; }
@@ -119,6 +122,7 @@
void SetDepletable(bool _in) { depletable = _in; }
void SetLethal(int _in) { lethal = _in; }
void SetSterile(int _in) { sterilize = _in; }
+ void SetDemeFraction(double _in) { deme_fraction = _in; }
void SetDetect(cResource* _in) { detect = _in; }
void SetDetectionThreshold(double _in) { detection_threshold = _in; }
void SetDetectionError(double _in) { detection_error = _in; }
Modified: development/source/main/cStats.cc
===================================================================
--- development/source/main/cStats.cc 2008-02-28 03:47:13 UTC (rev 2389)
+++ development/source/main/cStats.cc 2008-02-28 14:24:31 UTC (rev 2390)
@@ -1218,7 +1218,8 @@
{
++m_deme_num_repls;
m_deme_gestation_time.Add(source_deme.GetAge());
- m_deme_births.Add(source_deme.GetBirthCount());
+ m_deme_births.Add(source_deme.GetBirthCount());
+ m_deme_merit.Add(source_deme.GetHeritableDemeMerit().GetDouble());
}
@@ -1243,13 +1244,15 @@
df.Write(m_update, "Update [update]");
df.Write(m_deme_num_repls, "Number of deme replications [numrepl]");
df.Write(m_deme_gestation_time.Average(), "Mean deme gestation time [gesttime]");
- df.Write(m_deme_births.Average(), "Mean number of births [numbirths]");
+ df.Write(m_deme_births.Average(), "Mean number of births within replicated demes [numbirths]");
+ df.Write(m_deme_merit.Average(), "Mean heritable merit of replicated demes [merit]");
df.Endl();
m_deme_num_repls = 0;
m_deme_gestation_time.Clear();
m_deme_births.Clear();
+ m_deme_merit.Clear();
}
Modified: development/source/main/cStats.h
===================================================================
--- development/source/main/cStats.h 2008-02-28 03:47:13 UTC (rev 2389)
+++ development/source/main/cStats.h 2008-02-28 14:24:31 UTC (rev 2390)
@@ -704,6 +704,7 @@
int m_deme_num_repls; //!< Number of deme replications since last PrintDemeReplicationData.
cDoubleSum m_deme_gestation_time; //!< Gestation time for demes - mean age at deme replication.
cDoubleSum m_deme_births; //!< Mean number of births in replicated demes.
+ cDoubleSum m_deme_merit; //!< Mean merit of replicated demes.
cDoubleSum m_germline_generation; //!< "Generation" accumulator of replicated germlines.
};
Modified: development/source/tools/cMerit.h
===================================================================
--- development/source/tools/cMerit.h 2008-02-28 03:47:13 UTC (rev 2389)
+++ development/source/tools/cMerit.h 2008-02-28 14:24:31 UTC (rev 2390)
@@ -63,7 +63,8 @@
void operator=(double _merit) { UpdateValue(_merit); }
void operator+=(const cMerit & _m){ UpdateValue(value + _m.GetDouble()); }
-
+ void operator+=(double _merit) { UpdateValue(value + _merit); }
+ cMerit operator*(const cMerit& _m) const { return cMerit(value * _m.GetDouble()); }
int operator>(const cMerit & _m) const { return value > _m.GetDouble(); }
int operator<(const cMerit & _m) const { return value < _m.GetDouble(); }
int operator>=(const cMerit & _m) const { return value >= _m.GetDouble(); }
More information about the Avida-cvs
mailing list