[Avida-SVN] r2529 - in branches/jobScheduling/source: cpu main

beckma24 at myxo.css.msu.edu beckma24 at myxo.css.msu.edu
Thu Apr 10 06:51:46 PDT 2008


Author: beckma24
Date: 2008-04-10 09:51:46 -0400 (Thu, 10 Apr 2008)
New Revision: 2529

Modified:
   branches/jobScheduling/source/cpu/cHardwareCPU.cc
   branches/jobScheduling/source/cpu/cHardwareCPU.h
   branches/jobScheduling/source/cpu/cTestCPUInterface.h
   branches/jobScheduling/source/main/cDeme.h
   branches/jobScheduling/source/main/cOrgInterface.h
   branches/jobScheduling/source/main/cOrganism.h
   branches/jobScheduling/source/main/cPopulationInterface.cc
   branches/jobScheduling/source/main/cPopulationInterface.h
   branches/jobScheduling/source/main/cTaskLib.cc
   branches/jobScheduling/source/main/cTaskLib.h
Log:
Added event movement instructions and task

Modified: branches/jobScheduling/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/jobScheduling/source/cpu/cHardwareCPU.cc	2008-04-09 20:17:42 UTC (rev 2528)
+++ branches/jobScheduling/source/cpu/cHardwareCPU.cc	2008-04-10 13:51:46 UTC (rev 2529)
@@ -239,9 +239,12 @@
     tInstLibEntry<tMethod>("get-cell-x", &cHardwareCPU::Inst_GetCellPositionX),
     tInstLibEntry<tMethod>("get-cell-y", &cHardwareCPU::Inst_GetCellPositionY),
     tInstLibEntry<tMethod>("dist-from-diag", &cHardwareCPU::Inst_GetDistanceFromDiagonal),
+
     // @WRE additions for movement
     tInstLibEntry<tMethod>("tumble", &cHardwareCPU::Inst_Tumble, nInstFlag::STALL),
     tInstLibEntry<tMethod>("move", &cHardwareCPU::Inst_Move, nInstFlag::STALL),
+    tInstLibEntry<tMethod>("move-to-event", &cHardwareCPU::Inst_MoveToEvent, nInstFlag::STALL),
+    tInstLibEntry<tMethod>("if-event-in-unoccupied-neighbor-cell", &cHardwareCPU::Inst_IfNeighborEventInUnoccupiedCell),
     
     // Threading instructions
     tInstLibEntry<tMethod>("fork-th", &cHardwareCPU::Inst_ForkThread),
@@ -4013,8 +4016,44 @@
   }
 }
 
+bool cHardwareCPU::Inst_MoveToEvent(cAvidaContext& ctx) {
+  const int reg_used = FindModifiedRegister(REG_BX);
+  int orginalFacing = organism->GetFacing();
+  
+  for(int i = 0; i < organism->GetNeighborhoodSize(); i++) {
+    if(organism->IsNeighborCellOccupied()) // cannot move into occupied cell
+      continue;
+    else if(organism->GetNeighborCellContents() > 0) { 
+      Inst_Move(ctx);
+      GetRegister(reg_used) = 1;
+      return true;
+    }
+    organism->Rotate(1);
+  }
+  assert(organism->GetFacing() == orginalFacing);
+  
+  GetRegister(reg_used) = 0;
+  return true;
+}
+
+
+bool cHardwareCPU::Inst_IfNeighborEventInUnoccupiedCell(cAvidaContext& ctx) {
+  int orginalFacing = organism->GetFacing();
+  
+  for(int i = 0; i < organism->GetNeighborhoodSize(); i++) {
+    if(organism->IsNeighborCellOccupied()) // cannot move into occupied cell
+      continue;
+    else if(organism->GetNeighborCellContents() > 0) { 
+      return true;
+    }
+    organism->Rotate(1);
+  }
+  assert(organism->GetFacing() == orginalFacing);
+  IP().Advance();
+  return true;
+}
+
 // Multi-threading.
