[Avida-SVN] r1770 - in branches/collect/source: cpu main

blwalker at myxo.css.msu.edu blwalker at myxo.css.msu.edu
Tue Jul 10 08:22:01 PDT 2007


Author: blwalker
Date: 2007-07-10 11:22:01 -0400 (Tue, 10 Jul 2007)
New Revision: 1770

Modified:
   branches/collect/source/cpu/cHardwareCPU.cc
   branches/collect/source/main/cAvidaConfig.h
   branches/collect/source/main/cOrganism.cc
   branches/collect/source/main/cOrganism.h
Log:

Added an option to cap the total amount of resources an organism can store.


Modified: branches/collect/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/collect/source/cpu/cHardwareCPU.cc	2007-07-10 14:09:29 UTC (rev 1769)
+++ branches/collect/source/cpu/cHardwareCPU.cc	2007-07-10 15:22:01 UTC (rev 1770)
@@ -3166,15 +3166,18 @@
     }
   }
 
-  // Set up res_change and add resources to rbins
+  // Set up res_change and max total
   const tArray<double> res_count = organism->GetOrgInterface().GetResources();
   tArray<double> res_change(res_count.GetSize());
+  double total = organism->GetRBinsTotal();
+  double max = m_world->GetConfig().MAX_TOTAL_STORED.Get();
 
+	// Add resources to rbins if this does not put the organism over the maximum total allowed
   if(bin_used >= 0)
   {
     res_change[bin_used] = -1 * (res_count[bin_used] * m_world->GetConfig().ABSORB_RESOURCE_FRACTION.Get());
-    organism->AddToRBin(bin_used, -1 * res_change[bin_used]);
-//cout << "bin" << bin_used << ": " << organism->GetRBin(bin_used) << endl;
+    if(max < 0 || (total + -1 * res_change[bin_used]) <= max)
+    {organism->AddToRBin(bin_used, -1 * res_change[bin_used]);}
   }
   else
   {
@@ -3182,8 +3185,8 @@
     for(int i = start_bin; i <= end_bin; i++)
     {
       res_change[i] = -1 * (res_count[bin_used] * m_world->GetConfig().ABSORB_RESOURCE_FRACTION.Get() / num_bins);
-      organism->AddToRBin(i, -1 * res_change[i]);    
-//cout << "multibin" << i << ": " << organism->GetRBin(i) << endl;
+      if(max < 0 || (total + -1 * res_change[i]) <= max)
+      {organism->AddToRBin(i, -1 * res_change[i]);}    
     }
   }
   

Modified: branches/collect/source/main/cAvidaConfig.h
===================================================================
--- branches/collect/source/main/cAvidaConfig.h	2007-07-10 14:09:29 UTC (rev 1769)
+++ branches/collect/source/main/cAvidaConfig.h	2007-07-10 15:22:01 UTC (rev 1770)
@@ -348,6 +348,7 @@
   CONFIG_ADD_VAR(USE_RESOURCE_BINS, bool, 0, "Use resources stored in resource bins.  Unless the collect instruction is availible to the organisms, this will have no effect on organism behavior.  (Even when on, this only happens when there is no appropriate resource in the environment.)  Also controls output of resource bin contents, so you aren't bothered with them if you're not using them.");
   CONFIG_ADD_VAR(ABSORB_RESOURCE_FRACTION, double, .0025, "Fraction of available environmental resource an organism absorbs with the collect command");
   CONFIG_ADD_VAR(MULTI_ABSORB_TYPE, int, 0, "What to do if collect is called on a range of resources.\n 0 = absorb a random resource in the range\n 1 = absorb the first resource in the range\n 2 = absorb the last resource in the range\n 3 = absorb ABSORB_RESOURCE_FRACTION / (# of resources in range) of each resource in the range");
+  CONFIG_ADD_VAR(MAX_TOTAL_STORED, double, -1, "Maximum total amount of all resources an organism can store.\n <0 = no maximum");
   CONFIG_ADD_VAR(USE_STORED_FRACTION, double, 1.0, "The fraction of stored resource to use when there is no environmental resource available");
   CONFIG_ADD_VAR(RETURN_STORED_ON_DEATH, bool, 1, "Return an organism's stored resources to the world when it dies");
   

Modified: branches/collect/source/main/cOrganism.cc
===================================================================
--- branches/collect/source/main/cOrganism.cc	2007-07-10 14:09:29 UTC (rev 1769)
+++ branches/collect/source/main/cOrganism.cc	2007-07-10 15:22:01 UTC (rev 1770)
@@ -115,6 +115,15 @@
   m_interface = interface;
 }
 
+double cOrganism::GetRBinsTotal()
+{
+	double total = 0;
+	for(int i = 0; i < m_rbins.GetSize(); i++)
+	{total += m_rbins[i];}
+	
+	return total;
+}
+
 void cOrganism::SetRBins(const tArray<double>& rbins_in) 
 { 
 	m_rbins = rbins_in;

Modified: branches/collect/source/main/cOrganism.h
===================================================================
--- branches/collect/source/main/cOrganism.h	2007-07-10 14:09:29 UTC (rev 1769)
+++ branches/collect/source/main/cOrganism.h	2007-07-10 15:22:01 UTC (rev 1770)
@@ -170,6 +170,7 @@
 	const tArray<double>& GetRBins() const { return m_rbins; }
   tArray<double>& GetRBins() { return m_rbins; }
   double GetRBin(int index) { return m_rbins[index]; }
+  double GetRBinsTotal();
   void SetRBins(const tArray<double>& rbins_in);
   void SetRBin(const int index, const double value);
   void AddToRBin(const int index, const double value);




More information about the Avida-cvs mailing list