[Avida-SVN] r1870 - in branches/energy_dev/source: main tools

beckma24 at myxo.css.msu.edu beckma24 at myxo.css.msu.edu
Mon Jul 30 12:23:18 PDT 2007


Author: beckma24
Date: 2007-07-30 15:23:18 -0400 (Mon, 30 Jul 2007)
New Revision: 1870

Modified:
   branches/energy_dev/source/main/cDeme.cc
   branches/energy_dev/source/main/cOrganism.cc
   branches/energy_dev/source/main/cPopulation.cc
   branches/energy_dev/source/main/cResource.cc
   branches/energy_dev/source/main/cResourceCount.cc
   branches/energy_dev/source/main/cResourceCount.h
   branches/energy_dev/source/tools/tArray.h
Log:
Fixed bug in deme-level resource spec. Added + and subset methods to tArray.  Setup task checking for tasks that use deme level resources

Modified: branches/energy_dev/source/main/cDeme.cc
===================================================================
--- branches/energy_dev/source/main/cDeme.cc	2007-07-30 16:59:42 UTC (rev 1869)
+++ branches/energy_dev/source/main/cDeme.cc	2007-07-30 19:23:18 UTC (rev 1870)
@@ -61,6 +61,8 @@
 {
   birth_count = 0; 
   _age = 0;
+  
+  deme_resource_count.ReinitializeResources();
 }
 
 /*void cDeme::ResetResources() {

Modified: branches/energy_dev/source/main/cOrganism.cc
===================================================================
--- branches/energy_dev/source/main/cOrganism.cc	2007-07-30 16:59:42 UTC (rev 1869)
+++ branches/energy_dev/source/main/cOrganism.cc	2007-07-30 19:23:18 UTC (rev 1870)
@@ -228,12 +228,22 @@
   
   cTaskContext taskctx(m_interface, input_buffer, output_buffer, other_input_list, 
                        other_output_list, net_valid, 0, on_divide, received_messages_point);
-  bool task_completed = m_phenotype.TestOutput(ctx, taskctx, global_resource_count, global_res_change, insts_triggered);
+                       
+  //combine global and deme resource counts
+  const tArray<double> globalAndDeme_resource_count = global_resource_count + deme_resource_count;
+  tArray<double> globalAndDeme_res_change = global_res_change + deme_res_change;
   
-  if(deme_resource_count.GetSize() > 0) {
+  bool task_completed = m_phenotype.TestOutput(ctx, taskctx, globalAndDeme_resource_count, globalAndDeme_res_change, insts_triggered);
+//  bool task_completed = m_phenotype.TestOutput(ctx, taskctx, global_resource_count, global_res_change, insts_triggered);
+  
+  //disassemble global and deme resource counts
+  global_res_change = globalAndDeme_res_change.Subset(0, global_res_change.GetSize());
+  deme_res_change = globalAndDeme_res_change.Subset(global_res_change.GetSize(), globalAndDeme_res_change.GetSize());
+  
+/*  if(deme_resource_count.GetSize() > 0) {
     // deme task checking
     task_completed = m_phenotype.TestOutput(ctx, taskctx, deme_resource_count, deme_res_change, insts_triggered) || task_completed;
-  }
+  }*/
   
   if(m_world->GetConfig().ENERGY_ENABLED.Get() && m_world->GetConfig().APPLY_ENERGY_METHOD.Get() == 1 && task_completed) {
     m_phenotype.RefreshEnergy();

Modified: branches/energy_dev/source/main/cPopulation.cc
===================================================================
--- branches/energy_dev/source/main/cPopulation.cc	2007-07-30 16:59:42 UTC (rev 1869)
+++ branches/energy_dev/source/main/cPopulation.cc	2007-07-30 19:23:18 UTC (rev 1870)
@@ -195,14 +195,14 @@
   for(int i = 0; i < GetNumDemes(); i++) {
     cResourceCount tmp_deme_res_count(num_deme_res);
     GetDeme(i).GetDemeResourceCount() = tmp_deme_res_count;
-    //TODO: make sure grid is the right grid GetDeme(i).GetDemeResourceCount().ResizeSpatialGrids(world_x, world_y);
+    //TODO: make sure grid is the right grid
+    GetDeme(i).GetDemeResourceCount().ResizeSpatialGrids(world_x, world_y);
   }
 
   for (int i = 0; i < resource_lib.GetSize(); i++) {
     cResource * res = resource_lib.GetResource(i);
     if (!res->GetDemeResource()) {
       global_res_index++;
-      cerr<<global_res_index << " " << i <<endl;
       const double decay = 1.0 - res->GetOutflow();
       resource_count.Setup(global_res_index, res->GetName(), res->GetInitial(), 
                            res->GetInflow(), decay,

Modified: branches/energy_dev/source/main/cResource.cc
===================================================================
--- branches/energy_dev/source/main/cResource.cc	2007-07-30 16:59:42 UTC (rev 1869)
+++ branches/energy_dev/source/main/cResource.cc	2007-07-30 19:23:18 UTC (rev 1870)
@@ -95,10 +95,10 @@
 
 {
   _deme_resource.ToLower();
-  if ((_deme_resource == "false") || (_deme_resource = "0")) {
+  if ((_deme_resource == "false") || (_deme_resource == "0")) {
     deme_resource = false;
     return(true);
-  } else if ((_deme_resource == "true") || (_deme_resource = "1")) {
+  } else if ((_deme_resource == "true") || (_deme_resource == "1")) {
     deme_resource = true;
     return(true);
   } else {

Modified: branches/energy_dev/source/main/cResourceCount.cc
===================================================================
--- branches/energy_dev/source/main/cResourceCount.cc	2007-07-30 16:59:42 UTC (rev 1869)
+++ branches/energy_dev/source/main/cResourceCount.cc	2007-07-30 19:23:18 UTC (rev 1870)
@@ -24,6 +24,7 @@
  */
 
 #include "cResourceCount.h"
+#include "cResource.h"
 
 #include "nGeometry.h"
 
@@ -114,6 +115,8 @@
 }
 
 const cResourceCount &cResourceCount::operator=(const cResourceCount &rc) {
+  resource_name = rc.resource_name;
+  resource_initial = rc.resource_initial;
   resource_count = rc.resource_count;
   decay_rate = rc.decay_rate;
   inflow_rate = rc.inflow_rate;
@@ -131,6 +134,8 @@
 
 void cResourceCount::SetSize(int num_resources)
 {
+  resource_name.ResizeClear(num_resources);
+  resource_initial.ResizeClear(num_resources);
   resource_count.ResizeClear(num_resources);
   decay_rate.ResizeClear(num_resources);
   inflow_rate.ResizeClear(num_resources);
@@ -143,6 +148,8 @@
   curr_grid_res_cnt.ResizeClear(num_resources);
   curr_spatial_res_cnt.ResizeClear(num_resources);
 
+  resource_name.SetAll("");
+  resource_initial.SetAll(0.0);
   resource_count.SetAll(0.0);
   decay_rate.SetAll(0.0);
   inflow_rate.SetAll(0.0);
@@ -206,8 +213,8 @@
 
 
   /* If the verbose flag is set print out information about resources */
-
-  if (verbosity_level > VERBOSE_NORMAL) {
+  verbosity = verbosity_level;
+  if (verbosity > VERBOSE_NORMAL) {
     cout << "Setting up resource " << name
          << "(" << geo_name 
          << ") with initial quatity=" << initial
@@ -233,6 +240,8 @@
     }   
   }
 
+  resource_name[id] = name;
+  resource_initial[id] = initial;
   resource_count[id] = initial;
   spatial_resource_count[id].RateAll
                               (initial/spatial_resource_count[id].GetSize());
@@ -424,3 +433,9 @@
     }
   }
 }
+
+void cResourceCount::ReinitializeResources(){
+  for(int i = 0; i < resource_name.GetSize(); i++) {
+    Set(i, resource_initial[i]);
+  }
+}

Modified: branches/energy_dev/source/main/cResourceCount.h
===================================================================
--- branches/energy_dev/source/main/cResourceCount.h	2007-07-30 16:59:42 UTC (rev 1869)
+++ branches/energy_dev/source/main/cResourceCount.h	2007-07-30 19:23:18 UTC (rev 1870)
@@ -45,6 +45,8 @@
 class cResourceCount
 {
 private:
+  mutable tArray<cString> resource_name;
+  mutable tArray<double> resource_initial;  // Initial quantity of each resource
   mutable tArray<double> resource_count;  // Current quantity of each resource
   tArray<double> decay_rate;      // Multiplies resource count at each step
   tArray<double> inflow_rate;     // An increment for resource at each step
@@ -54,6 +56,7 @@
   mutable tArray<cSpatialResCount> spatial_resource_count;
   mutable tArray<double> curr_grid_res_cnt;
   mutable tArray< tArray<double> > curr_spatial_res_cnt;
+  int verbosity;
 
   // Setup the update process to use lazy evaluation...
   mutable double update_time;     // Portion of an update compleated...
@@ -101,9 +104,11 @@
   }
   void ResizeSpatialGrids(int in_x, int in_y);
   cSpatialResCount GetSpatialResource(int id) { return spatial_resource_count[id]; }
+  void ReinitializeResources();
 };
 
 
+
 #ifdef ENABLE_UNIT_TESTS
 namespace nResourceCount {
   /**

Modified: branches/energy_dev/source/tools/tArray.h
===================================================================
--- branches/energy_dev/source/tools/tArray.h	2007-07-30 16:59:42 UTC (rev 1869)
+++ branches/energy_dev/source/tools/tArray.h	2007-07-30 19:23:18 UTC (rev 1870)
@@ -75,6 +75,30 @@
     return *this;
   }
 
+  tArray operator+(const tArray in) const {
+    tArray tmp(0);
+    for(int i = 0; i < GetSize(); i++) {
+      tmp.Push(m_data[i]);
+    }
+    
+    for(int i = 0; i < in.GetSize(); i++) {
+      tmp.Push(in[i]);
+    }
+    return tmp;
+  }
+  
+  tArray Subset(int start, int end) {
+    assert(start <= end);
+    assert(0 <= start && start <= GetSize());
+    assert(0 <= end && end <= GetSize());
+    
+    tArray tmp(0);
+    for(int i = start; i < end; i++) {
+      tmp.Push(m_data[i]);
+    }
+    return tmp;
+  }
+  
   bool Good() const { return (m_data != NULL); }
   int GetSize() const { return m_size; }
 




More information about the Avida-cvs mailing list