[Avida-SVN] r1187 - in branches/coopcomm: Avida.xcodeproj documentation/coopcomm source/cpu source/main

beckma24 at myxo.css.msu.edu beckma24 at myxo.css.msu.edu
Fri Jan 12 12:50:32 PST 2007


Author: beckma24
Date: 2007-01-12 15:50:31 -0500 (Fri, 12 Jan 2007)
New Revision: 1187

Modified:
   branches/coopcomm/Avida.xcodeproj/project.pbxproj
   branches/coopcomm/documentation/coopcomm/CoopCommAdditionsToAvida.tex
   branches/coopcomm/source/cpu/cHardwareCPU.cc
   branches/coopcomm/source/cpu/cHardwareCPU.h
   branches/coopcomm/source/main/cAvidaConfig.h
   branches/coopcomm/source/main/cPopulation.cc
   branches/coopcomm/source/main/cTaskLib.cc
   branches/coopcomm/source/main/cTaskLib.h
Log:
Fixed bug in send-toward-sink task where the position of the bases station was not set correctly.

Am still trying to implement a task to reward a living-clade, however, i have been unsuccessful.

Added get-org-id instruction.  It write the calling organisms ID into its ?BX? regester.

Updated Xcode build script to look in /sw/bin/ for svn.

Modified: branches/coopcomm/Avida.xcodeproj/project.pbxproj
===================================================================
--- branches/coopcomm/Avida.xcodeproj/project.pbxproj	2007-01-12 19:41:24 UTC (rev 1186)
+++ branches/coopcomm/Avida.xcodeproj/project.pbxproj	2007-01-12 20:50:31 UTC (rev 1187)
@@ -1804,7 +1804,7 @@
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 			shellPath = /bin/bash;
-			shellScript = "mkdir -p $DERIVED_FILE_DIR\nif (test -x /usr/bin/svn)\nthen svncmd=/usr/bin/svn\nelif (test -x /usr/local/bin/svn)\nthen svncmd=/usr/local/bin/svn\nelif (test -x /usr/local/svn/bin/svn)\nthen svncmd=/usr/local/svn/bin/svn\nelif (test -x /opt/local/bin/svn)\nthen svncmd=/opt/local/bin/svn\nelse\n  echo \"Warning: 'svn' not found, please install subversion\"\n  if [[ ! -f $DERIVED_FILE_DIR/revision.h ]]\n  then\n    echo \"#ifndef revision_h\" > $DERIVED_FILE_DIR/revision.h\n    echo \"#define revision_h\" >> $DERIVED_FILE_DIR/revision.h\n    echo \"#define REVISION \\\"???\\\"\" >> $DERIVED_FILE_DIR/revision.h\n    echo \"#endif\" >> $DERIVED_FILE_DIR/revision.h\n  fi\nfi\n\necho \"#ifndef revision_h\" > /tmp/newrev.tmp\necho \"#define revision_h\" >> /tmp/newrev.tmp\n$svncmd status -v Avida.xcodeproj/project.pbxproj | sed '1!d' | sed 's/[^ ]* *\\([0-9]*\\).*/#define REVISION \"\\1\"/' >> /tmp/newrev.tmp\necho \"#endif\" >> /tmp/newrev.tmp\n\nif [[ -f $DERI!
 VED_FILE_DIR/revision.h ]]\nthen\n  revdiff=`diff $DERIVED_FILE_DIR/revision.h /tmp/newrev.tmp`\nelse\n  revdiff=\"yes\"\nfi\n\nif [[ -n \"$revdiff\" ]]\nthen\n  echo \"New revision.h Generated\"\n  cp /tmp/newrev.tmp $DERIVED_FILE_DIR/revision.h\n  touch $SRCROOT/source/main/avida.cc\nfi\n\nrm /tmp/newrev.tmp\n";
