[Avida-cvs] [avida-svn] r1008 - in branches/coopcomm: Avida.xcodeproj source/actions source/cpu source/main

beckma24 at myxo.css.msu.edu beckma24 at myxo.css.msu.edu
Wed Sep 27 14:02:30 PDT 2006


Author: beckma24
Date: 2006-09-27 17:02:30 -0400 (Wed, 27 Sep 2006)
New Revision: 1008

Modified:
   branches/coopcomm/Avida.xcodeproj/project.pbxproj
   branches/coopcomm/source/actions/PopulationActions.cc
   branches/coopcomm/source/cpu/cHardwareCPU.cc
   branches/coopcomm/source/main/cOrganism.cc
   branches/coopcomm/source/main/cPopulation.h
   branches/coopcomm/source/main/cTaskLib.cc
   branches/coopcomm/source/main/cTaskLib.h
Log:
Added sent-toward-sink task and changed recv-msg instruction to retrieve-msg

Modified: branches/coopcomm/Avida.xcodeproj/project.pbxproj
===================================================================
--- branches/coopcomm/Avida.xcodeproj/project.pbxproj	2006-09-27 20:31:04 UTC (rev 1007)
+++ branches/coopcomm/Avida.xcodeproj/project.pbxproj	2006-09-27 21:02:30 UTC (rev 1008)
@@ -373,6 +373,23 @@
 		};
 /* End PBXBuildRule section */
 
