[Avida-cvs] [avida-svn] r544 - in development: Avida.xcodeproj source/cpu source/main

brysonda@myxo.css.msu.edu brysonda at myxo.css.msu.edu
Wed Mar 29 19:31:14 PST 2006


Author: brysonda
Date: 2006-03-29 22:31:08 -0500 (Wed, 29 Mar 2006)
New Revision: 544

Added:
   development/source/main/cOrgSeqMessage.h
   development/source/main/cTaskContext.h
Modified:
   development/Avida.xcodeproj/project.pbxproj
   development/source/cpu/cTestCPUInterface.h
   development/source/main/cAvidaConfig.h
   development/source/main/cEnvironment.cc
   development/source/main/cEnvironment.h
   development/source/main/cOrgInterface.h
   development/source/main/cOrgSinkMessage.h
   development/source/main/cOrganism.cc
   development/source/main/cOrganism.h
   development/source/main/cPhenotype.cc
   development/source/main/cPhenotype.h
   development/source/main/cPopulationInterface.cc
   development/source/main/cPopulationInterface.h
   development/source/main/cReactionResult.cc
   development/source/main/cReactionResult.h
   development/source/main/cTaskLib.cc
   development/source/main/cTaskLib.h
Log:
Finish basic network communication framework in cOrganism, cTaskLib.   Also, move cTaskContext creation out into the origination point (cOrganism) to facilitate setting up additional task variables without having to pass them 3 steps into the TaskLib. 

Modified: development/Avida.xcodeproj/project.pbxproj
===================================================================
--- development/Avida.xcodeproj/project.pbxproj	2006-03-29 19:49:14 UTC (rev 543)
+++ development/Avida.xcodeproj/project.pbxproj	2006-03-30 03:31:08 UTC (rev 544)
@@ -550,6 +550,7 @@
 		7005A70109BA0FA90007E16E /* cTestCPUInterface.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cTestCPUInterface.h; sourceTree = "<group>"; };
 		7005A70209BA0FA90007E16E /* cTestCPUInterface.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = cTestCPUInterface.cc; sourceTree = "<group>"; };
 		7005A70909BA0FBE0007E16E /* cOrgInterface.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cOrgInterface.h; sourceTree = "<group>"; };
+		700AE91B09DB65F200A073FD /* cTaskContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cTaskContext.h; sourceTree = "<group>"; };
 		700E28CF0859FFD700CF158A /* tObjectFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tObjectFactory.h; sourceTree = "<group>"; };
 		700E2B83085DE50C00CF158A /* avida-viewer */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "avida-viewer"; sourceTree = BUILT_PRODUCTS_DIR; };
 		701384330900A45B0087ED2E /* organism.smtx */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = organism.smtx; sourceTree = "<group>"; };
@@ -845,6 +846,7 @@
 		70CA6EF208DB7F9E00068AC2 /* cInstruction.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cInstruction.h; sourceTree = "<group>"; };
 		70CA6EF308DB7F9E00068AC2 /* cInstSet.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cInstSet.h; sourceTree = "<group>"; };
 		70CA6EF408DB7F9E00068AC2 /* cInstUtil.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cInstUtil.h; sourceTree = "<group>"; };
+		70DA5E9D09DA1A8D00FFF42B /* cOrgSeqMessage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cOrgSeqMessage.h; sourceTree = "<group>"; };
 		70DCAC57097AF730002F8733 /* main.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = main.cc; sourceTree = "<group>"; };
 		70DCAC59097AF730002F8733 /* cBarScreen.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cBarScreen.cc; sourceTree = "<group>"; };
 		70DCAC5A097AF730002F8733 /* cBarScreen.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cBarScreen.h; sourceTree = "<group>"; };
@@ -1428,6 +1430,8 @@
 				701D51CB09C645F50009B4F8 /* cAvidaContext.h */,
 				7027621909D73E5900741717 /* cOrgSourceMessage.h */,
 				7027621A09D73E7700741717 /* cOrgSinkMessage.h */,
+				70DA5E9D09DA1A8D00FFF42B /* cOrgSeqMessage.h */,
+				700AE91B09DB65F200A073FD /* cTaskContext.h */,
 			);
 			path = main;
 			sourceTree = "<group>";

Modified: development/source/cpu/cTestCPUInterface.h
===================================================================
--- development/source/cpu/cTestCPUInterface.h	2006-03-29 19:49:14 UTC (rev 543)
+++ development/source/cpu/cTestCPUInterface.h	2006-03-30 03:31:08 UTC (rev 544)
@@ -50,7 +50,8 @@
   void Die();
   void Kaboom();
   bool SendMessage(cOrgMessage& mess);
