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

beckma24 at myxo.css.msu.edu beckma24 at myxo.css.msu.edu
Fri Aug 28 08:05:34 PDT 2009


Author: beckma24
Date: 2009-08-28 11:05:34 -0400 (Fri, 28 Aug 2009)
New Revision: 3389

Modified:
   development/source/cpu/cHardwareCPU.cc
   development/source/cpu/cHardwareCPU.h
Log:
Adding some heavy handed conditional instructions: if-aboveResLevel and if-notAboveResLevel

Modified: development/source/cpu/cHardwareCPU.cc
===================================================================
--- development/source/cpu/cHardwareCPU.cc	2009-08-28 03:53:03 UTC (rev 3388)
+++ development/source/cpu/cHardwareCPU.cc	2009-08-28 15:05:34 UTC (rev 3389)
@@ -108,6 +108,9 @@
     tInstLibEntry<tMethod>("if-bit-1", &cHardwareCPU::Inst_IfBit1),
     tInstLibEntry<tMethod>("if-grt-X", &cHardwareCPU::Inst_IfGrX),
     tInstLibEntry<tMethod>("if-equ-X", &cHardwareCPU::Inst_IfEquX),
+		
+		tInstLibEntry<tMethod>("if-aboveResLevel", &cHardwareCPU::Inst_IfAboveResLevel),
+		tInstLibEntry<tMethod>("if-notAboveResLevel", &cHardwareCPU::Inst_IfNotAboveResLevel),
 
 		// Probabilistic ifs.
 		tInstLibEntry<tMethod>("if-p-0.125", &cHardwareCPU::Inst_IfP0p125, nInstFlag::STALL),
@@ -2075,7 +2078,54 @@
   return true;
 }
 
+bool cHardwareCPU::Inst_IfAboveResLevel(cAvidaContext& ctx) {
+	const double resCrossoverLevel = 100;
+	
+	const cResourceLib& resLib = m_world->GetEnvironment().GetResourceLib();
+	
+	const tArray<double>& resource_count_array =  GetOrganism()->GetOrgInterface().GetResources(); 
+	const cResourceCount& resource_count = m_world->GetPopulation().GetResourceCount();
+	
+	if(resource_count.GetSize() == 0) assert(false); // change to: return false;
+	
+	double pher_amount = 0;
+	cResource* res = resLib.GetResource("pheromone");
+	
+	if(strncmp(resource_count.GetResName(res->GetID()), "pheromone", 9) == 0) {
+		pher_amount += resource_count_array[res->GetID()];
+	}
+	
+	if(pher_amount > resCrossoverLevel) {
+		IP().Advance();
+	}
+		
+	return true;
+}
 
+bool cHardwareCPU::Inst_IfNotAboveResLevel(cAvidaContext& ctx) {
+	const double resCrossoverLevel = 100;
+	
+	const cResourceLib& resLib = m_world->GetEnvironment().GetResourceLib();
+	
+	const tArray<double>& resource_count_array =  GetOrganism()->GetOrgInterface().GetResources(); 
+	const cResourceCount& resource_count = m_world->GetPopulation().GetResourceCount();
+	
+	if(resource_count.GetSize() == 0) assert(false); // change to: return false;
+	
+	double pher_amount = 0;
+	cResource* res = resLib.GetResource("pheromone");
+	
+	if(strncmp(resource_count.GetResName(res->GetID()), "pheromone", 9) == 0) {
+		pher_amount += resource_count_array[res->GetID()];
+	}
+	
+	if(pher_amount <= resCrossoverLevel) {
+		IP().Advance();
+	}
+	
+	return true;
+}
+
 bool cHardwareCPU::Inst_IfP0p125(cAvidaContext& ctx) {
 	if(m_world->GetRandom().P(0.875)) {
 		IP().Advance();

Modified: development/source/cpu/cHardwareCPU.h
===================================================================
--- development/source/cpu/cHardwareCPU.h	2009-08-28 03:53:03 UTC (rev 3388)
+++ development/source/cpu/cHardwareCPU.h	2009-08-28 15:05:34 UTC (rev 3389)
@@ -345,6 +345,9 @@
   bool Inst_IfANotEqC(cAvidaContext& ctx);
   bool Inst_IfGrX(cAvidaContext& ctx);
   bool Inst_IfEquX(cAvidaContext& ctx);
+	
+	bool Inst_IfAboveResLevel(cAvidaContext& ctx);
+	bool Inst_IfNotAboveResLevel(cAvidaContext& ctx);
 
 	// Probabilistic ifs.
 	bool Inst_IfP0p125(cAvidaContext& ctx);




More information about the Avida-cvs mailing list