[Avida-SVN] r3263 - development/source/actions

beckma24 at myxo.css.msu.edu beckma24 at myxo.css.msu.edu
Wed May 27 08:53:30 PDT 2009


Author: beckma24
Date: 2009-05-27 11:53:29 -0400 (Wed, 27 May 2009)
New Revision: 3263

Modified:
   development/source/actions/PopulationActions.cc
Log:
Augmented structural therapy actions with data files that print their stats

Modified: development/source/actions/PopulationActions.cc
===================================================================
--- development/source/actions/PopulationActions.cc	2009-05-27 15:10:20 UTC (rev 3262)
+++ development/source/actions/PopulationActions.cc	2009-05-27 15:53:29 UTC (rev 3263)
@@ -30,6 +30,7 @@
 #include "cGenome.h"
 #include "cGenomeUtil.h"
 #include "cHardwareManager.h"
+#include "cIntSum.h"
 #include "cOrgMessagePredicate.h"
 #include "cPopulation.h"
 #include "cPopulationCell.h"
@@ -910,14 +911,19 @@
 	cString m_inst;
 	double m_exprWeight;
 	double m_exponent;
+	int m_printUpdate;
+	cIntSum m_totalkilled;
 
 public:
-	cAction_TherapyStructuralNumInst(cWorld* world, const cString& args) : cAction(world, args), m_inst("nand"), m_exprWeight(1.0), m_exponent(1.0)
+	cAction_TherapyStructuralNumInst(cWorld* world, const cString& args) : cAction(world, args), m_inst("nand"), m_exprWeight(1.0), m_exponent(1.0), m_printUpdate(100)
 	{
 		cString largs(args);
 		if (largs.GetSize()) m_inst = largs.PopWord();
 		if (largs.GetSize()) m_exprWeight = largs.PopWord().AsDouble();
 		if (largs.GetSize()) m_exponent = largs.PopWord().AsDouble();
+		if (largs.GetSize()) m_printUpdate = largs.PopWord().AsInt();
+		cerr<<m_printUpdate<<endl;
+		m_totalkilled.Clear();
 	}
 	
 	static const cString GetDescription() { return "Arguments: [cString inst=nand] [double exprWeight=1.0] [double exponent=1.0(linear)]"; }
@@ -952,12 +958,21 @@
 				// decide if it should be killed or not, based on the kill probability
 				if (ctx.GetRandom().P(killprob)) {
 					m_world->GetPopulation().KillOrganism(cell);
-					totalkilled++;
+					++totalkilled;
 				}
 			}
-		// could keep track of the total number killed for statistics; in testing simply printed it out
-		// cout << "total killed = " << totalkilled << endl;
 		}
+		m_totalkilled.Add(totalkilled);
+			
+		const int update = m_world->GetStats().GetUpdate();
+		if(update % m_printUpdate == 0) {
+			cDataFile& df = m_world->GetDataFile("TherapyStructuralNumInst_kill.dat");
+			df.WriteComment("Number of organisms killed by structural therapy NumInst");
+			df.Write(update, "Update");
+			df.Write(m_totalkilled.Average(), "Mean organisms killed per update since last print");
+			df.Endl();
+			m_totalkilled.Clear();
+		}
 	}
 };
 
@@ -976,17 +991,21 @@
 	cString m_inst;
 	double m_exprWeight;
 	double m_exponent;
+	int m_printUpdate;
+	cIntSum m_totalkilled;
 	
 public:
-	cAction_TherapyStructuralRatioDistBetweenNearest(cWorld* world, const cString& args) : cAction(world, args), m_inst("nand"), m_exprWeight(1.0), m_exponent(1.0)
+	cAction_TherapyStructuralRatioDistBetweenNearest(cWorld* world, const cString& args) : cAction(world, args), m_inst("nand"), m_exprWeight(1.0), m_exponent(1.0), m_printUpdate(100)
 	{
 		cString largs(args);
 		if (largs.GetSize()) m_inst = largs.PopWord();
 		if (largs.GetSize()) m_exprWeight = largs.PopWord().AsDouble();
 		if (largs.GetSize()) m_exponent = largs.PopWord().AsDouble();
+		if (largs.GetSize()) m_printUpdate = largs.PopWord().AsInt();
+		m_totalkilled.Clear();
 	}
 	
-	static const cString GetDescription() { return "Arguments: [cString inst=nand] [double exprWeight=1.0] [double exponent=1.0(linear)]"; }
+	static const cString GetDescription() { return "Arguments: [cString inst=nand] [double exprWeight=1.0] [double exponent=1.0(linear)] [int print=100]"; }
 	
 	void Process(cAvidaContext& ctx)
 	{
@@ -1021,12 +1040,21 @@
 				// decide if it should be killed or not, based on the kill probability
 				if (ctx.GetRandom().P(killprob)) {
 					m_world->GetPopulation().KillOrganism(cell);
-					totalkilled++;
+					++totalkilled;
 				}
 			}
 		}
-		// could keep track of the total number killed for statistics; in testing simply printed it out
-		// cout << "total killed = " << totalkilled << endl;
+		m_totalkilled.Add(totalkilled);
+		
+		const int update = m_world->GetStats().GetUpdate();
+		if(update % m_printUpdate == 0) {
+			cDataFile& df = m_world->GetDataFile("TherapyStructuralRatioDistBetweenNearest_kill.dat");
+			df.WriteComment("Number of organisms killed by structural therapy RatioDistBetweenNearest");
+			df.Write(update, "Update");
+			df.Write(m_totalkilled.Average(), "Mean organisms killed per update since last print");
+			df.Endl();
+			m_totalkilled.Clear();
+		}
 	}
 };
 




More information about the Avida-cvs mailing list