[Avida-cvs] [avida-svn] r1001 - in branches/coopcomm/source: actions main

dknoester at myxo.css.msu.edu dknoester at myxo.css.msu.edu
Tue Sep 26 17:15:47 PDT 2006


Author: dknoester
Date: 2006-09-26 20:15:46 -0400 (Tue, 26 Sep 2006)
New Revision: 1001

Modified:
   branches/coopcomm/source/actions/PopulationActions.cc
   branches/coopcomm/source/actions/PrintActions.cc
   branches/coopcomm/source/main/cOrgMessage.h
   branches/coopcomm/source/main/cOrganism.h
   branches/coopcomm/source/main/cStats.cc
   branches/coopcomm/source/main/cStats.h
Log:
Added an event that prints a snapshot of messaging activity, cleaned up a few comments.  The event required an accessor on cOrganism for the list of sent messages.


Modified: branches/coopcomm/source/actions/PopulationActions.cc
===================================================================
--- branches/coopcomm/source/actions/PopulationActions.cc	2006-09-26 20:44:05 UTC (rev 1000)
+++ branches/coopcomm/source/actions/PopulationActions.cc	2006-09-27 00:15:46 UTC (rev 1001)
@@ -1245,6 +1245,7 @@
       } else if(type == "max") {
         m_resetType = MAX;
       } else {
+        assert(type.IsNumber());
         m_resetType = PARTIAL;
         m_count = type.AsInt();
       }        
@@ -1298,7 +1299,6 @@
 };
 
 
-
 void RegisterPopulationActions(cActionLibrary* action_lib)
 {
   action_lib->Register<cActionInject>("Inject");

Modified: branches/coopcomm/source/actions/PrintActions.cc
===================================================================
--- branches/coopcomm/source/actions/PrintActions.cc	2006-09-26 20:44:05 UTC (rev 1000)
+++ branches/coopcomm/source/actions/PrintActions.cc	2006-09-27 00:15:46 UTC (rev 1001)
@@ -65,13 +65,14 @@
 STATS_OUT_FILE(PrintGenotypeMap,       genotype_map.m      );
 STATS_OUT_FILE(PrintMarketData,		   market.dat		   );
 
+// Coop-comm
 STATS_OUT_FILE(PrintLeaderData, leader_log.dat);
 STATS_OUT_FILE(PrintCellData, cell_log.dat);
 STATS_OUT_FILE(PrintMessageData, message_log.dat);
 STATS_OUT_FILE(PrintIDData, id_log.dat);
+STATS_OUT_FILE(PrintMessageDataPerUpdate, message.dat);
+STATS_OUT_FILE(PrintMessageSnapshot, msg_snapshot.dat);
 
-STATS_OUT_FILE(PrintMessageDataPerUpdate,       message.dat);
-
 #define POP_OUT_FILE(METHOD, DEFAULT)                                                     /*  1 */ \
 class cAction ## METHOD : public cAction {                                                /*  2 */ \
 private:                                                                                  /*  3 */ \
@@ -1528,7 +1529,9 @@
   action_lib->Register<cActionPrintCellData>("PrintCellData");
   action_lib->Register<cActionPrintMessageData>("PrintMessageData"); 
   action_lib->Register<cActionPrintIDData>("PrintIDData");  
-
+  action_lib->Register<cActionPrintMessageDataPerUpdate>("PrintMessageDataPerUpdate");
+  action_lib->Register<cActionPrintMessageSnapshot>("PrintMessageSnapshot");
+  
   // @DMB - The following actions are DEPRECATED aliases - These will be removed in 2.7.
   action_lib->Register<cActionPrintAverageData>("print_average_data");
   action_lib->Register<cActionPrintErrorData>("print_error_data");
@@ -1583,6 +1586,4 @@
   action_lib->Register<cActionDumpReceiverGrid>("dump_receiver_grid");
 
   action_lib->Register<cActionSetVerbose>("VERBOSE");
-  
-  action_lib->Register<cActionPrintMessageDataPerUpdate>("PrintMessageDataPerUpdate");
 }