-  cOrgSinkMessage* NetReceive() { return NULL; } // @DMB - receive message
+  cOrgSinkMessage* NetReceive() { return NULL; } // @DMB - todo: receive message
+  bool NetRemoteValidate(cAvidaContext& ctx, cOrgSinkMessage* msg) { return false; } // @DMB - todo: validate 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-29 19:49:14 UTC (rev 543)
+++ development/source/main/cAvidaConfig.h	2006-03-30 03:31:08 UTC (rev 544)
@@ -262,6 +262,7 @@
   CONFIG_ADD_VAR(LINEAGE_CREATION_METHOD, int, 0, "");
   
   CONFIG_ADD_GROUP(ORGANISM_NETWORK_GROUP, "Organism Network Communication");
+  CONFIG_ADD_VAR(NET_ENABLED, bool, 0, "Enable Network Communication Support");
   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

Modified: development/source/main/cEnvironment.cc
===================================================================
--- development/source/main/cEnvironment.cc	2006-03-29 19:49:14 UTC (rev 543)
+++ development/source/main/cEnvironment.cc	2006-03-30 03:31:08 UTC (rev 544)
@@ -650,19 +650,13 @@
 }
 
 
-bool cEnvironment::TestOutput(cAvidaContext& ctx, cReactionResult& result,
-                              const tBuffer<int>& input_buf,
-                              const tBuffer<int>& output_buf,
-                              const tBuffer<int>& send_buf,
-                              const tBuffer<int>& receive_buf,
-                              const tArray<int>& task_count,
-                              const tArray<int>& reaction_count,
-                              const tArray<double>& resource_count,
-                              const tList< tBuffer<int> >& input_buffers,
-                              const tList< tBuffer<int> >& output_buffers) const
+bool cEnvironment::TestOutput(cAvidaContext& ctx, cReactionResult& result, cTaskContext& taskctx,
+                              const tBuffer<int>& send_buf, const tBuffer<int>& receive_buf,
+                              const tArray<int>& task_count, const tArray<int>& reaction_count,
+                              const tArray<double>& resource_count) const
 {
   // Do setup for reaction tests...
-  cTaskContext taskctx = task_lib.SetupTests(input_buf, output_buf, input_buffers, output_buffers);
+  task_lib.SetupTests(taskctx);
   
   // Loop through all reactions to see if any have been triggered...
   const int num_reactions = reaction_lib.GetSize();
@@ -701,7 +695,6 @@
   // if (receive_buf.GetSize() != 0)
   {
     // Do setup for reaction tests...
-    cTaskContext taskctx = task_lib.SetupTests(receive_buf, output_buf, input_buffers, output_buffers);
     
     for (int i = 0; i < num_reactions; i++) {
       cReaction * cur_reaction = reaction_lib.GetReaction(i);

Modified: development/source/main/cEnvironment.h
===================================================================
--- development/source/main/cEnvironment.h	2006-03-29 19:49:14 UTC (rev 543)
+++ development/source/main/cEnvironment.h	2006-03-30 03:31:08 UTC (rev 544)
@@ -43,6 +43,7 @@
 class cReactionProcess;
 class cReactionResult;
 template <class T> class tBuffer;
+class cTaskContext;
 class cWorld;
 
 class cEnvironment {
@@ -99,16 +100,10 @@
   bool TestInput(cReactionResult& result, const tBuffer<int>& inputs,
                  const tBuffer<int>& outputs, const tArray<double>& resource_count ) const;
 
-  bool TestOutput(cAvidaContext& ctx, cReactionResult& result,
-		    const tBuffer<int>& input_buf,
-		    const tBuffer<int>& output_buf,
-		    const tBuffer<int>& send_buf,
-		    const tBuffer<int>& receive_buf,
-		    const tArray<int>& task_count,
-		    const tArray<int>& reaction_count,
-		    const tArray<double>& resource_count,
-		    const tList<tBuffer<int> >& other_inputs,
-		    const tList<tBuffer<int> >& other_outputs) const;
+  bool TestOutput(cAvidaContext& ctx, cReactionResult& result, cTaskContext& taskctx,
+                  const tBuffer<int>& send_buf, const tBuffer<int>& receive_buf,
+                  const tArray<int>& task_count, const tArray<int>& reaction_count,
+                  const tArray<double>& resource_count) const;
 
   // Accessors
   const cResourceLib & GetResourceLib() const { return resource_lib; }

Modified: development/source/main/cOrgInterface.h
===================================================================
--- development/source/main/cOrgInterface.h	2006-03-29 19:49:14 UTC (rev 543)
+++ development/source/main/cOrgInterface.h	2006-03-30 03:31:08 UTC (rev 544)
@@ -45,6 +45,7 @@
   virtual void Kaboom() = 0;
   virtual bool SendMessage(cOrgMessage& mess) = 0;
   virtual cOrgSinkMessage* NetReceive() = 0;
+  virtual bool NetRemoteValidate(cAvidaContext& ctx, cOrgSinkMessage* msg) = 0;
   virtual int ReceiveValue() = 0;
   virtual bool InjectParasite(cOrganism* parent, const cGenome& injected_code) = 0;
   virtual bool UpdateMerit(double new_merit) = 0;

Added: development/source/main/cOrgSeqMessage.h
===================================================================
--- development/source/main/cOrgSeqMessage.h	2006-03-29 19:49:14 UTC (rev 543)
+++ development/source/main/cOrgSeqMessage.h	2006-03-30 03:31:08 UTC (rev 544)
@@ -0,0 +1,29 @@
+/*
+ *  cOrgSeqMessage.h
+ *  Avida
+ *
+ *  Created by David on 3/28/06.
+ *  Copyright 2006 Michigan State University. All rights reserved.
+ *
+ */
+
+#ifndef cOrgSeqMessage_h
+#define cOrgSeqMessage_h
+
+class cOrgSeqMessage
+{
+private:
+  int m_value;
+  bool m_recvd;
+  
+public:
+  cOrgSeqMessage() : m_value(0), m_recvd(false) { ; }
+
+  void SetValue(int value) { m_value = value; }
+  int GetValue() { return m_value; }
+
+  void SetReceived() { m_recvd = true; }
+  bool GetReceived() { return m_recvd; }
+};
+
+#endif


Property changes on: development/source/main/cOrgSeqMessage.h
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: development/source/main/cOrgSinkMessage.h
===================================================================
--- development/source/main/cOrgSinkMessage.h	2006-03-29 19:49:14 UTC (rev 543)
+++ development/source/main/cOrgSinkMessage.h	2006-03-30 03:31:08 UTC (rev 544)
@@ -16,15 +16,19 @@
   int m_source_id;
   int m_orig_val;
   int m_actual_val;
+  bool m_validated;
   
 public:
-  cOrgSinkMessage() : m_source_id(-1), m_orig_val(0), m_actual_val(0) { ; }
+  cOrgSinkMessage() : m_source_id(-1), m_orig_val(0), m_actual_val(0), m_validated(false) { ; }
   cOrgSinkMessage(int source, int original, int actual)
-    : m_source_id(source), m_orig_val(original), m_actual_val(actual) { ; }
+    : m_source_id(source), m_orig_val(original), m_actual_val(actual), m_validated(false) { ; }
   
   int GetSourceID() { return m_source_id; }
-  int GetOrignalValue() { return m_orig_val; }
+  int GetOriginalValue() { return m_orig_val; }
   int GetActualValue() { return m_actual_val; }
+  
+  void SetValidated() { m_validated = true; }
+  bool GetValidated() { return m_validated; }
 };
 
 #endif

Modified: development/source/main/cOrganism.cc
===================================================================
--- development/source/main/cOrganism.cc	2006-03-29 19:49:14 UTC (rev 543)
+++ development/source/main/cOrganism.cc	2006-03-30 03:31:08 UTC (rev 544)
@@ -24,6 +24,7 @@
 #include "cOrgMessage.h"
 #include "cOrgSinkMessage.h"
 #include "cStringUtil.h"
+#include "cTaskContext.h"
 #include "cTools.h"
 #include "cWorld.h"
 
@@ -52,6 +53,7 @@
   , lineage(NULL)
   , inbox(0)
   , sent(0)
+  , m_net(NULL)
   , is_running(false)
 {
   // Initialization of structures...
@@ -70,6 +72,8 @@
     // max_executed must be positive or an organism will not die!
     if (max_executed < 1) max_executed = 1;
   }
+  
+  if (m_world->GetConfig().NET_ENABLED.Get()) m_net = new cNetSupport();
 }
 
 
@@ -78,10 +82,15 @@
   assert(is_running == false);
   delete hardware;
   delete m_interface;
-  while (m_net_pending.GetSize()) delete m_net_pending.Pop();
-  for (int i = 0; i < m_net_received.GetSize(); i++) delete m_net_received[i];
+  if (m_net != NULL) delete m_net;
 }
 
+cOrganism::cNetSupport::~cNetSupport()
+{
+  while (pending.GetSize()) delete pending.Pop();
+  for (int i = 0; i < received.GetSize(); i++) delete received[i];
+}
+
 void cOrganism::SetOrgInterface(cOrgInterface* interface)
 {
   delete m_interface;
@@ -141,14 +150,16 @@
       other_output_list.Push( &(cur_neighbor->output_buf) );
     }
   }
