[Avida-SVN] r1441 - in branches/energy: Avida.xcodeproj source/main

beckma24 at myxo.css.msu.edu beckma24 at myxo.css.msu.edu
Fri Mar 30 06:07:47 PDT 2007


Author: beckma24
Date: 2007-03-30 09:07:47 -0400 (Fri, 30 Mar 2007)
New Revision: 1441

Modified:
   branches/energy/Avida.xcodeproj/project.pbxproj
   branches/energy/source/main/cAvidaConfig.h
   branches/energy/source/main/cPhenotype.cc
   branches/energy/source/main/cPopulation.cc
Log:
Added configuration variable to cap the amount of energy that can be stored.

Modified: branches/energy/Avida.xcodeproj/project.pbxproj
===================================================================
--- branches/energy/Avida.xcodeproj/project.pbxproj	2007-03-30 03:47:47 UTC (rev 1440)
+++ branches/energy/Avida.xcodeproj/project.pbxproj	2007-03-30 13:07:47 UTC (rev 1441)
@@ -887,7 +887,7 @@
 		70DCAC77097AF730002F8733 /* key_chart */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = key_chart; sourceTree = "<group>"; };
 		70DCAC78097AF730002F8733 /* viewer.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = viewer.cc; sourceTree = "<group>"; };
 		70DCAC9B097AF7C0002F8733 /* primitive.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = primitive.cc; sourceTree = "<group>"; };
-		70DCAD1C097AF7CC002F8733 /* avida-s */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "avida-s"; sourceTree = BUILT_PRODUCTS_DIR; };
+		70DCAD1C097AF7CC002F8733 /* avida-s */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = "compiled.mach-o.executable"; path = "avida-s"; sourceTree = BUILT_PRODUCTS_DIR; };
 		70DCAD1F097AF81A002F8733 /* AvidaScript.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = AvidaScript.h; sourceTree = "<group>"; };
 		70DCAD20097AF81A002F8733 /* cLexer.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cLexer.h; sourceTree = "<group>"; };
 		70DCAD21097AF81A002F8733 /* cLexer.l */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.lex; path = cLexer.l; sourceTree = "<group>"; };

Modified: branches/energy/source/main/cAvidaConfig.h
===================================================================
--- branches/energy/source/main/cAvidaConfig.h	2007-03-30 03:47:47 UTC (rev 1440)
+++ branches/energy/source/main/cAvidaConfig.h	2007-03-30 13:07:47 UTC (rev 1441)
@@ -322,11 +322,12 @@
   
   CONFIG_ADD_GROUP(ENERGY_GROUP, "Energy Settings");
   CONFIG_ADD_VAR(ENERGY_ENABLED, bool, 0, "Enable Energy Model. 0/1 (off/on)");
-  CONFIG_ADD_VAR(ENERGY_GIVEN_ON_INJECT, int, 0, "Energy given to organism upon injection.");
-  CONFIG_ADD_VAR(ENERGY_GIVEN_AT_BIRTH, int, 0, "Energy given to offspring upon birth.");
+  CONFIG_ADD_VAR(ENERGY_GIVEN_ON_INJECT, double, 0.0, "Energy given to organism upon injection.");
+  CONFIG_ADD_VAR(ENERGY_GIVEN_AT_BIRTH, double, 0.0, "Energy given to offspring upon birth.");
   CONFIG_ADD_VAR(FRAC_PARENT_ENERGY_GIVEN_AT_BIRTH, double, 0.5, "Fraction of energy given to offspring.");
   CONFIG_ADD_VAR(FRAC_ENERGY_DECAY_AT_BIRTH, double, 0.0, "Fraction of energy lost due to decay during reproduction.");
   CONFIG_ADD_VAR(NUM_INST_EXC_BEFORE_0_ENERGY, int, 0, "Number of instructions executed before energy is exhausted.");
+  CONFIG_ADD_VAR(ENERGY_CAP, double, DOUBLEMAX, "Maximun amount of energy that can be stored in an organism");
 //  CONFIG_ADD_VAR(FIX_METABOLIC_RATE, bool, 0, "When activated the metabolic rate of all orgiansims are equal. 0/1 (off/on)"); // TODO - check for correctness
   CONFIG_ADD_VAR(ENERGY_VERBOSE, bool, 0, "Print energy and merit values. 0/1 (off/on)");
 

