[Avida-SVN] r2655 - in development/source: actions cpu

connel42 at myxo.css.msu.edu connel42 at myxo.css.msu.edu
Tue Jun 17 14:21:09 PDT 2008


Author: connel42
Date: 2008-06-17 17:21:09 -0400 (Tue, 17 Jun 2008)
New Revision: 2655

Modified:
   development/source/actions/PopulationActions.cc
   development/source/cpu/cHardwareCPU.cc
Log:
* All movement instructions now have the STALL flag
* Moved some code inside a conditional in InjectDemesRandom action to increase efficiency



Modified: development/source/actions/PopulationActions.cc
===================================================================
--- development/source/actions/PopulationActions.cc	2008-06-17 16:20:43 UTC (rev 2654)
+++ development/source/actions/PopulationActions.cc	2008-06-17 21:21:09 UTC (rev 2655)
@@ -620,6 +620,10 @@
     if (largs.GetSize()) m_merit = largs.PopWord().AsDouble();
     if (largs.GetSize()) m_lineage_label = largs.PopWord().AsInt();
     if (largs.GetSize()) m_neutral_metric = largs.PopWord().AsDouble();
+
+    assert(m_num_orgs <= m_world->GetPopulation().GetSize());
+    assert(m_nest_cellid > -1);
+    assert(m_nest_cellid < m_world->GetPopulation().GetSize());
   } //End cActionInjectDemesFromNest constructor
 
   static const cString GetDescription() { return "Arguments: [int num_orgs=1] [int nest_cellid=0] [double merit=-1] [int lineage_label=0] [double neutral_metric=0]"; }
