[Avida-SVN] r3314 - in development/source: cpu main
beckma24 at myxo.css.msu.edu
beckma24 at myxo.css.msu.edu
Thu Jun 11 12:17:25 PDT 2009
Author: beckma24
Date: 2009-06-11 15:17:25 -0400 (Thu, 11 Jun 2009)
New Revision: 3314
Modified:
development/source/cpu/cHardwareBase.cc
development/source/cpu/cHardwareBase.h
development/source/cpu/cHardwareCPU.cc
development/source/main/cEnvironment.cc
development/source/main/cOrganism.cc
development/source/main/cPhenotype.cc
development/source/main/cPhenotype.h
Log:
Caught a few more ways that organisms can be assigned a zero merit when using the energy model. These organisms are now killed, as they should be
Modified: development/source/cpu/cHardwareBase.cc
===================================================================
--- development/source/cpu/cHardwareBase.cc 2009-06-11 03:29:57 UTC (rev 3313)
+++ development/source/cpu/cHardwareBase.cc 2009-06-11 19:17:25 UTC (rev 3314)
@@ -987,10 +987,10 @@
return true;
}
-bool cHardwareBase::Inst_HalfEnergyUsage(cAvidaContext& ctx)
+bool cHardwareBase::Inst_HalveEnergyUsage(cAvidaContext& ctx)
{
cPhenotype& phenotype = m_organism->GetPhenotype();
- phenotype.HalfEnergyUsage();
+ phenotype.HalveEnergyUsage();
double newOrgMerit = phenotype.ConvertEnergyToMerit(phenotype.GetStoredEnergy() * phenotype.GetEnergyUsageRatio());
m_organism->UpdateMerit(newOrgMerit);
return true;
Modified: development/source/cpu/cHardwareBase.h
===================================================================
--- development/source/cpu/cHardwareBase.h 2009-06-11 03:29:57 UTC (rev 3313)
+++ development/source/cpu/cHardwareBase.h 2009-06-11 19:17:25 UTC (rev 3314)
@@ -212,7 +212,7 @@
// -------- Execution Speed Instruction --------
bool Inst_DoubleEnergyUsage(cAvidaContext& ctx);
- bool Inst_HalfEnergyUsage(cAvidaContext& ctx);
+ bool Inst_HalveEnergyUsage(cAvidaContext& ctx);
bool Inst_DefaultEnergyUsage(cAvidaContext& ctx);
Modified: development/source/cpu/cHardwareCPU.cc
===================================================================
--- development/source/cpu/cHardwareCPU.cc 2009-06-11 03:29:57 UTC (rev 3313)
+++ development/source/cpu/cHardwareCPU.cc 2009-06-11 19:17:25 UTC (rev 3314)
@@ -473,7 +473,7 @@
// Energy usage
tInstLibEntry<tMethod>("double-energy-usage", &cHardwareCPU::Inst_DoubleEnergyUsage, nInstFlag::STALL),
- tInstLibEntry<tMethod>("half-energy-usage", &cHardwareCPU::Inst_HalfEnergyUsage, nInstFlag::STALL),
+ tInstLibEntry<tMethod>("halve-energy-usage", &cHardwareCPU::Inst_HalveEnergyUsage, nInstFlag::STALL),
tInstLibEntry<tMethod>("default-energy-usage", &cHardwareCPU::Inst_DefaultEnergyUsage, nInstFlag::STALL),
// Messaging
Modified: development/source/main/cEnvironment.cc
===================================================================
--- development/source/main/cEnvironment.cc 2009-06-11 03:29:57 UTC (rev 3313)
+++ development/source/main/cEnvironment.cc 2009-06-11 19:17:25 UTC (rev 3314)
@@ -1270,7 +1270,7 @@
result.MarkReaction(reaction_id);
double bonus = consumed * cur_process->GetValue();
-
+
if (!cur_process->GetIsGermline())
{
// normal bonus
Modified: development/source/main/cOrganism.cc
===================================================================
--- development/source/main/cOrganism.cc 2009-06-11 03:29:57 UTC (rev 3313)
+++ development/source/main/cOrganism.cc 2009-06-11 19:17:25 UTC (rev 3314)
@@ -428,9 +428,10 @@
m_phenotype.RefreshEnergy();
m_phenotype.ApplyToEnergyStore();
double newMerit = m_phenotype.ConvertEnergyToMerit(m_phenotype.GetStoredEnergy() * m_phenotype.GetEnergyUsageRatio());
- if(newMerit != -1) {
- m_interface->UpdateMerit(newMerit);
- }
+ m_interface->UpdateMerit(newMerit);
+ if(GetPhenotype().GetMerit().GetDouble() == 0.0) {
+ GetPhenotype().SetToDie();
+ }
}
m_interface->UpdateResources(global_res_change);
Modified: development/source/main/cPhenotype.cc
===================================================================
--- development/source/main/cPhenotype.cc 2009-06-11 03:29:57 UTC (rev 3313)
+++ development/source/main/cPhenotype.cc 2009-06-11 19:17:25 UTC (rev 3314)
@@ -1401,7 +1401,7 @@
executionRatio *= 2.0;
}
-void cPhenotype::HalfEnergyUsage() {
+void cPhenotype::HalveEnergyUsage() {
executionRatio *= 0.5;
}
@@ -1491,15 +1491,18 @@
ReduceEnergy(GetStoredEnergy() * frac_energy_decay_at_birth);
// calculate energy to be given to child
- double child_energy = min(GetStoredEnergy() * frac_parent_energy_given_at_birth + energy_given_at_birth, energy_cap);
-
+ double child_energy = max(0.0, min(GetStoredEnergy() * frac_parent_energy_given_at_birth + energy_given_at_birth, energy_cap));
+ assert(GetStoredEnergy()>0.0);
// adjust energy in parent
ReduceEnergy(child_energy - 2*energy_given_at_birth); // 2*energy_given_at_birth: 1 in child_energy & 1 for parent
//TODO: add energy_given_at_birth to Stored_energy
cMerit parentMerit(ConvertEnergyToMerit(GetStoredEnergy() * GetEnergyUsageRatio()));
- SetMerit(parentMerit);
-
+ if(parentMerit.GetDouble() > 0.0)
+ SetMerit(parentMerit);
+ else
+ SetToDie();
+
return child_energy;
}
Modified: development/source/main/cPhenotype.h
===================================================================
--- development/source/main/cPhenotype.h 2009-06-11 03:29:57 UTC (rev 3313)
+++ development/source/main/cPhenotype.h 2009-06-11 19:17:25 UTC (rev 3314)
@@ -573,7 +573,7 @@
bool& IsMultiThread() { assert(initialized == true); return is_multi_thread; }
void DoubleEnergyUsage();
- void HalfEnergyUsage();
+ void HalveEnergyUsage();
void DefaultEnergyUsage();
void RefreshEnergy();
More information about the Avida-cvs
mailing list