[Avida-SVN] r3436 - in development/source: actions main

goingssh at myxo.css.msu.edu goingssh at myxo.css.msu.edu
Wed Sep 30 18:51:44 PDT 2009


Author: goingssh
Date: 2009-09-30 21:51:44 -0400 (Wed, 30 Sep 2009)
New Revision: 3436

Modified:
   development/source/actions/PrintActions.cc
   development/source/main/cPhenotype.cc
   development/source/main/cStats.cc
   development/source/main/cStats.h
Log:
Added 2 new events 
1. PrintNewTasksDataPlus - prints same info as PrintNewTasksData but adds 2 columns for each task, one which gives the average number of tasks the parent org performed for each org that evolved the new task, and one which gives the average number of task the actual org evolving the new task performs (default file newtasksplus.dat)
2. PrintAveNumTasks - on a given update prints the average number of tasks performed by all current organisms who perform at least one task (default file avenumtasks.dat)

Modified: development/source/actions/PrintActions.cc
===================================================================
--- development/source/actions/PrintActions.cc	2009-09-30 20:43:12 UTC (rev 3435)
+++ development/source/actions/PrintActions.cc	2009-10-01 01:51:44 UTC (rev 3436)
@@ -82,6 +82,7 @@
 STATS_OUT_FILE(PrintTasksExeData,           tasks_exe.dat       );
 STATS_OUT_FILE(PrintNewTasksData,			newtasks.dat		);
 STATS_OUT_FILE(PrintNewReactionData,		newreactions.dat	);
+STATS_OUT_FILE(PrintNewTasksDataPlus,		newtasksplus.dat	);
 STATS_OUT_FILE(PrintTasksQualData,          tasks_quality.dat   );
 STATS_OUT_FILE(PrintResourceData,           resource.dat        );
 STATS_OUT_FILE(PrintReactionData,           reactions.dat       );
@@ -2182,7 +2183,55 @@
   }
 };
 
+class cActionPrintAveNumTasks : public cAction
+{
+private:
+  cString m_filename;
+  
+public:
+  cActionPrintAveNumTasks(cWorld* world, const cString& args) : cAction(world, args), m_filename("ave_num_tasks.dat")
+  {
+    cString largs(args);
+    if (largs.GetSize()) m_filename = largs.PopWord();  
+  }
+  static const cString GetDescription() { return "Arguments: [string fname='']"; }
+  void Process(cAvidaContext& ctx)
+  {
+    cDataFile& df = m_world->GetDataFile(m_filename);  
+    cPopulation& pop = m_world->GetPopulation();
+  
+	int ave_tot_tasks = 0;
+	int num_task_orgs = 0;
+    for (int i = 0; i < pop.GetSize(); i++) {
+      if (pop.GetCell(i).IsOccupied() == false) continue;
+      
+	  cPhenotype& phenotype = pop.GetCell(i).GetOrganism()->GetPhenotype();
+      int num_tasks = m_world->GetEnvironment().GetNumTasks();
+      
+	  int sum_tasks = 0;
+      for (int j = 0; j < num_tasks; j++) 
+        sum_tasks += ( phenotype.GetCurTaskCount()[j] == 0 ) ? 0 : 1;
+	  if (sum_tasks>0) {
+		  ave_tot_tasks += sum_tasks;
+		  num_task_orgs++;
+	  }
+	}
+	double pop_ave = -1;
+	if (num_task_orgs>0)
+		pop_ave = ave_tot_tasks/double(num_task_orgs);
 
+	df.WriteComment("Avida num tasks data");
+    df.WriteTimeStamp();
+    df.WriteComment("First column gives the current update, 2nd column gives the average number of tasks performed");
+    df.WriteComment("by each organism in the current population that performs at least one task ");
+
+    df.Write(m_world->GetStats().GetUpdate(), "Update");
+	df.Write(pop_ave, "Ave num tasks done by single org that is doing at least one task");
+	df.Endl();
+  }
+};
+
+
 class cActionPrintViableTasksData : public cAction
 {
 private:
@@ -3028,6 +3077,7 @@
   action_lib->Register<cActionPrintTasksExeData>("PrintTasksExeData");
   action_lib->Register<cActionPrintNewTasksData>("PrintNewTasksData");
   action_lib->Register<cActionPrintNewReactionData>("PrintNewReactionData");
+  action_lib->Register<cActionPrintNewTasksDataPlus>("PrintNewTasksDataPlus");
   action_lib->Register<cActionPrintTasksQualData>("PrintTasksQualData");
   action_lib->Register<cActionPrintResourceData>("PrintResourceData");
   action_lib->Register<cActionPrintReactionData>("PrintReactionData");
@@ -3141,6 +3191,7 @@
   action_lib->Register<cActionTestDominant>("TestDominant");
   action_lib->Register<cActionPrintTaskSnapshot>("PrintTaskSnapshot");
   action_lib->Register<cActionPrintViableTasksData>("PrintViableTasksData");
+  action_lib->Register<cActionPrintAveNumTasks>("PrintAveNumTasks");
   action_lib->Register<cActionPrintTreeDepths>("PrintTreeDepths");
   
   action_lib->Register<cActionPrintGenomicSiteEntropy>("PrintGenomicSiteEntropy");

Modified: development/source/main/cPhenotype.cc
===================================================================
--- development/source/main/cPhenotype.cc	2009-09-30 20:43:12 UTC (rev 3435)
+++ development/source/main/cPhenotype.cc	2009-10-01 01:51:44 UTC (rev 3436)
@@ -1194,6 +1194,21 @@
     cur_task_value[i] = result.TaskValue(i);
     cur_task_time[i] = cur_update_time; // Find out time from context
   }