+			shellScript = "mkdir -p $DERIVED_FILE_DIR\nif (test -x /usr/bin/svn)\nthen svncmd=/usr/bin/svn\nelif (test -x /sw/bin/svn)\nthen svncmd=/sw/bin/svn\nelif (test -x /usr/local/bin/svn)\nthen svncmd=/usr/local/bin/svn\nelif (test -x /usr/local/svn/bin/svn)\nthen svncmd=/usr/local/svn/bin/svn\nelif (test -x /opt/local/bin/svn)\nthen svncmd=/opt/local/bin/svn\nelse\n  echo \"Warning: 'svn' not found, please install subversion\"\n  if [[ ! -f $DERIVED_FILE_DIR/revision.h ]]\n  then\n    echo \"#ifndef revision_h\" > $DERIVED_FILE_DIR/revision.h\n    echo \"#define revision_h\" >> $DERIVED_FILE_DIR/revision.h\n    echo \"#define REVISION \\\"???\\\"\" >> $DERIVED_FILE_DIR/revision.h\n    echo \"#endif\" >> $DERIVED_FILE_DIR/revision.h\n  fi\nfi\n\necho \"#ifndef revision_h\" > /tmp/newrev.tmp\necho \"#define revision_h\" >> /tmp/newrev.tmp\n$svncmd status -v Avida.xcodeproj/project.pbxproj | sed '1!d' | sed 's/[^ ]* *\\([0-9]*\\).*/#define REVISION \"\\1\"/' >> /tmp/newrev.tmp\!
 necho \"#endif\" >> /tmp/newrev.tmp\n\nif [[ -f $DERIVED_FILE_DIR/revision.h ]]\nthen\n  revdiff=`diff $DERIVED_FILE_DIR/revision.h /tmp/newrev.tmp`\nelse\n  revdiff=\"yes\"\nfi\n\nif [[ -n \"$revdiff\" ]]\nthen\n  echo \"New revision.h Generated\"\n  cp /tmp/newrev.tmp $DERIVED_FILE_DIR/revision.h\n  touch $SRCROOT/source/main/avida.cc\nfi\n\nrm /tmp/newrev.tmp\n";
 		};
 		704EAD9808FF3C1F005D5C24 /* ShellScript */ = {
 			isa = PBXShellScriptBuildPhase;

Modified: branches/coopcomm/documentation/coopcomm/CoopCommAdditionsToAvida.tex
===================================================================
--- branches/coopcomm/documentation/coopcomm/CoopCommAdditionsToAvida.tex	2007-01-12 19:41:24 UTC (rev 1186)
+++ branches/coopcomm/documentation/coopcomm/CoopCommAdditionsToAvida.tex	2007-01-12 20:50:31 UTC (rev 1187)
@@ -77,6 +77,16 @@
 %%%%%%%%%%%%%%%%%%%%% Sink Tree Tasks
 \subsection{Sink Tree Tasks}
 \begin{description}
+
+\item[living-clade]  (skeleton: Revision 1185 implemented: Revision ??)
+%
+
+\item[sent-id-toward-sink] (Revision 1185)
+%
+This task rewards an organism for sending any organism's random cell ID in a message to a neighbor that is closer to a base station.
+%
+Distance is measured in hops between organism and base station.
+
 \item[send-non-self-toward-sink] (Revision 1168)
 %
 This task rewards an organism for sending another organism's random cell ID in a message to a neighbor that is closer to a base station.
@@ -220,6 +230,10 @@
 %
 Sets the call organism's ?BX? register to $1$ if it is currently a base station, $0$ otherwise.
 
+\item[get-org-id] (Revision ??)
+%
+Sets the call organism's ?BX? register to its organism ID.
+
 \end{description}
 
 %%%%%%%%%%%%%%%%%%%%%% Messaging instructions

Modified: branches/coopcomm/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/coopcomm/source/cpu/cHardwareCPU.cc	2007-01-12 19:41:24 UTC (rev 1186)
+++ branches/coopcomm/source/cpu/cHardwareCPU.cc	2007-01-12 20:50:31 UTC (rev 1187)
@@ -369,6 +369,7 @@
     cInstEntryCPU("retrieve-msg", &cHardwareCPU::Inst_RetrieveMessage),
     cInstEntryCPU("retrieve-msg-0-0", &cHardwareCPU::Inst_RetrieveMessage_0_0),
     cInstEntryCPU("get-id", &cHardwareCPU::Inst_GetID),
+    cInstEntryCPU("get-org-id", &cHardwareCPU::Inst_GetOrgID),
     cInstEntryCPU("get-pos", &cHardwareCPU::Inst_GetPosition),
     cInstEntryCPU("get-facing", &cHardwareCPU::Inst_GetFacing),
     cInstEntryCPU("set-leader", &cHardwareCPU::Inst_SetLeader),
@@ -3591,6 +3592,15 @@
   return true;
 }
 
