[Avida-SVN] r2359 - in development/source: actions main
barrick at myxo.css.msu.edu
barrick at myxo.css.msu.edu
Thu Feb 21 20:16:54 PST 2008
Author: barrick
Date: 2008-02-21 23:16:54 -0500 (Thu, 21 Feb 2008)
New Revision: 2359
Modified:
development/source/actions/EnvironmentActions.cc
development/source/actions/PrintActions.cc
development/source/main/cSpatialResCount.cc
development/source/main/cStats.cc
development/source/main/cStats.h
Log:
Changed PrintReactionData event to print last-lifetime statistics and added PrintCurReactionData event to print out current-lifetime reaction statistics.
Added ZeroAllResources event.
Added quick optimization to spatial resources so that they don't do the slow "flow" if gravity and diffusion are entirely off.
Modified: development/source/actions/EnvironmentActions.cc
===================================================================
--- development/source/actions/EnvironmentActions.cc 2008-02-22 04:09:04 UTC (rev 2358)
+++ development/source/actions/EnvironmentActions.cc 2008-02-22 04:16:54 UTC (rev 2359)
@@ -151,6 +151,28 @@
}
};
+class cZeroResources : public cAction
+{
+private:
+
+public:
+ cZeroResources(cWorld* world, const cString& args) : cAction(world, args)
+ {
+ cString largs(args);
+ }
+
+ static const cString GetDescription() { return "Arguments: none"; }
+
+ void Process(cAvidaContext& ctx)
+ {
+ cResourceLib & res_lib = m_world->GetEnvironment().GetResourceLib();
+ for (int i=0; i < res_lib.GetSize(); i++) {
+ cResource* res = res_lib.GetResource(i);
+ m_world->GetPopulation().SetResource(res->GetID(), 0.0);
+ }
+ }
+};
+
class cActionSetCellResource : public cAction
{
private:
@@ -696,6 +718,7 @@
action_lib->Register<cActionInjectScaledResource>("InjectScaledResource");
action_lib->Register<cActionOutflowScaledResource>("OutflowScaledResource");
action_lib->Register<cActionSetResource>("SetResource");
+ action_lib->Register<cZeroResources>("ZeroResources");
action_lib->Register<cActionSetCellResource>("SetCellResource");
action_lib->Register<cActionSetReactionValue>("SetReactionValue");
Modified: development/source/actions/PrintActions.cc
===================================================================
--- development/source/actions/PrintActions.cc 2008-02-22 04:09:04 UTC (rev 2358)
+++ development/source/actions/PrintActions.cc 2008-02-22 04:16:54 UTC (rev 2359)
@@ -81,6 +81,7 @@
STATS_OUT_FILE(PrintTasksQualData, tasks_quality.dat );
STATS_OUT_FILE(PrintResourceData, resource.dat );
STATS_OUT_FILE(PrintReactionData, reactions.dat );
+STATS_OUT_FILE(PrintCurrentReactionData, cur_reactions.dat );
STATS_OUT_FILE(PrintReactionRewardData, reaction_reward.dat );
STATS_OUT_FILE(PrintTimeData, time.dat );
STATS_OUT_FILE(PrintMutationRateData, mutation_rates.dat );
@@ -2622,6 +2623,7 @@
action_lib->Register<cActionPrintTasksQualData>("PrintTasksQualData");
action_lib->Register<cActionPrintResourceData>("PrintResourceData");
action_lib->Register<cActionPrintReactionData>("PrintReactionData");
+ action_lib->Register<cActionPrintCurrentReactionData>("PrintCurrentReactionData");
action_lib->Register<cActionPrintReactionRewardData>("PrintReactionRewardData");
action_lib->Register<cActionPrintTimeData>("PrintTimeData");
action_lib->Register<cActionPrintMutationRateData>("PrintMutationRateData");
Modified: development/source/main/cSpatialResCount.cc
===================================================================
--- development/source/main/cSpatialResCount.cc 2008-02-22 04:09:04 UTC (rev 2358)
+++ development/source/main/cSpatialResCount.cc 2008-02-22 04:16:54 UTC (rev 2359)
@@ -315,6 +315,9 @@
void cSpatialResCount::FlowAll() {
+ // @JEB save time if diffusion and gravity off...
+ if ((xdiffuse == 0.0) && (ydiffuse == 0.0) && (xgravity == 0.0) && (ygravity == 0.0)) return;
+
int i,k,ii,xdist,ydist;
double dist;
Modified: development/source/main/cStats.cc
===================================================================
--- development/source/main/cStats.cc 2008-02-22 04:09:04 UTC (rev 2358)
+++ development/source/main/cStats.cc 2008-02-22 04:16:54 UTC (rev 2359)
@@ -822,6 +822,42 @@
for(int i=0; i<m_world->GetPopulation().GetSize(); ++i) {
cPopulationCell& cell = m_world->GetPopulation().GetCell(i);
if(cell.IsOccupied()) {
+ const tArray<int>& org_rx = cell.GetOrganism()->GetPhenotype().GetLastReactionCount();
+ for(int j=0; j<num_reactions; ++j) {
+ reactions[j] += org_rx[j];
+ }
+ }
+ }
+
+ for(int i=0; i<num_reactions; ++i) {
+ df.Write(reactions[i], m_world->GetEnvironment().GetReactionLib().GetReaction(i)->GetName());
+ }
+
+// df.Write( 0.0,
+// df.Write(reaction_count[i], reaction_names[i] );
+// task_exe_count[i] = 0;
+// }
+ df.Endl();
+}
+
+void cStats::PrintCurrentReactionData(const cString& filename)
+{
+ cDataFile& df = m_world->GetDataFile(filename);
+
+ df.WriteComment("Avida reaction data");
+ df.WriteTimeStamp();
+ df.WriteComment("First column gives the current update, all further columns give the number");
+ df.WriteComment("of currently living organisms each reaction has affected.");
+
+ df.Write(m_update, "Update");
+
+ const int num_reactions=m_world->GetEnvironment().GetReactionLib().GetSize();
+ tArray<int> reactions(num_reactions);
+ reactions.SetAll(0);
+
+ for(int i=0; i<m_world->GetPopulation().GetSize(); ++i) {
+ cPopulationCell& cell = m_world->GetPopulation().GetCell(i);
+ if(cell.IsOccupied()) {
const tArray<int>& org_rx = cell.GetOrganism()->GetPhenotype().GetCurReactionCount();
for(int j=0; j<num_reactions; ++j) {
reactions[j] += org_rx[j];
@@ -840,6 +876,7 @@
df.Endl();
}
+
void cStats::PrintReactionRewardData(const cString& filename)
{
cDataFile& df = m_world->GetDataFile(filename);
Modified: development/source/main/cStats.h
===================================================================
--- development/source/main/cStats.h 2008-02-22 04:09:04 UTC (rev 2358)
+++ development/source/main/cStats.h 2008-02-22 04:16:54 UTC (rev 2359)
@@ -641,6 +641,7 @@
void PrintTasksExeData(const cString& filename);
void PrintTasksQualData(const cString& filename);
void PrintReactionData(const cString& filename);
+ void PrintCurrentReactionData(const cString& filename);
void PrintReactionRewardData(const cString& filename);
void PrintResourceData(const cString& filename);
void PrintSpatialResData(const cString& filename, int i);
More information about the Avida-cvs
mailing list