[Avida-SVN] r2392 - in development/source: cpu main
dknoester at myxo.css.msu.edu
dknoester at myxo.css.msu.edu
Thu Feb 28 08:16:03 PST 2008
Author: dknoester
Date: 2008-02-28 11:16:03 -0500 (Thu, 28 Feb 2008)
New Revision: 2392
Modified:
development/source/cpu/cTestCPUInterface.h
development/source/main/cEnvironment.cc
development/source/main/cOrgInterface.h
development/source/main/cPhenotype.cc
development/source/main/cPopulationInterface.cc
development/source/main/cPopulationInterface.h
development/source/main/cReactionProcess.h
development/source/main/cReactionResult.cc
development/source/main/cReactionResult.h
Log:
Last commit to enable deme merit. Reaction processes now apply process:demefrac to the heritable merit of each deme.
Modified: development/source/cpu/cTestCPUInterface.h
===================================================================
--- development/source/cpu/cTestCPUInterface.h 2008-02-28 15:32:07 UTC (rev 2391)
+++ development/source/cpu/cTestCPUInterface.h 2008-02-28 16:16:03 UTC (rev 2392)
@@ -46,6 +46,7 @@
int GetCellID() { return -1; }
int GetDemeID() { return -1; }
+ cDeme* GetDeme() { return 0; }
void SetCellID(int in_id) { ; }
void SetDemeID(int in_id) { ; }
Modified: development/source/main/cEnvironment.cc
===================================================================
--- development/source/main/cEnvironment.cc 2008-02-28 15:32:07 UTC (rev 2391)
+++ development/source/main/cEnvironment.cc 2008-02-28 16:16:03 UTC (rev 2392)
@@ -1021,8 +1021,11 @@
// Mark the reaction as having been performed if we get here.
result.MarkReaction(reaction_id);
- // Calculate the bonus
- double bonus = consumed * cur_process->GetValue();
+ // How much of this bonus belongs to the deme, and how much belongs to the organism?
+ double deme_bonus = cur_process->GetDemeFraction() * consumed * cur_process->GetValue();
+ double bonus = (1.0 - cur_process->GetDemeFraction()) * consumed * cur_process->GetValue();
+
+ result.DemeBonus(deme_bonus);
switch (cur_process->GetType()) {
case nReaction::PROCTYPE_ADD:
Modified: development/source/main/cOrgInterface.h
===================================================================
--- development/source/main/cOrgInterface.h 2008-02-28 15:32:07 UTC (rev 2391)
+++ development/source/main/cOrgInterface.h 2008-02-28 16:16:03 UTC (rev 2392)
@@ -36,6 +36,7 @@
class cAvidaContext;
class cCodeLabel;
+class cDeme;
class cGenome;
class cOrganism;
class cOrgMessage;
@@ -55,6 +56,7 @@
virtual int GetCellID() = 0;
virtual int GetDemeID() = 0;
+ virtual cDeme* GetDeme() = 0;
virtual void SetCellID(int in_id) = 0;
virtual void SetDemeID(int in_id) = 0;
Modified: development/source/main/cPhenotype.cc
===================================================================
--- development/source/main/cPhenotype.cc 2008-02-28 15:32:07 UTC (rev 2391)
+++ development/source/main/cPhenotype.cc 2008-02-28 16:16:03 UTC (rev 2392)
@@ -26,6 +26,7 @@
#include "cPhenotype.h"
#include "cEnvironment.h"
+#include "cDeme.h"
#include "cHardwareManager.h"
#include "cInstSet.h"
#include "cReactionResult.h"
@@ -1005,6 +1006,11 @@
cur_bonus *= result.GetMultBonus();
cur_bonus += result.GetAddBonus();
+ // Update deme merit.
+ if(taskctx.GetOrganism()->GetOrgInterface().GetDeme()) {
+ taskctx.GetOrganism()->GetOrgInterface().GetDeme()->UpdateHeritableDemeMerit(result.GetDemeBonus());
+ }
+
// Update the energy bonus
cur_energy_bonus += result.GetAddEnergy();
Modified: development/source/main/cPopulationInterface.cc
===================================================================
--- development/source/main/cPopulationInterface.cc 2008-02-28 15:32:07 UTC (rev 2391)
+++ development/source/main/cPopulationInterface.cc 2008-02-28 16:16:03 UTC (rev 2392)
@@ -41,7 +41,12 @@
#define NULL 0
#endif
+cDeme* cPopulationInterface::GetDeme()
+{
+ return &m_world->GetPopulation().GetDeme(m_deme_id);
+}
+
bool cPopulationInterface::Divide(cAvidaContext& ctx, cOrganism* parent, cGenome& child_genome)
{
assert(parent != NULL);
Modified: development/source/main/cPopulationInterface.h
===================================================================
--- development/source/main/cPopulationInterface.h 2008-02-28 15:32:07 UTC (rev 2391)
+++ development/source/main/cPopulationInterface.h 2008-02-28 16:16:03 UTC (rev 2392)
@@ -35,6 +35,7 @@
#ifndef cWorldDriver_h
#include "cWorldDriver.h"
#endif
+#include "cDeme.h"
class cPopulation;
class cOrgMessage;
@@ -57,6 +58,7 @@
int GetCellID() { return m_cell_id; }
int GetDemeID() { return m_deme_id; }
+ cDeme* GetDeme();
void SetCellID(int in_id) { m_cell_id = in_id; }
void SetDemeID(int in_id) { m_deme_id = in_id; }
Modified: development/source/main/cReactionProcess.h
===================================================================
--- development/source/main/cReactionProcess.h 2008-02-28 15:32:07 UTC (rev 2391)
+++ development/source/main/cReactionProcess.h 2008-02-28 16:16:03 UTC (rev 2392)
@@ -122,7 +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 SetDemeFraction(double _in) { assert(_in>=0.0); assert(_in<=1.0); 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/cReactionResult.cc
===================================================================
--- development/source/main/cReactionResult.cc 2008-02-28 15:32:07 UTC (rev 2391)
+++ development/source/main/cReactionResult.cc 2008-02-28 16:16:03 UTC (rev 2392)
@@ -44,6 +44,7 @@
, lethal(false)
, sterilize(false)
, active_reaction(false)
+ , deme_bonus(0.0)
{
}
@@ -135,6 +136,13 @@
bonus_mult *= value;
}
+void cReactionResult::DemeBonus(double value)
+{
+ ActivateReaction();
+ deme_bonus += value;
+}
+
+
void cReactionResult::AddInst(int id)
{
insts_triggered.Push(id);
Modified: development/source/main/cReactionResult.h
===================================================================
--- development/source/main/cReactionResult.h 2008-02-28 15:32:07 UTC (rev 2391)
+++ development/source/main/cReactionResult.h 2008-02-28 16:16:03 UTC (rev 2392)
@@ -48,6 +48,8 @@
bool sterilize;
bool active_reaction;
+ double deme_bonus; //!< Bonus applied to the deme as a result of this reaction.
+
inline void ActivateReaction();
cReactionResult(); // @not_implemented
@@ -71,6 +73,7 @@
void AddEnergy(double value);
void AddBonus(double value, int id);
void MultBonus(double value);
+ void DemeBonus(double value);
void AddInst(int id);
@@ -88,6 +91,7 @@
double GetReactionAddBonus(const int i) { return reaction_add_bonus[i]; }
double GetMultBonus() { return bonus_mult; }
tArray<int>& GetInstArray() { return insts_triggered; }
+ double GetDemeBonus() { return deme_bonus; }
};
More information about the Avida-cvs
mailing list