[Avida-SVN] r3344 - in branches/interrupt: documentation source/actions source/cpu source/main

beckma24 at myxo.css.msu.edu beckma24 at myxo.css.msu.edu
Thu Jun 25 14:37:46 PDT 2009


Author: beckma24
Date: 2009-06-25 17:37:46 -0400 (Thu, 25 Jun 2009)
New Revision: 3344

Modified:
   branches/interrupt/documentation/environment.html
   branches/interrupt/source/actions/EnvironmentActions.cc
   branches/interrupt/source/cpu/cHardwareCPU.cc
   branches/interrupt/source/cpu/cHardwareCPU.h
   branches/interrupt/source/main/cDeme.h
   branches/interrupt/source/main/cPopulation.cc
Log:
merged development r3300:HEAD into interrupt branch.  All tests pass.  Interrupt branch is inline with development./run_tests --builddir=./build/Development/ !  But should NOT be merged into development.

Modified: branches/interrupt/documentation/environment.html
===================================================================
--- branches/interrupt/documentation/environment.html	2009-06-25 21:32:26 UTC (rev 3343)
+++ branches/interrupt/documentation/environment.html	2009-06-25 21:37:46 UTC (rev 3344)
@@ -135,8 +135,7 @@
 <tr>
   <td class="resall">energy</td>
   <td>
-    Is this an energy resource. Currently, only implemented for
-    spacial resources, and the energy model must be used.
+    Is this an energy resource. The energy model must be used.
     (<em>True</em> or <em>False</em>)
   </td>
   <td>
@@ -566,6 +565,7 @@
     <br />&nbsp;&nbsp;&nbsp;<em>enzyme</em>: Add bonus * resource / (resource + frac) to the current merit.
     	This is gives a Michaelis-Menten enzyme type reward where bonus is the K<sub>cat</sub>
     	and frac is the K<sub>m</sub>. Does not work with unlimited resources.
+    <br />&nbsp;&nbsp;&nbsp;<em>energy</em>: Add the bonus energy to the organism's energy waiting to be applied buffer.  Bonus energy can be applied on completion of a reaction, execution of the sleep/eat instruction, or when the organisms divides.  See <a href="energy_model.html">Energy Model</a> documentation for more information.
   </td>
   <td>add</td>
 </tr>

Modified: branches/interrupt/source/actions/EnvironmentActions.cc
===================================================================
--- branches/interrupt/source/actions/EnvironmentActions.cc	2009-06-25 21:32:26 UTC (rev 3343)
+++ branches/interrupt/source/actions/EnvironmentActions.cc	2009-06-25 21:37:46 UTC (rev 3344)
@@ -153,6 +153,36 @@
   }
 };
 
+class cActionSetDemeResource : public cAction
+	{
+	private:
+		cString m_res_name;
+		double m_res_count;
+		
+	public:
+		cActionSetDemeResource(cWorld* world, const cString& args) : cAction(world, args), m_res_name(""), m_res_count(0.0)
+		{
+			cString largs(args);
+			if (largs.GetSize()) m_res_name = largs.PopWord();
+			if (largs.GetSize()) m_res_count = largs.PopWord().AsDouble();
+		}
+		
+		static const cString GetDescription() { return "Arguments: <string res_name> <double res_count>"; }
+		
+		void Process(cAvidaContext& ctx)
+		{
+			cResource* res = m_world->GetEnvironment().GetResourceLib().GetResource(m_res_name);
+			if (res != NULL) {
+				cPopulation& pop = m_world->GetPopulation();
+				int numDemes =  pop.GetNumDemes();
+				for(int demeID = 0; demeID < numDemes; ++demeID) {
+					cDeme& deme = pop.GetDeme(demeID);
+					deme.SetResource(res->GetID(), m_res_count);
+				}
+			}
+		}
+	};
+
 class cZeroResources : public cAction
 {
 private:
@@ -981,6 +1011,7 @@
   action_lib->Register<cActionInjectScaledResource>("InjectScaledResource");
   action_lib->Register<cActionOutflowScaledResource>("OutflowScaledResource");
   action_lib->Register<cActionSetResource>("SetResource");
+  action_lib->Register<cActionSetDemeResource>("SetDemeResource");
   action_lib->Register<cZeroResources>("ZeroResources");
   action_lib->Register<cActionSetCellResource>("SetCellResource");
   action_lib->Register<cActionChangeEnvironment>("ChangeEnvironment");

Modified: branches/interrupt/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/interrupt/source/cpu/cHardwareCPU.cc	2009-06-25 21:32:26 UTC (rev 3343)
+++ branches/interrupt/source/cpu/cHardwareCPU.cc	2009-06-25 21:37:46 UTC (rev 3344)
@@ -771,6 +771,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),
@@ -7707,7 +7708,7 @@
   cDeme &deme = pop.GetDeme(pop.GetCell(cellid).GetDemeID());
   int relative_cell_id = deme.GetRelativeCellID(cellid);
 	