+  for (int i = 0; i < num_tasks; i++) {
+	  if (cur_task_count[i] && !last_task_count[i])
+	  {
+		  int prev_num_tasks = 0;
+		  int cur_num_tasks = 0;
+		  for (int j=0; j< num_tasks; j++)
+		  {
+			  if (last_task_count[j]>0)
+				  prev_num_tasks++;
+			  if (cur_task_count[j]>0)
+				  cur_num_tasks++;
+		  }
+		  m_world->GetStats().AddOtherTaskCounts(i, prev_num_tasks, cur_num_tasks);
+	  }
+  }
 
   for (int i = 0; i < num_reactions; i++) {
 //    if (result.ReactionTriggered(i) == true) cur_reaction_count[i]++;  // moved into cEnvironment::TestOutput to allow reaction requisites to be satisified at the time a reaction is completed

Modified: development/source/main/cStats.cc
===================================================================
--- development/source/main/cStats.cc	2009-09-30 20:43:12 UTC (rev 3435)
+++ development/source/main/cStats.cc	2009-10-01 01:51:44 UTC (rev 3436)
@@ -153,6 +153,8 @@
   task_last_max_quality.Resize(num_tasks);
   task_exe_count.Resize(num_tasks);
   new_task_count.Resize(num_tasks);
+  prev_task_count.Resize(num_tasks);
+  cur_task_count.Resize(num_tasks);
   new_reaction_count.Resize(env.GetNumReactions());
   task_cur_count.SetAll(0);
   task_cur_quality.SetAll(0);
@@ -164,6 +166,8 @@
   task_last_max_quality.SetAll(0);
   task_exe_count.SetAll(0);
   new_task_count.SetAll(0);
+  prev_task_count.SetAll(0);
+  cur_task_count.SetAll(0);
   new_reaction_count.SetAll(0);
   
   // Stats for internal resource use
@@ -982,12 +986,42 @@
   new_task_count.SetAll(0);
 }
 
