[Avida-SVN] r1423 - branches/energy/source/main

beckma24 at myxo.css.msu.edu beckma24 at myxo.css.msu.edu
Fri Mar 23 07:46:38 PDT 2007


Author: beckma24
Date: 2007-03-23 10:46:37 -0400 (Fri, 23 Mar 2007)
New Revision: 1423

Modified:
   branches/energy/source/main/cOrganism.cc
   branches/energy/source/main/cPhenotype.cc
   branches/energy/source/main/cPhenotype.h
Log:
Merit is updated every time an organism gains energy.

Modified: branches/energy/source/main/cOrganism.cc
===================================================================
--- branches/energy/source/main/cOrganism.cc	2007-03-23 02:54:38 UTC (rev 1422)
+++ branches/energy/source/main/cOrganism.cc	2007-03-23 14:46:37 UTC (rev 1423)
@@ -37,6 +37,7 @@
 #include "cInjectGenotype.h"
 #include "cInstSet.h"
 #include "cOrgSinkMessage.h"
+#include "cPopulation.h"
 #include "cStringUtil.h"
 #include "cTaskContext.h"
 #include "cTools.h"
@@ -207,6 +208,16 @@
   
   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, &  clear_input);
+  
+  if(m_world->GetConfig().ENERGY_ENABLED.Get()) {
+    double newMerit = m_phenotype.RefreshEnergy();
+    if(newMerit != -1) {
+      std::cerr<<GetCellID()<<" "<<newMerit<<std::endl;
+      m_world->GetPopulation().UpdateMerit(GetCellID(), newMerit);
+    }
+  }
+
+  
   m_interface->UpdateResources(res_change);
 
   for (int i = 0; i < insts_triggered.GetSize(); i++) {

Modified: branches/energy/source/main/cPhenotype.cc
===================================================================
--- branches/energy/source/main/cPhenotype.cc	2007-03-23 02:54:38 UTC (rev 1422)
+++ branches/energy/source/main/cPhenotype.cc	2007-03-23 14:46:37 UTC (rev 1423)
@@ -826,3 +826,13 @@
 
   return out_size;
 }
+
+double cPhenotype::RefreshEnergy() {
+  if(cur_energy_bonus > 0) {
+    energy_store += cur_energy_bonus;
+    cur_energy_bonus = 0;
+    std::cerr<<energy_store<<"/"<<m_world->GetConfig().NUM_INST_EXC_BEFORE_0_ENERGY.Get()<<std::endl;
+    return 100 * energy_store / (m_world->GetConfig().NUM_INST_EXC_BEFORE_0_ENERGY.Get());
+  }
+  return -1;
+}

Modified: branches/energy/source/main/cPhenotype.h
===================================================================
--- branches/energy/source/main/cPhenotype.h	2007-03-23 02:54:38 UTC (rev 1422)
+++ branches/energy/source/main/cPhenotype.h	2007-03-23 14:46:37 UTC (rev 1423)
@@ -325,6 +325,8 @@
   int& CrossNum()     { assert(initialized == true); return cross_num; }
   bool& ChildFertile() { assert(initialized == true); return child_fertile; }
   bool& IsMultiThread() { assert(initialized == true); return is_multi_thread; }
+  
+  double RefreshEnergy();
 };
 
 




More information about the Avida-cvs mailing list