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

blwalker at myxo.css.msu.edu blwalker at myxo.css.msu.edu
Tue Mar 27 09:27:20 PDT 2007


Author: blwalker
Date: 2007-03-27 12:27:20 -0400 (Tue, 27 Mar 2007)
New Revision: 1434

Modified:
   branches/collect/source/cpu/cHardwareCPU.cc
   branches/collect/source/cpu/cHardwareCPU.h
   branches/collect/source/main/cAvidaConfig.h
   branches/collect/source/main/cEnvironment.cc
   branches/collect/source/main/cEnvironment.h
   branches/collect/source/main/cOrganism.cc
   branches/collect/source/main/cOrganism.h
   branches/collect/source/main/cPhenotype.cc
   branches/collect/source/main/cPhenotype.h
Log:
Changed several things around; resource bins are now in the Organism rather than HardwareCPU.

Everything necessary for resource uptake (via collect instruction) and use should now be in place.


Modified: branches/collect/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/collect/source/cpu/cHardwareCPU.cc	2007-03-26 20:24:32 UTC (rev 1433)
+++ branches/collect/source/cpu/cHardwareCPU.cc	2007-03-27 16:27:20 UTC (rev 1434)
@@ -367,7 +367,6 @@
 , m_threads(hardware_cpu.m_threads)
 , m_thread_id_chart(hardware_cpu.m_thread_id_chart)
 , m_cur_thread(hardware_cpu.m_cur_thread)
-, m_rbins(hardware_cpu.m_rbins)
 , m_mal_active(hardware_cpu.m_mal_active)
 , m_advance_ip(hardware_cpu.m_advance_ip)
 , m_executedmatchstrings(hardware_cpu.m_executedmatchstrings)
@@ -391,9 +390,6 @@
   m_thread_id_chart = 1; // Mark only the first thread as taken...
   m_cur_thread = 0;
   
-  //Reset resource bins to correct number (# of resources) of empty bins
-  m_rbins.Resize(m_world->GetNumResources(), 0.0);
-  
   m_mal_active = false;
   m_executedmatchstrings = false;
   
@@ -615,13 +611,6 @@
     fp << setbase(16) << "[0x" << GetRegister(i) << "]  " << setbase(10);
   }
   
-  // Print resource bin contents if USE_RESOURCE_BINS is enabled in avida.cfg
-  if (m_world->GetConfig().USE_RESOURCE_BINS.Get()) {
-    for (int i = 0; i < m_rbins.GetSize(); i++) {
-      fp << i << ": " << m_rbins[i] << " ";
-    }
-  }
-  
   // Add some extra information if additional time costs are used for instructions,
   // leave this out if there are no differences to keep it cleaner
   if ( organism->GetPhenotype().GetTimeUsed() != organism->GetPhenotype().GetCPUCyclesUsed() )
@@ -3060,8 +3049,8 @@
   if(bin_used >= 0)
   {
     res_change[bin_used] = -1 * (res_count[bin_used] * m_world->GetConfig().ABSORB_RESOURCE_FRACTION.Get());
-    m_rbins[bin_used] += -1 * res_change[bin_used];
-//cout << "bin" << bin_used << ": " << m_rbins[bin_used] << endl;
+    organism->AddToRBin(bin_used, -1 * res_change[bin_used]);
+//cout << "bin" << bin_used << ": " << organism->m_rbins[bin_used] << endl;
   }
   else
   {
@@ -3069,8 +3058,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);
-      m_rbins[i] += -1 * res_change[i];    
-//cout << "multibin" << i << ": " << m_rbins[i] << endl;
+      organism->AddToRBin(i, -1 * res_change[i]);    
+//cout << "multibin" << i << ": " << organism->m_rbins[i] << endl;
     }
   }
   

Modified: branches/collect/source/cpu/cHardwareCPU.h
===================================================================
--- branches/collect/source/cpu/cHardwareCPU.h	2007-03-26 20:24:32 UTC (rev 1433)
+++ branches/collect/source/cpu/cHardwareCPU.h	2007-03-27 16:27:20 UTC (rev 1434)
@@ -132,8 +132,6 @@
   tArray<cLocalThread> m_threads;
   int m_thread_id_chart;
   int m_cur_thread;