-void cStats::PrintNewReactionData(const cString& filename)
+void cStats::PrintNewTasksDataPlus(const cString& filename)
 {
   cDataFile& df = m_world->GetDataFile(filename);
 
   df.WriteComment("Avida new tasks data");
   df.WriteTimeStamp();
+  df.WriteComment("First column gives the current update, all further columns are in sets of 3, giving the number");
+  df.WriteComment("of times the particular task has newly evolved since the last time printed, then the average");
+  df.WriteComment("number of tasks the parent of the organism evolving the new task performed, then the average");
+  df.WriteComment("number of tasks the organism evolving the new task performed.  One set of 3 for each task");
+
+  df.Write(m_update,   "Update");
+  for (int i = 0; i < new_task_count.GetSize(); i++) {
+    df.Write(new_task_count[i], task_names[i] + " - num times newly evolved");
+	double prev_ave = -1;
+	double cur_ave = -1;
+	if (new_task_count[i]>0) {
+		prev_ave = prev_task_count[i]/double(new_task_count[i]);
+		cur_ave = cur_task_count[i]/double(new_task_count[i]);
+	}
+	df.Write(prev_ave, "ave num tasks parent performed");
+	df.Write(cur_ave, "ave num tasks cur org performed");
+
+  }
+  df.Endl();
+  new_task_count.SetAll(0);
+  prev_task_count.SetAll(0);
+  cur_task_count.SetAll(0);
+}
+
+void cStats::PrintNewReactionData(const cString& filename)
+{
+  cDataFile& df = m_world->GetDataFile(filename);
+
+  df.WriteComment("Avida new reactions data");
+  df.WriteTimeStamp();
   df.WriteComment("First column gives the current update, all further columns give the number");
   df.WriteComment("of times the particular reaction has newly evolved since the last time printed.");
 
@@ -2313,7 +2347,7 @@
 	
 	df.Write(GetUpdate(), "Update [update]");
 	
-	if(treatableOpinionCounts.N() > 0 and untreatableOpinionCounts.N() > 0) {
+	if(treatableOpinionCounts.N() > 0 && untreatableOpinionCounts.N() > 0) {
 		df.Write(treatableOpinionCounts.Average(), "Average number of opinions set in Treatable demes");
 		df.Write(untreatableOpinionCounts.Average(), "Average number of opinions set in Unreatable demes");
 		df.Write(treatableDensityCounts.Average(), "Average density of Treatable demes");

Modified: development/source/main/cStats.h
===================================================================
--- development/source/main/cStats.h	2009-09-30 20:43:12 UTC (rev 3435)
+++ development/source/main/cStats.h	2009-10-01 01:51:44 UTC (rev 3436)
@@ -243,6 +243,8 @@
   tArray<double> task_last_max_quality;
   tArray<int> task_exe_count;
   tArray<int> new_task_count;
+  tArray<int> prev_task_count;
+  tArray<int> cur_task_count;
   tArray<int> new_reaction_count;
   
   // Stats for internal resource bins and use of internal resources
@@ -584,6 +586,10 @@
 	  if (quality > task_last_max_quality[task_num]) task_last_max_quality[task_num] = quality;
   }
   void AddNewTaskCount(int task_num) {new_task_count[task_num]++; }
+  void AddOtherTaskCounts(int task_num, int prev_tasks, int cur_tasks) {
+	  prev_task_count[task_num] += prev_tasks; 
+	  cur_task_count[task_num] += cur_tasks;
+  }
   void AddNewReactionCount(int reaction_num) {new_reaction_count[reaction_num]++; }
   void IncTaskExeCount(int task_num, int task_count) { task_exe_count[task_num] += task_count; }
   void ZeroTasks();
@@ -770,6 +776,7 @@
   void PrintDynamicMaxMinData(const cString& filename);
   void PrintNewTasksData(const cString& filename);
   void PrintNewReactionData(const cString& filename);
+  void PrintNewTasksDataPlus(const cString& filename);
   void PrintReactionData(const cString& filename);
   void PrintReactionExeData(const cString& filename);
   void PrintCurrentReactionData(const cString& filename);




More information about the Avida-cvs mailing list