[Avida-SVN] r1714 - branches/dkdev/source/cpu

dknoester at myxo.css.msu.edu dknoester at myxo.css.msu.edu
Mon Jun 25 10:12:22 PDT 2007


Author: dknoester
Date: 2007-06-25 13:12:22 -0400 (Mon, 25 Jun 2007)
New Revision: 1714

Modified:
   branches/dkdev/source/cpu/cHardwareCPU.cc
   branches/dkdev/source/cpu/cHardwareCPU.h
Log:
Added conditional instructions for detecting if the cell has a link in the faced direction.

Modified: branches/dkdev/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/dkdev/source/cpu/cHardwareCPU.cc	2007-06-25 16:01:43 UTC (rev 1713)
+++ branches/dkdev/source/cpu/cHardwareCPU.cc	2007-06-25 17:12:22 UTC (rev 1714)
@@ -370,7 +370,9 @@
     cInstEntryCPU("get-lpos", &cHardwareCPU::Inst_GetLocalPosition),
     cInstEntryCPU("get-cpos", &cHardwareCPU::Inst_GetCellPosition),
     cInstEntryCPU("get-altitude", &cHardwareCPU::Inst_GetAltitude),
-    cInstEntryCPU("rotate-cell", &cHardwareCPU::Inst_RotateCell)
+    cInstEntryCPU("rotate-cell", &cHardwareCPU::Inst_RotateCell),
+    cInstEntryCPU("if-linked", &cHardwareCPU::Inst_IfLinked),
+    cInstEntryCPU("if-not-linked", &cHardwareCPU::Inst_IfNotLinked)
   };
   
   const int n_size = sizeof(s_n_array)/sizeof(cNOPEntryCPU);
@@ -3724,3 +3726,57 @@
   cell.ConnectionList().FindPtr(target);  
   return true;
 }
+
+
+bool cHardwareCPU::Inst_IfLinked(cAvidaContext& ctx) {
+  typedef cDeme::Network::adjacency_iterator adjacency_iterator;
+  
+  if(organism->GetCellID()==-1) return false;
+  cPopulationCell& cell = m_world->GetPopulation().GetCell(organism->GetCellID());
+	cDeme& deme = m_world->GetPopulation().GetDeme(cell.GetDemeID());
+  cDeme::Network& network = deme.GetNetwork();
+  cDeme::CellVertexMap& cvMap = deme.GetCellVertexMap();
+
+  assert(cell.ConnectionList().GetSize()>0);
+  cDeme::CellVertexMap::iterator u = cvMap.find(cell.GetID());
+  cDeme::CellVertexMap::iterator v = cvMap.find(cell.ConnectionList().GetFirst()->GetID());
+  
+  // Are these vertices in the graph?
+  if(u!=cvMap.end() && v!=cvMap.end()) {
+    // Yes; are they also adjacent?
+    if(boost::edge(u->second, v->second, network).second==true) {
+      // Yes; return.
+      return true;
+    }
+  } 
+
+  // U,v not adjacent.  Advance the IP.
+  IP().Advance();
+  return true;
+}
+
+
+bool cHardwareCPU::Inst_IfNotLinked(cAvidaContext& ctx) {
+  typedef cDeme::Network::adjacency_iterator adjacency_iterator;
+  
+  if(organism->GetCellID()==-1) return false;
+  cPopulationCell& cell = m_world->GetPopulation().GetCell(organism->GetCellID());
+	cDeme& deme = m_world->GetPopulation().GetDeme(cell.GetDemeID());
+  cDeme::Network& network = deme.GetNetwork();
+  cDeme::CellVertexMap& cvMap = deme.GetCellVertexMap();
+  
+  assert(cell.ConnectionList().GetSize()>0);
+  cDeme::CellVertexMap::iterator u = cvMap.find(cell.GetID());
+  cDeme::CellVertexMap::iterator v = cvMap.find(cell.ConnectionList().GetFirst()->GetID());
+  
+  // Are these vertices in the graph?
+  if(u!=cvMap.end() && v!=cvMap.end()) {
+    // Yes; are they also adjacent?
+    if(boost::edge(u->second, v->second, network).second==true) {
+      // Yes; advance the IP.
+      IP().Advance();
+    }
+  } 
+  
+  return true;
+}

Modified: branches/dkdev/source/cpu/cHardwareCPU.h
===================================================================
--- branches/dkdev/source/cpu/cHardwareCPU.h	2007-06-25 16:01:43 UTC (rev 1713)
+++ branches/dkdev/source/cpu/cHardwareCPU.h	2007-06-25 17:12:22 UTC (rev 1714)
@@ -488,6 +488,8 @@
   bool Inst_GetCellPosition(cAvidaContext& ctx); //!< Returns the (x,y) position of one of two cells.
   bool Inst_GetAltitude(cAvidaContext& ctx); //!< Returns the distance of the caller from the line connecting two cells.
   bool Inst_RotateCell(cAvidaContext& ctx); //!< Rotates the caller to face (as close as is possible) in the direction of one of twocells.
+  bool Inst_IfLinked(cAvidaContext& ctx); //!< Executes the next instruction if the caller has a link in the faced direction.  
+  bool Inst_IfNotLinked(cAvidaContext& ctx); //!< Executes the next instruction if the caller does not have a link in the faced direction.  
 };
 
 




More information about the Avida-cvs mailing list