-  
-  tArray<double> m_rbins;     //Resource bins holding stored resources (as acquired with collect instr.)
 
   // Flags...
   bool m_mal_active;         // Has an allocate occured since last divide?
@@ -179,7 +177,6 @@
   bool ForkThread(); // Adds a new thread based off of m_cur_thread.
   bool KillThread(); // Kill the current thread!
   
-  
   // ---------- Instruction Helpers -----------
   int FindModifiedRegister(int default_register);
   int FindModifiedNextRegister(int default_register);

Modified: branches/collect/source/main/cAvidaConfig.h
===================================================================
--- branches/collect/source/main/cAvidaConfig.h	2007-03-26 20:24:32 UTC (rev 1433)
+++ branches/collect/source/main/cAvidaConfig.h	2007-03-27 16:27:20 UTC (rev 1434)
@@ -317,7 +317,7 @@
   CONFIG_ADD_VAR(BUY_PRICE, int, 0, "price offered by organisms attempting to buy");
   CONFIG_ADD_VAR(SELL_PRICE, int, 0, "price offered by organisms attempting to sell");
   
-  CONFIG_ADD_GROUP(HOARD_RESOURCE_GROUP, "Resource Hoarding Parameters\n These have no effect unless the organisms are using the collect instruction.");
+  CONFIG_ADD_GROUP(HOARD_RESOURCE_GROUP, "Resource Hoarding Parameters\n These have no effect unless the organisms are using the collect instruction.  DO NOT USE with hardwares other than the \"original\".");
   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");

Modified: branches/collect/source/main/cEnvironment.cc
===================================================================
--- branches/collect/source/main/cEnvironment.cc	2007-03-26 20:24:32 UTC (rev 1433)
+++ branches/collect/source/main/cEnvironment.cc	2007-03-27 16:27:20 UTC (rev 1434)
@@ -796,7 +796,9 @@
 
 bool cEnvironment::TestOutput(cAvidaContext& ctx, cReactionResult& result,
                               cTaskContext& taskctx, const tArray<int>& task_count,
-                              const tArray<int>& reaction_count, const tArray<double>& resource_count) const
+                              const tArray<int>& reaction_count, 
+                              const tArray<double>& resource_count, 
+                              tArray<double>& rbin_count) const
 {
   // Do setup for reaction tests...
   m_tasklib.SetupTests(taskctx);
@@ -833,7 +835,7 @@
     result.MarkTask(task_id, task_quality);
 
     // And let's process it!
-    DoProcesses(ctx, cur_reaction->GetProcesses(), resource_count, task_quality, task_cnt, i, result);
+    DoProcesses(ctx, cur_reaction->GetProcesses(), resource_count, rbin_count, task_quality, task_cnt, i, result);
     
     // Mark this reaction as occuring...
     result.MarkReaction(cur_reaction->GetID());
@@ -904,8 +906,9 @@
 
 
 void cEnvironment::DoProcesses(cAvidaContext& ctx, const tList<cReactionProcess>& process_list,
-                               const tArray<double>& resource_count, const double task_quality,
-                               const int task_count, const int reaction_id, cReactionResult& result) const
+                               const tArray<double>& resource_count, tArray<double>& rbins_count, 
+                               const double task_quality, const int task_count, 
+                               const int reaction_id, cReactionResult& result) const
 {
   const int num_process = process_list.GetSize();
   
@@ -930,9 +933,16 @@
       consumed = resource_count[res_id] - result.GetConsumed(res_id);
       consumed *= cur_process->GetMaxFraction();
       
-      // @blw TODO check for internal use here; set flag
-      bool using_rbins = false;
+      bool may_use_rbins = m_world->GetConfig().USE_RESOURCE_BINS.Get();
+      bool using_rbins = false;  //default: not using resource bins
       
+      //check to see if we do want to use this resource from a bin instead of the environment
+      if (may_use_rbins && rbins_count[res_id] > consumed)
+      {
+        consumed = rbins_count[res_id];
+        using_rbins = true;
+      }
+      
       // Make sure we're not above the maximum consumption.
       if (consumed > max_consumed) consumed = max_consumed;
 
@@ -946,6 +956,10 @@
       
       // Mark in the results the resource consumed.
       result.Consume(res_id, consumed, !using_rbins);
+      
+      //if we consumed resource from an internal resource bin, remove it
+      if (may_use_rbins && using_rbins)
+      {rbins_count[res_id] -= consumed;}
     }
     
     // Calculate the bonus

