[Avida-SVN] r3442 - in development/source: cpu main
dk at myxo.css.msu.edu
dk at myxo.css.msu.edu
Sat Oct 3 07:31:56 PDT 2009
Author: dk
Date: 2009-10-03 10:31:56 -0400 (Sat, 03 Oct 2009)
New Revision: 3442
Modified:
development/source/cpu/cHardwareCPU.cc
development/source/main/cAvidaConfig.h
development/source/main/cOrganism.cc
development/source/main/cOrganism.h
Log:
Added buffer size limit for opinion-setting, removed stale messaging config options, renamed energy-requesting broadcast config option to be part of the energy group.
Modified: development/source/cpu/cHardwareCPU.cc
===================================================================
--- development/source/cpu/cHardwareCPU.cc 2009-10-02 20:12:24 UTC (rev 3441)
+++ development/source/cpu/cHardwareCPU.cc 2009-10-03 14:31:56 UTC (rev 3442)
@@ -5087,7 +5087,7 @@
cOrgMessage msg(m_organism);
// Could set the data field of the message to be the multiplier
- m_organism->BroadcastMessage(ctx, msg, m_world->GetConfig().MESSAGE_BCAST_RADIUS.Get());
+ m_organism->BroadcastMessage(ctx, msg, m_world->GetConfig().ENERGY_REQUEST_RADIUS.Get());
m_organism->GetPhenotype().SetIsEnergyRequestor();
m_organism->GetPhenotype().IncreaseNumEnergyRequests();
Modified: development/source/main/cAvidaConfig.h
===================================================================
--- development/source/main/cAvidaConfig.h 2009-10-02 20:12:24 UTC (rev 3441)
+++ development/source/main/cAvidaConfig.h 2009-10-03 14:31:56 UTC (rev 3442)
@@ -503,10 +503,8 @@
CONFIG_ADD_VAR(NET_STYLE, int, 0, "Communication Style. 0 = Random Next, 1 = Receiver Facing");
CONFIG_ADD_GROUP(ORGANISM_MESSAGING_GROUP, "Organism Message-Based Communication");
- CONFIG_ADD_VAR(MESSAGE_TYPE, int, 0, "Messaging Style. 0=Receiver Facing, 1=Broadcast");
- CONFIG_ADD_VAR(MESSAGE_BCAST_RADIUS, int, 1, "Broadcast message radius (cells)");
- CONFIG_ADD_VAR(MESSAGE_SEND_BUFFER_SIZE, bool, -1, "Size of message send buffer (stores messages that were sent)\nTASKS NOT CHECKED ON 0!\n-1=inf (default)");
- CONFIG_ADD_VAR(MESSAGE_RECV_BUFFER_SIZE, bool, -1, "Size of message receive buffer (stores messages that are received); -1=inf (default)");
+ CONFIG_ADD_VAR(MESSAGE_SEND_BUFFER_SIZE, bool, 1, "Size of message send buffer (stores messages that were sent)\nTASKS NOT CHECKED ON 0!\n-1=inf, default=1.");
+ CONFIG_ADD_VAR(MESSAGE_RECV_BUFFER_SIZE, bool, 8, "Size of message receive buffer (stores messages that are received); -1=inf, default=8.");
CONFIG_ADD_VAR(MESSAGE_RECV_BUFFER_BEHAVIOR, bool, 0, "Behavior of message receive buffer; 0=drop oldest (default), 1=drop incoming");
CONFIG_ADD_GROUP(BUY_SELL_GROUP, "Buying and Selling Parameters");
@@ -549,7 +547,8 @@
CONFIG_ADD_VAR(ENERGY_THRESH_LOW, double, .33, "Threshold percent below which energy level is considered low. Requires ENERGY_CAP.");
CONFIG_ADD_VAR(ENERGY_THRESH_HIGH, double, .75, "Threshold percent above which energy level is considered high. Requires ENERGY_CAP.");
CONFIG_ADD_VAR(ENERGY_COMPARISON_EPSILON, double, 0.0, "Percent difference (relative to executing organism) required in energy level comparisons");
-
+ CONFIG_ADD_VAR(ENERGY_REQUEST_RADIUS, int, 1, "Radius of broadcast energy request messages.");
+
CONFIG_ADD_GROUP(ENERGY_SHARING_GROUP, "Energy Sharing Settings");
CONFIG_ADD_VAR(ENERGY_SHARING_METHOD, int, 0, "Method for sharing energy. 0=receiver must actively receive/request, 1=energy pushed on receiver");
CONFIG_ADD_VAR(ENERGY_SHARING_PCT, double, 0.0, "Percent of energy to share");
@@ -676,6 +675,11 @@
CONFIG_ADD_VAR(INST_RES_FLOOR, double, 0.0, "Assumed lower level of resource in environment. Used for probability dist.");
CONFIG_ADD_VAR(INST_RES_CEIL, double, 0.0, "Assumed upper level of resource in environment. Used for probability dist.");
+ // -------- Opinion-setting config options --------
+ CONFIG_ADD_GROUP(OPINION_GROUP, "Organism opinion settings");
+ CONFIG_ADD_VAR(OPINION_BUFFER_SIZE, int, 1, "Size of the opinion buffer (stores opinions set over the organism's lifetime); -1=inf, default=1, cannot be 0.");
+
+
#endif
inline void Load(const cString& filename) { Load(filename, false); }
Modified: development/source/main/cOrganism.cc
===================================================================
--- development/source/main/cOrganism.cc 2009-10-02 20:12:24 UTC (rev 3441)
+++ development/source/main/cOrganism.cc 2009-10-03 14:31:56 UTC (rev 3442)
@@ -813,7 +813,9 @@
m_output_buf.Clear();
}
-//! Called as the bottom-half of a successfully sent message.
+
+/*! Called as the bottom-half of a successfully sent message.
+ */
void cOrganism::MessageSent(cAvidaContext& ctx, cOrgMessage& msg) {
// check to see if we should store it:
const int bsize = m_world->GetConfig().MESSAGE_SEND_BUFFER_SIZE.Get();
@@ -824,11 +826,10 @@
// and set the receiver-pointer of this message to NULL. We don't want to
// walk this list later thinking that the receivers are still around.
m_msg->sent.back().SetReceiver(0);
- // now, if our buffer is too large, chop off old messages:
- if((bsize != -1) && (static_cast<int>(m_msg->sent.size()) > bsize)) {
- while(static_cast<int>(m_msg->sent.size()) > bsize) { m_msg->sent.pop_front(); }
+ // if our buffer is too large, chop off old messages:
+ while((bsize != -1) && (static_cast<int>(m_msg->sent.size()) > bsize)) {
+ m_msg->sent.pop_front();
}
-
// check to see if we've performed any tasks:
DoOutput(ctx);
}
@@ -944,10 +945,22 @@
/*! Called to set this organism's opinion, which remains valid until a new opinion
is expressed.
*/
-void cOrganism::SetOpinion(const Opinion& opinion)
-{
+void cOrganism::SetOpinion(const Opinion& opinion) {
InitOpinions();
- m_opinion->opinion_list.push_back(std::make_pair(opinion, m_world->GetStats().GetUpdate()));
+
+ const int bsize = m_world->GetConfig().OPINION_BUFFER_SIZE.Get();
+
+ if(bsize == 0) {
+ m_world->GetDriver().RaiseFatalException(-1, "OPINION_BUFFER_SIZE is set to an invalid value.");
+ }
+
+ if((bsize > 0) || (bsize == -1)) {
+ m_opinion->opinion_list.push_back(std::make_pair(opinion, m_world->GetStats().GetUpdate()));
+ // if our buffer is too large, chop off old messages:
+ while((bsize != -1) && (static_cast<int>(m_opinion->opinion_list.size()) > bsize)) {
+ m_opinion->opinion_list.pop_front();
+ }
+ }
}
Modified: development/source/main/cOrganism.h
===================================================================
--- development/source/main/cOrganism.h 2009-10-02 20:12:24 UTC (rev 3441)
+++ development/source/main/cOrganism.h 2009-10-03 14:31:56 UTC (rev 3442)
@@ -471,7 +471,7 @@
public:
typedef int Opinion; //!< Typedef for an opinion.
typedef std::pair<Opinion, int> DatedOpinion; //!< Typedef for an opinion held at a given update.
- typedef std::vector<DatedOpinion> DatedOpinionList; //!< Typedef for a list of dated opinions.
+ typedef std::deque<DatedOpinion> DatedOpinionList; //!< Typedef for a list of dated opinions.
//! Called to set this organism's opinion.
void SetOpinion(const Opinion& opinion);
//! Retrieve this organism's current opinion.
More information about the Avida-cvs
mailing list