[Avida-SVN] r3441 - in branches/goings/source: actions main
goingssh at myxo.css.msu.edu
goingssh at myxo.css.msu.edu
Fri Oct 2 13:12:25 PDT 2009
Author: goingssh
Date: 2009-10-02 16:12:24 -0400 (Fri, 02 Oct 2009)
New Revision: 3441
Modified:
branches/goings/source/actions/PrintActions.cc
branches/goings/source/main/cPhenotype.cc
branches/goings/source/main/cStats.cc
branches/goings/source/main/cStats.h
Log:
added new print events to my own branch
Modified: branches/goings/source/actions/PrintActions.cc
===================================================================
--- branches/goings/source/actions/PrintActions.cc 2009-10-02 20:10:42 UTC (rev 3440)
+++ branches/goings/source/actions/PrintActions.cc 2009-10-02 20:12:24 UTC (rev 3441)
@@ -79,6 +79,9 @@
STATS_OUT_FILE(PrintTotalsData, totals.dat );
STATS_OUT_FILE(PrintTasksData, tasks.dat );
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 );
@@ -2005,7 +2008,54 @@
}
};
+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.GetLastTaskCount()[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:
@@ -2812,6 +2862,9 @@
action_lib->Register<cActionPrintTotalsData>("PrintTotalsData");
action_lib->Register<cActionPrintTasksData>("PrintTasksData");
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");
@@ -2910,6 +2963,7 @@
action_lib->Register<cActionTestDominant>("TestDominant");
action_lib->Register<cActionPrintTaskSnapshot>("PrintTaskSnapshot");
+ action_lib->Register<cActionPrintAveNumTasks>("PrintAveNumTasks");
action_lib->Register<cActionPrintViableTasksData>("PrintViableTasksData");
action_lib->Register<cActionPrintTreeDepths>("PrintTreeDepths");
Modified: branches/goings/source/main/cPhenotype.cc
===================================================================
--- branches/goings/source/main/cPhenotype.cc 2009-10-02 20:10:42 UTC (rev 3440)
+++ branches/goings/source/main/cPhenotype.cc 2009-10-02 20:12:24 UTC (rev 3441)
@@ -1140,9 +1140,28 @@
cur_task_time[i] = cur_update_time; // Find out time from context
}
+ for (int i = 0; i < num_tasks; i++) {
+ if (result.TaskDone(i) && !last_task_count[i])
+ {
+ m_world->GetStats().AddNewTaskCount(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]++;
cur_reaction_add_reward[i] += result.GetReactionAddBonus(i);
+ if (result.ReactionTriggered(i) && last_reaction_count[i]==0)
+ m_world->GetStats().AddNewReactionCount(i);
}
// Update the merit bonus
@@ -1292,10 +1311,10 @@
{
cGenotype * genotype =
cClassificationManager* classmgr = m_world->GetClassificationManager();
- for (cGenotype * cur_genotype = classmgr->ResetThread(0); cur_genotype != NULL;
- cur_genotype = classmgr.NextGenotype(0))
- {
- int cur_num = cur_genotype->GetNumOrganisms();
+ for (cGenotype * cur_genotype = classmgr->ResetThread(0); cur_genotype != NULL;
+ cur_genotype = classmgr.NextGenotype(0))
+ {
+ int cur_num = cur_genotype->GetNumOrganisms();
}
}*/
Modified: branches/goings/source/main/cStats.cc
===================================================================
--- branches/goings/source/main/cStats.cc 2009-10-02 20:10:42 UTC (rev 3440)
+++ branches/goings/source/main/cStats.cc 2009-10-02 20:12:24 UTC (rev 3441)
@@ -147,6 +147,10 @@
task_cur_max_quality.Resize(num_tasks);
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);
task_cur_max_quality.SetAll(0);
@@ -156,6 +160,10 @@
task_cur_max_quality.SetAll(0);
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
task_internal_cur_count.Resize(num_tasks);
@@ -957,6 +965,70 @@
df.Endl();
}
+void cStats::PrintNewTasksData(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 give the number");
+ df.WriteComment("of times the particular task has newly evolved since the last time printed.");
+
+ df.Write(m_update, "Update");
+ for (int i = 0; i < new_task_count.GetSize(); i++) {
+ df.Write(new_task_count[i], task_names[i]);
+ }
+ df.Endl();
+ new_task_count.SetAll(0);
+}
+
+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.");
+
+ df.Write(m_update, "Update");
+ for (int i = 0; i < new_reaction_count.GetSize(); i++) {
+ df.Write(new_reaction_count[i], reaction_names[i]);
+ }
+ df.Endl();
+ new_reaction_count.SetAll(0);
+}
+
void cStats::PrintDynamicMaxMinData(const cString& filename)
{
cDataFile& df = m_world->GetDataFile(filename);
Modified: branches/goings/source/main/cStats.h
===================================================================
--- branches/goings/source/main/cStats.h 2009-10-02 20:10:42 UTC (rev 3440)
+++ branches/goings/source/main/cStats.h 2009-10-02 20:12:24 UTC (rev 3441)
@@ -239,6 +239,10 @@
tArray<double> task_cur_max_quality;
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
tArray<int> task_internal_cur_count;
@@ -575,6 +579,12 @@
task_last_quality[task_num] += quality;
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();
@@ -751,12 +761,15 @@
void PrintParasiteData(const cString& filename);
void PrintStatsData(const cString& filename);
void PrintCountData(const cString& filename);
- void PrintMessageData(const cString& filename);
+ void PrintMessageData(const cString& filename);
void PrintTotalsData(const cString& filename);
void PrintTasksData(const cString& filename);
void PrintTasksExeData(const cString& filename);
void PrintTasksQualData(const cString& filename);
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