[Avida-SVN] r2884 - branches/movement/source/actions
grabow38 at myxo.css.msu.edu
grabow38 at myxo.css.msu.edu
Mon Oct 27 07:55:56 PDT 2008
Author: grabow38
Date: 2008-10-27 10:55:56 -0400 (Mon, 27 Oct 2008)
New Revision: 2884
Modified:
branches/movement/source/actions/PopulationActions.cc
Log:
Added deme competition based on steps on path vs. steps off path.
Modified: branches/movement/source/actions/PopulationActions.cc
===================================================================
--- branches/movement/source/actions/PopulationActions.cc 2008-10-27 11:13:08 UTC (rev 2883)
+++ branches/movement/source/actions/PopulationActions.cc 2008-10-27 14:55:56 UTC (rev 2884)
@@ -1706,8 +1706,8 @@
double current_res = 0.0;// Current total resource in deme
double initial_res = 0.0;// Initial total resource in deme
- for(int i = 0; i < res.GetSize(); i++) {
- if( (res.GetResourcesGeometry())[i] != nGeometry::GLOBAL) {
+ for (int i = 0; i < res.GetSize(); i++) {
+ if ( (res.GetResourcesGeometry())[i] != nGeometry::GLOBAL) {
cSpatialResCount sp_res = res.GetSpatialResource(i);
current_res += sp_res.GetAmount(i);
initial_res += res.GetInitialResourceValue(i);
@@ -1721,6 +1721,53 @@
}
};
+// @ LMG
+// Compete demes based on how many steps the organism took on the path compared to how many steps it took off the path
+class cAbstractCompeteDemes_FollowPath : public cAbstractCompeteDemes {
+ public:
+ cAbstractCompeteDemes_FollowPath(cWorld* world, const cString& args) : cAbstractCompeteDemes(world, args) { }
+
+ static const cString GetDescription() { return "No Arguments"; }
+
+ double Fitness(const cDeme& deme) {
+
+ cResourceCount res = deme.GetDemeResourceCount();
+ double current_good_res = 0.0;// Current total good resource in deme
+ double initial_good_res = 0.0;// Initial total good resource in deme
+ double current_poison = 0.0; // Current total poison in deme
+ double initial_poison = 0.0; // Initial total poison in deme
+ double consumed_good = 0.0; // Amount of good resource consumed
+ double consumed_poison = 0.0; // Amount of poison consumed
+ cString res_name; // Name of resource
+ double fitnessOfDeme = 0.0; // Fitness of deme
+
+ for (int i = 0; i < res.GetSize(); i++) {
+ if ( (res.GetResourcesGeometry())[i] != nGeometry::GLOBAL) {
+ cSpatialResCount sp_res = res.GetSpatialResource(i);
+ res_name = res.GetResName(i);
+ if ( res_name != "poison" ) {
+ current_good_res += sp_res.GetAmount(i);
+ initial_good_res += res.GetInitialResourceValue(i);
+ }
+ else {
+ current_poison = sp_res.GetAmount(i);
+ initial_poison = res.GetInitialResourceValue(i);
+ }
+ }
+ }
+
+ consumed_good = initial_good_res - current_good_res;
+ consumed_poison = initial_poison - current_poison;
+
+ // If consumed more good resources than poison, fitness is square of difference, otherwise fitness = 0.0
+ if ( consumed_good > consumed_poison )
+ fitnessOfDeme = pow( (consumed_good - consumed_poison), 2.0 );
+
+ return fitnessOfDeme;
+ }
+};
+
+
/* This Action will check if any demes have met the critera to be replicated
and do so. There are several bases this can be checked on:
@@ -2420,6 +2467,7 @@
action_lib->Register<cAssignRandomCellData>("AssignRandomCellData");
action_lib->Register<cActionIteratedConsensus>("IteratedConsensus");
action_lib->Register<cAbstractCompeteDemes_ConsumeCellResources>("CompeteDemes_ConsumeCellResources"); // @ LMG
+ action_lib->Register<cAbstractCompeteDemes_FollowPath>("CompeteDemes_FollowPath"); // @ LMG
action_lib->Register<cActionSynchronization>("Synchronization");
action_lib->Register<cActionDesynchronization>("Desynchronization");
More information about the Avida-cvs
mailing list