-
 bool cHardwareCPU::Inst_ForkThread(cAvidaContext& ctx)
 {
   IP().Advance();

Modified: branches/jobScheduling/source/cpu/cHardwareCPU.h
===================================================================
--- branches/jobScheduling/source/cpu/cHardwareCPU.h	2008-04-09 20:17:42 UTC (rev 2528)
+++ branches/jobScheduling/source/cpu/cHardwareCPU.h	2008-04-10 13:51:46 UTC (rev 2529)
@@ -500,6 +500,8 @@
   // @WRE additions for movement
   bool Inst_Tumble(cAvidaContext& ctx);
   bool Inst_Move(cAvidaContext& ctx);
+  bool Inst_MoveToEvent(cAvidaContext& ctx);
+  bool Inst_IfNeighborEventInUnoccupiedCell(cAvidaContext& ctx);
 
   // Multi-threading...
 

Modified: branches/jobScheduling/source/cpu/cTestCPUInterface.h
===================================================================
--- branches/jobScheduling/source/cpu/cTestCPUInterface.h	2008-04-09 20:17:42 UTC (rev 2528)
+++ branches/jobScheduling/source/cpu/cTestCPUInterface.h	2008-04-10 13:51:46 UTC (rev 2529)
@@ -58,6 +58,7 @@
   cOrganism* GetNeighbor();
   bool IsNeighborCellOccupied();
   int GetNumNeighbors();
+  int GetNeighborCellContents() { return 0; }
   void Rotate(int direction = 1);
   void Breakpoint() { ; }
   int GetInputAt(int& input_pointer);

Modified: branches/jobScheduling/source/main/cDeme.h
===================================================================
--- branches/jobScheduling/source/main/cDeme.h	2008-04-09 20:17:42 UTC (rev 2528)
+++ branches/jobScheduling/source/main/cDeme.h	2008-04-10 13:51:46 UTC (rev 2529)
@@ -165,6 +165,8 @@
                          int m_total_events_per_slot_min, int m_tolal_event_flow_levels);
 
   void KillCellEvent(const int eventID);
+  cDemeCellEvent* GetCellEvent(const int i) { return &cell_events[i]; };
+  int GetNumCellEvents() const { return cell_events.GetSize(); }
   
   double CalculateTotalEnergy();
   double GetTotalEnergyTestament() { return total_energy_testament; }

Modified: branches/jobScheduling/source/main/cOrgInterface.h
===================================================================
--- branches/jobScheduling/source/main/cOrgInterface.h	2008-04-09 20:17:42 UTC (rev 2528)
+++ branches/jobScheduling/source/main/cOrgInterface.h	2008-04-10 13:51:46 UTC (rev 2529)
@@ -68,6 +68,7 @@
   virtual bool IsNeighborCellOccupied() = 0;
   virtual int GetNumNeighbors() = 0;
   virtual int GetFacing() = 0; //!< Returns the facing of this organism.
+  virtual int GetNeighborCellContents() = 0;
   virtual void Rotate(int direction = 1) = 0;
   virtual void Breakpoint() = 0;
   virtual int GetInputAt(int& input_pointer) = 0;

Modified: branches/jobScheduling/source/main/cOrganism.h
===================================================================
--- branches/jobScheduling/source/main/cOrganism.h	2008-04-09 20:17:42 UTC (rev 2528)
+++ branches/jobScheduling/source/main/cOrganism.h	2008-04-10 13:51:46 UTC (rev 2529)
@@ -191,6 +191,7 @@
   bool IsNeighborCellOccupied() { return m_interface->IsNeighborCellOccupied(); }
   int GetNeighborhoodSize() { return m_interface->GetNumNeighbors(); }
   int GetFacing() { assert(m_interface); return m_interface->GetFacing(); }  // Returns the facing of this organism.
+  int GetNeighborCellContents() const { return m_interface->GetNeighborCellContents(); }
   void Rotate(int direction) { m_interface->Rotate(direction); }
   void DoBreakpoint() { m_interface->Breakpoint(); }
   int GetNextInput() { return m_interface->GetInputAt(m_input_pointer); }

