[Avida-SVN] r3210 - development/source/main
blwalker at myxo.css.msu.edu
blwalker at myxo.css.msu.edu
Thu Apr 16 12:59:43 PDT 2009
Author: blwalker
Date: 2009-04-16 15:59:43 -0400 (Thu, 16 Apr 2009)
New Revision: 3210
Modified:
development/source/main/cEnvironment.cc
Log:
Fixing several bugs that made internal resources unusable when there were no external resources. Boy do I feel silly.
Modified: development/source/main/cEnvironment.cc
===================================================================
--- development/source/main/cEnvironment.cc 2009-04-16 16:01:18 UTC (rev 3209)
+++ development/source/main/cEnvironment.cc 2009-04-16 19:59:43 UTC (rev 3210)
@@ -1149,9 +1149,6 @@
// Otherwise we're using a finite resource
const int res_id = in_resource->GetID();
- bool may_use_rbins = m_world->GetConfig().USE_RESOURCE_BINS.Get();
- bool using_rbins = false; //default: not using resource bins
-
// check to see if the value of this resource was set to 0 for this cell
if (resource_count[res_id]==0) {
consumed = 0;
@@ -1161,29 +1158,34 @@
consumed = resource_count[res_id] - result.GetConsumed(res_id);
consumed *= cur_process->GetMaxFraction();
assert(consumed >= 0.0);
+ }
+
+ bool may_use_rbins = m_world->GetConfig().USE_RESOURCE_BINS.Get();
+ bool using_rbins = false; //default: not using resource bins
+
+ if (may_use_rbins) assert(rbins_count.GetSize() > res_id);
- if (may_use_rbins) assert(rbins_count.GetSize() > res_id);
+ /* Check to see if we do want to use this resource from a bin instead of the environment:
+ * - Can we use the resource bins?
+ * - Is there anything in the bin for this resource?
+ * - Is the usable fraction in the bin strictly greater than the threshold fraction
+ * of what we could consume from the outside environment?
+ */
+ if (may_use_rbins && rbins_count[res_id] > 0 &&
+ (m_world->GetConfig().USE_STORED_FRACTION.Get() * rbins_count[res_id]) >
+ (m_world->GetConfig().ENV_FRACTION_THRESHOLD.Get() * consumed)
+ ) {
+ consumed = m_world->GetConfig().USE_STORED_FRACTION.Get() * rbins_count[res_id];
+ using_rbins = true;
+ }
- /* Check to see if we do want to use this resource from a bin instead of the environment:
- * - Can we use the resource bins?
- * - Is there anything in the bin for this resource?
- * - Is the usable fraction in the bin strictly greater than the threshold fraction
- * of what we could consume from the outside environment?
- */
- if (may_use_rbins && rbins_count[res_id] > 0 &&
- (m_world->GetConfig().USE_STORED_FRACTION.Get() * rbins_count[res_id]) >
- (m_world->GetConfig().ENV_FRACTION_THRESHOLD.Get() * consumed)
- ) {
- consumed = m_world->GetConfig().USE_STORED_FRACTION.Get() * rbins_count[res_id];
- using_rbins = true;
- }
+ // Make sure we're not above the maximum consumption.
+ if (consumed > max_consumed) consumed = max_consumed;
+
+ // Multiply by task_quality
+ assert((task_quality >= 0.0) && (task_quality <= 1.0));
+ consumed *= task_quality; // modify consumed based on task quality
- // Make sure we're not above the maximum consumption.
- if (consumed > max_consumed) consumed = max_consumed;
-
- assert((task_quality >= 0.0) && (task_quality <= 1.0));
- consumed *= task_quality; // modify consumed based on task quality
- }
// Test if we are below the minimum consumption.
if (consumed < min_consumed) consumed = 0.0;
@@ -1191,7 +1193,8 @@
if (consumed == 0.0) continue;
// Can't consume more resource than what's available.
- consumed = std::min(consumed, resource_count[res_id]);
+ if (!using_rbins) consumed = std::min(consumed, resource_count[res_id]);
+ else consumed = std::min(consumed, rbins_count[res_id]);
// Mark in the results the resource consumed.
if (cur_process->GetDepletable()) {
More information about the Avida-cvs
mailing list