[Avida-SVN] r1102 - in branches/coopcomm: Avida.xcodeproj source/actions source/main
beckma24 at myxo.css.msu.edu
beckma24 at myxo.css.msu.edu
Tue Nov 28 11:27:54 PST 2006
Author: beckma24
Date: 2006-11-28 14:27:46 -0500 (Tue, 28 Nov 2006)
New Revision: 1102
Modified:
branches/coopcomm/Avida.xcodeproj/project.pbxproj
branches/coopcomm/source/actions/PopulationActions.cc
branches/coopcomm/source/main/cOrgMessage.h
branches/coopcomm/source/main/cTaskLib.cc
branches/coopcomm/source/main/cTaskLib.h
Log:
Added population event called 'AddBaseStationPredicate' that logs data which reaches a base station. Also, added send-ID-not-self task which rewards organisms for sending IDs of other organisms.
Modified: branches/coopcomm/Avida.xcodeproj/project.pbxproj
===================================================================
--- branches/coopcomm/Avida.xcodeproj/project.pbxproj 2006-11-28 02:50:41 UTC (rev 1101)
+++ branches/coopcomm/Avida.xcodeproj/project.pbxproj 2006-11-28 19:27:46 UTC (rev 1102)
@@ -360,6 +360,23 @@
E626209E0A372C2A00C07685 /* SaveLoadActions.cc in Sources */ = {isa = PBXBuildFile; fileRef = 708051A80A1F65FE00CBB8B6 /* SaveLoadActions.cc */; };
/* End PBXBuildFile section */
+/* Begin PBXBuildStyle section */
+ B532BFFC0B1B4911008BEB97 /* Development */ = {
+ isa = PBXBuildStyle;
+ buildSettings = {
+ COPY_PHASE_STRIP = NO;
+ };
+ name = Development;
+ };
+ B532BFFD0B1B4911008BEB97 /* Deployment */ = {
+ isa = PBXBuildStyle;
+ buildSettings = {
+ COPY_PHASE_STRIP = YES;
+ };
+ name = Deployment;
+ };
+/* End PBXBuildStyle section */
+
/* Begin PBXCopyFilesBuildPhase section */
700E2B6D085DE50C00CF158A /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase;
@@ -1745,6 +1762,12 @@
DCC30C4D0762532C008F7A48 /* Project object */ = {
isa = PBXProject;
buildConfigurationList = 702442D70859E0B00059BD9B /* Build configuration list for PBXProject "Avida" */;
+ buildSettings = {
+ };
+ buildStyles = (
+ B532BFFC0B1B4911008BEB97 /* Development */,
+ B532BFFD0B1B4911008BEB97 /* Deployment */,
+ );
hasScannedForEncodings = 0;
mainGroup = DCC30C490762532C008F7A48;
productRefGroup = DCC3164E07626CF3008F7A48 /* Products */;
Modified: branches/coopcomm/source/actions/PopulationActions.cc
===================================================================
--- branches/coopcomm/source/actions/PopulationActions.cc 2006-11-28 02:50:41 UTC (rev 1101)
+++ branches/coopcomm/source/actions/PopulationActions.cc 2006-11-28 19:27:46 UTC (rev 1102)
@@ -1347,6 +1347,42 @@
};
+/*! \brief An event that adds a predicate to be evaluated for every message sent to a base station.
+*/
+class cActionAddBaseStationPredicate : public cAction
+{
+public:
+ //! Constructor.
+ cActionAddBaseStationPredicate(cWorld* world, const cString& args) :
+ cAction(world, args)
+ { }
+
+ //! Destructor.
+ virtual ~cActionAddBaseStationPredicate() {
+ }
+
+ //! Return a string description of the arguments for this action.
+ static const cString GetDescription()
+ {
+ return "Tracks data coming to base station(s).";
+ }
+
+ //! Perform this action.
+ void Process(cAvidaContext& ctx)
+ {
+ cPopulationCell::t_id_map& ids = cPopulationCell::GetRandomCellIDMap();
+ assert(ids.size()>0);
+
+ tVector<int> bs = m_world->GetPopulation().GetBaseStations();
+
+ for(int i = 0; i < bs.Size(); i++) {
+ cOrgMessage_PredSinkReceiverEQU* tmp = new cOrgMessage_PredSinkReceiverEQU(bs[i]);
+ m_world->GetStats().AddMessagePredicate(tmp);
+ }
+ }
+};
+
+
/*! \brief Responsible for "raining" messages down on the population.
* This action may be used to prime the population with a given message -
* It's most immediate application is getting a homogeneous population of organisms
@@ -1421,6 +1457,7 @@
action_lib->Register<cActionResetRandomCellIDs>("ResetRandomCellIDs");
action_lib->Register<cActionSetStaticBaseStation>("SetStaticBaseStation");
action_lib->Register<cActionAddMessagePredicate>("AddMessagePredicate");
+ action_lib->Register<cActionAddBaseStationPredicate>("AddBaseStationPredicate");
action_lib->Register<cActionMessageRain>("MessageRain");
// @DMB - The following actions are DEPRECATED aliases - These will be removed in 2.7.
Modified: branches/coopcomm/source/main/cOrgMessage.h
===================================================================
--- branches/coopcomm/source/main/cOrgMessage.h 2006-11-28 02:50:41 UTC (rev 1101)
+++ branches/coopcomm/source/main/cOrgMessage.h 2006-11-28 19:27:46 UTC (rev 1102)
@@ -16,6 +16,7 @@
#include <set>
#include "cOrganism.h"
+#include "cPopulationCell.h"
class cOrgMessage
{
@@ -124,20 +125,34 @@
/*! A predicate that returns true and tracks the label and data field for messages
that contain a sink as the receiver.
*/
-/*struct cOrgMessage_PredSinkReceiverEQU : public cOrgMessage_Predicate {
+struct cOrgMessage_PredSinkReceiverEQU : public cOrgMessage_Predicate {
cOrgMessage_PredSinkReceiverEQU(unsigned int data) : m_data(data) { }
virtual bool operator()(cOrgMessage& msg) {
- if(m_data==msg.GetReceiver().get) {
- m_cell_ids.insert(msg.GetSender()->GetCellID());
+ if(m_data==msg.GetReceiver()->GetCellID()) {
+ m_cell_ids.insert(msg.GetData());
}
}
virtual void print(std::ostream& out) {
+ cPopulationCell::t_id_map& ids = cPopulationCell::GetRandomCellIDMap();
+ int badMSGs = 0;
+
out << "data==" << m_data << ":{";
for(std::set<int>::iterator i=m_cell_ids.begin(); i!=m_cell_ids.end(); ++i) {
- out << *i << ",";
+ int x,y;
+ //check if # is ID and log cell location and count bad messages
+ if(cPopulationCell::IsRandomCellID(*i)) {
+ cPopulationCell* cell = ids.find(*i)->second;
+ cell->GetPosition(x, y);
+ out << x <<" "<< y << ",";
+ } else {
+ badMSGs++;
+// out << *i << ",";
+ }
}
+ //write # bad messages in last slot
+ out << badMSGs;
out << "}";
}
@@ -148,8 +163,8 @@
unsigned int m_data;
std::set<int> m_cell_ids;
};
-*/
+
#ifdef ENABLE_UNIT_TESTS
namespace nOrgMessage {
/**
Modified: branches/coopcomm/source/main/cTaskLib.cc
===================================================================
--- branches/coopcomm/source/main/cTaskLib.cc 2006-11-28 02:50:41 UTC (rev 1101)
+++ branches/coopcomm/source/main/cTaskLib.cc 2006-11-28 19:27:46 UTC (rev 1102)
@@ -350,6 +350,8 @@
NewTask(name, "Rewards sending max(received data, organism ID) iff data is a cell ID.", &cTaskLib::Task_MaxID);
else if(name == "send-id")
NewTask(name, "Reward the sending of an ID as the data field of a message.", &cTaskLib::Task_SendID);
+ else if(name == "send-id-not-self")
+ NewTask(name, "Reward the sending of an ID (excluding the sender's ID) as the data field of a message.", &cTaskLib::Task_SendIDNotSelf);
else if(name == "send-non-id")
NewTask(name, "Reward sending a message that does NOT have an ID as the data field.", &cTaskLib::Task_SendNonID);
else if(name == "send-self")
@@ -1936,6 +1938,22 @@
}
+/*! This task rewards an organism for sending a message where the data field
+of the message contains any organism's ID (excluding the sender's). There are
+no restrictions on /how/ this ID was determined.
+*/
+double cTaskLib::Task_SendIDNotSelf(cTaskContext* ctx) const
+{
+ cOrgMessage* msg = ctx->GetMessage();
+ if(msg==NULL) return 0.0;
+
+ if(msg->GetData() != msg->GetSender()->GetRandomCellID() && cPopulationCell::IsRandomCellID(msg->GetData()))
+ return 1.0;
+
+ return 0.0;
+}
+
+
/*! This task 'rewards' an organism for sending a message where the data field of
the message is not an ID. This task is usually configured as a penalty, e.g.,
"process:value=.25:type=mult" in the environment file.
Modified: branches/coopcomm/source/main/cTaskLib.h
===================================================================
--- branches/coopcomm/source/main/cTaskLib.h 2006-11-28 02:50:41 UTC (rev 1101)
+++ branches/coopcomm/source/main/cTaskLib.h 2006-11-28 19:27:46 UTC (rev 1102)
@@ -235,6 +235,7 @@
// Coop-comm Tasks
double Task_MaxID(cTaskContext* ctx) const; //!< Rewards an organism for sending its max known ID.
double Task_SendID(cTaskContext* ctx) const; //!< Rewards an organism for sending an ID.
+ double Task_SendIDNotSelf(cTaskContext* ctx) const; //!< Rewards an organism for sending an ID that is not its own.
double Task_SendNonID(cTaskContext* ctx) const; //!< Rewards an organism for not sending an ID.
double Task_SendSelf(cTaskContext* ctx) const; //!< Rewards an organism for sending its ID.
More information about the Avida-cvs
mailing list