[Avida-SVN] r2120 - development/source/cpu

barrick at myxo.css.msu.edu barrick at myxo.css.msu.edu
Tue Oct 2 18:42:32 PDT 2007


Author: barrick
Date: 2007-10-02 21:42:28 -0400 (Tue, 02 Oct 2007)
New Revision: 2120

Modified:
   development/source/cpu/cHardwareBase.cc
   development/source/cpu/cHardwareCPU.cc
Log:
1. Fixed problem with organisms that had just died from using too much time trying to IMPLICIT_REPRO. No children of the dead, please. This is not a horror movie. Potentially an interesting evolutionary strategy, though.

2. Added boundary condition for sense (INT_MIN returned in log mode if the sum of all sensed resources is zero).



Modified: development/source/cpu/cHardwareBase.cc
===================================================================
--- development/source/cpu/cHardwareBase.cc	2007-10-02 13:49:10 UTC (rev 2119)
+++ development/source/cpu/cHardwareBase.cc	2007-10-03 01:42:28 UTC (rev 2120)
@@ -799,6 +799,9 @@
 // @JEB Check implicit repro conditions -- meant to be called at the end of SingleProcess
 void cHardwareBase::CheckImplicitRepro(cAvidaContext& ctx, bool exec_last_inst)         
 {  
+  //Dividing a dead organism causes all kinds of problems
+  if (organism->IsDead()) return;
+
   if( (m_world->GetConfig().IMPLICIT_REPRO_TIME.Get() && (organism->GetPhenotype().GetTimeUsed() >= m_world->GetConfig().IMPLICIT_REPRO_TIME.Get()))
    || (m_world->GetConfig().IMPLICIT_REPRO_CPU_CYCLES.Get() && (organism->GetPhenotype().GetCPUCyclesUsed() >= m_world->GetConfig().IMPLICIT_REPRO_CPU_CYCLES.Get()))
    || (m_world->GetConfig().IMPLICIT_REPRO_BONUS.Get() && (organism->GetPhenotype().GetCurBonus() >= m_world->GetConfig().IMPLICIT_REPRO_BONUS.Get()))

Modified: development/source/cpu/cHardwareCPU.cc
===================================================================
--- development/source/cpu/cHardwareCPU.cc	2007-10-02 13:49:10 UTC (rev 2119)
+++ development/source/cpu/cHardwareCPU.cc	2007-10-03 01:42:28 UTC (rev 2120)
@@ -522,6 +522,7 @@
 
 void cHardwareCPU::SingleProcess(cAvidaContext& ctx)
 {
+
   int last_IP_pos = IP().GetPosition();
   
   // Mark this organism as running...
@@ -611,7 +612,7 @@
     } // if exec
         
   } // Previous was executed once for each thread...
-  
+
   // Kill creatures who have reached their max num of instructions executed
   const int max_executed = organism->GetMaxExecuted();
   if ((max_executed > 0 && phenotype.GetTimeUsed() >= max_executed)
@@ -619,8 +620,10 @@
     organism->Die();
   }
   
+  // Note: if organism just died, this will NOT let it repro.
+  CheckImplicitRepro(ctx, last_IP_pos > IP().GetPosition());
+  
   organism->SetRunning(false);
-  CheckImplicitRepro(ctx, last_IP_pos > IP().GetPosition());
 }
 
 // This method will handle the actual execution of an instruction
@@ -2576,6 +2579,7 @@
       }
     }
   }
+  
   Divide_DoMutations(ctx);
   
   // Many tests will require us to run the offspring through a test CPU;
@@ -3066,13 +3070,18 @@
     } 
   }
   
-  // Take the log after adding resource amounts together!
-  // Otherwise 
+  // Take the log after adding resource amounts together! This way a zero can be assigned to INT_MIN
   if (conversion_method == 0) // Log2
   {
     // You really shouldn't be using the log method if you can get to zero resources
-    assert(dresource_result != 0);
-    resource_result = (int)(log(dresource_result)/log(base));
+    if(dresource_result == 0.0)
+    {
+      resource_result = INT_MIN;
+    }
+    else
+    {
+      resource_result = (int)(log(dresource_result)/log(base));
+    }
   }
     
   //Dump this value into an arbitrary register: BX




More information about the Avida-cvs mailing list