+  
+  bool net_valid = false;
+  if (m_net) net_valid = NetValidate(ctx, value);
 
   // Do the testing of tasks performed...
   output_buf.Add(value);
   tArray<double> res_change(resource_count.GetSize());
   tArray<int> insts_triggered;
-  phenotype.TestOutput(ctx, input_buf, output_buf, send_buf, receive_buf,
-		       resource_count, res_change, insts_triggered,
-		       other_input_list, other_output_list);
+  cTaskContext taskctx(input_buf, output_buf, other_input_list, other_output_list, net_valid, 0);
+  phenotype.TestOutput(ctx, taskctx, send_buf, receive_buf, resource_count, res_change, insts_triggered);
   m_interface->UpdateResources(res_change);
 
   for (int i = 0; i < insts_triggered.GetSize(); i++) {
@@ -174,30 +185,41 @@
   return true;
 }
 
+
+void cOrganism::NetGet(cAvidaContext& ctx, int& value, int& seq)
+{
+  assert(m_net);
+  seq = m_net->seq.GetSize();
+  m_net->seq.Resize(seq + 1);
+  value = ctx.GetRandom().GetUInt(1 << 16);
+  m_net->seq[seq].SetValue(value);
+}
+
 void cOrganism::NetSend(cAvidaContext& ctx, int value)
 {
+  assert(m_net);
   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) {
+  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();
+      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);
+    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();
+    m_net->sent[index].SetDropped();
     return;
   }
   
