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

dknoester at myxo.css.msu.edu dknoester at myxo.css.msu.edu
Fri Feb 8 13:09:32 PST 2008


Author: dknoester
Date: 2008-02-08 16:09:31 -0500 (Fri, 08 Feb 2008)
New Revision: 2317

Modified:
   development/Avida.xcodeproj/project.pbxproj
   development/source/cpu/cHardwareCPU.cc
   development/source/cpu/cHardwareCPU.h
   development/source/main/cPopulation.cc
Log:
Added an assert to protect against using deme-level merit in the development branch (not yet supported).

Added a resource-sensing 'if' instruction.  If-resources checks the amount of resources that are available to the caller, executing the following instruction only if there are sufficient resources to satisfy all reactions.  This is a cheap way around the different flavors of sense instructions.



Modified: development/Avida.xcodeproj/project.pbxproj
===================================================================
--- development/Avida.xcodeproj/project.pbxproj	2008-02-08 19:37:08 UTC (rev 2316)
+++ development/Avida.xcodeproj/project.pbxproj	2008-02-08 21:09:31 UTC (rev 2317)
@@ -213,23 +213,6 @@
 		};
 /* End PBXBuildRule section */
 
-/* Begin PBXBuildStyle section */
-		B500C57F0D5CCA6600E31219 /* Development */ = {
-			isa = PBXBuildStyle;
-			buildSettings = {
-				COPY_PHASE_STRIP = NO;
-			};
-			name = Development;
-		};
-		B500C5800D5CCA6600E31219 /* Deployment */ = {
-			isa = PBXBuildStyle;
-			buildSettings = {
-				COPY_PHASE_STRIP = YES;
-			};
-			name = Deployment;
-		};
-/* End PBXBuildStyle section */
-
 /* Begin PBXContainerItemProxy section */
 		56F555DA0C3B36FC00E2E929 /* PBXContainerItemProxy */ = {
 			isa = PBXContainerItemProxy;
@@ -1801,12 +1784,6 @@
 		DCC30C4D0762532C008F7A48 /* Project object */ = {
 			isa = PBXProject;
 			buildConfigurationList = 702442D70859E0B00059BD9B /* Build configuration list for PBXProject "Avida" */;
-			buildSettings = {
-			};
-			buildStyles = (
-				B500C57F0D5CCA6600E31219 /* Development */,
-				B500C5800D5CCA6600E31219 /* Deployment */,
-			);
 			hasScannedForEncodings = 0;
 			mainGroup = DCC30C490762532C008F7A48;
 			productRefGroup = DCC3164E07626CF3008F7A48 /* Products */;

Modified: development/source/cpu/cHardwareCPU.cc
===================================================================
--- development/source/cpu/cHardwareCPU.cc	2008-02-08 19:37:08 UTC (rev 2316)
+++ development/source/cpu/cHardwareCPU.cc	2008-02-08 21:09:31 UTC (rev 2317)
@@ -29,6 +29,7 @@
 #include "cAvidaContext.h"
 #include "cCPUTestInfo.h"
 #include "functions.h"
+#include "cEnvironment.h"
 #include "cGenomeUtil.h"
 #include "cGenotype.h"
 #include "cHardwareManager.h"
@@ -42,6 +43,10 @@
 #include "cPhenotype.h"
 #include "cPopulation.h"
 #include "cPopulationCell.h"
+#include "cReaction.h"
+#include "cReactionLib.h"
+#include "cReactionProcess.h"
+#include "cResource.h"
 #include "cStringUtil.h"
 #include "cTestCPU.h"
 #include "cWorldDriver.h"
@@ -203,6 +208,7 @@
     tInstLibEntry<tMethod>("sense", &cHardwareCPU::Inst_SenseLog2, nInstFlag::STALL),           // If you add more sense instructions
     tInstLibEntry<tMethod>("sense-unit", &cHardwareCPU::Inst_SenseUnit, nInstFlag::STALL),      // and want to keep stats, also add
     tInstLibEntry<tMethod>("sense-m100", &cHardwareCPU::Inst_SenseMult100, nInstFlag::STALL),   // the names to cStats::cStats() @JEB
+    tInstLibEntry<tMethod>("if-resources", &cHardwareCPU::Inst_IfResources, nInstFlag::STALL),
     // Data collection
     tInstLibEntry<tMethod>("collect-cell-data", &cHardwareCPU::Inst_CollectCellData, nInstFlag::STALL),
 
@@ -3113,6 +3119,36 @@
   // Note that we are converting <double> resources to <int> register values
 }
 
+
+/*! Sense the level of resources in this organism's cell, and if all of the 
+resources present are above the min level for that resource, execute the following
+intruction.  Otherwise, skip the following instruction.
+*/
+bool cHardwareCPU::Inst_IfResources(cAvidaContext& ctx)
+{
+  // These are the current levels of resources at this cell:
+  const tArray<double>& resources = organism->GetOrgInterface().GetResources();
+
+  // Now we loop through the different reactions, checking to see if their
+  // required resources are below what's available.  If so, we skip ahead an
+  // instruction and return.
+  const cReactionLib& rxlib = m_world->GetEnvironment().GetReactionLib();
+  for(int i=0; i<rxlib.GetSize(); ++i) {
+    cReaction* rx = rxlib.GetReaction(i);
+    tLWConstListIterator<cReactionProcess> processes(rx->GetProcesses());
+    while(!processes.AtEnd()) {
+      const cReactionProcess* proc = processes.Next();
+      cResource* res = proc->GetResource(); // Infinite resource == 0.
+      if((res != 0) && (proc->GetMinNumber() < resources[res->GetID()])) {
+        IP().Advance();
+        return true;
+      }
+    }
+  }
+  return true;
+}
+
+
 bool cHardwareCPU::Inst_CollectCellData(cAvidaContext& ctx) {
   int cellID = organism->GetCellID();
   const int out_reg = FindModifiedRegister(REG_BX);
@@ -4673,6 +4709,7 @@
   return true;
 }
 
+
 //// Placebo insts ////
 bool cHardwareCPU::Inst_Skip(cAvidaContext& ctx)
 {

Modified: development/source/cpu/cHardwareCPU.h
===================================================================
--- development/source/cpu/cHardwareCPU.h	2008-02-08 19:37:08 UTC (rev 2316)
+++ development/source/cpu/cHardwareCPU.h	2008-02-08 21:09:31 UTC (rev 2317)
@@ -452,6 +452,8 @@
   bool Inst_SenseUnit(cAvidaContext& ctx);
   bool Inst_SenseMult100(cAvidaContext& ctx);
   bool DoSense(cAvidaContext& ctx, int conversion_method, double base);
+  //! Execute the following instruction if all resources are above their min level.
+  bool Inst_IfResources(cAvidaContext& ctx);
   bool Inst_CollectCellData(cAvidaContext& ctx);
 
   void DoDonate(cOrganism * to_org);

Modified: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc	2008-02-08 19:37:08 UTC (rev 2316)
+++ development/source/main/cPopulation.cc	2008-02-08 21:09:31 UTC (rev 2317)
@@ -120,6 +120,7 @@
   
   // Not yet supported:
   assert(m_world->GetConfig().DEMES_REPLICATE_SIZE.Get()==1);
+  assert(m_world->GetConfig().DEMES_HAVE_MERIT.Get()==0);
   
 #ifdef DEBUG
   const int birth_method = m_world->GetConfig().BIRTH_METHOD.Get();




More information about the Avida-cvs mailing list