[Avida-SVN] r1713 - in development: Avida.xcodeproj documentation source/cpu source/main

beckma24 at myxo.css.msu.edu beckma24 at myxo.css.msu.edu
Mon Jun 25 09:01:43 PDT 2007


Author: beckma24
Date: 2007-06-25 12:01:43 -0400 (Mon, 25 Jun 2007)
New Revision: 1713

Modified:
   development/Avida.xcodeproj/project.pbxproj
   development/documentation/inst_set.html
   development/source/cpu/cHardwareCPU.cc
   development/source/cpu/cHardwareCPU.h
   development/source/cpu/cTestCPUInterface.h
   development/source/main/cOrgInterface.h
   development/source/main/cOrganism.h
   development/source/main/cPopulation.cc
   development/source/main/cPopulationCell.cc
   development/source/main/cPopulationCell.h
   development/source/main/cPopulationInterface.cc
   development/source/main/cPopulationInterface.h
Log:
Added rotate-label instruction to cHardwareCPU.

Modified: development/Avida.xcodeproj/project.pbxproj
===================================================================
--- development/Avida.xcodeproj/project.pbxproj	2007-06-25 14:25:27 UTC (rev 1712)
+++ development/Avida.xcodeproj/project.pbxproj	2007-06-25 16:01:43 UTC (rev 1713)
@@ -198,6 +198,23 @@
 		};
 /* End PBXBuildRule section */
 
