[Avida-SVN] r3326 - in development/source: cpu main

beckma24 at myxo.css.msu.edu beckma24 at myxo.css.msu.edu
Fri Jun 19 11:07:52 PDT 2009


Author: beckma24
Date: 2009-06-19 14:07:51 -0400 (Fri, 19 Jun 2009)
New Revision: 3326

Modified:
   development/source/cpu/cHardwareCPU.cc
   development/source/cpu/cHardwareCPU.h
   development/source/main/cPopulation.cc
Log:
BUG FIX: when a single deme is used that deme's update function was skipped at the end of an update.  Also added instruction sense-pheromone-inDemeGlobal

Modified: development/source/cpu/cHardwareCPU.cc
===================================================================
--- development/source/cpu/cHardwareCPU.cc	2009-06-19 17:45:46 UTC (rev 3325)
+++ development/source/cpu/cHardwareCPU.cc	2009-06-19 18:07:51 UTC (rev 3326)
@@ -507,6 +507,7 @@
     tInstLibEntry<tMethod>("sensef-m100", &cHardwareCPU::Inst_SenseMult100Facing),
     tInstLibEntry<tMethod>("sense-pheromone", &cHardwareCPU::Inst_SensePheromone),
     tInstLibEntry<tMethod>("sense-pheromone-faced", &cHardwareCPU::Inst_SensePheromoneFaced),
+    tInstLibEntry<tMethod>("sense-pheromone-inDemeGlobal", &cHardwareCPU::Inst_SensePheromoneInDemeGlobal),
     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),
@@ -6972,6 +6973,26 @@
 
 } //End DoSensePheromone()
 
+bool cHardwareCPU::DoSensePheromoneInDemeGlobal(cAvidaContext& ctx) {
+	if(m_organism->GetCellID() == -1) {
+		return false;
+	}
+	int reg_to_set = FindModifiedRegister(REG_BX);
+  cDeme& deme = m_world->GetPopulation().GetDeme(m_organism->GetDemeID());
+	cResourceCount deme_resource_count = deme.GetDemeResourceCount();
+
+	if(deme_resource_count.GetSize() == 0) assert(false); // change to: return false;
+	
+	double pher_amount = 0;
+	for (int i = 0; i < deme_resource_count.GetSize(); i++) {
+    if(strncmp(deme_resource_count.GetResName(i), "pheromone", 9) == 0) {
+      pher_amount += deme_resource_count.Get(i);
+    }
+  }
+	GetRegister(reg_to_set) = (int)floor(pher_amount + 0.5);
+	return true;
+}
+
 bool cHardwareCPU::Inst_SensePheromone(cAvidaContext& ctx)
 {
   int cellid = m_organism->GetCellID(); //absolute id of current cell
@@ -6999,6 +7020,10 @@
   return DoSensePheromone(ctx, fcellid);
 } //End Inst_SensePheromoneFacing()
 
+bool cHardwareCPU::Inst_SensePheromoneInDemeGlobal(cAvidaContext& ctx) {
+	return DoSensePheromoneInDemeGlobal(ctx);
+}
+
 bool cHardwareCPU::Inst_Exploit(cAvidaContext& ctx)
 {
   int num_rotations = 0;

Modified: development/source/cpu/cHardwareCPU.h
===================================================================
--- development/source/cpu/cHardwareCPU.h	2009-06-19 17:45:46 UTC (rev 3325)
+++ development/source/cpu/cHardwareCPU.h	2009-06-19 18:07:51 UTC (rev 3326)
@@ -773,8 +773,10 @@
   bool Inst_SenseTarget(cAvidaContext& ctx);
   bool Inst_SenseTargetFaced(cAvidaContext& ctx);
   bool DoSensePheromone(cAvidaContext& ctx, int cellid);
+	bool DoSensePheromoneInDemeGlobal(cAvidaContext& ctx);
   bool Inst_SensePheromone(cAvidaContext& ctx);
   bool Inst_SensePheromoneFaced(cAvidaContext& ctx);
+	bool Inst_SensePheromoneInDemeGlobal(cAvidaContext& ctx);
   bool Inst_Exploit(cAvidaContext& ctx);
   bool Inst_ExploitForward5(cAvidaContext& ctx);
   bool Inst_ExploitForward3(cAvidaContext& ctx);

Modified: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc	2009-06-19 17:45:46 UTC (rev 3325)
+++ development/source/main/cPopulation.cc	2009-06-19 18:07:51 UTC (rev 3326)
@@ -3788,7 +3788,7 @@
   resource_count.Update(step_size);
   
   // Deme specific
-  if (GetNumDemes() > 1)
+  if (GetNumDemes() >= 1)
   {
     for(int i = 0; i < GetNumDemes(); i++) GetDeme(i).Update(step_size);
     




More information about the Avida-cvs mailing list