+/*! Places this organism's id in register ?BX?.
+*/
+bool cHardwareCPU::Inst_GetOrgID(cAvidaContext& ctx) {
+        std::cerr<<"Inst_GetOrgID start\n";
+	const int reg_used = FindModifiedRegister(REG_BX);
+	GetRegister(reg_used) = organism->GetID();
+        std::cerr<<"Inst_GetOrgID end\n";
+        return true;
+}
 
 
 /*! Places this organism's random-cell-id in register ?BX?.

Modified: branches/coopcomm/source/cpu/cHardwareCPU.h
===================================================================
--- branches/coopcomm/source/cpu/cHardwareCPU.h	2007-01-12 19:41:24 UTC (rev 1186)
+++ branches/coopcomm/source/cpu/cHardwareCPU.h	2007-01-12 20:50:31 UTC (rev 1187)
@@ -487,7 +487,8 @@
 
   bool Inst_RetrieveMessage(cAvidaContext& ctx); //!< Retrieve a message.
   bool Inst_RetrieveMessage_0_0(cAvidaContext& ctx); //!< Retrieve a message and write 0,0 to regs if failed.
-  bool Inst_GetID(cAvidaContext& ctx); //!< Retrieve this organism's ID.
+  bool Inst_GetOrgID(cAvidaContext& ctx); //!< Retrieve this organism's ID.
+  bool Inst_GetID(cAvidaContext& ctx); //!< Retrieve this organism's random-cell-ID.
   bool Inst_GetPosition(cAvidaContext& ctx); //!< Retrieve this organism's position.
   bool Inst_GetFacing(cAvidaContext& ctx); //!< Retrieve this organism's facing.
   bool Inst_SetLeader(cAvidaContext& ctx); //!< Set the leader of this organism.

Modified: branches/coopcomm/source/main/cAvidaConfig.h
===================================================================
--- branches/coopcomm/source/main/cAvidaConfig.h	2007-01-12 19:41:24 UTC (rev 1186)
+++ branches/coopcomm/source/main/cAvidaConfig.h	2007-01-12 20:50:31 UTC (rev 1187)
@@ -261,7 +261,7 @@
   CONFIG_ADD_VAR(LOG_SPECIES, bool, 0, "0/1 (off/on) toggle to print file.");
   
   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(LOG_LINEAGES, bool, 1, "");
   CONFIG_ADD_VAR(LINEAGE_CREATION_METHOD, int, 0, "");
   
   CONFIG_ADD_GROUP(ORGANISM_NETWORK_GROUP, "Organism Network Communication");

Modified: branches/coopcomm/source/main/cPopulation.cc
===================================================================
--- branches/coopcomm/source/main/cPopulation.cc	2007-01-12 19:41:24 UTC (rev 1186)
+++ branches/coopcomm/source/main/cPopulation.cc	2007-01-12 20:50:31 UTC (rev 1187)
@@ -2173,24 +2173,21 @@
 
 vector<cPopulation::nTreeNode> cPopulation::LivingDescendants(int orgID) {
   vector<cPopulation::nTreeNode> descendants;
-  /*
+  
   map<int, cPopulation::nTreeNode>::iterator i = sentOrgIDRecord.find(orgID);
   if(i == sentOrgIDRecord.end())
     return descendants;
-  cPopulation::nTreeNode n = i.get();
-  return LivingDescendants((*i).second());
-  */
-  return descendants;
+  return LivingDescendants(i->second);
 }
 
 vector<cPopulation::nTreeNode> cPopulation::LivingDescendants(cPopulation::nTreeNode org) {
   vector<cPopulation::nTreeNode> descendants;
-  /*
+
   if(org.alive) {
     //check to see if it is still alive in current population
     t_CellArray::iterator cells = CellBegin();
     while(cells != CellEnd()) {
-      if(*cells->GetOrganism()->GetID() == org.id)
+      if((*cells).GetOrganism()->GetID() == org.id)
         break;
     }
     if(cells == CellEnd())  //org not found therefore its dead
@@ -2198,19 +2195,18 @@
     else  // org is alive and must be added to living descendants list
       descendants.push_back(org);
   }
-  
+
   if(org.children.size() == 0) {
     return descendants;
   } else {
-  
-//  HERE
     //iterate through children
-    vector<int>::iterator kids = org.children.iterator();
-    while(kids != kids.end()) {
+    std::vector<int>::iterator kids = org.children.begin();
+    while(kids != org.children.end()) {
       map<int, cPopulation::nTreeNode>::iterator kid = sentOrgIDRecord.find(*kids);
       //append descendants to vector
-      descendants.insert(descendants.end(), LivingDescendants(kid.second).begin(), LivingDescendants(kid.second).end());
+      vector<cPopulation::nTreeNode> livingDescendents = LivingDescendants(kid->second);
+      descendants.insert(descendants.end(), livingDescendents.begin(), livingDescendents.end());
     }
-  }*/
+  }
   return descendants;
 }