+/* Begin PBXBuildStyle section */
+		B543837A0C300EE2005F1A1E /* Development */ = {
+			isa = PBXBuildStyle;
+			buildSettings = {
+				COPY_PHASE_STRIP = NO;
+			};
+			name = Development;
+		};
+		B543837B0C300EE2005F1A1E /* Deployment */ = {
+			isa = PBXBuildStyle;
+			buildSettings = {
+				COPY_PHASE_STRIP = YES;
+			};
+			name = Deployment;
+		};
+/* End PBXBuildStyle section */
+
 /* Begin PBXContainerItemProxy section */
 		7023ECA60C0A436000362B9C /* PBXContainerItemProxy */ = {
 			isa = PBXContainerItemProxy;
@@ -1673,6 +1690,12 @@
 		DCC30C4D0762532C008F7A48 /* Project object */ = {
 			isa = PBXProject;
 			buildConfigurationList = 702442D70859E0B00059BD9B /* Build configuration list for PBXProject "Avida" */;
+			buildSettings = {
+			};
+			buildStyles = (
+				B543837A0C300EE2005F1A1E /* Development */,
+				B543837B0C300EE2005F1A1E /* Deployment */,
+			);
 			hasScannedForEncodings = 0;
 			mainGroup = DCC30C490762532C008F7A48;
 			productRefGroup = DCC3164E07626CF3008F7A48 /* Products */;

Modified: development/documentation/inst_set.html
===================================================================
--- development/documentation/inst_set.html	2007-06-25 14:25:27 UTC (rev 1712)
+++ development/documentation/inst_set.html	2007-06-25 16:01:43 UTC (rev 1713)
@@ -303,6 +303,10 @@
 it has made a full 360 degree turn, or else it finds an organism that
 possesses the complement label.
 
+<h3><code>rotate-label</code></h3>
+
+Rotates the calling organism to the direction specified by the label that follows.  If no label is present the organisms rotates to face south.
+
 <h3><code>div-asex</code></h3>
 Same as h-divide (added for symetry with the divide-sex). 
 

Modified: development/source/cpu/cHardwareCPU.cc
===================================================================
--- development/source/cpu/cHardwareCPU.cc	2007-06-25 14:25:27 UTC (rev 1712)
+++ development/source/cpu/cHardwareCPU.cc	2007-06-25 16:01:43 UTC (rev 1713)
@@ -216,6 +216,8 @@
 
     tInstLibEntry<tMethod>("rotate-l", &cHardwareCPU::Inst_RotateL),
     tInstLibEntry<tMethod>("rotate-r", &cHardwareCPU::Inst_RotateR),
+    tInstLibEntry<tMethod>("rotate-label", &cHardwareCPU::Inst_RotateLabel),
+
     
     tInstLibEntry<tMethod>("set-cmut", &cHardwareCPU::Inst_SetCopyMut),
     tInstLibEntry<tMethod>("mod-cmut", &cHardwareCPU::Inst_ModCopyMut),
@@ -3661,6 +3663,31 @@
   return true;
 }
 
+/**
+  Rotate to facing specified by following label
+*/
+bool cHardwareCPU::Inst_RotateLabel(cAvidaContext& ctx)
+{
+  int standardNeighborhoodSize, actualNeighborhoodSize, newFacing, currentFacing;
+  actualNeighborhoodSize = organism->GetNeighborhoodSize();
+  
+  ReadLabel();
+  if(m_world->GetConfig().WORLD_GEOMETRY.Get() == nGeometry::TORUS || m_world->GetConfig().WORLD_GEOMETRY.Get() == nGeometry::GRID)
+    standardNeighborhoodSize = 8;
+  else {
+    exit(-1);
+  }
+  newFacing = GetLabel().AsIntGreyCode(NUM_NOPS) % standardNeighborhoodSize;
+  
+  for(int i = 0; i < actualNeighborhoodSize; i++) {
+    currentFacing = organism->GetFacing();
+    if(newFacing == currentFacing)
+      break;
+    organism->Rotate(1);
+  }
+  return true;
+}
+
 bool cHardwareCPU::Inst_SetCopyMut(cAvidaContext& ctx)
 {
   const int reg_used = FindModifiedRegister(REG_BX);

Modified: development/source/cpu/cHardwareCPU.h
===================================================================
--- development/source/cpu/cHardwareCPU.h	2007-06-25 14:25:27 UTC (rev 1712)
+++ development/source/cpu/cHardwareCPU.h	2007-06-25 16:01:43 UTC (rev 1713)
@@ -450,6 +450,7 @@
 
   bool Inst_RotateL(cAvidaContext& ctx);
   bool Inst_RotateR(cAvidaContext& ctx);
+  bool Inst_RotateLabel(cAvidaContext& ctx);
   bool Inst_SetCopyMut(cAvidaContext& ctx);
   bool Inst_ModCopyMut(cAvidaContext& ctx);
 

Modified: development/source/cpu/cTestCPUInterface.h
===================================================================
--- development/source/cpu/cTestCPUInterface.h	2007-06-25 14:25:27 UTC (rev 1712)
+++ development/source/cpu/cTestCPUInterface.h	2007-06-25 16:01:43 UTC (rev 1713)
@@ -68,6 +68,7 @@
   bool InjectParasite(cOrganism* parent, const cCodeLabel& label, const cGenome& injected_code);
   bool UpdateMerit(double new_merit);
   bool TestOnDivide() { return false; }
+  int GetFacing() { return 0; }
 };
 
 

Modified: development/source/main/cOrgInterface.h
===================================================================
--- development/source/main/cOrgInterface.h	2007-06-25 14:25:27 UTC (rev 1712)
+++ development/source/main/cOrgInterface.h	2007-06-25 16:01:43 UTC (rev 1713)
@@ -58,6 +58,7 @@
   virtual bool Divide(cAvidaContext& ctx, cOrganism* parent, cGenome& child_genome) = 0;
   virtual cOrganism* GetNeighbor() = 0;
   virtual int GetNumNeighbors() = 0;
+  virtual int GetFacing() = 0; //!< Returns the facing of this organism.
   virtual void Rotate(int direction = 1) = 0;
   virtual void Breakpoint() = 0;
   virtual int GetInputAt(int& input_pointer) = 0;

Modified: development/source/main/cOrganism.h
===================================================================
--- development/source/main/cOrganism.h	2007-06-25 14:25:27 UTC (rev 1712)
+++ development/source/main/cOrganism.h	2007-06-25 16:01:43 UTC (rev 1713)
@@ -182,6 +182,7 @@
   cHardwareBase& GetHardware() { return *m_hardware; }
   cOrganism* GetNeighbor() { return m_interface->GetNeighbor(); }
   int GetNeighborhoodSize() { return m_interface->GetNumNeighbors(); }
+  int GetFacing() { assert(m_interface); return m_interface->GetFacing(); }  // Returns the facing of this organism.
   void Rotate(int direction) { m_interface->Rotate(direction); }
   void DoBreakpoint() { m_interface->Breakpoint(); }
   int GetNextInput() { return m_interface->GetInputAt(m_input_pointer); }

Modified: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc	2007-06-25 14:25:27 UTC (rev 1712)
+++ development/source/main/cPopulation.cc	2007-06-25 16:01:43 UTC (rev 1713)
@@ -123,7 +123,7 @@
   
   // Setup the cells.  Do things that are not dependent upon topology here.
 	for(int i=0; i<num_cells; ++i) {
-		cell_array[i].Setup(world, i, environment.GetMutRates());
+		cell_array[i].Setup(world, i, environment.GetMutRates(), i%world_x, i/world_x);
     // Setup the reaper queue.
 		if (world->GetConfig().BIRTH_METHOD.Get() == POSITION_CHILD_FULL_SOUP_ELDEST) {
 			reaper_queue.Push(&(cell_array[i]));

Modified: development/source/main/cPopulationCell.cc
===================================================================
--- development/source/main/cPopulationCell.cc	2007-06-25 14:25:27 UTC (rev 1712)
+++ development/source/main/cPopulationCell.cc	2007-06-25 16:01:43 UTC (rev 1713)
@@ -78,10 +78,12 @@
   }
 }
 
-void cPopulationCell::Setup(cWorld* world, int in_id, const cMutationRates& in_rates)
+void cPopulationCell::Setup(cWorld* world, int in_id, const cMutationRates& in_rates, int x, int y)
 {
   m_world = world;
   cell_id = in_id;
+  m_x = x;
+  m_y = y;
   deme_id = -1;
   
   if (mutation_rates == NULL)
@@ -105,7 +107,52 @@
   }
 }
 