@@ -206,36 +228,118 @@
   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();
+    m_net->sent[index].SetCorrupted();
   }
   
   assert(m_interface);
   cOrgSinkMessage* msg = new cOrgSinkMessage(m_interface->GetCellID(), value, actual_value);
-  m_net_pending.Push(msg);
+  m_net->pending.Push(msg);
 }
 
 bool cOrganism::NetReceive(int& value)
 {
-  assert(m_interface);
+  assert(m_net && m_interface);
   cOrgSinkMessage* msg = m_interface->NetReceive();
   if (msg == NULL) {
     value = 0;
     return false;
   }
   
-  m_net_received.Push(msg);
+  m_net->received.Push(msg);
   value = msg->GetActualValue();
   return true;
 }
 
-bool cOrganism::NetValidate(int value)
+bool cOrganism::NetValidate(cAvidaContext& ctx, int value)
 {
-  // @DMB - check value against internal received buffer
+  assert(m_net);
   
+  if (0xFFFF0000 & value) return false;
+  
+  for (int i = 0; i < m_net->received.GetSize(); i++) {
+    cOrgSinkMessage* msg = m_net->received[i];
+    if (!msg->GetValidated() && (msg->GetOriginalValue() & 0xFFFF) == value) {
+      msg->SetValidated();
+      assert(m_interface);
+      return m_interface->NetRemoteValidate(ctx, msg);
+    }
+  }
+    
   return false;
 }
 
