[Avida-cvs] [avida-svn] r536 - in development/source: cpu main
brysonda@myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Mon Mar 27 19:26:06 PST 2006
Author: brysonda
Date: 2006-03-27 22:26:06 -0500 (Mon, 27 Mar 2006)
New Revision: 536
Modified:
development/source/cpu/cTestCPUInterface.h
development/source/main/cAvidaConfig.h
development/source/main/cOrgInterface.h
development/source/main/cOrgSourceMessage.h
development/source/main/cOrganism.cc
development/source/main/cOrganism.h
development/source/main/cPopulationInterface.h
Log:
Implement some network send/receive methods and support in cOrganism.
Modified: development/source/cpu/cTestCPUInterface.h
===================================================================
--- development/source/cpu/cTestCPUInterface.h 2006-03-27 18:36:56 UTC (rev 535)
+++ development/source/cpu/cTestCPUInterface.h 2006-03-28 03:26:06 UTC (rev 536)
@@ -20,6 +20,10 @@
class cOrgMessage;
class cTestCPU;
+#ifndef NULL
+#define NULL 0
+#endif
+
class cTestCPUInterface : public cOrgInterface
{
private:
@@ -46,6 +50,7 @@
void Die();
void Kaboom();
bool SendMessage(cOrgMessage& mess);
+ cOrgSinkMessage* NetReceive() { return NULL; } // @DMB - receive message
int ReceiveValue();
bool InjectParasite(cOrganism* parent, const cGenome& injected_code);
bool UpdateMerit(double new_merit);
Modified: development/source/main/cAvidaConfig.h
===================================================================
--- development/source/main/cAvidaConfig.h 2006-03-27 18:36:56 UTC (rev 535)
+++ development/source/main/cAvidaConfig.h 2006-03-28 03:26:06 UTC (rev 536)
@@ -260,6 +260,10 @@
CONFIG_ADD_GROUP(LINEAGE_GROUP, "Lineage\nNOTE: This should probably be called \"Clade\"\nThis one can slow down avida a lot. It is used to get an idea of how\noften an advantageous mutation arises, and where it goes afterwards.\nLineage creation options are. Works only when LOG_LINEAGES is set to 1.\n 0 = manual creation (on inject, use successive integers as lineage labels).\n 1 = when a child's (potential) fitness is higher than that of its parent.\n 2 = when a child's (potential) fitness is higher than max in population.\n 3 = when a child's (potential) fitness is higher than max in dom. lineage\n*and* the child is in the dominant lineage, or (2)\n 4 = when a child's (potential) fitness is higher than max in dom. lineage\n(and that of its own lineage)\n 5 = same as child's (potential) fitness is higher than that of the\n currently dominant organism, and also than that of any organism\n currently in the same lineage.\n 6 = when a child's (potential) f!
itness is higher than any organism\n currently in the same lineage.\n 7 = when a child's (potential) fitness is higher than that of any\n organism in its line of descent");
CONFIG_ADD_VAR(LOG_LINEAGES, bool, 0, "");
CONFIG_ADD_VAR(LINEAGE_CREATION_METHOD, int, 0, "");
+
+ CONFIG_ADD_GROUP(ORGANISM_NETWORK_GROUP, "Organism Network Communication");
+ CONFIG_ADD_VAR(NET_DROP_PROB, double, 0.0, "Message drop rate");
+ CONFIG_ADD_VAR(NET_MUT_PROB, double, 0.0, "Message corruption probability");
#endif
void Load(const cString & filename);
Modified: development/source/main/cOrgInterface.h
===================================================================
--- development/source/main/cOrgInterface.h 2006-03-27 18:36:56 UTC (rev 535)
+++ development/source/main/cOrgInterface.h 2006-03-28 03:26:06 UTC (rev 536)
@@ -12,6 +12,7 @@
class cAvidaContext;
class cOrganism;
+class cOrgSinkMessage;
class cGenome;
template <class T> class tArray;
class cOrgMessage;
@@ -43,6 +44,7 @@
virtual void Die() = 0;
virtual void Kaboom() = 0;
virtual bool SendMessage(cOrgMessage& mess) = 0;
+ virtual cOrgSinkMessage* NetReceive() = 0;
virtual int ReceiveValue() = 0;
virtual bool InjectParasite(cOrganism* parent, const cGenome& injected_code) = 0;
virtual bool UpdateMerit(double new_merit) = 0;
Modified: development/source/main/cOrgSourceMessage.h
===================================================================
--- development/source/main/cOrgSourceMessage.h 2006-03-27 18:36:56 UTC (rev 535)
+++ development/source/main/cOrgSourceMessage.h 2006-03-28 03:26:06 UTC (rev 536)
@@ -16,10 +16,11 @@
int m_value;
int m_sent;
int m_dropped;
+ int m_corrupt;
public:
- cOrgSourceMessage() : m_value(0), m_sent(0), m_dropped(0) { ; }
- cOrgSourceMessage(int value) : m_value(value), m_sent(1), m_dropped(0) { ; }
+ cOrgSourceMessage() : m_value(0), m_sent(0), m_dropped(0), m_corrupt(0) { ; }
+ cOrgSourceMessage(int value) : m_value(value), m_sent(1), m_dropped(0), m_corrupt(0) { ; }
int GetValue() { return m_value; }
@@ -27,6 +28,8 @@
void SetSent() { m_sent++; }
int GetDropped() { return m_dropped; }
void SetDropped() { m_dropped++; }
+ int GetCorrupted() { return m_corrupt; }
+ void SetCorrupted() { m_corrupt++; }
};
#endif
Modified: development/source/main/cOrganism.cc
===================================================================
--- development/source/main/cOrganism.cc 2006-03-27 18:36:56 UTC (rev 535)
+++ development/source/main/cOrganism.cc 2006-03-28 03:26:06 UTC (rev 536)
@@ -174,13 +174,62 @@
return true;
}
-void cOrganism::NetSend(int value)
+void cOrganism::NetSend(cAvidaContext& ctx, int value)
{
- // @DMB - process message send
+ int index = -1;
+
+ // Search for previously sent value
+ for (int i = m_net_sent.GetSize() - 1; i >= 0; i--) {
+ if (m_net_sent[i].GetValue() == value) {
+ index = i;
+ m_net_sent[i].SetSent();
+ break;
+ }
+ }
+
+ // If not found, add new message
+ if (index == -1) {
+ index = m_net_sent.GetSize();
+ m_net_sent.Resize(index + 1);
+ m_net_sent[index] = cOrgSourceMessage(value);
+ }
+
+ // Test if this message will be dropped
+ const double drop_prob = m_world->GetConfig().NET_DROP_PROB.Get();
+ if (drop_prob > 0.0 && ctx.GetRandom().P(drop_prob)) {
+ m_net_sent[index].SetDropped();
+ return;
+ }
+
+ // Test if this message will be corrupted
+ int actual_value = value;
+ const double mut_prob = m_world->GetConfig().NET_MUT_PROB.Get();
+ if (mut_prob > 0.0 && ctx.GetRandom().P(mut_prob)) {
+ actual_value ^= 1 << ctx.GetRandom().GetUInt(31); // Flip a single random bit
+ m_net_sent[index].SetCorrupted();
+ }
+
+ assert(m_interface);
+ cOrgSinkMessage* msg = new cOrgSinkMessage(m_interface->GetCellID(), value, actual_value);
+ m_net_pending.Push(msg);
}
-bool NetValidate(int value)
+bool cOrganism::NetReceive(int& value)
{
+ assert(m_interface);
+ cOrgSinkMessage* msg = m_interface->NetReceive();
+ if (msg == NULL) {
+ value = 0;
+ return false;
+ }
+
+ m_net_received.Push(msg);
+ value = msg->GetActualValue();
+ return true;
+}
+
+bool cOrganism::NetValidate(int value)
+{
// @DMB - check value against internal received buffer
return false;
Modified: development/source/main/cOrganism.h
===================================================================
--- development/source/main/cOrganism.h 2006-03-27 18:36:56 UTC (rev 535)
+++ development/source/main/cOrganism.h 2006-03-28 03:26:06 UTC (rev 536)
@@ -146,8 +146,9 @@
bool ReceiveMessage(cOrgMessage & mess);
// Network Stuff
- void NetSend(int value);
- cOrgSinkMessage* NetReceive() { return m_net_pending.PopRear(); }
+ void NetSend(cAvidaContext& ctx, int value);
+ cOrgSinkMessage* NetPopBuffer() { return m_net_pending.PopRear(); }
+ bool NetReceive(int& value);
bool NetValidate(int value);
bool InjectParasite(const cGenome & genome);
Modified: development/source/main/cPopulationInterface.h
===================================================================
--- development/source/main/cPopulationInterface.h 2006-03-27 18:36:56 UTC (rev 535)
+++ development/source/main/cPopulationInterface.h 2006-03-28 03:26:06 UTC (rev 536)
@@ -57,6 +57,7 @@
void Die();
void Kaboom();
bool SendMessage(cOrgMessage& mess);
+ cOrgSinkMessage* NetReceive() { return NULL; } // @DMB - receive message
int ReceiveValue();
bool InjectParasite(cOrganism* parent, const cGenome& injected_code);
bool UpdateMerit(double new_merit);
More information about the Avida-cvs
mailing list