Modified: branches/coopcomm/source/main/cOrgMessage.h
===================================================================
--- branches/coopcomm/source/main/cOrgMessage.h	2006-09-26 20:44:05 UTC (rev 1000)
+++ branches/coopcomm/source/main/cOrgMessage.h	2006-09-27 00:15:46 UTC (rev 1001)
@@ -23,6 +23,8 @@
   int m_data;
   int m_label;
   
+  cOrgMessage() : m_pSender(NULL), m_pReceiver(NULL), m_data(0), m_label(0) { }
+  
 public:
   cOrgMessage(cOrganism* sender) : 
     m_pSender(sender),
@@ -31,6 +33,13 @@
     m_label(0)  
   { }
   
+  explicit cOrgMessage(int data, int label) : 
+    m_pSender(NULL), m_pReceiver(NULL), m_data(data), m_label(label) {
+    }
+    
+
+  static cOrgMessage EmptyMessage() { return cOrgMessage(); }
+  
   cOrganism* GetSender() { return m_pSender; }
   cOrganism* GetReceiver() { return m_pReceiver; }
   void SetReceiver(cOrganism* recvr) { m_pReceiver = recvr; }
@@ -53,6 +62,14 @@
 	}
 };
 
+/*! \brief An STL-compatible functor that sums cOrgMessages.
+*/
+struct cOrgMessage_Sum : 
+public std::binary_function<cOrgMessage, cOrgMessage, cOrgMessage> {
+  cOrgMessage operator()(const cOrgMessage& a, const cOrgMessage& b) {
+    return cOrgMessage(a.GetData()+b.GetData(), a.GetLabel()+b.GetLabel());
+  }
+};
 
 #ifdef ENABLE_UNIT_TESTS
 namespace nOrgMessage {

Modified: branches/coopcomm/source/main/cOrganism.h
===================================================================
--- branches/coopcomm/source/main/cOrganism.h	2006-09-26 20:44:05 UTC (rev 1000)
+++ branches/coopcomm/source/main/cOrganism.h	2006-09-27 00:15:46 UTC (rev 1001)
@@ -297,6 +297,8 @@
   int GetRandomCellID() const { assert(m_interface); return m_interface->GetRandomCellID(); }
   //! Returns the list of all messsages received by this organism.
   t_message_list& GetReceivedMessages() { return m_received_messages; }
+  //! Returns the list of all messages sent by this organism.
+  t_message_list& GetSentMessages() { return m_sent_messages; }
   //! Returns a sorted list of all unique received messages.
   t_sorted_messages& GetSortedReceivedMessages() { return m_sorted_recv_messages; }
   //! Returns a sorted list of all unique received messages.

Modified: branches/coopcomm/source/main/cStats.cc
===================================================================
--- branches/coopcomm/source/main/cStats.cc	2006-09-26 20:44:05 UTC (rev 1000)
+++ branches/coopcomm/source/main/cStats.cc	2006-09-27 00:15:46 UTC (rev 1001)
@@ -17,11 +17,13 @@
 #include "cWorld.h"
 #include "cWorldDriver.h"
 #include "cOrgMessage.h"
+#include "cPopulation.h"
 #include "cPopulationCell.h"
 #include "cOrganism.h"
 
 #include <float.h>
 #include <math.h>
+#include <numeric>
 
 
 cStats::cStats(cWorld* world)
@@ -886,13 +888,13 @@
 
 /*! This captures all information that can be gleaned from a single message.
 
-IMPORTANT: Go look at the comments here before you rely too heavily cOrgMessages:
+IMPORTANT: Go look at the comments here before you rely too heavily on cOrgMessages:
 \see cOrganism::SendMessage
 */
 void cStats::SentMessage(cOrgMessage& msg)
 {
   ++m_count_msgs;
-  num_msg_sent++; //<! added because m_count_msgs is reset in cStats::PrintMessageData
+  num_msg_sent++; // added because m_count_msgs is reset in cStats::PrintMessageData
   m_msg_data.Add(msg.GetData());
   m_max_id = cPopulationCell::GetMaxRandomCellID();
   if(cPopulationCell::IsRandomCellID(msg.GetData())) {
@@ -947,8 +949,6 @@
 <mean max-valued msg> \
 <#cells that sent the leader's id> \
 <cell-id that sent leader>...
-
-\todo These statistics need work; these aren't being tracked correctly.
 */
 void cStats::PrintCellData(const cString& filename)
 {
@@ -1006,7 +1006,7 @@
 /*! The format of this data file is:
 <update> <cell id>:<id>...
 
-\todo Not yt implemented.
+\todo Not yet implemented.
 */
 void cStats::PrintIDData(const cString& filename)
 {
@@ -1016,9 +1016,11 @@
 }
 
 //added by ben
-//! prints message numbers for an update
-void cStats::PrintMessageDataPerUpdate(const cString& filename) {
-    cDataFile & df = m_world->GetDataFile(filename);
+/*! prints message numbers for an update
+*/
+void cStats::PrintMessageDataPerUpdate(const cString& filename)
+{
+  cDataFile & df = m_world->GetDataFile(filename);
 
   df.WriteComment( "Avida message data" );
   df.WriteTimeStamp();
@@ -1035,4 +1037,37 @@
   df.Write(inbox_size.Average(),         "average inbox size");
   df.Write(sent_size.Average(),          "average sent box size");
   df.Endl();
-}
\ No newline at end of file
+}
+
+
+/*! This method iterates through every cell in the population, and for every
+organism that it finds, it prints:
+<cell_id:random_cell_id:mean_data_field:mean_label_field>...
+
+The intent is that these snapshots can be strung together in order to get a picture
+of the types of messages that are being sent throughout the population.
+
+Note: This will generate a large data file.
+*/
+void cStats::PrintMessageSnapshot(const cString& filename)
+{
+  cDataFile& df = m_world->GetDataFile(filename);
+  df.WriteColumnDesc("Update.");
+  df.WriteColumnDesc("<cell_id:random_cell_id:mean_data_field:mean_label_field>...");
+
+  df.WriteAnonymous(m_update);
+  std::ofstream& out = df.GetOFStream();
+  cPopulation::t_CellArray& cells = m_world->GetPopulation().GetCellArray();
+  for(int i=0; i<cells.GetSize(); ++i) {
+    if(cells[i].IsOccupied()) {
+      cOrganism::t_message_list& sent = cells[i].GetOrganism()->GetSentMessages();
+      if(sent.empty()) continue;
+      cOrgMessage sum = std::accumulate(sent.begin(), sent.end(), 
+                                        cOrgMessage::EmptyMessage(), cOrgMessage_Sum());
+      out << cells[i].GetID() << ":" << cells[i].GetRandomCellID() 
+        << ":" << sum.GetData() / (double)sent.size() 
+        << ":" << sum.GetLabel() / (double)sent.size();
+    }
+  }
+  df.Endl();  
+}

Modified: branches/coopcomm/source/main/cStats.h
===================================================================
--- branches/coopcomm/source/main/cStats.h	2006-09-26 20:44:05 UTC (rev 1000)
+++ branches/coopcomm/source/main/cStats.h	2006-09-27 00:15:46 UTC (rev 1001)
@@ -610,11 +610,11 @@
   void PrintMessageData(const cString& filename);
   //! Log ID-specific data.
   void PrintIDData(const cString& filename);
-  
-  
-    //added by ben
-  void PrintMessageDataPerUpdate(const cString& filename);//!< prints message date file
-  
+  //! Print message data file.
+  void PrintMessageDataPerUpdate(const cString& filename);
+  //! Print a snapshot of specific message activity.
+  void PrintMessageSnapshot(const cString& filename);
+    
   //added by ben for messaging stats
   void IncSent() {num_msg_sent++;} //!< inc. number of messages sent
   void IncSentToNonFacing() {num_msg_sent_to_nonfacing++;}




More information about the Avida-cvs mailing list