[Avida-cvs] [avida-svn] r1002 - branches/coopcomm/source/main

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


Author: dknoester
Date: 2006-09-26 20:53:26 -0400 (Tue, 26 Sep 2006)
New Revision: 1002

Modified:
   branches/coopcomm/source/main/cOrgMessage.h
   branches/coopcomm/source/main/cPopulationCell.cc
   branches/coopcomm/source/main/cStats.cc
Log:
Message snaphot: added tracking of the label field, fixed overflow error.

Modified: branches/coopcomm/source/main/cOrgMessage.h
===================================================================
--- branches/coopcomm/source/main/cOrgMessage.h	2006-09-27 00:15:46 UTC (rev 1001)
+++ branches/coopcomm/source/main/cOrgMessage.h	2006-09-27 00:53:26 UTC (rev 1002)
@@ -64,11 +64,22 @@
 
 /*! \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());
+struct cOrgMessage_Sum :
+public std::unary_function<cOrgMessage, void> {
+  double m_data;
+  double m_label;
+  unsigned int m_count;
+  
+  cOrgMessage_Sum() : m_data(0), m_label(0), m_count(0) { }
+  
+  void operator()(const cOrgMessage& a) {
+    m_data += a.GetData();
+    m_label += a.GetLabel();
+    ++m_count;
   }
+  
+  double MeanData() { return (m_count>0) ? m_data / m_count : 0; }
+  double MeanLabel() { return (m_count>0) ? m_label / m_count : 0; }
 };
 
 #ifdef ENABLE_UNIT_TESTS

Modified: branches/coopcomm/source/main/cPopulationCell.cc
===================================================================
--- branches/coopcomm/source/main/cPopulationCell.cc	2006-09-27 00:15:46 UTC (rev 1001)
+++ branches/coopcomm/source/main/cPopulationCell.cc	2006-09-27 00:53:26 UTC (rev 1002)
@@ -70,7 +70,7 @@
   cell_id = in_id;
   m_x = x;
   m_y = y;
-  m_rand_id = m_world->GetRandom().GetUInt(UINT_MAX);
+  m_rand_id = m_world->GetRandom().GetUInt(INT_MAX);
   s_rand_ids.insert(std::make_pair(m_rand_id, this));
   
   if (mutation_rates == NULL)
@@ -201,6 +201,6 @@
 void cPopulationCell::ResetRandomID()
 {
   s_rand_ids.erase(m_rand_id);
-  m_rand_id = m_world->GetRandom().GetUInt(UINT_MAX);
+  m_rand_id = m_world->GetRandom().GetUInt(INT_MAX);
   s_rand_ids.insert(std::make_pair(m_rand_id, this));
 }

Modified: branches/coopcomm/source/main/cStats.cc
===================================================================
--- branches/coopcomm/source/main/cStats.cc	2006-09-27 00:15:46 UTC (rev 1001)
+++ branches/coopcomm/source/main/cStats.cc	2006-09-27 00:53:26 UTC (rev 1002)
@@ -23,7 +23,7 @@
 
 #include <float.h>
 #include <math.h>
-#include <numeric>
+#include <algorithm>
 
 
 cStats::cStats(cWorld* world)
@@ -1062,11 +1062,10 @@
     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());
+      cOrgMessage_Sum sum = std::for_each(sent.begin(), sent.end(), cOrgMessage_Sum());
       out << cells[i].GetID() << ":" << cells[i].GetRandomCellID() 
-        << ":" << sum.GetData() / (double)sent.size() 
-        << ":" << sum.GetLabel() / (double)sent.size();
+        << ":" << sum.MeanData()
+        << ":" << sum.MeanLabel() << " ";
     }
   }
   df.Endl();  




More information about the Avida-cvs mailing list