[Avida-SVN] r1185 - in branches/coopcomm: documentation/coopcomm source/main

beckma24 at myxo.css.msu.edu beckma24 at myxo.css.msu.edu
Fri Jan 12 08:12:19 PST 2007


Author: beckma24
Date: 2007-01-12 11:12:19 -0500 (Fri, 12 Jan 2007)
New Revision: 1185

Modified:
   branches/coopcomm/documentation/coopcomm/CoopCommAdditionsToAvida.tex
   branches/coopcomm/source/main/cOrganism.h
   branches/coopcomm/source/main/cPopulation.cc
   branches/coopcomm/source/main/cPopulation.h
   branches/coopcomm/source/main/cPopulationInterface.cc
   branches/coopcomm/source/main/cTaskLib.cc
   branches/coopcomm/source/main/cTaskLib.h
Log:
Added the skeleton for a descendent based reward, and the task send-id-toward-sink

Modified: branches/coopcomm/documentation/coopcomm/CoopCommAdditionsToAvida.tex
===================================================================
--- branches/coopcomm/documentation/coopcomm/CoopCommAdditionsToAvida.tex	2007-01-12 14:29:27 UTC (rev 1184)
+++ branches/coopcomm/documentation/coopcomm/CoopCommAdditionsToAvida.tex	2007-01-12 16:12:19 UTC (rev 1185)
@@ -55,14 +55,14 @@
 \subsection{Messaging Tasks}
 \begin{description}
 
-\item[send-id-exponential](Revision ??)
+\item[send-id-exponential](Revision 1174)
 %
 Exponentially reward the sending of an ID as the data field of a message.
 %
 This task is identical to send-id, however the reward grows exponentially.
 
 
-\item[send-id-not-self-exponential](Revision ??)
+\item[send-id-not-self-exponential](Revision 1174)
 %
 Exponentially reward the sending of an ID (excluding the sender's ID) as the data field of a message.
 %

Modified: branches/coopcomm/source/main/cOrganism.h
===================================================================
--- branches/coopcomm/source/main/cOrganism.h	2007-01-12 14:29:27 UTC (rev 1184)
+++ branches/coopcomm/source/main/cOrganism.h	2007-01-12 16:12:19 UTC (rev 1185)
@@ -15,7 +15,6 @@
 #include <vector>
 #include <map>
 #include <set>
-//#include <pair>
 
 
 #ifndef cCPUMemory_h

Modified: branches/coopcomm/source/main/cPopulation.cc
===================================================================
--- branches/coopcomm/source/main/cPopulation.cc	2007-01-12 14:29:27 UTC (rev 1184)
+++ branches/coopcomm/source/main/cPopulation.cc	2007-01-12 16:12:19 UTC (rev 1185)
@@ -51,6 +51,7 @@
 
 using namespace std;
 
+std::map<int, cPopulation::nTreeNode> cPopulation::sentOrgIDRecord;  //count is the number of msgs sent from ID containing its ID.
 
 cPopulation::cPopulation(cWorld* world)
 : m_world(world)
@@ -2169,3 +2170,47 @@
     baseStations[i] = newBSCellID;
   }
 }
+
+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;
+}
+
+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)
+        break;
+    }
+    if(cells == CellEnd())  //org not found therefore its dead
+      org.alive = false;
+    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()) {
+      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());
+    }
+  }*/
+  return descendants;
+}
\ No newline at end of file

Modified: branches/coopcomm/source/main/cPopulation.h
===================================================================
--- branches/coopcomm/source/main/cPopulation.h	2007-01-12 14:29:27 UTC (rev 1184)
+++ branches/coopcomm/source/main/cPopulation.h	2007-01-12 16:12:19 UTC (rev 1185)
@@ -43,6 +43,8 @@
 
 #include <vector>
 #include <utility>
+#include <set>
+#include <map>
 
 class cAvidaContext;
 class cCodeLabel;
@@ -69,6 +71,14 @@
   //! A list of cell ranges.
   typedef std::vector<t_CellRange> t_CellRangeList;
   
+  struct nTreeNode {
+    int id;
+    std::vector<int> children;
+    int parent;  //!< asexual
+    int count;
+    bool alive;
+  };
+
 private:
   // Components...
   cWorld* m_world;
@@ -216,6 +226,10 @@
   void AddBaseStation(int cell_ID) {baseStations.Add(cell_ID);}
   void MoveBaseStation(int currentBSCellID, int newBSCellID);
   tVector<int> GetBaseStations() {return baseStations;};
+  vector<nTreeNode> LivingDescendants(int orgID);
+  vector<nTreeNode> LivingDescendants(nTreeNode org);
+
+  static std::map<int, nTreeNode> sentOrgIDRecord;  //count is the number of msgs sent from ID containing its ID.
 };
 
 

Modified: branches/coopcomm/source/main/cPopulationInterface.cc
===================================================================
--- branches/coopcomm/source/main/cPopulationInterface.cc	2007-01-12 14:29:27 UTC (rev 1184)
+++ branches/coopcomm/source/main/cPopulationInterface.cc	2007-01-12 16:12:19 UTC (rev 1185)
@@ -12,6 +12,7 @@
 
 #include "cGenotype.h"
 #include "cHardwareManager.h"
