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

beckma24 at myxo.css.msu.edu beckma24 at myxo.css.msu.edu
Fri Mar 9 05:27:12 PST 2007


Author: beckma24
Date: 2007-03-09 08:27:12 -0500 (Fri, 09 Mar 2007)
New Revision: 1393

Modified:
   branches/energy/source/main/cAvidaConfig.h
   branches/energy/source/main/cPhenotype.cc
   branches/energy/source/main/cPopulation.cc
Log:
Atlered cAvidaConfig.h
Changed Initial_Energy_given to Energy_Given_At_Birth.
Added Energy_Given_Upon_Inject.


Modified: branches/energy/source/main/cAvidaConfig.h
===================================================================
--- branches/energy/source/main/cAvidaConfig.h	2007-03-08 20:31:02 UTC (rev 1392)
+++ branches/energy/source/main/cAvidaConfig.h	2007-03-09 13:27:12 UTC (rev 1393)
@@ -322,11 +322,12 @@
   
   CONFIG_ADD_GROUP(ENERGY_GROUP, "Energy Settings");
   CONFIG_ADD_VAR(ENERGY_ENABLED, bool, false, "Enable Energy Model");
+  CONFIG_ADD_VAR(ENERGY_GIVEN_ON_INJECT, int, 0, "Energy given to organism upon injection.");
   CONFIG_ADD_VAR(FRAC_ENERGY_GIVEN, double, 0.5, "Fraction of energy given to offspring.");
-  CONFIG_ADD_VAR(INITIAL_ENERGY_GIVEN, int, 0, "Initial energy given to offspring.");
-  CONFIG_ADD_VAR(NUM_INST_EXC_BEFORE_0_ENERGY, int, 0, "Number of instructions executed before energy is exhausted."); 
+  CONFIG_ADD_VAR(ENERGY_GIVEN_AT_BIRTH, int, 0, "Energy given to offspring upon birth.");
+  CONFIG_ADD_VAR(NUM_INST_EXC_BEFORE_0_ENERGY, int, 0, "Number of instructions executed before energy is exhausted.");
+//  CONFIG_ADD_VAR(FIX_METABOLIC_RATE, bool, false, "When activated the metabolic rate of all orgiansims are equal"); // TODO - check for correctness
 
-
 #endif
   
   void Load(const cString& filename, const bool& crash_if_not_found);

Modified: branches/energy/source/main/cPhenotype.cc
===================================================================
--- branches/energy/source/main/cPhenotype.cc	2007-03-08 20:31:02 UTC (rev 1392)
+++ branches/energy/source/main/cPhenotype.cc	2007-03-09 13:27:12 UTC (rev 1393)
@@ -105,7 +105,7 @@
 {
   // Copy divide values from parent, which should already be setup.
   merit           = parent_phenotype.merit;
-  energy_store    = (parent_phenotype.energy_store * m_world->GetConfig().FRAC_ENERGY_GIVEN.Get())+m_world->GetConfig().INITIAL_ENERGY_GIVEN.Get();
+  energy_store    = (parent_phenotype.energy_store * m_world->GetConfig().FRAC_ENERGY_GIVEN.Get())+m_world->GetConfig().ENERGY_GIVEN_AT_BIRTH.Get();
   genome_length   = _length;
   copied_size     = parent_phenotype.child_copied_size;
   executed_size   = parent_phenotype.executed_size;

Modified: branches/energy/source/main/cPopulation.cc
===================================================================
--- branches/energy/source/main/cPopulation.cc	2007-03-08 20:31:02 UTC (rev 1392)
+++ branches/energy/source/main/cPopulation.cc	2007-03-09 13:27:12 UTC (rev 1393)
@@ -291,7 +291,7 @@
   tArray<cMerit> merit_array;
   
   //for energy model
-  int init_energy_given = m_world->GetConfig().INITIAL_ENERGY_GIVEN.Get();
+  int init_energy_given = m_world->GetConfig().ENERGY_GIVEN_AT_BIRTH.Get();
   int inst_2_exc = m_world->GetConfig().NUM_INST_EXC_BEFORE_0_ENERGY.Get();
 
   
@@ -346,8 +346,12 @@
       double child_energy = child_array[i]->GetPhenotype().GetStoredEnergy();
       
       parent_phenotype.ReduceEnergy(child_energy - init_energy_given);  // trying to avoid floating point error
-      //TODO the average cost per instruction varies depending on the merit.
-      merit_array[i] = 100 * child_energy / (inst_2_exc); //TODO - make sure that instruction cost = merit * inst_cost (check)
+
+      if(m_world->GetConfig().FIX_METABOLIC_RATE.Get()) {
+        merit_array[i] = parent_phenotype.GetMerit();
+      } else {
+        merit_array[i] = 100 * child_energy / (inst_2_exc);
+      }
       cerr<<"child merit: "<<merit_array[i]<<endl<<"child energy: "<< child_energy <<endl;
     }
 
@@ -362,9 +366,12 @@
   //TODO set parents merit
   // SEXUAL
   if(m_world->GetConfig().ENERGY_ENABLED.Get()) {
-    parent_phenotype.ReduceEnergy(-1.0*m_world->GetConfig().INITIAL_ENERGY_GIVEN.Get());
-    cMerit parentMerit = cMerit(100 * parent_phenotype.GetStoredEnergy()/(inst_2_exc));
-    parent_phenotype.SetMerit(parentMerit);
+    parent_phenotype.ReduceEnergy(-1.0*init_energy_given);
+    
+    if(!(m_world->GetConfig().FIX_METABOLIC_RATE.Get())) {
+      cMerit parentMerit = cMerit(100 * parent_phenotype.GetStoredEnergy()/(inst_2_exc));
+      parent_phenotype.SetMerit(parentMerit);
+    }
     cerr<<"parent merit: "<<parent_phenotype.GetMerit()<<endl<<"parent energy: "<< parent_phenotype.GetStoredEnergy() <<endl;
   }
   
@@ -2233,16 +2240,13 @@
   phenotype.SetupInject(new_genotype->GetLength());  //TODO  sets merit to lenght of genotype
   
   //TODO -- add energy here
-  double initial_energy = m_world->GetConfig().INITIAL_ENERGY_GIVEN.Get(); // PUT INSIDE IF
+  double initial_energy = m_world->GetConfig().ENERGY_GIVEN_ON_INJECT.Get(); // PUT INSIDE IF
   if(m_world->GetConfig().ENERGY_ENABLED.Get()) { //TODO -- check for correctness
-//    int inst_to_exc = m_world->GetConfig().NUM_INST_EXC_BEFORE_0_ENERGY.Get();
-//    double avg_energy_cost_per_inst = m_world->GetHardwareManager().GetInstSet().GetAvgEnergyCostPerInst();
     phenotype.SetEnergy(initial_energy);
-//    phenotype.SetMerit(cMerit(1.0));    //merit = 1;
   }
-  //else {
-    phenotype.SetMerit( cMerit(new_genotype->GetTestMerit(ctx)) );
-  //}
+  // BB - Don't need to fix metabolic rate here, only on birth
+  phenotype.SetMerit( cMerit(new_genotype->GetTestMerit(ctx)) );
+  
   cerr<<"initial energy: " <<initial_energy<<endl<<"initial Merit: "<<phenotype.GetMerit().GetDouble()<<endl;
   
   // @CAO are these really needed?




More information about the Avida-cvs mailing list