[Avida-cvs] [avida-svn] r978 - in branches/coopcomm/source: actions cpu main
dknoester at myxo.css.msu.edu
dknoester at myxo.css.msu.edu
Sun Sep 24 11:36:36 PDT 2006
Author: dknoester
Date: 2006-09-24 14:36:36 -0400 (Sun, 24 Sep 2006)
New Revision: 978
Modified:
branches/coopcomm/source/actions/PrintActions.cc
branches/coopcomm/source/cpu/cHardwareCPU.cc
branches/coopcomm/source/cpu/cTestCPUInterface.h
branches/coopcomm/source/main/cOrgInterface.h
branches/coopcomm/source/main/cOrganism.cc
branches/coopcomm/source/main/cOrganism.h
branches/coopcomm/source/main/cPopulationInterface.cc
branches/coopcomm/source/main/cPopulationInterface.h
branches/coopcomm/source/main/cStats.cc
branches/coopcomm/source/main/cStats.h
Log:
Current revision: 977
This is the second-to-last major merge of coop-comm. This commit adds a majority of the logging facilities for messages, leadership, and cell activity.
Still to come: cell id / org id logging, max-id task optimization.
Modified: branches/coopcomm/source/actions/PrintActions.cc
===================================================================
--- branches/coopcomm/source/actions/PrintActions.cc 2006-09-24 15:48:53 UTC (rev 977)
+++ branches/coopcomm/source/actions/PrintActions.cc 2006-09-24 18:36:36 UTC (rev 978)
@@ -65,6 +65,11 @@
STATS_OUT_FILE(PrintGenotypeMap, genotype_map.m );
STATS_OUT_FILE(PrintMarketData, market.dat );
+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);
+
#define POP_OUT_FILE(METHOD, DEFAULT) /* 1 */ \
class cAction ## METHOD : public cAction { /* 2 */ \
private: /* 3 */ \
@@ -1572,4 +1577,10 @@
action_lib->Register<cActionDumpReceiverGrid>("dump_receiver_grid");
action_lib->Register<cActionSetVerbose>("VERBOSE");
+
+ // Coop-comm actions.
+ action_lib->Register<cActionPrintLeaderData>("PrintLeaderData");
+ action_lib->Register<cActionPrintCellData>("PrintCellData");
+ action_lib->Register<cActionPrintMessageData>("PrintMessageData");
+ action_lib->Register<cActionPrintIDData>("PrintIDData");
}
Modified: branches/coopcomm/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/coopcomm/source/cpu/cHardwareCPU.cc 2006-09-24 15:48:53 UTC (rev 977)
+++ branches/coopcomm/source/cpu/cHardwareCPU.cc 2006-09-24 18:36:36 UTC (rev 978)
@@ -3424,7 +3424,7 @@
bool cHardwareCPU::Inst_GetPosition(cAvidaContext& ctx) {
const int xreg = FindModifiedRegister(REG_BX);
const int yreg = FindNextRegister(xreg);
- organism->GetPosition(GetRegister(xreg),GetRegister(yreg));
+ organism->GetPosition(GetRegister(xreg), GetRegister(yreg));
return true;
}
Modified: branches/coopcomm/source/cpu/cTestCPUInterface.h
===================================================================
--- branches/coopcomm/source/cpu/cTestCPUInterface.h 2006-09-24 15:48:53 UTC (rev 977)
+++ branches/coopcomm/source/cpu/cTestCPUInterface.h 2006-09-24 18:36:36 UTC (rev 978)
@@ -13,6 +13,7 @@
#ifndef cOrgInterface_h
#include "cOrgInterface.h"
#endif
+#include "cPopulationCell.h"
class cTestCPU;
@@ -30,6 +31,7 @@
virtual ~cTestCPUInterface() { ; }
int GetCellID() { return -1; }
+ cPopulationCell* GetCell() { return NULL; }
void SetCellID(int in_id) { ; }
bool Divide(cAvidaContext& ctx, cOrganism* parent, cGenome& child_genome);
Modified: branches/coopcomm/source/main/cOrgInterface.h
===================================================================
--- branches/coopcomm/source/main/cOrgInterface.h 2006-09-24 15:48:53 UTC (rev 977)
+++ branches/coopcomm/source/main/cOrgInterface.h 2006-09-24 18:36:36 UTC (rev 978)
@@ -16,6 +16,7 @@
class cOrganism;
class cOrgMessage;
class cOrgSinkMessage;
+class cPopulationCell;
template <class T> class tArray;
@@ -30,6 +31,7 @@
virtual ~cOrgInterface() { ; }
virtual int GetCellID() = 0;
+ virtual cPopulationCell* GetCell() = 0;
virtual void SetCellID(int in_id) = 0;
virtual bool Divide(cAvidaContext& ctx, cOrganism* parent, cGenome& child_genome) = 0;
Modified: branches/coopcomm/source/main/cOrganism.cc
===================================================================
--- branches/coopcomm/source/main/cOrganism.cc 2006-09-24 15:48:53 UTC (rev 977)
+++ branches/coopcomm/source/main/cOrganism.cc 2006-09-24 18:36:36 UTC (rev 978)
@@ -511,6 +511,9 @@
{
assert(m_interface);
if(m_interface->SendMessage(msg)) {
+ // Stat-tracking.
+ m_world->GetStats().SentMessage(msg);
+
// store the message.
m_sent_messages.push_back(msg);
Modified: branches/coopcomm/source/main/cOrganism.h
===================================================================
--- branches/coopcomm/source/main/cOrganism.h 2006-09-24 15:48:53 UTC (rev 977)
+++ branches/coopcomm/source/main/cOrganism.h 2006-09-24 18:36:36 UTC (rev 978)
@@ -57,7 +57,6 @@
#include "cSaleItem.h"
#endif
-
/**
* The cOrganism class controls the running and manages all the statistics
* about a creature. Effectively the chemistry acting on the genome.
@@ -158,6 +157,7 @@
void Die() { assert(m_interface); m_interface->Die(); }
void Kaboom(int dist) { assert(m_interface); m_interface->Kaboom(dist);}
int GetCellID() { assert(m_interface); return m_interface->GetCellID(); }
+ cPopulationCell* GetCell() { assert(m_interface); return m_interface->GetCell(); }
int GetDebugInfo() { assert(m_interface); return m_interface->Debug(); }
int GetID() { return m_id; }
bool GetSentActive() { return sent_active; }
Modified: branches/coopcomm/source/main/cPopulationInterface.cc
===================================================================
--- branches/coopcomm/source/main/cPopulationInterface.cc 2006-09-24 15:48:53 UTC (rev 977)
+++ branches/coopcomm/source/main/cPopulationInterface.cc 2006-09-24 18:36:36 UTC (rev 978)
@@ -26,6 +26,12 @@
#define NULL 0
#endif
+cPopulationCell* cPopulationInterface::GetCell()
+{
+ cPopulationCell& cell = m_world->GetPopulation().GetCell(m_cell_id);
+ assert(cell.IsOccupied());
+ return &cell;
+}
bool cPopulationInterface::Divide(cAvidaContext& ctx, cOrganism* parent, cGenome& child_genome)
{
@@ -198,9 +204,13 @@
bool cPopulationInterface::SendMessage(cOrgMessage & msg)
{
cPopulationCell& cell = m_world->GetPopulation().GetCell(m_cell_id);
- if((cell.ConnectionList().GetFirst() == NULL) || !cell.IsOccupied())
+ assert(cell.IsOccupied()); // this organism; sanity.
+ cPopulationCell* rcell = cell.ConnectionList().GetFirst();
+ assert(rcell != NULL); // cells should never be null.
+ if(!rcell->IsOccupied())
return false;
- cOrganism* recvr = cell.ConnectionList().GetFirst()->GetOrganism();
+ cOrganism* recvr = rcell->GetOrganism();
+ assert(recvr != NULL);
msg.SetReceiver(recvr);
return recvr->ReceiveMessage(msg);
}
Modified: branches/coopcomm/source/main/cPopulationInterface.h
===================================================================
--- branches/coopcomm/source/main/cPopulationInterface.h 2006-09-24 15:48:53 UTC (rev 977)
+++ branches/coopcomm/source/main/cPopulationInterface.h 2006-09-24 18:36:36 UTC (rev 978)
@@ -22,8 +22,8 @@
#endif
class cPopulation;
+class cPopulationCell;
-
class cPopulationInterface : public cOrgInterface
{
private:
@@ -39,6 +39,7 @@
virtual ~cPopulationInterface() { ; }
int GetCellID() { return m_cell_id; }
+ cPopulationCell* GetCell();
void SetCellID(int in_id) { m_cell_id = in_id; }
bool Divide(cAvidaContext& ctx, cOrganism* parent, cGenome& child_genome);
Modified: branches/coopcomm/source/main/cStats.cc
===================================================================
--- branches/coopcomm/source/main/cStats.cc 2006-09-24 15:48:53 UTC (rev 977)
+++ branches/coopcomm/source/main/cStats.cc 2006-09-24 18:36:36 UTC (rev 978)
@@ -16,6 +16,8 @@
#include "tDataEntry.h"
#include "cWorld.h"
#include "cWorldDriver.h"
+#include "cOrgMessage.h"
+#include "cPopulationCell.h"
#include <float.h>
#include <math.h>
@@ -87,6 +89,14 @@
, num_sold(0)
, num_used(0)
, num_own_used(0)
+ , m_count_org_died(0)
+ , m_count_cell_sent_leader(0)
+ , m_count_msgs(0)
+ , m_max_id(0)
+ , m_data_is_id(0)
+ , m_data_is_sender(0)
+ , m_data_is_id_and_grt_sender(0)
+ , m_data_is_leader(0)
{
task_cur_count.Resize( m_world->GetNumTasks() );
task_last_count.Resize( m_world->GetNumTasks() );
@@ -848,3 +858,113 @@
num_bought = num_sold = num_used = num_own_used = 0;
df.Endl();
}
+
+
+/*! This captures all information that can be gleaned from a single message.
+*/
+void cStats::SentMessage(cOrgMessage& msg)
+{
+ ++m_count_msgs;
+ m_msg_data.Add(msg.GetData());
+ m_max_id = cPopulationCell::GetMaxRandomCellID();
+ if(cPopulationCell::IsRandomCellID(msg.GetData())) {
+ ++m_data_is_id;
+ if(msg.GetData() > msg.GetSender()->GetRandomCellID()) {
+ ++m_data_is_id_and_grt_sender;
+ }
+ if(msg.GetData() != msg.GetSender()->GetRandomCellID()) {
+ m_data_is_id_not_sender.Add(msg.GetData());
+ } else {
+ ++m_data_is_sender;
+ }
+ if(msg.GetData() == m_max_id) {
+ ++m_data_is_leader;
+ }
+ }
+}
+
+
+/*! \brief Prints out a line of the leadership-tracking data file.
+
+The format of this data file is:
+<update> <id>:<#votes>...
+
+\todo Not yet implemented.
+*/
+void cStats::PrintLeaderData(const cString& filename)
+{
+ cDataFile& df = m_world->GetDataFile(filename);
+ df.Write(m_update, "Update");
+}
+
+
+/*! \brief Prints out a line of the cell-tracking data file.
+
+The format of this data file is:
+<update> \
+<# died orgs> \
+<mean max-valued msg> \
+<#cells that sent the leader's id> \
+<cell-id that sent leader>...
+*/
+void cStats::PrintCellData(const cString& filename)
+{
+ cDataFile& df = m_world->GetDataFile(filename);
+ df.Write(m_update, "Update");
+ df.Write(m_count_org_died, "Count of organisms that have died.");
+ df.Write(m_max_cell_msg_data.Ave(), "Mean of the maximum data fields sent by each cell.");
+ df.Write(m_count_cell_sent_leader, "Number of cells that sent a message containing the leader's ID.");
+ // list of cells the sent the leader's id.
+ df.Endl();
+
+ m_max_cell_msg_data.Clear();
+ m_count_org_died = m_count_cell_sent_leader = 0;
+}
+
+
+/*! \brief Prints out a line of the message-tracking data file.
+
+The format of this data file is:
+<update> \
+<total msgs sent> \
+<mean data field> \
+<max. id> \
+<# msgs: data==ID> \
+<# msgs: data==sender's ID> \
+<# msgs: data==ID and data > sender's ID> \
+<# msgs: data==leader's ID> \
+<mean non-sender data field and data==ID>
+*/
+void cStats::PrintMessageData(const cString& filename)
+{
+ cDataFile& df = m_world->GetDataFile(filename);
+ df.Write(m_update, "Update");
+ df.Write(m_count_msgs, "Count of the number of messages sent.");
+ df.Write(m_msg_data.Ave(), "Mean of all message data fields.");
+ df.Write(m_max_id, "The maximum ID in the population.");
+ df.Write(m_data_is_id, "Count of messages where the data field carries an ID.");
+ df.Write(m_data_is_sender, "Count of messages where the data field carries the sender's ID.");
+ df.Write(m_data_is_id_and_grt_sender, "Count of messages where the data field carries an ID, and is greater than the sender's ID.");
+ df.Write(m_data_is_leader, "Count of messages where the data field is the leader's ID.");
+ df.Write(m_data_is_id_not_sender.Ave(), "Mean of message data fields where the data field is an ID that is not the sender's ID.");
+ df.Endl();
+
+ m_msg_data.Clear();
+ m_data_is_id_not_sender.Clear();
+ m_count_msgs = m_max_id = m_data_is_id = m_data_is_sender = m_data_is_id_and_grt_sender = m_data_is_leader = 0;
+}
+
+
+/*! \brief prints out a line of the ID-tracking data file.
+
+The format of this data file is:
+<update> <cell id>:<id>...
+
+\todo Not yt implemented.
+*/
+void cStats::PrintIDData(const cString& filename)
+{
+ cDataFile& df = m_world->GetDataFile(filename);
+ df.Write(m_update, "Update");
+ df.Endl();
+}
Modified: branches/coopcomm/source/main/cStats.h
===================================================================
--- branches/coopcomm/source/main/cStats.h 2006-09-24 15:48:53 UTC (rev 977)
+++ branches/coopcomm/source/main/cStats.h 2006-09-24 18:36:36 UTC (rev 978)
@@ -43,6 +43,7 @@
class cGenotype;
class cInjectGenotype;
class cWorld;
+class cOrgMessage;
class cStats
{
@@ -216,6 +217,21 @@
int num_used;
int num_own_used;
+ // Stats for coop-comm.
+ // Per-cell stats.
+ int m_count_org_died; //!< Count of the number of organisms that died.
+ cDoubleSum m_max_cell_msg_data; //!< Sum of the maximum data fields sent by each cell.
+ int m_count_cell_sent_leader; //!< Count of the number of cells that sent a message containing the leader's ID.
+ // Message stats.
+ int m_count_msgs; //!< Count of the number of messages sent.
+ cDoubleSum m_msg_data; //!< Sum of all message data fields.
+ int m_max_id; //!< The maximum ID in the population.
+ int m_data_is_id; //!< Count of messages where the data field carries an ID.
+ int m_data_is_sender; //!< Count of messages where the data field carries the sender's ID.
+ int m_data_is_id_and_grt_sender; //!< Count of messages where the data field carries an ID, and is greater than the sender's ID.
+ int m_data_is_leader; //!< Count of messages where the data field is the leader's ID.
+ cDoubleSum m_data_is_id_not_sender; //!< Sum of message data fields where the data field is an ID that is not the sender's ID.
+
cStats(); // @not_implemented
cStats(const cStats&); // @not_implemented
cStats& operator=(const cStats&); // @not_implemented
@@ -558,6 +574,18 @@
void PrintInstructionData(const cString& filename);
void PrintGenotypeMap(const cString& filename);
void PrintMarketData(const cString& filename);
+
+ // Coop-comm.
+ //! Capture information related to sending a message.
+ void SentMessage(cOrgMessage& msg);
+ //! Log leadership-specific data.
+ void PrintLeaderData(const cString& filename);
+ //! Log cell-specific data.
+ void PrintCellData(const cString& filename);
+ //! Log message-specific data.
+ void PrintMessageData(const cString& filename);
+ //! Log ID-specific data.
+ void PrintIDData(const cString& filename);
};
More information about the Avida-cvs
mailing list