+/* Begin PBXBuildStyle section */
+		B50F02EF0AC9BEC10085CE1A /* Development */ = {
+			isa = PBXBuildStyle;
+			buildSettings = {
+				COPY_PHASE_STRIP = NO;
+			};
+			name = Development;
+		};
+		B50F02F00AC9BEC10085CE1A /* Deployment */ = {
+			isa = PBXBuildStyle;
+			buildSettings = {
+				COPY_PHASE_STRIP = YES;
+			};
+			name = Deployment;
+		};
+/* End PBXBuildStyle section */
+
 /* Begin PBXCopyFilesBuildPhase section */
 		700E2B6D085DE50C00CF158A /* CopyFiles */ = {
 			isa = PBXCopyFilesBuildPhase;
@@ -1759,6 +1776,12 @@
 		DCC30C4D0762532C008F7A48 /* Project object */ = {
 			isa = PBXProject;
 			buildConfigurationList = 702442D70859E0B00059BD9B /* Build configuration list for PBXProject "Avida" */;
+			buildSettings = {
+			};
+			buildStyles = (
+				B50F02EF0AC9BEC10085CE1A /* Development */,
+				B50F02F00AC9BEC10085CE1A /* Deployment */,
+			);
 			hasScannedForEncodings = 0;
 			mainGroup = DCC30C490762532C008F7A48;
 			productRefGroup = DCC3164E07626CF3008F7A48 /* Products */;

Modified: branches/coopcomm/source/actions/PopulationActions.cc
===================================================================
--- branches/coopcomm/source/actions/PopulationActions.cc	2006-09-27 20:31:04 UTC (rev 1007)
+++ branches/coopcomm/source/actions/PopulationActions.cc	2006-09-27 21:02:30 UTC (rev 1008)
@@ -1210,7 +1210,9 @@
   
   void Process(cAvidaContext& ctx)
   {
+    std::cerr<<baseStation<<endl;
     m_world->GetPopulation().AddBaseStation(baseStation);
+    std::cerr<<baseStation<<endl;
   }
 };
 

Modified: branches/coopcomm/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/coopcomm/source/cpu/cHardwareCPU.cc	2006-09-27 20:31:04 UTC (rev 1007)
+++ branches/coopcomm/source/cpu/cHardwareCPU.cc	2006-09-27 21:02:30 UTC (rev 1008)
@@ -353,7 +353,7 @@
     
     // Coop-comm
     cInstEntryCPU("send-msg", &cHardwareCPU::Inst_SendMessage),
-    cInstEntryCPU("recv-msg", &cHardwareCPU::Inst_ReceiveMessage),
+    cInstEntryCPU("retrieve-msg", &cHardwareCPU::Inst_ReceiveMessage),
     cInstEntryCPU("get-id", &cHardwareCPU::Inst_GetID),
     cInstEntryCPU("get-pos", &cHardwareCPU::Inst_GetPosition),
     cInstEntryCPU("get-facing", &cHardwareCPU::Inst_GetFacing)

Modified: branches/coopcomm/source/main/cOrganism.cc
===================================================================
--- branches/coopcomm/source/main/cOrganism.cc	2006-09-27 20:31:04 UTC (rev 1007)
+++ branches/coopcomm/source/main/cOrganism.cc	2006-09-27 21:02:30 UTC (rev 1008)
@@ -540,6 +540,7 @@
 bool cOrganism::SendMessage(cAvidaContext& ctx, cOrgMessage& msg)
 {
   assert(m_interface);
+  m_world->GetStats().IncSent();
   if(m_interface->SendMessage(msg)) {
     // Stat-tracking.
     m_world->GetStats().SentMessage(msg);

Modified: branches/coopcomm/source/main/cPopulation.h
===================================================================
--- branches/coopcomm/source/main/cPopulation.h	2006-09-27 20:31:04 UTC (rev 1007)
+++ branches/coopcomm/source/main/cPopulation.h	2006-09-27 21:02:30 UTC (rev 1008)
@@ -195,6 +195,7 @@
   void SetChangeList(cChangeList* change_list);
   cChangeList* GetChangeList();
   void AddBaseStation(int cell_ID) {baseStations.Add(cell_ID);}
+  tVector<int> GetBaseStations() {return baseStations;};
 };
 
 

Modified: branches/coopcomm/source/main/cTaskLib.cc
===================================================================
--- branches/coopcomm/source/main/cTaskLib.cc	2006-09-27 20:31:04 UTC (rev 1007)
+++ branches/coopcomm/source/main/cTaskLib.cc	2006-09-27 21:02:30 UTC (rev 1008)
@@ -15,7 +15,7 @@
 
 #include "cArgSchema.h"
 #include "cPopulationCell.h"
-
+#include "cPopulation.h"
 #include <stdlib.h>
 extern "C" {
 #include <math.h>
@@ -354,8 +354,9 @@
     NewTask(name, "Reward sending a message that does NOT have an ID as the data field.", &cTaskLib::Task_SendNonID);
   else if(name == "send-self")
     NewTask(name, "Reward the sending of the sender's ID.", &cTaskLib::Task_SendSelf);
+  else if(name == "send-toward-sink")
+    NewTask(name, "Reward the sender for sending toward the sink", &cTaskLib::Task_SendTowardSink);
   
-  
   // Make sure we have actually found a task  
   if (task_array.GetSize() == start_size) {
     cerr << "Unknown task entry '" << name << "'." << endl;
@@ -1944,3 +1945,39 @@
   
   return 0.0;
 }
+
+double cTaskLib::Task_SendTowardSink(cTaskContext* ctx) const {
+  if(ctx->GetMessage() == NULL)
+    return 0.0;
+
+  tVector<int> BS_iter = m_world->GetPopulation().GetBaseStations();
+  int x_sender, y_sender, x_receiver, y_receiver, x_BS, y_BS;
+  
+  ctx->GetMessage()->GetSender()->GetPosition(x_sender,y_sender);
+  ctx->GetMessage()->GetReceiver()->GetPosition(x_receiver,y_receiver);
+
+  //check all base stations
+  for(int i =0; i < BS_iter.Size(); i++) {
+    m_world->GetPopulation().GetCell(BS_iter[i]).GetPosition(x_BS,y_BS);
+
+    if(nGeometry::GRID == m_world->GetConfig().WORLD_GEOMETRY.Get()) {     //bounded grid
+      if(max(abs(x_receiver-x_BS), abs(y_receiver-y_BS)) < max(abs(x_sender-x_BS), abs(y_sender-y_BS))) {
+        //sent to closer organisms
+        return 1.0;
+      }
+    } else if(nGeometry::TORUS == m_world->GetConfig().WORLD_GEOMETRY.Get()) {    //torus
+      int x_world = m_world->GetConfig().WORLD_X.Get();
+      int y_world = m_world->GetConfig().WORLD_Y.Get();
+      
+      if(min(max(abs(x_receiver-x_BS), abs(y_receiver-y_BS)), max(x_world-abs(x_receiver-x_BS), y_world-abs(y_receiver-y_BS))) <
+          min(max(abs(x_sender-x_BS), abs(y_sender-y_BS)), max(x_world-abs(x_sender-x_BS), y_world-abs(y_sender-y_BS)))) {
+        //sent to closer organisms
+        return 1.0;        
+      }
+    } else {    //other - error
+      cerr<< "ERROR: Unknown WORLD_GEOMETRY\n";
+      exit(-1);
+    }
+  }
+  return 0.0;
+}
\ No newline at end of file

Modified: branches/coopcomm/source/main/cTaskLib.h
===================================================================
--- branches/coopcomm/source/main/cTaskLib.h	2006-09-27 20:31:04 UTC (rev 1007)
+++ branches/coopcomm/source/main/cTaskLib.h	2006-09-27 21:02:30 UTC (rev 1008)
@@ -26,8 +26,10 @@
 #ifndef cStats_h
 #include "cStats.h"
 #endif
+#ifndef tVector_h
+#include "tVector.h"
+#endif
 
-
 class cString;
 class cWorld;
 
@@ -235,6 +237,9 @@
   double Task_SendID(cTaskContext* ctx) const; //!< Rewards an organism for sending an ID.
   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.
+  
+  //! Reward an organism for sending message to organism who is closer to the sink
+  double Task_SendTowardSink(cTaskContext* ctx) const;
 };
 
 




More information about the Avida-cvs mailing list