Modified: branches/collect/source/main/cEnvironment.h
===================================================================
--- branches/collect/source/main/cEnvironment.h	2007-03-26 20:24:32 UTC (rev 1433)
+++ branches/collect/source/main/cEnvironment.h	2007-03-27 16:27:20 UTC (rev 1434)
@@ -102,9 +102,12 @@
 
   bool LoadSetActive(cString desc);
 
-  bool TestRequisites(const tList<cReactionRequisite>& req_list, int task_count, const tArray<int>& reaction_count, const bool on_divide = false) const;
-  void DoProcesses(cAvidaContext& ctx, const tList<cReactionProcess>& process_list, const tArray<double>& resource_count,
-                   const double task_quality, const int task_count, const int reaction_id, cReactionResult& result) const;
+  bool TestRequisites(const tList<cReactionRequisite>& req_list, int task_count, 
+                      const tArray<int>& reaction_count, const bool on_divide = false) const;
+  void DoProcesses(cAvidaContext& ctx, const tList<cReactionProcess>& process_list, 
+                   const tArray<double>& resource_count, tArray<double>& rbin_count,
+                   const double task_quality, const int task_count, const int reaction_id, 
+                   cReactionResult& result) const;
 
   cEnvironment(); // @not_implemented
   cEnvironment(const cEnvironment&); // @not_implemented
@@ -125,7 +128,7 @@
 
   bool TestOutput(cAvidaContext& ctx, cReactionResult& result, cTaskContext& taskctx,
                   const tArray<int>& task_count, const tArray<int>& reaction_count,
-                  const tArray<double>& resource_count) const;
+                  const tArray<double>& resource_count, tArray<double>& rbins_count) const;
 
   // Accessors
   int GetNumTasks() const { return m_tasklib.GetSize(); }

Modified: branches/collect/source/main/cOrganism.cc
===================================================================
--- branches/collect/source/main/cOrganism.cc	2007-03-26 20:24:32 UTC (rev 1433)
+++ branches/collect/source/main/cOrganism.cc	2007-03-27 16:27:20 UTC (rev 1434)
@@ -57,6 +57,7 @@
   , m_interface(NULL)
   , m_lineage_label(-1)
   , m_lineage(NULL)
+  , m_rbins(world->GetNumResources())
   , m_input_pointer(0)
   , m_input_buf(world->GetEnvironment().GetInputSize())
   , m_output_buf(world->GetEnvironment().GetOutputSize())
@@ -85,6 +86,9 @@
     if (m_max_executed < 1) m_max_executed = 1;
   }
   
+  // Ensure all those nice new resource bins are set to 0
+  m_rbins.Resize(m_world->GetNumResources(), 0.0);
+  
   if (m_world->GetConfig().NET_ENABLED.Get()) m_net = new cNetSupport();
   m_id = m_world->GetStats().GetTotCreatures();
 }
@@ -206,7 +210,7 @@
   if (!m_world->GetConfig().SAVE_RECEIVED.Get()) received_messages_point = NULL;
   
   cTaskContext taskctx(m_interface, m_input_buf, m_output_buf, other_input_list, other_output_list, net_valid, 0, on_divide, received_messages_point);