+/*! These values are chosen so as to make loops on the facing 'easy'.
+111 = NE
+101 = E
+100 = SE
+000 = S
+001 = SW
+011 = W
+010 = NW
+110 = N
 
+Facing is determined by the relative positions of this cell and the cell that 
+is currently faced. Note that we cannot differentiate between directions on a 2x2 
+torus.
+*/
+int cPopulationCell::GetFacing()
+{
+  // This whole function is a hack.
+	cPopulationCell* faced = ConnectionList().GetFirst();
+	
+        int x=0,y=0,lr=0,du=0;
+	faced->GetPosition(x,y);
+  
+	if((x==m_x-1) || (x>m_x+1))
+		lr = -1; //left
+	else if((x==m_x+1) || (x<m_x-1))
+		lr = 1; //right
+	
+	if((y==m_y-1) || (y>m_y+1))
+		du = -1; //down
+	else if((y==m_y+1) || (y<m_y-1))
+		du = 1; //up
+  
+	// This is hackish.
+        // If you change these return values then the directional send tasks, like sent-north, need to be updated.
+	if(lr==0 && du==-1) return 0; //S
+	if(lr==-1 && du==-1) return 1; //SW
+	if(lr==-1 && du==0) return 3; //W
+	if(lr==-1 && du==1) return 2; //NW
+	if(lr==0 && du==1) return 6; //N
+	if(lr==1 && du==1) return 7; //NE
+	if(lr==1 && du==0) return 5; //E
+	if(lr==1 && du==-1) return 4; //SE
+  
+	assert(false);
+}
+
 int cPopulationCell::GetInputAt(int & input_pointer)
 {
   input_pointer %= input_array.GetSize();

Modified: development/source/main/cPopulationCell.h
===================================================================
--- development/source/main/cPopulationCell.h	2007-06-25 14:25:27 UTC (rev 1712)
+++ development/source/main/cPopulationCell.h	2007-06-25 16:01:43 UTC (rev 1713)
@@ -57,6 +57,9 @@
   int deme_id;           // ID of the deme that this cell is part of.
   int organism_count;    // Total number of orgs to ever inhabit this cell.
 
+  //location in population
+  int m_x; //!< The x-coordinate of the position of this cell in the environment.
+  int m_y; //!< The y-coordinate of the position of this cell in the environment.
 
   void InsertOrganism(cOrganism & new_org);
   cOrganism* RemoveOrganism();
@@ -68,13 +71,15 @@
 
   void operator=(const cPopulationCell& in_cell);
 
-  void Setup(cWorld* world, int in_id, const cMutationRates & in_rates);
+  void Setup(cWorld* world, int in_id, const cMutationRates & in_rates, int x, int y);
   void SetDemeID(int in_id) { deme_id = in_id; }
   void Rotate(cPopulationCell & new_facing);
 
   cOrganism* GetOrganism() const { return organism; }
   tList<cPopulationCell> & ConnectionList() { return connection_list; }
   cPopulationCell & GetCellFaced() { return *(connection_list.GetFirst()); }
+  int GetFacing();  // Returns the facing of this cell.
+  void GetPosition(int& x, int& y) { x = m_x; y = m_y; } // Retrieves the position (x,y) coordinates of this cell.
   const cMutationRates & MutationRates() const { return *mutation_rates; }
   cMutationRates & MutationRates() { return *mutation_rates; }
   int GetInput(int);

Modified: development/source/main/cPopulationInterface.cc
===================================================================
--- development/source/main/cPopulationInterface.cc	2007-06-25 14:25:27 UTC (rev 1712)
+++ development/source/main/cPopulationInterface.cc	2007-06-25 16:01:43 UTC (rev 1713)
@@ -64,6 +64,13 @@
   return cell.ConnectionList().GetSize();
 }
 
+int cPopulationInterface::GetFacing()
+{
+	cPopulationCell& cell = m_world->GetPopulation().GetCell(m_cell_id);
+	assert(cell.IsOccupied());
+	return cell.GetFacing();
+}
+
 void cPopulationInterface::Rotate(int direction)
 {
   cPopulationCell & cell = m_world->GetPopulation().GetCell(m_cell_id);

Modified: development/source/main/cPopulationInterface.h
===================================================================
--- development/source/main/cPopulationInterface.h	2007-06-25 14:25:27 UTC (rev 1712)
+++ development/source/main/cPopulationInterface.h	2007-06-25 16:01:43 UTC (rev 1713)
@@ -59,6 +59,7 @@
   bool Divide(cAvidaContext& ctx, cOrganism* parent, cGenome& child_genome);
   cOrganism* GetNeighbor();
   int GetNumNeighbors();
+  int GetFacing(); // Returns the facing of this organism.
   void Rotate(int direction = 1);
   void Breakpoint() { m_world->GetDriver().SignalBreakpoint(); }
   int GetInputAt(int& input_pointer);




More information about the Avida-cvs mailing list