[Avida-SVN] r3195 - in development/source: actions main
connel42 at myxo.css.msu.edu
connel42 at myxo.css.msu.edu
Mon Mar 23 08:23:20 PDT 2009
Author: connel42
Date: 2009-03-23 11:23:20 -0400 (Mon, 23 Mar 2009)
New Revision: 3195
Modified:
development/source/actions/PopulationActions.cc
development/source/actions/PrintActions.cc
development/source/main/cStats.cc
development/source/main/cStats.h
Log:
Added actions to kill organisms if resource level in their cell is above/below a threshold. Also added corresponding stats and print action for this
Modified: development/source/actions/PopulationActions.cc
===================================================================
--- development/source/actions/PopulationActions.cc 2009-03-20 17:56:46 UTC (rev 3194)
+++ development/source/actions/PopulationActions.cc 2009-03-23 15:23:20 UTC (rev 3195)
@@ -2612,7 +2612,104 @@
};
+/*
+ Kill organisms in N randomly-chosen cells if the level of the given resource
+ in the chosen cell is below the configured threshold
+
+ Parameters:
+ - The number of cells to kill (default: 0)
+ - The name of the resource
+ - The amount of resource below which to execute the kill (default: 0)
+ */
+class cActionKillNBelowResourceThreshold : public cAction
+ {
+ private:
+ cString m_resname;
+ int m_numkills;
+ double m_threshold;
+ public:
+ cActionKillNBelowResourceThreshold(cWorld* world, const cString& args) : cAction(world, args), m_numkills(0), m_threshold(0)
+ {
+ cString largs(args);
+ if (largs.GetSize()) m_numkills = largs.PopWord().AsInt();
+ if (largs.GetSize()) m_resname = largs.PopWord();
+ if (largs.GetSize()) m_threshold = largs.PopWord().AsDouble();
+ }
+
+ static const cString GetDescription() { return "Arguments: [int numkills=0, string resource name, double threshold=0]"; }
+
+ void Process(cAvidaContext& ctx)
+ {
+ double level;
+ int target_cell;
+ int res_id = m_world->GetPopulation().GetResourceCount().GetResourceCountID(m_resname);
+
+ assert(res_id != -1);
+
+ for(int i=0; i < m_numkills; i++) {
+ target_cell = m_world->GetRandom().GetInt(0, m_world->GetPopulation().GetSize()-1);
+ level = m_world->GetPopulation().GetResourceCount().GetSpatialResource(res_id).GetAmount(target_cell);
+
+ if(level < m_threshold) {
+ m_world->GetPopulation().KillOrganism(m_world->GetPopulation().GetCell(target_cell));
+ m_world->GetStats().IncNumOrgsKilled();
+ }
+ }
+
+ } //End Process()
+ };
+
+
+/*
+ Kill organisms in N randomly-chosen cells if the level of the given resource
+ in the chosen cell is below the configured threshold
+
+ Parameters:
+ - The number of cells to kill (default: 0)
+ - The name of the resource
+ - The amount of resource below which to execute the kill (default: 0)
+ */
+
+class cActionKillNAboveResourceThreshold : public cAction
+ {
+ private:
+ cString m_resname;
+ int m_numkills;
+ double m_threshold;
+ public:
+ cActionKillNAboveResourceThreshold(cWorld* world, const cString& args) : cAction(world, args), m_numkills(0), m_threshold(0)
+ {
+ cString largs(args);
+ if (largs.GetSize()) m_numkills = largs.PopWord().AsInt();
+ if (largs.GetSize()) m_resname = largs.PopWord();
+ if (largs.GetSize()) m_threshold = largs.PopWord().AsDouble();
+ }
+
+ static const cString GetDescription() { return "Arguments: [int numkills=0, string resource name, double threshold=0]"; }
+
+ void Process(cAvidaContext& ctx)
+ {
+ double level;
+ int target_cell;
+ int res_id = m_world->GetPopulation().GetResourceCount().GetResourceCountID(m_resname);
+
+ assert(res_id != -1);
+
+ for(int i=0; i < m_numkills; i++) {
+ target_cell = m_world->GetRandom().GetInt(0, m_world->GetPopulation().GetSize()-1);
+ level = m_world->GetPopulation().GetResourceCount().GetSpatialResource(res_id).GetAmount(target_cell);
+
+ if(level > m_threshold) {
+ m_world->GetPopulation().KillOrganism(m_world->GetPopulation().GetCell(target_cell));
+ m_world->GetStats().IncNumOrgsKilled();
+ }
+ }
+
+ } //End Process()
+ };
+
+
void RegisterPopulationActions(cActionLibrary* action_lib)
{
action_lib->Register<cActionInject>("Inject");
@@ -2712,4 +2809,7 @@
action_lib->Register<cActionPred_DemeEventMoveCenter>("Pred_DemeEventMoveCenter");
action_lib->Register<cActionPred_DemeEventMoveBetweenTargets>("Pred_DemeEventMoveBetweenTargets");
action_lib->Register<cActionPred_DemeEventEventNUniqueIndividualsMovedIntoTarget>("Pred_DemeEventNUniqueIndividualsMovedIntoTarget");
+
+ action_lib->Register<cActionKillNBelowResourceThreshold>("KillNBelowResourceThreshold");
+ action_lib->Register<cActionKillNAboveResourceThreshold>("KillNAboveResourceThreshold");
}
Modified: development/source/actions/PrintActions.cc
===================================================================
--- development/source/actions/PrintActions.cc 2009-03-20 17:56:46 UTC (rev 3194)
+++ development/source/actions/PrintActions.cc 2009-03-23 15:23:20 UTC (rev 3195)
@@ -128,6 +128,7 @@
STATS_OUT_FILE(PrintCellVisitsData, visits.dat );
STATS_OUT_FILE(PrintFlowRateTuples, flow_rate_tuples.dat);
STATS_OUT_FILE(PrintDynamicMaxMinData, maxmin.dat );
+STATS_OUT_FILE(PrintNumOrgsKilledData, orgs_killed.dat);
#define POP_OUT_FILE(METHOD, DEFAULT) /* 1 */ \
@@ -2837,8 +2838,8 @@
// Print Settings
action_lib->Register<cActionSetVerbose>("SetVerbose");
+ action_lib->Register<cActionPrintNumOrgsKilledData>("PrintNumOrgsKilledData");//ZOOZ
-
// @DMB - The following actions are DEPRECATED aliases - These will be removed in 2.7.
action_lib->Register<cActionPrintAverageData>("print_average_data");
action_lib->Register<cActionPrintErrorData>("print_error_data");
Modified: development/source/main/cStats.cc
===================================================================
--- development/source/main/cStats.cc 2009-03-20 17:56:46 UTC (rev 3194)
+++ development/source/main/cStats.cc 2009-03-23 15:23:20 UTC (rev 3195)
@@ -133,6 +133,7 @@
, m_spec_total(0)
, m_spec_num(0)
, m_spec_waste(0)
+ , num_orgs_killed(0)
, m_deme_num_repls(0)
{
const cEnvironment& env = m_world->GetEnvironment();
@@ -560,6 +561,8 @@
m_spec_total = 0;
m_spec_num = 0;
m_spec_waste = 0;
+
+ num_orgs_killed = 0;
}
void cStats::RemoveLineage(int id_num, int parent_id, int update_born, double generation_born, int total_CPUs,
@@ -2051,3 +2054,16 @@
m_flash_times.clear();
}
+
+void cStats::PrintNumOrgsKilledData(const cString& filename)
+{
+ cDataFile& df = m_world->GetDataFile(filename);
+
+ df.WriteComment("Organisms killed using kill actions");
+ df.WriteTimeStamp();
+ df.WriteComment("First column is the current update and the second column lists the number of organisms killed");
+
+ df.Write(m_update, "Update");
+ df.Write(num_orgs_killed, "Num Orgs Killed");
+ df.Endl();
+} //End PrintNumOrgsKilledData()
Modified: development/source/main/cStats.h
===================================================================
--- development/source/main/cStats.h 2009-03-20 17:56:46 UTC (rev 3194)
+++ development/source/main/cStats.h 2009-03-23 15:23:20 UTC (rev 3195)
@@ -326,6 +326,9 @@
int m_spec_num;
int m_spec_waste;
+ // Number of organisms killed by kill actions
+ int num_orgs_killed;
+
cStats(); // @not_implemented
cStats(const cStats&); // @not_implemented
@@ -553,6 +556,8 @@
int total_genotypes, double fitness, double lineage_stat1, double lineage_stat2 );
void IncExecuted() { num_executed++; }
+
+ void IncNumOrgsKilled() { num_orgs_killed++; }
void AddCurTask(int task_num) { task_cur_count[task_num]++; }
void AddCurTaskQuality(int task_num, double quality)
@@ -720,6 +725,8 @@
double GetAveSpeculative() const { return (m_spec_num) ? ((double)m_spec_total / (double)m_spec_num) : 0.0; }
int GetSpeculativeWaste() const { return m_spec_waste; }
+
+ int GetNumOrgsKilled() const { return num_orgs_killed; }
// this value gets recorded when a creature with the particular
// fitness value gets born. It will never change to a smaller value,
@@ -767,6 +774,7 @@
void PrintCompetitionData(const cString& filename);
void PrintCellVisitsData(const cString& filename);
void PrintExtendedTimeData(const cString& filename);
+ void PrintNumOrgsKilledData(const cString& filename);
// deme predicate stats
void IncEventCount(int x, int y);
More information about the Avida-cvs
mailing list