@@ -628,11 +632,11 @@
   {
     for(int i=0; i<m_world->GetPopulation().GetNumDemes(); ++i) {
 
-      // The first deme will have initially had one organism injected.  If this
+      // Each deme will have initially had one organism injected.  If this
       // is the first injection and energy is used, increment the injected
       // count (the initial injection wasn't counted) and skip the first deme
       // so that the energies don't get messed up.
-      if( (i==0) && (m_world->GetConfig().ENERGY_ENABLED.Get() == 1) &&
+      if( (m_world->GetConfig().ENERGY_ENABLED.Get() == 1) &&
           (m_world->GetPopulation().GetDeme(i).GetInjectedCount() == 0) ) {
         m_world->GetPopulation().GetDeme(i).IncInjectedCount();
         continue;
@@ -687,6 +691,7 @@
     if (largs.GetSize()) m_merit = largs.PopWord().AsDouble();
     if (largs.GetSize()) m_lineage_label = largs.PopWord().AsInt();
     if (largs.GetSize()) m_neutral_metric = largs.PopWord().AsDouble();
+    assert(m_num_orgs <= m_world->GetPopulation().GetSize());
   } //End cActionInjectDemesRandom constructor
 
   static const cString GetDescription() { return "Arguments: [int num_orgs=1] [double merit=-1] [int lineage_label=0] [double neutral_metric=0]"; }
@@ -698,35 +703,35 @@
 
     for(int i=0; i<m_world->GetPopulation().GetNumDemes(); ++i) {
 
-      // The first deme will have initially had one organism injected.  If this
+      // Each deme will have initially had one organism injected.  If this
       // is the first injection and energy is used, increment the injected
       // count (the initial injection wasn't counted) and skip the first deme
       // so that the energies don't get messed up.
-      if( (i==0) && (m_world->GetConfig().ENERGY_ENABLED.Get() == 1) &&
+      if( (m_world->GetConfig().ENERGY_ENABLED.Get() == 1) &&
           (m_world->GetPopulation().GetDeme(i).GetInjectedCount() == 0) ) {
         m_world->GetPopulation().GetDeme(i).IncInjectedCount();
         continue;
       }
 
-      target_cell = -1;
-      target_cellr = -1;
-      deme_size = m_world->GetPopulation().GetDeme(i).GetSize();
+      if(m_world->GetPopulation().GetDeme(i).GetInjectedCount() < m_num_orgs) {
+        target_cell = -1;
+        target_cellr = -1;
+        deme_size = m_world->GetPopulation().GetDeme(i).GetSize();
 
-      // Find a random, unoccupied cell to use. Assumes one exists.
-      do {
-        target_cellr = m_world->GetRandom().GetInt(0, deme_size-1);
-        target_cell = m_world->GetPopulation().GetDeme(i).GetCellID(target_cellr);
-      } while (m_world->GetPopulation().GetCell(target_cell).IsOccupied());
+        // Find a random, unoccupied cell to use. Assumes one exists.
+        do {
+          target_cellr = m_world->GetRandom().GetInt(0, deme_size-1);
+          target_cell = m_world->GetPopulation().GetDeme(i).GetCellID(target_cellr);
+        } while (m_world->GetPopulation().GetCell(target_cell).IsOccupied());
 
-      assert(target_cell > -1);
-      assert(target_cell < m_world->GetPopulation().GetSize());
+        assert(target_cell > -1);
+        assert(target_cell < m_world->GetPopulation().GetSize());
 
-      if(m_world->GetPopulation().GetDeme(i).GetInjectedCount() < m_num_orgs) {
         m_world->GetPopulation().Inject(m_world->GetPopulation().GetDeme(i).GetGermline().GetLatest(),
                                         target_cell, m_merit,
                                         m_lineage_label, m_neutral_metric);
         m_world->GetPopulation().GetDeme(i).IncInjectedCount();
-      }
+      } //End if there are still orgs to be inserted
 
     } //End iterating through demes
 

Modified: development/source/cpu/cHardwareCPU.cc
===================================================================
--- development/source/cpu/cHardwareCPU.cc	2008-06-17 16:20:43 UTC (rev 2654)
+++ development/source/cpu/cHardwareCPU.cc	2008-06-17 21:21:09 UTC (rev 2655)
@@ -431,19 +431,19 @@
     tInstLibEntry<tMethod>("sensef-m100", &cHardwareCPU::Inst_SenseMult100Facing),
     tInstLibEntry<tMethod>("sense-pheromone", &cHardwareCPU::Inst_SensePheromone),
     tInstLibEntry<tMethod>("sense-pheromone-faced", &cHardwareCPU::Inst_SensePheromoneFaced),
-    tInstLibEntry<tMethod>("exploit", &cHardwareCPU::Inst_Exploit),
-    tInstLibEntry<tMethod>("exploit-forward5", &cHardwareCPU::Inst_ExploitForward5),
-    tInstLibEntry<tMethod>("exploit-forward3", &cHardwareCPU::Inst_ExploitForward3),
-    tInstLibEntry<tMethod>("explore", &cHardwareCPU::Inst_Explore),
-    tInstLibEntry<tMethod>("movetarget", &cHardwareCPU::Inst_MoveTarget),
-    tInstLibEntry<tMethod>("movetarget-forward5", &cHardwareCPU::Inst_MoveTargetForward5),
-    tInstLibEntry<tMethod>("movetarget-forward3", &cHardwareCPU::Inst_MoveTargetForward3),
-    tInstLibEntry<tMethod>("supermove", &cHardwareCPU::Inst_SuperMove),
+    tInstLibEntry<tMethod>("exploit", &cHardwareCPU::Inst_Exploit, nInstFlag::STALL),
+    tInstLibEntry<tMethod>("exploit-forward5", &cHardwareCPU::Inst_ExploitForward5, nInstFlag::STALL),
+    tInstLibEntry<tMethod>("exploit-forward3", &cHardwareCPU::Inst_ExploitForward3, nInstFlag::STALL),
+    tInstLibEntry<tMethod>("explore", &cHardwareCPU::Inst_Explore, nInstFlag::STALL),
+    tInstLibEntry<tMethod>("movetarget", &cHardwareCPU::Inst_MoveTarget, nInstFlag::STALL),
+    tInstLibEntry<tMethod>("movetarget-forward5", &cHardwareCPU::Inst_MoveTargetForward5, nInstFlag::STALL),
+    tInstLibEntry<tMethod>("movetarget-forward3", &cHardwareCPU::Inst_MoveTargetForward3, nInstFlag::STALL),
+    tInstLibEntry<tMethod>("supermove", &cHardwareCPU::Inst_SuperMove, nInstFlag::STALL),
     tInstLibEntry<tMethod>("if-target", &cHardwareCPU::Inst_IfTarget),
     tInstLibEntry<tMethod>("if-not-target", &cHardwareCPU::Inst_IfNotTarget),
     tInstLibEntry<tMethod>("if-pheromone", &cHardwareCPU::Inst_IfPheromone),
     tInstLibEntry<tMethod>("if-not-pheromone", &cHardwareCPU::Inst_IfNotPheromone),
-    tInstLibEntry<tMethod>("drop-pheromone", &cHardwareCPU::Inst_DropPheromone),
+    tInstLibEntry<tMethod>("drop-pheromone", &cHardwareCPU::Inst_DropPheromone, nInstFlag::STALL),
 
     // Must always be the last instruction in the array
     tInstLibEntry<tMethod>("NULL", &cHardwareCPU::Inst_Nop, 0, "True no-operation instruction: does nothing"),
@@ -5958,9 +5958,6 @@
     mycell.ConnectionList().CircNext();
   }
 
-// apparently this doesn't work on macs
-//  assert(faced == pop.GetCell(fromcellID).GetCellFaced());
-
   // Rotate until we face the neighbor with a target.
   // If there was no winner, just move forward.
   for(int i = 0; i < num_rotations; i++) {




More information about the Avida-cvs mailing list