+#include "cLineage.h"
 #include "cOrganism.h"
 #include "cOrgMessage.h"
 #include "cOrgSinkMessage.h"
@@ -212,6 +213,23 @@
   cOrganism* recvr = rcell->GetOrganism();
   assert(recvr != NULL);
   msg.SetReceiver(recvr);
+  
+  if(msg.GetData() == msg.GetSender()->GetID()) {
+    map<int, cPopulation::nTreeNode>::iterator i = cPopulation::sentOrgIDRecord.find(msg.GetSender()->GetID());
+    if(i == cPopulation::sentOrgIDRecord.end()) {
+      cPopulation::nTreeNode n;
+      n.id = msg.GetSender()->GetID();
+      n.count = 1;
+      n.alive = true;
+      n.parent = msg.GetSender()->GetLineage()->GetParentID();
+      cPopulation::sentOrgIDRecord.insert(make_pair(msg.GetSender()->GetID(), n));
+      map<int, cPopulation::nTreeNode>::iterator i = cPopulation::sentOrgIDRecord.find(n.parent);
+      ((*i).second).children.push_back(msg.GetSender()->GetID());
+    } else {
+      ((*i).second).count++;
+    }
+  }
+  
   return recvr->ReceiveMessage(msg);
 }
 

Modified: branches/coopcomm/source/main/cTaskLib.cc
===================================================================
--- branches/coopcomm/source/main/cTaskLib.cc	2007-01-12 14:29:27 UTC (rev 1184)
+++ branches/coopcomm/source/main/cTaskLib.cc	2007-01-12 16:12:19 UTC (rev 1185)
@@ -366,6 +366,8 @@
     NewTask(name, "Reward the sender for sending their random ID toward the sink", &cTaskLib::Task_SendSelfTowardSink);
   else if(name == "send-non-self-toward-sink")
     NewTask(name, "Reward the sender for sending another organism's random ID toward the sink", &cTaskLib::Task_SendNonSelfTowardSink);
+  else if(name == "send-id-toward-sink")
+    NewTask(name, "Reward the sender for sending organism's random cell ID toward the sink", &cTaskLib::Task_SendIDTowardSink);
   else if(name == "send-multiple-non-self-toward-sink")
     NewTask(name, "Reward the sender for sending multiple other organism's random ID toward the sink", &cTaskLib::Task_SendMultipleNonSelfTowardSink);  
   else if(name == "send-toward-sink-multi-path")
@@ -2089,7 +2091,14 @@
   return 0.0;
 }
 
+//! Reward an organism for sending a message containing an organism's ID closer to the sink
+double cTaskLib::Task_SendIDTowardSink(cTaskContext* ctx) const{
+  if(Task_SendTowardSink(ctx) == 1.0 && (Task_SendSelf(ctx) == 1.0 || Task_SendIDNotSelf(ctx) == 1.0))
+    return 1.0;
+  return 0.0;
+}
 
+
 /******************************************/
 /******************************************/
 /*               Not done                 */
@@ -2291,3 +2300,28 @@
 {
   return 0.0;
 }
+
+/*!
+  Reward decendents of organisms whose ID has been received by a base station
+*/
+double cTaskLib::Task_Royal_Lineage(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()) {
+      //check for valid org ID
+      map<int, cPopulation::nTreeNode>::iterator ancestor = cPopulation::sentOrgIDRecord.find(ctx->GetMessage()->GetData());
+      if(ancestor != cPopulation::sentOrgIDRecord.end()) {
+        //find living descendents
+        
+        //reward living descendents (possibly differently)
+      }
+    }
+  }
+  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 14:29:27 UTC (rev 1184)
+++ branches/coopcomm/source/main/cTaskLib.h	2007-01-12 16:12:19 UTC (rev 1185)
@@ -248,10 +248,12 @@
   //! REward an organism for sending a message to multiple closer neighbors (by hop count)
   double Task_SendTowardSinkMultiPath(cTaskContext* ctx) const;
 
-  //! Reward an organism for sending message to organism who is closer to the sink
+  //! Reward an organism for sending its ID in a message to organism who is closer to the sink
   double Task_SendSelfTowardSink(cTaskContext* ctx) const;
-  //! Reward an organism for sending message to organism who is closer to the sink
+  //! Reward an organism for sending an ID (not its own) in a message to organism who is closer to the sink
   double Task_SendNonSelfTowardSink(cTaskContext* ctx) const;
+  //! Reward an organism for sending an ID in a message to organism who is closer to the sink
+  double Task_SendIDTowardSink(cTaskContext* ctx) const;
 
   double Task_SendMultipleNonSelfTowardSink(cTaskContext* ctx) const;
   
@@ -265,6 +267,8 @@
   double Task_SentEast(cTaskContext* ctx) const;
   double Task_SentNorthEast(cTaskContext* ctx) const;
   
+  double Task_Royal_Lineage(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