+bool cOrganism::NetRemoteValidate(cAvidaContext& ctx, int value)
+{
+  assert(m_net);
 
+  bool found = false;
+
+  for (int i = m_net->last_seq; i < m_net->seq.GetSize(); i++) {
+    cOrgSeqMessage& msg = m_net->seq[i];
+    if (msg.GetValue() == value && !msg.GetReceived()) {
+      m_net->seq[i].SetReceived();
+      found = true;
+      break;
+    }
+  }
+
+  if (!found) return false;
+
+  int completed = 0;
+  while (m_net->seq[m_net->last_seq].GetReceived()) {
+    completed++;
+    m_net->last_seq++;
+  }
+  
+  if (completed) {
+    assert(m_interface);
+    const tArray<double>& resource_count = m_interface->GetResources();
+    
+    tList<tBuffer<int> > other_input_list;
+    tList<tBuffer<int> > other_output_list;
+    
+    // If tasks require us to consider neighbor inputs, collect them...
+    if (m_world->GetEnvironment().GetTaskLib().UseNeighborInput() == true) {
+      const int num_neighbors = m_interface->GetNumNeighbors();
+      for (int i = 0; i < num_neighbors; i++) {
+        m_interface->Rotate();
+        cOrganism * cur_neighbor = m_interface->GetNeighbor();
+        if (cur_neighbor == NULL) continue;
+        
+        other_input_list.Push( &(cur_neighbor->input_buf) );
+      }
+    }
+    
+    // If tasks require us to consider neighbor outputs, collect them...
+    if (m_world->GetEnvironment().GetTaskLib().UseNeighborOutput() == true) {
+      const int num_neighbors = m_interface->GetNumNeighbors();
+      for (int i = 0; i < num_neighbors; i++) {
+        m_interface->Rotate();
+        cOrganism * cur_neighbor = m_interface->GetNeighbor();
+        if (cur_neighbor == NULL) continue;
+        
+        other_output_list.Push( &(cur_neighbor->output_buf) );
+      }
+    }
+        
+    // Do the testing of tasks performed...
+    output_buf.Add(value);
+    tArray<double> res_change(resource_count.GetSize());
+    tArray<int> insts_triggered;
+    cTaskContext taskctx(input_buf, output_buf, other_input_list, other_output_list, false, completed);
+    phenotype.TestOutput(ctx, taskctx, send_buf, receive_buf, resource_count, res_change, insts_triggered);
+    m_interface->UpdateResources(res_change);
+    
+    for (int i = 0; i < insts_triggered.GetSize(); i++) {
+      const int cur_inst = insts_triggered[i];
+      hardware->ProcessBonusInst(ctx, cInstruction(cur_inst) );
+    }
+  }
+  
+  return true;
+}
+
+
 bool cOrganism::InjectParasite(const cGenome & injected_code)
 {
   assert(m_interface);

Modified: development/source/main/cOrganism.h
===================================================================
--- development/source/main/cOrganism.h	2006-03-29 19:49:14 UTC (rev 543)
+++ development/source/main/cOrganism.h	2006-03-30 03:31:08 UTC (rev 544)
@@ -35,6 +35,9 @@
 #ifndef cOrgInterface_h
 #include "cOrgInterface.h"
 #endif
+#ifndef cOrgSeqMessage_h
+#include "cOrgSeqMessage.h"
+#endif
 #ifndef cOrgSourceMessage_h
 #include "cOrgSourceMessage.h"
 #endif
@@ -101,9 +104,19 @@
   tBuffer<cOrgMessage> inbox;
   tBuffer<cOrgMessage> sent;
   
-  tList<cOrgSinkMessage> m_net_pending;
-  tSmartArray<cOrgSinkMessage*> m_net_received;
-  tSmartArray<cOrgSourceMessage> m_net_sent;
+  class cNetSupport
+  {
+  public:
+    tList<cOrgSinkMessage> pending;
+    tSmartArray<cOrgSinkMessage*> received;
+    tSmartArray<cOrgSourceMessage> sent;
+    tSmartArray<cOrgSeqMessage> seq; 
+    int last_seq;
+    
+    cNetSupport() : last_seq(-1) { ; }
+    ~cNetSupport();
+  };
+  cNetSupport* m_net;
 
 #ifdef DEBUG
   bool initialized;      // Has this CPU been initialized yet, w/hardware.
@@ -146,10 +159,13 @@
   bool ReceiveMessage(cOrgMessage & mess);
   
   // Network Stuff
+  void NetGet(cAvidaContext& ctx, int& value, int& seq);
   void NetSend(cAvidaContext& ctx, int value);
-  cOrgSinkMessage* NetPopBuffer() { return m_net_pending.PopRear(); }
+  cOrgSinkMessage* NetPop() { return m_net->pending.PopRear(); }
   bool NetReceive(int& value);
-  bool NetValidate(int value);
+  bool NetValidate(cAvidaContext& ctx, int value);
+  bool NetRemoteValidate(cAvidaContext& ctx, int value);
+  int NetLast() { return m_net->last_seq; }
 
   bool InjectParasite(const cGenome & genome);
   bool InjectHost(const cCodeLabel & in_label, const cGenome & genome);

Modified: development/source/main/cPhenotype.cc
===================================================================
--- development/source/main/cPhenotype.cc	2006-03-29 19:49:14 UTC (rev 543)
+++ development/source/main/cPhenotype.cc	2006-03-30 03:31:08 UTC (rev 544)
@@ -488,13 +488,9 @@
   return false; // Nothing happened...
 }
 
