[Avida-cvs] [avida-svn] r979 - branches/coopcomm/source/main
dknoester at myxo.css.msu.edu
dknoester at myxo.css.msu.edu
Sun Sep 24 15:28:27 PDT 2006
Author: dknoester
Date: 2006-09-24 18:28:26 -0400 (Sun, 24 Sep 2006)
New Revision: 979
Modified:
branches/coopcomm/source/main/cOrganism.cc
branches/coopcomm/source/main/cOrganism.h
branches/coopcomm/source/main/cStats.cc
branches/coopcomm/source/main/cStats.h
branches/coopcomm/source/main/cTaskLib.cc
Log:
Current revision: 978
This commit completes the log files and task optimization for the leader-election portion on coop-comm. Should merge into the trunk once testing is complete.
Modified: branches/coopcomm/source/main/cOrganism.cc
===================================================================
--- branches/coopcomm/source/main/cOrganism.cc 2006-09-24 18:36:36 UTC (rev 978)
+++ branches/coopcomm/source/main/cOrganism.cc 2006-09-24 22:28:26 UTC (rev 979)
@@ -504,8 +504,8 @@
/*! Attempt to send the message (which is actually based on the facing of the
-cell), and if successful, store the sent message, check to see if sending this
-message completed any tasks, and run any message-specific callbacks.
+cell), and if successful, store the sent message, and check to see if sending this
+message completed any tasks.
*/
bool cOrganism::SendMessage(cAvidaContext& ctx, cOrgMessage& msg)
{
@@ -568,11 +568,15 @@
}
-/*! Add this message to the list of messages that this organism has received.
+/*! Add this message to the list of messages that this organism has received. We
+do something a litle funky here, in that we also store a sorted list of the messages
+that have been received. Yes, we're storing the messages twice. Yes, there are ways
+to avoid doing that. You can suffer the 16 bytes.
*/
bool cOrganism::ReceiveMessage(cOrgMessage& msg)
{
m_received_messages.push_back(msg);
+ m_sorted_recv_messages.insert(std::make_pair(msg.GetData(), msg));
return true;
}
Modified: branches/coopcomm/source/main/cOrganism.h
===================================================================
--- branches/coopcomm/source/main/cOrganism.h 2006-09-24 18:36:36 UTC (rev 978)
+++ branches/coopcomm/source/main/cOrganism.h 2006-09-24 22:28:26 UTC (rev 979)
@@ -13,6 +13,7 @@
#include <fstream>
#include <vector>
+#include <map>
#ifndef cCPUMemory_h
#include "cCPUMemory.h"
@@ -76,7 +77,14 @@
class cOrganism
{
public:
+ // Note: The two typedefs below support different ways of storing cOrgMessages.
+ // The t_message_list is a receive-order-preserving list of the messages that
+ // have been received, while the t_sorted_messages is a sorted, non-receive-
+ // order-preserving map of data fields->cOrgMessages. Note that in the later
+ // case, only ONE of each unique data field is kept, and it is the most recently
+ // received. This may change in future versions.
typedef std::vector<cOrgMessage> t_message_list; //!< Container for cOrgMessages.
+ typedef std::map<int, cOrgMessage> t_sorted_messages; //!< A sorted container for cOrgMessages.
protected:
cWorld* m_world;
@@ -138,7 +146,7 @@
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.
cOrganism(); // @not_implemented
cOrganism(const cOrganism&); // @not_implemented
@@ -288,6 +296,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 a sorted list of all unique received messages.
+ t_sorted_messages& GetSortedReceivedMessages() { return m_sorted_recv_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/cStats.cc
===================================================================
--- branches/coopcomm/source/main/cStats.cc 2006-09-24 18:36:36 UTC (rev 978)
+++ branches/coopcomm/source/main/cStats.cc 2006-09-24 22:28:26 UTC (rev 979)
@@ -861,6 +861,9 @@
/*! This captures all information that can be gleaned from a single message.
+
+Note that the sender and receiver fields of the message are not valid after this
+method completes!
*/
void cStats::SentMessage(cOrgMessage& msg)
{
@@ -879,6 +882,7 @@
}
if(msg.GetData() == m_max_id) {
++m_data_is_leader;
+ m_cell_sent_leader.insert(msg.GetSender()->GetCellID());
}
}
}
@@ -895,6 +899,7 @@
{
cDataFile& df = m_world->GetDataFile(filename);
df.Write(m_update, "Update");
+ df.Endl();
}
@@ -910,15 +915,25 @@
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.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);
+ 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_cell_sent_leader.clear();
}
Modified: branches/coopcomm/source/main/cStats.h
===================================================================
--- branches/coopcomm/source/main/cStats.h 2006-09-24 18:36:36 UTC (rev 978)
+++ branches/coopcomm/source/main/cStats.h 2006-09-24 22:28:26 UTC (rev 979)
@@ -14,6 +14,7 @@
#include <assert.h>
#include <fstream>
#include <iostream>
+#include <set>
#ifndef defs_h
#include "defs.h"
@@ -231,6 +232,7 @@
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.
+ std::set<int> m_cell_sent_leader; //!< Set of all cells that sent a message carrying the leader's ID.
cStats(); // @not_implemented
cStats(const cStats&); // @not_implemented
Modified: branches/coopcomm/source/main/cTaskLib.cc
===================================================================
--- branches/coopcomm/source/main/cTaskLib.cc 2006-09-24 18:36:36 UTC (rev 978)
+++ branches/coopcomm/source/main/cTaskLib.cc 2006-09-24 22:28:26 UTC (rev 979)
@@ -1886,20 +1886,15 @@
cOrgMessage* msg = ctx->GetMessage();
if(msg == NULL) return 0.0;
- cOrganism::t_message_list& received_msgs = msg->GetSender()->GetReceivedMessages();
- if(!cPopulationCell::IsRandomCellID(msg->GetData()) || received_msgs.empty())
+ cOrganism::t_sorted_messages& received_msgs = msg->GetSender()->GetSortedReceivedMessages();
+ if(!cPopulationCell::IsRandomCellID(msg->GetData()) || received_msgs.empty()) {
return 0.0;
-
- // Find the maximum ID in the receive buffer for the sender. Uses the message_less
- // comparator (above).
- cOrganism::t_message_list::iterator i=std::max_element(received_msgs.begin(),
- received_msgs.end(),
- cOrgMessage_Less());
-
- // Check the sent data against max(received message, self.ID).
- if(msg->GetData() == std::max(i->GetData(), msg->GetSender()->GetRandomCellID()))
- return 1.0;
+ }
+ if(msg->GetData() == std::max(msg->GetSender()->GetRandomCellID(), received_msgs.rbegin()->first)) {
+ return 1.0;
+ }
+
return 0.0;
}
More information about the Avida-cvs
mailing list