Modified: branches/jobScheduling/source/main/cPopulationInterface.cc
===================================================================
--- branches/jobScheduling/source/main/cPopulationInterface.cc	2008-04-09 20:17:42 UTC (rev 2528)
+++ branches/jobScheduling/source/main/cPopulationInterface.cc	2008-04-10 13:51:46 UTC (rev 2529)
@@ -89,6 +89,11 @@
 	return cell.GetFacing();
 }
 
+int cPopulationInterface::GetNeighborCellContents() {
+  cPopulationCell & cell = m_world->GetPopulation().GetCell(m_cell_id);
+  return cell.ConnectionList().GetFirst()->GetCellData();
+}
+
 void cPopulationInterface::Rotate(int direction)
 {
   cPopulationCell & cell = m_world->GetPopulation().GetCell(m_cell_id);

Modified: branches/jobScheduling/source/main/cPopulationInterface.h
===================================================================
--- branches/jobScheduling/source/main/cPopulationInterface.h	2008-04-09 20:17:42 UTC (rev 2528)
+++ branches/jobScheduling/source/main/cPopulationInterface.h	2008-04-10 13:51:46 UTC (rev 2529)
@@ -70,6 +70,7 @@
   bool IsNeighborCellOccupied();
   int GetNumNeighbors();
   int GetFacing(); // Returns the facing of this organism.
+  int GetNeighborCellContents();
   void Rotate(int direction = 1);
   void Breakpoint() { m_world->GetDriver().SignalBreakpoint(); }
   int GetInputAt(int& input_pointer);

Modified: branches/jobScheduling/source/main/cTaskLib.cc
===================================================================
--- branches/jobScheduling/source/main/cTaskLib.cc	2008-04-09 20:17:42 UTC (rev 2528)
+++ branches/jobScheduling/source/main/cTaskLib.cc	2008-04-10 13:51:46 UTC (rev 2529)
@@ -27,6 +27,7 @@
 #include "cTaskLib.h"
 
 #include "cArgSchema.h"
+#include "cDeme.h"
 #include "cEnvReqs.h"
 #include "tHashTable.h"
 #include "cTaskState.h"
@@ -384,8 +385,10 @@
   else if (name == "net_receive")
     NewTask(name, "Successfully Received Network Message", &cTaskLib::Task_NetReceive);
   
+  //movement
+  if(name == "move_to_event")
+    NewTask(name, "Moved into cell containing event", &cTaskLib::Task_MoveToEvent);
   
-  
   // Make sure we have actually found a task  
   if (task_array.GetSize() == start_size) {
     if (errors != NULL && errors->GetSize() == 0) {
@@ -2834,3 +2837,17 @@
   if (ctx.NetIsValid()) return 1.0;
   return 0.0;
 }
+
+
+double cTaskLib::Task_MoveToEvent(cTaskContext& ctx) const {
+  cDeme* deme = ctx.GetOrganism()->GetOrgInterface().GetDeme();
+  int cell_data = ctx.GetOrganism()->GetOrgInterface().GetCellData();
+  if(cell_data <= 0)
+    return 0.0;
+    
+  for(int i = 0; i < deme->GetNumCellEvents(); i++) {
+    if(deme->GetCellEvent(i)->GetEventID() == cell_data)
+      return 1.0;
+  }
+  return 0.0;
+}

Modified: branches/jobScheduling/source/main/cTaskLib.h
===================================================================
--- branches/jobScheduling/source/main/cTaskLib.h	2008-04-09 20:17:42 UTC (rev 2528)
+++ branches/jobScheduling/source/main/cTaskLib.h	2008-04-10 13:51:46 UTC (rev 2529)
@@ -278,6 +278,9 @@
   // Network Tasks
   double Task_NetSend(cTaskContext& ctx) const;
   double Task_NetReceive(cTaskContext& ctx) const;
+  
+  // movement
+  double Task_MoveToEvent(cTaskContext& ctx) const;
 };
 
 




More information about the Avida-cvs mailing list