[Avida-SVN] r3208 - in branches/hjg-dev/source: actions main
hjg at myxo.css.msu.edu
hjg at myxo.css.msu.edu
Thu Apr 16 08:18:36 PDT 2009
Author: hjg
Date: 2009-04-16 11:18:36 -0400 (Thu, 16 Apr 2009)
New Revision: 3208
Modified:
branches/hjg-dev/source/actions/PrintActions.cc
branches/hjg-dev/source/main/cStats.cc
branches/hjg-dev/source/main/cStats.h
Log:
additional stats tracking for greenbeard project
Modified: branches/hjg-dev/source/actions/PrintActions.cc
===================================================================
--- branches/hjg-dev/source/actions/PrintActions.cc 2009-04-12 01:25:35 UTC (rev 3207)
+++ branches/hjg-dev/source/actions/PrintActions.cc 2009-04-16 15:18:36 UTC (rev 3208)
@@ -115,6 +115,7 @@
// reputation
STATS_OUT_FILE(PrintReputationData, reputation.dat);
STATS_OUT_FILE(PrintGreenBeardSupport, gbstrategy.dat);
+STATS_OUT_FILE(PrintShadedAltruists, shadedaltruists.dat);
STATS_OUT_FILE(PrintDirectReciprocityData, reciprocity.dat);
STATS_OUT_FILE(PrintStringMatchData, stringmatch.dat);
@@ -2756,6 +2757,7 @@
action_lib->Register<cActionPrintDirectReciprocityData>("PrintDirectReciprocityData");
action_lib->Register<cActionPrintStringMatchData>("PrintStringMatchData");
action_lib->Register<cActionPrintGreenBeardSupport>("PrintGreenBeardSupport");
+ action_lib->Register<cActionPrintShadedAltruists>("PrintShadedAltruists");
Modified: branches/hjg-dev/source/main/cStats.cc
===================================================================
--- branches/hjg-dev/source/main/cStats.cc 2009-04-12 01:25:35 UTC (rev 3207)
+++ branches/hjg-dev/source/main/cStats.cc 2009-04-16 15:18:36 UTC (rev 3208)
@@ -2031,4 +2031,86 @@
}
+void cStats::PrintShadedAltruists(const cString& filename) {
+ cDataFile& df = m_world->GetDataFile(filename);
+ df.WriteComment("The number of organisms in different bins of shaded altruism");
+
+ // Cycle through the population -- count the number of altruists in each bin.
+ // Also average their shaded donations.
+ // Check how many prefer the shaded strategy
+
+ //int num_shaded_pref = 0; //!num orgs that prefer shaded
+ int pop = m_world->GetPopulation().GetSize(); //!the population size for convenience
+ int shaded_100 = 0;
+ int shaded_90 = 0;
+ int shaded_80 = 0;
+ int shaded_70 = 0;
+ int shaded_60 = 0;
+ int shaded_50 = 0;
+ int shaded_40 = 0;
+ int shaded_30 = 0;
+ int shaded_20 = 0;
+ int shaded_10 = 0;
+ int shaded_0 = 0;
+ int total_shaded = 0;
+ //int other_donations = 0;
+ int shade_of_gb;
+ cOrganism* org;
+
+
+ for(int i=0; i<m_world->GetPopulation().GetSize(); ++i) {
+ cPopulationCell& cell = m_world->GetPopulation().GetCell(i);
+ org = cell.GetOrganism();
+
+ if(cell.IsOccupied()) {
+ org = cell.GetOrganism();
+
+ cInstSet& inst_set = m_world->GetHardwareManager().GetInstSet();
+ const int num_inst = m_world->GetNumInstructions();
+ for (int i = 0; i < num_inst; i++) {
+ if ((inst_set.GetName(i) == "donate-shadedgb") &&
+ (org->GetPhenotype().GetTestCPUInstCount().GetSize() > 0)) {
+ shade_of_gb = org->GetPhenotype().GetTestCPUInstCount()[i];
+ }
+ }
+ if (shade_of_gb == 100) shaded_100++;
+ if (shade_of_gb > 90) shaded_90++;
+ if (shade_of_gb > 80) shaded_80++;
+ if (shade_of_gb > 70) shaded_70++;
+ if (shade_of_gb > 60) shaded_60++;
+ if (shade_of_gb > 50) shaded_50++;
+ if (shade_of_gb > 40) shaded_40++;
+ if (shade_of_gb > 30) shaded_30++;
+ if (shade_of_gb > 20) shaded_20++;
+ if (shade_of_gb > 10) shaded_10++;
+ if (shade_of_gb > 0) shaded_0++;
+ total_shaded += shade_of_gb;
+ }
+ }
+
+ float high_alt = (float) shaded_90/pop;
+ float avg_shade = (float) total_shaded/pop;
+
+ df.WriteComment("Bins of orgs of shaded strategies.");
+ df.WriteTimeStamp();
+ df.Write(m_update, "Update [update]");
+ df.Write(pop, "Population [population]");
+ df.Write(shaded_100, "shaded-100 [shaded100]");
+ df.Write(shaded_90, "shaded-90 [shaded90]");
+ df.Write(shaded_80, "shaded-80 [shaded80]");
+ df.Write(shaded_70, "shaded-70 [shaded70]");
+ df.Write(shaded_60, "shaded-60 [shaded60]");
+ df.Write(shaded_50, "shaded-50 [shaded50]");
+ df.Write(shaded_40, "shaded-40 [shaded40]");
+ df.Write(shaded_30, "shaded-30 [shaded30]");
+ df.Write(shaded_20, "shaded-20 [shaded20]");
+ df.Write(shaded_10, "shaded-10 [shaded10]");
+ df.Write(shaded_0, "shaded-0 [shaded0]");
+ df.Write(high_alt, "percent-high-alt [highalt]");
+ df.Write(avg_shade, "avg-shade [avgshade]");
+ df.Endl();
+
+}
+
+
Modified: branches/hjg-dev/source/main/cStats.h
===================================================================
--- branches/hjg-dev/source/main/cStats.h 2009-04-12 01:25:35 UTC (rev 3207)
+++ branches/hjg-dev/source/main/cStats.h 2009-04-16 15:18:36 UTC (rev 3208)
@@ -823,6 +823,7 @@
void IncNumRandDonates(int n) {m_num_rand_donates+=n; }
void IncNumNopX() {m_num_nopx++; }
void IncNumNopXDonates(int n) {m_num_nopx_donates+=n; }
+ void PrintShadedAltruists(const cString& filename);
protected:
int m_num_kin;
More information about the Avida-cvs
mailing list