\ No newline at end of file

Modified: branches/coopcomm/source/main/cTaskLib.cc
===================================================================
--- branches/coopcomm/source/main/cTaskLib.cc	2007-01-12 19:41:24 UTC (rev 1186)
+++ branches/coopcomm/source/main/cTaskLib.cc	2007-01-12 20:50:31 UTC (rev 1187)
@@ -394,6 +394,8 @@
     NewTask(name, "Reward the sender for sending northeast", &cTaskLib::Task_SentNorthEast);
   else if(name == "graph-equ-tree")
     NewTask(name, "Reward an organism for being part of a tree.", &cTaskLib::Task_GraphEquTree);
+  else if(name == "living-clade")
+    NewTask(name, "Reward a clade of living organisms.", &cTaskLib::Task_Living_Clade);
   
   // Make sure we have actually found a task  
   if (task_array.GetSize() == start_size) {
@@ -2046,6 +2048,8 @@
   for(int i =0; i < BS_iter.Size(); i++) {
     cPopulationCell& bsCell = m_world->GetPopulation().GetCell(BS_iter[i]);
     if(nGeometry::GRID == m_world->GetConfig().WORLD_GEOMETRY.Get()) {     //bounded grid
+      bsCell.GetPosition(x_BS, y_BS);
+      //std::cerr<<"Task_SendTowardSink " << x_BS <<" "<< y_BS<<endl;
       if(hopWiseCloserGRID(x_sender, y_sender, x_receiver, y_receiver, x_BS, y_BS)) {
         //sent to closer organisms
         return 1.0;
@@ -2304,24 +2308,27 @@
 /*!
   Reward decendents of organisms whose ID has been received by a base station
 */
-double cTaskLib::Task_Royal_Lineage(cTaskContext* ctx) const {
+double cTaskLib::Task_Living_Clade(cTaskContext* ctx) const {
   if(ctx->GetMessage() == NULL)
     return 0.0;
 
   tVector<int> BS_iter = m_world->GetPopulation().GetBaseStations();
-    
   //check all base stations
   for(int i =0; i < BS_iter.Size(); i++) {
     cPopulationCell& bsCell = m_world->GetPopulation().GetCell(BS_iter[i]);
-    if(ctx->GetMessage()->GetReceiver()->GetID() == bsCell.GetOrganism()->GetID()) {
+    if(bsCell.GetOrganism() != NULL && ctx->GetMessage()->GetReceiver()->GetID() == bsCell.GetOrganism()->GetID()) {
+
       //check for valid org ID
       map<int, cPopulation::nTreeNode>::iterator ancestor = cPopulation::sentOrgIDRecord.find(ctx->GetMessage()->GetData());
       if(ancestor != cPopulation::sentOrgIDRecord.end()) {
+        //dec count
+        (ancestor->second).count--;
         //find living descendents
-        
+        vector<cPopulation::nTreeNode> descendents = m_world->GetPopulation().LivingDescendants(ancestor->second);
         //reward living descendents (possibly differently)
+        std::cerr<<descendents.size()<<" should be rewarded\n";
       }
     }
   }
   return 0.0;
-}
\ No newline at end of file
+}

Modified: branches/coopcomm/source/main/cTaskLib.h
===================================================================
--- branches/coopcomm/source/main/cTaskLib.h	2007-01-12 19:41:24 UTC (rev 1186)
+++ branches/coopcomm/source/main/cTaskLib.h	2007-01-12 20:50:31 UTC (rev 1187)
@@ -267,7 +267,7 @@
   double Task_SentEast(cTaskContext* ctx) const;
   double Task_SentNorthEast(cTaskContext* ctx) const;
   
-  double Task_Royal_Lineage(cTaskContext* ctx) const;
+  double Task_Living_Clade(cTaskContext* ctx) const;
   
   //! Rewards an organism for being part of a tree.
   double Task_GraphEquTree(cTaskContext* ctx) const;




More information about the Avida-cvs mailing list