-  cResourceCount deme_resource_count = deme.GetDemeResourceCount();
+  const cResourceCount& deme_resource_count = deme.GetDemeResourceCount();
   tArray<double> cell_resources = deme_resource_count.GetCellResources(relative_cell_id);
   double pher_amount = 0;
 	
@@ -7728,6 +7729,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());
+	const 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
@@ -7755,6 +7776,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: branches/interrupt/source/cpu/cHardwareCPU.h
===================================================================
--- branches/interrupt/source/cpu/cHardwareCPU.h	2009-06-25 21:32:26 UTC (rev 3343)
+++ branches/interrupt/source/cpu/cHardwareCPU.h	2009-06-25 21:37:46 UTC (rev 3344)
@@ -874,8 +874,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: branches/interrupt/source/main/cDeme.h
===================================================================
--- branches/interrupt/source/main/cDeme.h	2009-06-25 21:32:26 UTC (rev 3343)
+++ branches/interrupt/source/main/cDeme.h	2009-06-25 21:37:46 UTC (rev 3344)
@@ -261,6 +261,7 @@
 	void OrganismDeath(cPopulationCell& cell);
   
   const cResourceCount& GetDemeResourceCount() const { return deme_resource_count; }
+	void SetResource(int id, double new_level) { deme_resource_count.Set(id, new_level); }
   double GetSpatialResource(int rel_cellid, int resource_id) const;
   void AdjustSpatialResource(int rel_cellid, int resource_id, double amount);
   void AdjustResource(int resource_id, double amount);

Modified: branches/interrupt/source/main/cPopulation.cc
===================================================================
--- branches/interrupt/source/main/cPopulation.cc	2009-06-25 21:32:26 UTC (rev 3343)
+++ branches/interrupt/source/main/cPopulation.cc	2009-06-25 21:37:46 UTC (rev 3344)
@@ -3948,13 +3948,15 @@
   m_world->GetStats().IncExecuted();
   resource_count.Update(step_size);
   
-  // Deme specific
-  if (GetNumDemes() > 1)
+	// these must be done even if there is only one deme.
+	for(int i = 0; i < GetNumDemes(); i++)
+		GetDeme(i).Update(step_size);
+    
+	cDeme & deme = GetDeme(GetCell(cell_id).GetDemeID());
+	deme.IncTimeUsed(merit);
+  
+  if (GetNumDemes() >= 1)
   {
-    for(int i = 0; i < GetNumDemes(); i++) GetDeme(i).Update(step_size);
-    
-    cDeme & deme = GetDeme(GetCell(cell_id).GetDemeID());
-    deme.IncTimeUsed(merit);
     CheckImplicitDemeRepro(deme);
   }
 }
@@ -4015,10 +4017,15 @@
 // Loop through all the demes getting stats and doing calculations
 // which must be done on a deme by deme basis.
 void cPopulation::UpdateDemeStats() {
-  
+
+	// these must be updated, even if there is only one deme
+	for(int i = 0; i < GetNumDemes(); i++) {
+    GetDeme(i).UpdateDemeRes();
+  }
+	
   // bail early to save time if there are no demes
   if (GetNumDemes() == 1) return ;
-  
+	
   cStats& stats = m_world->GetStats();
   
   stats.SumDemeAge().Clear();
@@ -4246,12 +4253,6 @@
   stats.SetResources(resource_count.GetResources());
   stats.SetSpatialRes(resource_count.GetSpatialRes());
   stats.SetResourcesGeometry(resource_count.GetResourcesGeometry());
-  
-  //TODO: update deme resource  (what calls DoOutput)
-  
-  for(int i = 0; i < GetNumDemes(); i++) {
-    GetDeme(i).UpdateDemeRes();
-  }
 }
 
 




More information about the Avida-cvs mailing list