-  m_phenotype.TestOutput(ctx, taskctx, resource_count, res_change, insts_triggered);
+  m_phenotype.TestOutput(ctx, taskctx, resource_count, m_rbins, res_change, insts_triggered);
   m_interface->UpdateResources(res_change);
 
   for (int i = 0; i < insts_triggered.GetSize(); i++) {
@@ -371,7 +375,7 @@
     bool clear_input;
 
     cTaskContext taskctx(m_interface, m_input_buf, m_output_buf, other_input_list, other_output_list, false, completed);
-    m_phenotype.TestOutput(ctx, taskctx, resource_count, res_change, insts_triggered);
+    m_phenotype.TestOutput(ctx, taskctx, resource_count, m_rbins, res_change, insts_triggered);
     m_interface->UpdateResources(res_change);
     
     for (int i = 0; i < insts_triggered.GetSize(); i++) {

Modified: branches/collect/source/main/cOrganism.h
===================================================================
--- branches/collect/source/main/cOrganism.h	2007-03-26 20:24:32 UTC (rev 1433)
+++ branches/collect/source/main/cOrganism.h	2007-03-27 16:27:20 UTC (rev 1434)
@@ -95,6 +95,7 @@
   int m_id;                               // unique id for each org, is just the number it was born
   int m_lineage_label;                    // a lineages tag; inherited unchanged in offspring
   cLineage* m_lineage;                    // A lineage descriptor... (different from label)
+  tArray<double> m_rbins;				  // Holds amount of resources internal to org
 
   // Other stats
   cCPUMemory m_child_genome; // Child genome, while under construction.
@@ -160,6 +161,12 @@
   void SetLineage(cLineage* in_lineage) { m_lineage = in_lineage; }
   cLineage* GetLineage() const { return m_lineage; }
   
+  const tArray<double>& GetRBins() const { return m_rbins; }
+  tArray<double>& GetRBins() { return m_rbins; }
+  void SetRBins(const tArray<double>& rbins_in) { m_rbins = rbins_in; }
+  void SetRBin(const int index, const double value) { m_rbins[index] = value; }
+  void AddToRBin(const int index, const double value) { m_rbins[index] += value; }  
+  
   int GetMaxExecuted() const { return m_max_executed; }
   
   cCPUMemory& ChildGenome() { return m_child_genome; }

Modified: branches/collect/source/main/cPhenotype.cc
===================================================================
--- branches/collect/source/main/cPhenotype.cc	2007-03-26 20:24:32 UTC (rev 1433)
+++ branches/collect/source/main/cPhenotype.cc	2007-03-27 16:27:20 UTC (rev 1434)
@@ -568,7 +568,7 @@
 }
 
 bool cPhenotype::TestOutput(cAvidaContext& ctx, cTaskContext& taskctx,
-			    const tArray<double>& res_in, tArray<double>& res_change,
+			    const tArray<double>& res_in, tArray<double>& rbins_in, tArray<double>& res_change,
 			    tArray<int>& insts_triggered)
 {
   assert(initialized == true);
@@ -582,7 +582,7 @@
   cReactionResult result(num_resources, num_tasks, num_reactions);
 			
   // Run everything through the environment.
-  bool found = env.TestOutput(ctx, result, taskctx, eff_task_count, cur_reaction_count, res_in);
+  bool found = env.TestOutput(ctx, result, taskctx, eff_task_count, cur_reaction_count, res_in, rbins_in);
 
   // If nothing was found, stop here.
   if (found == false) {

Modified: branches/collect/source/main/cPhenotype.h
===================================================================
--- branches/collect/source/main/cPhenotype.h	2007-03-26 20:24:32 UTC (rev 1433)
+++ branches/collect/source/main/cPhenotype.h	2007-03-27 16:27:20 UTC (rev 1434)
@@ -191,7 +191,7 @@
   // Input and Output Reaction Tests
   bool TestInput(tBuffer<int>& inputs, tBuffer<int>& outputs);
   bool TestOutput(cAvidaContext& ctx, cTaskContext& taskctx,
-                  const tArray<double>& res_in, tArray<double>& res_change,
+                  const tArray<double>& res_in, tArray<double>& rbins_in, tArray<double>& res_change,
                   tArray<int>& insts_triggered);
 
   // State saving and loading, and printing...




More information about the Avida-cvs mailing list