Modified: branches/energy/source/main/cPhenotype.cc
===================================================================
--- branches/energy/source/main/cPhenotype.cc	2007-03-30 03:47:47 UTC (rev 1440)
+++ branches/energy/source/main/cPhenotype.cc	2007-03-30 13:07:47 UTC (rev 1441)
@@ -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_PARENT_ENERGY_GIVEN_AT_BIRTH.Get())+m_world->GetConfig().ENERGY_GIVEN_AT_BIRTH.Get();
+  energy_store    = min((parent_phenotype.energy_store * m_world->GetConfig().FRAC_PARENT_ENERGY_GIVEN_AT_BIRTH.Get())+m_world->GetConfig().ENERGY_GIVEN_AT_BIRTH.Get(), m_world->GetConfig().ENERGY_CAP.Get());
   genome_length   = _length;
   copied_size     = parent_phenotype.child_copied_size;
   executed_size   = parent_phenotype.executed_size;
@@ -199,7 +199,7 @@
 {
   // Setup reasonable initial values injected organism...
   merit           = _length;
-  energy_store    = m_world->GetConfig().ENERGY_GIVEN_ON_INJECT.Get();
+  energy_store    = min(m_world->GetConfig().ENERGY_GIVEN_ON_INJECT.Get(), m_world->GetConfig().ENERGY_CAP.Get());
   genome_length   = _length;
   copied_size     = _length;
   executed_size   = _length;
@@ -832,7 +832,7 @@
     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 min(100 * energy_store / (m_world->GetConfig().NUM_INST_EXC_BEFORE_0_ENERGY.Get()), m_world->GetConfig().ENERGY_CAP.Get());
   }
   return -1;
 }

Modified: branches/energy/source/main/cPopulation.cc
===================================================================
--- branches/energy/source/main/cPopulation.cc	2007-03-30 03:47:47 UTC (rev 1440)
+++ branches/energy/source/main/cPopulation.cc	2007-03-30 13:07:47 UTC (rev 1441)
@@ -298,7 +298,7 @@
   tArray<cMerit> merit_array;
   
   //for energy model
-  int init_energy_given = m_world->GetConfig().ENERGY_GIVEN_AT_BIRTH.Get();
+  double 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();
 
   
@@ -357,7 +357,7 @@
 //      if(m_world->GetConfig().FIX_METABOLIC_RATE.Get()) {  //TODO check correctness
 //        merit_array[i] = parent_phenotype.GetMerit();
 //      } else {
-        merit_array[i] = 100 * child_energy / (inst_2_exc);
+        merit_array[i] = min(100 * child_energy / (inst_2_exc), m_world->GetConfig().ENERGY_CAP.Get());
       //}
       if(m_world->GetConfig().ENERGY_VERBOSE.Get())
         cerr<<"child merit: "<<merit_array[i]<<endl<<"child energy: "<< child_energy <<endl;
@@ -373,10 +373,10 @@
   
   // TODO: SEXUAL
   if(m_world->GetConfig().ENERGY_ENABLED.Get()) {
-    parent_phenotype.ReduceEnergy(-1.0*init_energy_given);
+//    parent_phenotype.ReduceEnergy(-1.0*init_energy_given);  //moved in to marentMerit calculation
     
 //    if(!(m_world->GetConfig().FIX_METABOLIC_RATE.Get())) {
-      cMerit parentMerit = cMerit(100 * parent_phenotype.GetStoredEnergy()/(inst_2_exc));
+      cMerit parentMerit = cMerit(min(100 * (parent_phenotype.GetStoredEnergy() + init_energy_given)/(inst_2_exc), m_world->GetConfig().ENERGY_CAP.Get()));
       parent_phenotype.SetMerit(parentMerit);
 //    }
     if(m_world->GetConfig().ENERGY_VERBOSE.Get())
@@ -2259,7 +2259,7 @@
   
   if(m_world->GetConfig().ENERGY_ENABLED.Get()) { //TODO -- check for correctness
     //TODO -- add energy here
-    double initial_energy = m_world->GetConfig().ENERGY_GIVEN_ON_INJECT.Get();
+    double initial_energy = min(m_world->GetConfig().ENERGY_GIVEN_ON_INJECT.Get(), m_world->GetConfig().ENERGY_CAP.Get());
     phenotype.SetEnergy(initial_energy);
   }
   // BB - Don't need to fix metabolic rate here, only on birth




More information about the Avida-cvs mailing list