-bool cPhenotype::TestOutput(cAvidaContext& ctx, tBuffer<int> & input_buf, tBuffer<int> &output_buf,
-			    tBuffer<int> & send_buf, tBuffer<int> &receive_buf,
-			    const tArray<double> & res_in,
-			    tArray<double> & res_change,
-			    tArray<int> & insts_triggered,
-			    tList<tBuffer<int> > & other_inputs,
-			    tList<tBuffer<int> > & other_outputs)
+bool cPhenotype::TestOutput(cAvidaContext& ctx, cTaskContext& taskctx, tBuffer<int>& send_buf,
+                            tBuffer<int>& receive_buf, const tArray<double>& res_in,
+                            tArray<double>& res_change, tArray<int>& insts_triggered)
 {
   assert(initialized == true);
 
@@ -506,9 +502,7 @@
   cReactionResult result(num_resources, num_tasks, num_reactions);
 			
   // Run everything through the environment.
-  bool found = env.TestOutput(ctx, result, input_buf, output_buf, send_buf,
-			      receive_buf, cur_task_count, cur_reaction_count,
-			      res_in, other_inputs, other_outputs);
+  bool found = env.TestOutput(ctx, result, taskctx, send_buf, receive_buf, cur_task_count, cur_reaction_count, res_in);
 
   // If nothing was found, stop here.
   if (found == false) {

Modified: development/source/main/cPhenotype.h
===================================================================
--- development/source/main/cPhenotype.h	2006-03-29 19:49:14 UTC (rev 543)
+++ development/source/main/cPhenotype.h	2006-03-30 03:31:08 UTC (rev 544)
@@ -54,6 +54,7 @@
 class cEnvironment;
 template <class T> class tBuffer;
 template <class T> class tList;
+class cTaskContext;
 class cWorld;
 
 class cPhenotype
@@ -156,11 +157,8 @@
 
   // Input and Output Reaction Tests
   bool TestInput(tBuffer<int>& inputs, tBuffer<int>& outputs);
-  bool TestOutput(cAvidaContext& ctx, tBuffer<int>& input_buf, tBuffer<int>& output_buf, 
-                  tBuffer<int>& send_buf, tBuffer<int>& receive_buf,
-                  const tArray<double>& res_in, tArray<double>& res_change,
-                  tArray<int>& insts_triggered, tList<tBuffer<int> >& other_inputs, 
-                  tList<tBuffer<int> >& other_outputs);
+  bool TestOutput(cAvidaContext& ctx, cTaskContext& ctx, tBuffer<int>& send_buf, tBuffer<int>& receive_buf,
+                  const tArray<double>& res_in, tArray<double>& res_change, tArray<int>& insts_triggered);
 
   // State saving and loading, and printing...
   bool SaveState(std::ofstream& fp);

Modified: development/source/main/cPopulationInterface.cc
===================================================================
--- development/source/main/cPopulationInterface.cc	2006-03-29 19:49:14 UTC (rev 543)
+++ development/source/main/cPopulationInterface.cc	2006-03-30 03:31:08 UTC (rev 544)
@@ -14,6 +14,7 @@
 #include "cHardwareManager.h"
 #include "cOrganism.h"
 #include "cOrgMessage.h"
+#include "cOrgSinkMessage.h"
 #include "cPopulation.h"
 #include "cPopulationCell.h"
 #include "cStats.h"
@@ -120,6 +121,29 @@
   return cell.ConnectionList().GetFirst()->GetOrganism()->ReceiveMessage(mess);
 }
 
+cOrgSinkMessage* cPopulationInterface::NetReceive()
+{
+  cPopulationCell& cell = m_world->GetPopulation().GetCell(cell_id);
+  assert(cell.IsOccupied());
+  
+  const int num_neighbors = cell.ConnectionList().GetSize();
+  for (int i = 0; i < num_neighbors; i++) {
+    cell.ConnectionList().CircNext();
+    
+    cOrganism* cur_neighbor = cell.ConnectionList().GetFirst()->GetOrganism();
+    cOrgSinkMessage* msg;
+    if (cur_neighbor != NULL || (msg = cur_neighbor->NetPop()) != NULL ) return msg;
+  }
+  
+  return NULL;
+}
+
+bool cPopulationInterface::NetRemoteValidate(cAvidaContext& ctx, cOrgSinkMessage* msg)
+{
+  cOrganism* org = m_world->GetPopulation().GetCell(msg->GetSourceID()).GetOrganism();
+  return (org != NULL && org->NetRemoteValidate(ctx, msg->GetOriginalValue()));
+}
+
 int cPopulationInterface::ReceiveValue()
 {
   cPopulationCell & cell = m_world->GetPopulation().GetCell(cell_id);
@@ -127,10 +151,9 @@
   
   const int num_neighbors = cell.ConnectionList().GetSize();
   for (int i = 0; i < num_neighbors; i++) {
-    cPopulationCell & cell = m_world->GetPopulation().GetCell(cell_id);
     cell.ConnectionList().CircNext();
     
-    cOrganism * cur_neighbor = cell.ConnectionList().GetFirst()->GetOrganism();
+    cOrganism* cur_neighbor = cell.ConnectionList().GetFirst()->GetOrganism();
     if (cur_neighbor == NULL || cur_neighbor->GetSentActive() == false) {
       continue;
     }

Modified: development/source/main/cPopulationInterface.h
===================================================================
--- development/source/main/cPopulationInterface.h	2006-03-29 19:49:14 UTC (rev 543)
+++ development/source/main/cPopulationInterface.h	2006-03-30 03:31:08 UTC (rev 544)
@@ -57,7 +57,8 @@
   void Die();
   void Kaboom();
   bool SendMessage(cOrgMessage& mess);
-  cOrgSinkMessage* NetReceive() { return NULL; } // @DMB - receive message
+  cOrgSinkMessage* NetReceive();
+  bool NetRemoteValidate(cAvidaContext& ctx, cOrgSinkMessage* msg);
   int ReceiveValue();
   bool InjectParasite(cOrganism* parent, const cGenome& injected_code);
   bool UpdateMerit(double new_merit);

Modified: development/source/main/cReactionResult.cc
===================================================================
--- development/source/main/cReactionResult.cc	2006-03-29 19:49:14 UTC (rev 543)
+++ development/source/main/cReactionResult.cc	2006-03-30 03:31:08 UTC (rev 544)
@@ -29,11 +29,6 @@
 {
 }
 
-cReactionResult::~cReactionResult()
-{
-}
-
-
 void cReactionResult::ActivateReaction()
 {
   // If this reaction is already active, don't worry about it.
@@ -161,21 +156,3 @@
   if (GetActive() == false) return false;
   return tasks_done[id];
 }
-
-double cReactionResult::GetAddBonus()
-{
-  if (GetActive() == false) return 0.0;
-  return bonus_add;
-}
-
-double cReactionResult::GetMultBonus()
-{
-  if (GetActive() == false) return 1.0;
-  return bonus_mult;
-}
-
-tArray<int> & cReactionResult::GetInstArray()
-{
-  return insts_triggered;
-}
-

Modified: development/source/main/cReactionResult.h
===================================================================
--- development/source/main/cReactionResult.h	2006-03-29 19:49:14 UTC (rev 543)
+++ development/source/main/cReactionResult.h	2006-03-30 03:31:08 UTC (rev 544)
@@ -39,7 +39,7 @@
 
 public:
   cReactionResult(const int num_resources, const int num_tasks, const int num_reactions);
-  ~cReactionResult();
+  ~cReactionResult() { ; }
 
   bool GetActive() { return active_reaction; }
 
@@ -61,9 +61,9 @@
   bool GetLethal();
   bool ReactionTriggered(int id);
   bool TaskDone(int id);
-  double GetAddBonus();
-  double GetMultBonus();
-  tArray<int>& GetInstArray();
+  double GetAddBonus() { return bonus_add; }
+  double GetMultBonus() { return bonus_mult; }
+  tArray<int>& GetInstArray() { return insts_triggered; }
 };
 
 #endif

Added: development/source/main/cTaskContext.h
===================================================================
--- development/source/main/cTaskContext.h	2006-03-29 19:49:14 UTC (rev 543)
+++ development/source/main/cTaskContext.h	2006-03-30 03:31:08 UTC (rev 544)
@@ -0,0 +1,42 @@
+/*
+ *  cTaskContext.h
+ *  Avida
+ *
+ *  Created by David on 3/29/06.
+ *  Copyright 2006 Michigan State University. All rights reserved.
+ *
+ */
+
+#ifndef cTaskContext_h
+#define cTaskContext_h
+
+#ifndef tBuffer_h
+#include "tBuffer.h"
+#endif
+#ifndef tList_h
+#include "tList.h"
+#endif
+
+
+class cTaskContext
+{
+  friend class cTaskLib;
+private:
+  const tBuffer<int>& input_buffer;
+  const tBuffer<int>& output_buffer;
+  const tList<tBuffer<int> >& other_input_buffers;
+  const tList<tBuffer<int> >& other_output_buffers;
+  bool net_valid;
+  int net_completed;
+  int logic_id;
+
+public:
+  cTaskContext(const tBuffer<int>& inputs, const tBuffer<int>& outputs, const tList<tBuffer<int> >& other_inputs,
+               const tList<tBuffer<int> >& other_outputs, bool in_net_valid, int in_net_completed)
+    : input_buffer(inputs), output_buffer(outputs), other_input_buffers(other_inputs),
+    other_output_buffers(other_outputs), net_valid(in_net_valid), net_completed(in_net_completed), logic_id(0)
+  {
+  }
+};
+
+#endif


Property changes on: development/source/main/cTaskContext.h
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: development/source/main/cTaskLib.cc
===================================================================
--- development/source/main/cTaskLib.cc	2006-03-29 19:49:14 UTC (rev 543)
+++ development/source/main/cTaskLib.cc	2006-03-30 03:31:08 UTC (rev 544)
@@ -326,6 +326,14 @@
   else if (name == "comm_not")
 	  NewTask(name, "Not of Neighbor's INput", &cTaskLib::Task_CommNot,
             REQ_NEIGHBOR_INPUT);
+
+  else if (name == "net_send")
+	  NewTask(name, "Successfully Sent Network Message", &cTaskLib::Task_NetSend);
+  else if (name == "net_receive")
+	  NewTask(name, "Successfully Received Network Message", &cTaskLib::Task_NetReceive);
+  
+  
+  
   // Make sure we have actually found a task.
   
   if (task_array.GetSize() == start_size) {
@@ -342,15 +350,15 @@
   return *(task_array[id]);
 }
 
-int cTaskLib::SetupLogicTests(const tBuffer<int>& inputs, const tBuffer<int>& outputs) const
+void cTaskLib::SetupTests(cTaskContext& ctx) const
 {
   // Collect the inputs in a useful form.
-  const int num_inputs = inputs.GetNumStored();
+  const int num_inputs = ctx.input_buffer.GetNumStored();
   int test_inputs[3];
   for (int i = 0; i < 3; i++) {
-    test_inputs[i] = (num_inputs > i) ? inputs[i] : 0;
+    test_inputs[i] = (num_inputs > i) ? ctx.input_buffer[i] : 0;
   }
-  int test_output = outputs[0];
+  int test_output = ctx.output_buffer[0];
   
   
   // Setup logic_out to test the output for each logical combination...
@@ -384,7 +392,10 @@
   }
   
   // If there were any inconsistancies, deal with them.
-  if (func_OK == false) return -1;
+  if (func_OK == false) {
+    ctx.logic_id = -1;
+    return;
+  }
   
   // Determine the logic ID number of this task.
   if (num_inputs < 1) {  // 000 -> 001
@@ -414,7 +425,7 @@
   int logicid = 0;
   for (int i = 0; i < 8; i++) logicid += logic_out[i] << i;
   
-  return logicid;
+  ctx.logic_id = logicid;
 }
 
 
@@ -1756,3 +1767,14 @@
   
   return 0.0;
 }
+
+double cTaskLib::Task_NetSend(cTaskContext* ctx) const
+{
+  return 1.0 * ctx->net_completed;
+}
+
+double cTaskLib::Task_NetReceive(cTaskContext* ctx) const
+{
+  if (ctx->net_valid) return 1.0;
+  return 0.0;
+}

Modified: development/source/main/cTaskLib.h
===================================================================
--- development/source/main/cTaskLib.h	2006-03-29 19:49:14 UTC (rev 543)
+++ development/source/main/cTaskLib.h	2006-03-30 03:31:08 UTC (rev 544)
@@ -11,62 +11,20 @@
 #ifndef cTaskLib_h
 #define cTaskLib_h
 
+#ifndef cTaskContext_h
+#include "cTaskContext.h"
+#endif
 #ifndef cTaskEntry_h
 #include "cTaskEntry.h"
 #endif
 #ifndef tArray_h
 #include "tArray.h"
 #endif
-#ifndef tBuffer_h
-#include "tBuffer.h"
-#endif
-#ifndef tList_h
-#include "tList.h"
-#endif
 
 
 class cString;
 
-//class cTaskContext
-//{
-//public:
-//  tBuffer<int> input_buffer;
-//  tBuffer<int> output_buffer;
-//  tList<tBuffer<int> > other_input_buffers;
-//  tList<tBuffer<int> > other_output_buffers;
-//  int logic_id;
-//  
-//  cTaskContext(const tBuffer<int>& inputs, const tBuffer<int>& outputs,
-//               const tList<tBuffer<int> >& other_inputs,
-//               const tList<tBuffer<int> >& other_outputs, int in_logic_id)
-//  : input_buffer(3), output_buffer(3), logic_id(in_logic_id)
-//  {
-//    input_buffer = inputs;
-//    output_buffer = outputs;
-//    other_input_buffers.Copy(other_inputs);
-//    other_output_buffers.Copy(other_outputs);
-//  }
-//};
 
-class cTaskContext
-{
-public:
-  const tBuffer<int>& input_buffer;
-  const tBuffer<int>& output_buffer;
-  const tList<tBuffer<int> >& other_input_buffers;
-  const tList<tBuffer<int> >& other_output_buffers;
-  int logic_id;
-  
-  cTaskContext(const tBuffer<int>& inputs, const tBuffer<int>& outputs,
-               const tList<tBuffer<int> >& other_inputs,
-               const tList<tBuffer<int> >& other_outputs, int in_logic_id)
-    : input_buffer(inputs), output_buffer(outputs), other_input_buffers(other_inputs),
-    other_output_buffers(other_outputs), logic_id(in_logic_id)
-  {
-  }
-};
-
-
 class cTaskLib
 {
 private:
@@ -100,12 +58,7 @@
   cTaskEntry* AddTask(const cString& name);
   const cTaskEntry& GetTask(int id) const;
   
-  cTaskContext SetupTests(const tBuffer<int>& inputs, const tBuffer<int>& outputs,
-                          const tList<tBuffer<int> >& other_inputs,
-                          const tList<tBuffer<int> >& other_outputs) const
-  {
-    return cTaskContext(inputs, outputs, other_inputs, other_outputs, SetupLogicTests(inputs, outputs));
-  }
+  void SetupTests(cTaskContext& ctx) const;
   inline double TestOutput(const cTaskEntry& task, cTaskContext* ctx) const;
 
   bool UseNeighborInput() const { return use_neighbor_input; }
@@ -113,7 +66,6 @@
   
 private:  // Direct task related methods
   void NewTask(const cString& name, const cString& desc, tTaskTest task_fun, int reqs = 0);
-  int SetupLogicTests(const tBuffer<int>& inputs, const tBuffer<int>& outputs) const;
 
   inline double FractionalReward(unsigned int supplied, unsigned int correct);  
 
@@ -261,6 +213,9 @@
   // Communication Tasks...
   double Task_CommEcho(cTaskContext* ctx) const;
   double Task_CommNot(cTaskContext* ctx) const;
+  
+  double Task_NetSend(cTaskContext* ctx) const;
+  double Task_NetReceive(cTaskContext* ctx) const;
 };
 
 




More information about the Avida-cvs mailing list