[Avida-cvs] [avida-svn] r982 - branches/coopcomm/source/main
dknoester at myxo.css.msu.edu
dknoester at myxo.css.msu.edu
Mon Sep 25 06:44:55 PDT 2006
Author: dknoester
Date: 2006-09-25 09:44:54 -0400 (Mon, 25 Sep 2006)
New Revision: 982
Modified:
branches/coopcomm/source/main/cOrganism.cc
branches/coopcomm/source/main/cOrganism.h
branches/coopcomm/source/main/cPopulation.cc
branches/coopcomm/source/main/cStats.cc
branches/coopcomm/source/main/cStats.h
Log:
Adds statistics for organism death (not duplicate of RecordDeath), and sorted tracking for messages sent by an organism.
Modified: branches/coopcomm/source/main/cOrganism.cc
===================================================================
--- branches/coopcomm/source/main/cOrganism.cc 2006-09-25 12:04:30 UTC (rev 981)
+++ branches/coopcomm/source/main/cOrganism.cc 2006-09-25 13:44:54 UTC (rev 982)
@@ -82,6 +82,9 @@
cOrganism::~cOrganism()
{
+ // Stat-tracking.
+ m_world->GetStats().OrganismDeath(this);
+
assert(is_running == false);
delete m_hardware;
delete m_interface;
@@ -514,8 +517,11 @@
// Stat-tracking.
m_world->GetStats().SentMessage(msg);
- // store the message.
+ // store the message. yes, we're storing it twice. yes, we could save memory
+ // by using pointers. this is number two; if we need another sorted list of
+ // messages, it'll be time to refactor.
m_sent_messages.push_back(msg);
+ m_sorted_sent_messages.insert(std::make_pair(msg.GetData(), msg));
assert(m_interface);
const tArray<double>& resource_count = m_interface->GetResources();
Modified: branches/coopcomm/source/main/cOrganism.h
===================================================================
--- branches/coopcomm/source/main/cOrganism.h 2006-09-25 12:04:30 UTC (rev 981)
+++ branches/coopcomm/source/main/cOrganism.h 2006-09-25 13:44:54 UTC (rev 982)
@@ -146,7 +146,8 @@
t_message_list m_received_messages; //!< List of messages that this organism has received, in order.
// t_message_list m_retrieved_messages; //!< List of messages that this organism has retrieved, in order.
t_message_list::size_type m_retrieve_pos; //!< Index of the message that will be returned on next RetrieveMessage().
- t_sorted_messages m_sorted_recv_messages; //!< Sorted map of data fields->cOrgMessages.
+ t_sorted_messages m_sorted_recv_messages; //!< Sorted map of received messages.
+ t_sorted_messages m_sorted_sent_messages; //!< Sorted map of sent messages.
cOrganism(); // @not_implemented
cOrganism(const cOrganism&); // @not_implemented
@@ -298,6 +299,8 @@
t_message_list& GetReceivedMessages() { return m_received_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.
+ t_sorted_messages& GetSortedSentMessages() { return m_sorted_sent_messages; }
//! Retrieves the position (x,y coordinates) of this organism.
void GetPosition(int& x, int& y) { assert(m_interface); m_interface->GetPosition(x, y); }
//! Returns the facing of this organism.
Modified: branches/coopcomm/source/main/cPopulation.cc
===================================================================
--- branches/coopcomm/source/main/cPopulation.cc 2006-09-25 12:04:30 UTC (rev 981)
+++ branches/coopcomm/source/main/cPopulation.cc 2006-09-25 13:44:54 UTC (rev 982)
@@ -477,10 +477,15 @@
}
// And clear it!
+ // @DK: We need the cell-organism connection to be valid until /after/
+ // the organism's destructor is called.
+ if (!organism->GetIsRunning()) {
+ delete organism;
+ } else {
+ organism->GetPhenotype().SetToDelete();
+ }
in_cell.RemoveOrganism();
- if (!organism->GetIsRunning()) delete organism;
- else organism->GetPhenotype().SetToDelete();
-
+
// Alert the scheduler that this cell has a 0 merit.
schedule->Adjust(in_cell.GetID(), cMerit(0));
Modified: branches/coopcomm/source/main/cStats.cc
===================================================================
--- branches/coopcomm/source/main/cStats.cc 2006-09-25 12:04:30 UTC (rev 981)
+++ branches/coopcomm/source/main/cStats.cc 2006-09-25 13:44:54 UTC (rev 982)
@@ -18,6 +18,7 @@
#include "cWorldDriver.h"
#include "cOrgMessage.h"
#include "cPopulationCell.h"
+#include "cOrganism.h"
#include <float.h>
#include <math.h>
@@ -90,7 +91,6 @@
, 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)
@@ -888,9 +888,22 @@
}
-/*! \brief Prints out a line of the leadership-tracking data file.
+/*! This captures all information related to an organism's death.
-The format of this data file is:
+This is different than RecordDeath() (above), in that we have a handle to the
+organism that is about to die. This let us record things like the max message
+sent by the organism, correlate that to the cell, etc.
+
+\todo mean max-valued message per cell.
+\todo mean message per cell
+*/
+void cStats::OrganismDeath(cOrganism* org)
+{
+ ++m_count_org_died;
+}
+
+
+/*! The format of this data file is:
<update> <id>:<#votes>...
\todo Not yet implemented.
@@ -903,43 +916,38 @@
}
-/*! \brief Prints out a line of the cell-tracking data file.
-
-The format of this data file is:
+/*! 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>...
+
+\todo These statistics need work; these aren't being tracked correctly.
*/
void cStats::PrintCellData(const cString& filename)
{
cDataFile& df = m_world->GetDataFile(filename);
df.WriteColumnDesc("Update.");
df.WriteColumnDesc("Count of organisms that have died.");
- df.WriteColumnDesc("Mean of the maximum data fields sent by each cell.");
df.WriteColumnDesc("Number of cells that sent a message containing the leader's ID.");
df.WriteColumnDesc("IDs of cells that sent a message carrying the leader's ID (may be empty).");
df.FlushComments();
df.WriteAnonymous(m_update);
df.WriteAnonymous(m_count_org_died);
- df.WriteAnonymous(m_max_cell_msg_data.Ave());
- df.WriteAnonymous(m_count_cell_sent_leader);
+ df.WriteAnonymous((int)m_cell_sent_leader.size());
for(std::set<int>::iterator i=m_cell_sent_leader.begin(); i!=m_cell_sent_leader.end(); ++i) {
df.WriteAnonymous(*i);
}
df.Endl();
- m_max_cell_msg_data.Clear();
- m_count_org_died = m_count_cell_sent_leader = 0;
+ m_count_org_died = 0;
m_cell_sent_leader.clear();
}
-/*! \brief Prints out a line of the message-tracking data file.
-
-The format of this data file is:
+/*! The format of this data file is:
<update> \
<total msgs sent> \
<mean data field> \
@@ -970,9 +978,7 @@
}
-/*! \brief prints out a line of the ID-tracking data file.
-
-The format of this data file is:
+/*! The format of this data file is:
<update> <cell id>:<id>...
\todo Not yt implemented.
Modified: branches/coopcomm/source/main/cStats.h
===================================================================
--- branches/coopcomm/source/main/cStats.h 2006-09-25 12:04:30 UTC (rev 981)
+++ branches/coopcomm/source/main/cStats.h 2006-09-25 13:44:54 UTC (rev 982)
@@ -45,6 +45,7 @@
class cInjectGenotype;
class cWorld;
class cOrgMessage;
+class cOrganism;
class cStats
{
@@ -219,11 +220,7 @@
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.
@@ -580,6 +577,8 @@
// Coop-comm.
//! Capture information related to sending a message.
void SentMessage(cOrgMessage& msg);
+ //! Capture information related to organism death.
+ void OrganismDeath(cOrganism* org);
//! Log leadership-specific data.
void PrintLeaderData(const cString& filename);
//! Log cell-specific data.
More information about the Avida-cvs
mailing list