[Avida-SVN] r1442 - branches/energy/source/main
beckma24 at myxo.css.msu.edu
beckma24 at myxo.css.msu.edu
Fri Mar 30 08:03:40 PDT 2007
Author: beckma24
Date: 2007-03-30 11:03:40 -0400 (Fri, 30 Mar 2007)
New Revision: 1442
Modified:
branches/energy/source/main/cAvidaConfig.h
branches/energy/source/main/cPhenotype.cc
branches/energy/source/main/cPopulation.cc
Log:
Fixed initialization of configuration variable to cap the amount of energy that can be stored. It is now MAXINT when this option is disabled.
Modified: branches/energy/source/main/cAvidaConfig.h
===================================================================
--- branches/energy/source/main/cAvidaConfig.h 2007-03-30 13:07:47 UTC (rev 1441)
+++ branches/energy/source/main/cAvidaConfig.h 2007-03-30 15:03:40 UTC (rev 1442)
@@ -322,12 +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, 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(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(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(ENERGY_CAP, int, -1, "Maximun amount of energy that can be stored in an organism. -1 means the cap is set to Max Int");
// 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 13:07:47 UTC (rev 1441)
+++ branches/energy/source/main/cPhenotype.cc 2007-03-30 15:03:40 UTC (rev 1442)
@@ -105,7 +105,7 @@
{
// Copy divide values from parent, which should already be setup.
merit = parent_phenotype.merit;
- 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());
+ 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(), (double) m_world->GetConfig().ENERGY_CAP.Get());
genome_length = _length;
copied_size = parent_phenotype.child_copied_size;
executed_size = parent_phenotype.executed_size;
@@ -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 min(100 * energy_store / (m_world->GetConfig().NUM_INST_EXC_BEFORE_0_ENERGY.Get()), m_world->GetConfig().ENERGY_CAP.Get());
+ return min(100 * energy_store / (m_world->GetConfig().NUM_INST_EXC_BEFORE_0_ENERGY.Get()), (double) m_world->GetConfig().ENERGY_CAP.Get());
}
return -1;
}
Modified: branches/energy/source/main/cPopulation.cc
===================================================================
--- branches/energy/source/main/cPopulation.cc 2007-03-30 13:07:47 UTC (rev 1441)
+++ branches/energy/source/main/cPopulation.cc 2007-03-30 15:03:40 UTC (rev 1442)
@@ -59,6 +59,7 @@
#include <float.h>
#include <math.h>
#include <limits.h>
+//#include <stdint.h>
using namespace std;
@@ -79,6 +80,9 @@
int geometry = world->GetConfig().WORLD_GEOMETRY.Get();
const int num_cells = world_x * world_y;
+ if(m_world->GetConfig().ENERGY_CAP.Get() == -1)
+ m_world->GetConfig().ENERGY_CAP.Set(INT_MAX);
+
if(m_world->GetConfig().ENERGY_ENABLED.Get())
sleep_log = new tVector<pair<int,int> >[world_x*world_y];
// Print out world details
@@ -357,7 +361,7 @@
// if(m_world->GetConfig().FIX_METABOLIC_RATE.Get()) { //TODO check correctness
// merit_array[i] = parent_phenotype.GetMerit();
// } else {
- merit_array[i] = min(100 * child_energy / (inst_2_exc), m_world->GetConfig().ENERGY_CAP.Get());
+ merit_array[i] = min(100 * child_energy / (inst_2_exc), (double) 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;
@@ -376,7 +380,7 @@
// parent_phenotype.ReduceEnergy(-1.0*init_energy_given); //moved in to marentMerit calculation
// if(!(m_world->GetConfig().FIX_METABOLIC_RATE.Get())) {
- cMerit parentMerit = cMerit(min(100 * (parent_phenotype.GetStoredEnergy() + init_energy_given)/(inst_2_exc), m_world->GetConfig().ENERGY_CAP.Get()));
+ cMerit parentMerit = cMerit(min(100 * (parent_phenotype.GetStoredEnergy() + init_energy_given)/(inst_2_exc), (double) m_world->GetConfig().ENERGY_CAP.Get()));
parent_phenotype.SetMerit(parentMerit);
// }
if(m_world->GetConfig().ENERGY_VERBOSE.Get())
@@ -2259,6 +2263,7 @@
if(m_world->GetConfig().ENERGY_ENABLED.Get()) { //TODO -- check for correctness
//TODO -- add energy here
+
double initial_energy = min(m_world->GetConfig().ENERGY_GIVEN_ON_INJECT.Get(), m_world->GetConfig().ENERGY_CAP.Get());
phenotype.SetEnergy(initial_energy);
}
More information about the Avida-cvs
mailing list