[Avida-SVN] r2947 - in branches/hjg-dev/source: actions main

hjg at myxo.css.msu.edu hjg at myxo.css.msu.edu
Mon Nov 17 06:31:32 PST 2008


Author: hjg
Date: 2008-11-17 09:31:32 -0500 (Mon, 17 Nov 2008)
New Revision: 2947

Modified:
   branches/hjg-dev/source/actions/PrintActions.cc
   branches/hjg-dev/source/main/cStats.cc
   branches/hjg-dev/source/main/cStats.h
Log:
stats for direct reciprocity

Modified: branches/hjg-dev/source/actions/PrintActions.cc
===================================================================
--- branches/hjg-dev/source/actions/PrintActions.cc	2008-11-17 13:59:37 UTC (rev 2946)
+++ branches/hjg-dev/source/actions/PrintActions.cc	2008-11-17 14:31:32 UTC (rev 2947)
@@ -114,6 +114,7 @@
 
 // reputation
 STATS_OUT_FILE(PrintReputationData,         reputation.dat);
+STATS_OUT_FILE(PrintDirectReciprocityData,         reciprocity.dat);
 
 
 
@@ -2750,8 +2751,9 @@
   
   // Reputation
   action_lib->Register<cActionPrintReputationData>("PrintReputationData");
-  
+	action_lib->Register<cActionPrintDirectReciprocityData>("PrintDirectReciprocityData");
 
+
   
   // Grid Information Dumps
   action_lib->Register<cActionDumpMemory>("DumpMemory");

Modified: branches/hjg-dev/source/main/cStats.cc
===================================================================
--- branches/hjg-dev/source/main/cStats.cc	2008-11-17 13:59:37 UTC (rev 2946)
+++ branches/hjg-dev/source/main/cStats.cc	2008-11-17 14:31:32 UTC (rev 2947)
@@ -1719,22 +1719,61 @@
 }
 
 
-/* This method prints the number of organisms of each lineage in a deme. */
-void cStats::PrintDemeLineageData(const cString& filename){
-  cDataFile& df = m_world->GetDataFile(filename);
-	df.WriteComment("Avida deme lineage data");
-	df.WriteTimeStamp();
-	df.WriteComment("First column gives the current update, next columns give the number");
-	df.WriteComment("of organisms per deme of each lineage.");
+/* Print information pertinent to direct reciprocity experiments*/
+void cStats::PrintDirectReciprocityData(const cString& filename){
+	cDataFile& df = m_world->GetDataFile(filename);
 
-	vector <int> deme_lineages; 
-//  tArray<int> deme_lineages;
-//  deme_tasks.ResizeClear(num_tasks);
-//  deme_tasks.SetAll(num_tasks);
+	cDoubleSum donations;
+	cDoubleSum reciprocations; 
+	cDoubleSum donors;
+	cDoubleSum num_donations_received; 
+
+	cOrganism* org; 
+
+	int num_alt =0;
+	int num_coop = 0;
+	int num_lin_2 = 0;
+	int num_lin_1 = 0;
+	int total_org = 0;
 	
-// built in assumption that there are 2 lineages. 
+	
+	df.WriteComment("Avida organism direct reciprocity information");
+	df.WriteTimeStamp();
+	df.Write(m_update,   "Update [update]");
+	
+	
+  for(int i=0; i<m_world->GetPopulation().GetSize(); ++i) {
+    cPopulationCell& cell = m_world->GetPopulation().GetCell(i);
+		org = cell.GetOrganism();
+		
+    if(cell.IsOccupied()) {
+			donations.Add(org->GetNumberOfDonations());
+			num_donations_received.Add(org->GetNumberOfDonationsReceived());
+			reciprocations.Add(org->GetNumberOfReciprocations());
+			donors.Add(org->GetNumberOfDonors());
+			if (org->GetNumberOfDonations() > 0) num_alt++;
+			if ((org->GetNumberOfDonationsReceived() && org->GetNumberOfDonations()) > 0) num_coop++;
+			if (org->GetLineageLabel() == 1) num_lin_1++;
+			if (org->GetLineageLabel() == 2) num_lin_2++;
+			total_org++;
+	  }
 	}
 
+	df.Write(donations.Average(), "Avg. donations [donation]");
+	df.Write(num_donations_received.Average(), "Avg. donations received [received]");
+	df.Write(donors.Average(), "Avg. number of donor partners [partners]");	
+	df.Write(num_alt, "Number of altruists [altruists]");
+	df.Write(num_coop, "Number of cooperators [cooperators]");
+	df.Write(num_lin_1, "Number of organisms of lineage 1 [lineage1]");
+	df.Write(num_lin_2, "Number of organisms of lineage 2 [lineage2]");
+	df.Write(total_org, "Number of organisms in population [popsize]");
+	
+  df.Endl();
+	
+	
+}
+
+
 /* Print information about the reputation... */
 void cStats::PrintReputationData(const cString& filename){
 	cDataFile& df = m_world->GetDataFile(filename);
@@ -1758,6 +1797,7 @@
 	int num_alt =0;
 	int num_coop = 0;
 	
+	
 	df.WriteComment("Avida organism reputation information -- average donations, min donations, max donations");
 	df.WriteTimeStamp();
 	df.Write(m_update,   "Update [update]");

Modified: branches/hjg-dev/source/main/cStats.h
===================================================================
--- branches/hjg-dev/source/main/cStats.h	2008-11-17 13:59:37 UTC (rev 2946)
+++ branches/hjg-dev/source/main/cStats.h	2008-11-17 14:31:32 UTC (rev 2947)
@@ -787,6 +787,7 @@
 public: 
   // Print statistics about reputation
   void PrintReputationData(const cString& filename);
+	void PrintDirectReciprocityData(const cString& filename);
 	void IncDonateToDonor() { m_donate_to_donor++; } 
 	void IncDonateToFacing() { m_donate_to_facing++; }
 protected: 




More information about the Avida-cvs mailing list