[Avida-SVN] r3284 - in development/source: cpu main tools
beckma24 at myxo.css.msu.edu
beckma24 at myxo.css.msu.edu
Thu Jun 4 08:16:11 PDT 2009
Author: beckma24
Date: 2009-06-04 11:16:11 -0400 (Thu, 04 Jun 2009)
New Revision: 3284
Modified:
development/source/cpu/cHardwareBase.cc
development/source/cpu/cHardwareBase.h
development/source/main/cDeme.cc
development/source/main/cPopulation.cc
development/source/tools/cProbSchedule.cc
Log:
BUG FIX: parent could have zero merit in energy model because of decay
Modified: development/source/cpu/cHardwareBase.cc
===================================================================
--- development/source/cpu/cHardwareBase.cc 2009-06-04 14:13:53 UTC (rev 3283)
+++ development/source/cpu/cHardwareBase.cc 2009-06-04 15:16:11 UTC (rev 3284)
@@ -970,17 +970,15 @@
bool cHardwareBase::SingleProcess_PayCosts(cAvidaContext& ctx, const cInstruction& cur_inst)
{
#if INSTRUCTION_COSTS
-
if (m_world->GetConfig().ENERGY_ENABLED.Get() > 0) {
// TODO: Get rid of magic number. check avaliable energy first
double energy_req = m_inst_energy_cost[cur_inst.GetOp()] * (m_organism->GetPhenotype().GetMerit().GetDouble() / 100.0); //compensate by factor of 100
int cellID = m_organism->GetCellID();
-
+
if((cellID != -1) && (energy_req > 0.0)) { // guard against running in the test cpu.
-
if (m_organism->GetPhenotype().GetStoredEnergy() >= energy_req) {
- m_inst_energy_cost[cur_inst.GetOp()] = 0;
- // subtract energy used from current org energy.
+ m_inst_energy_cost[cur_inst.GetOp()] = 0.0;
+ // subtract energy used from current org energy.
m_organism->GetPhenotype().ReduceEnergy(energy_req);
// tracking sleeping organisms
@@ -996,7 +994,7 @@
}
} else {
m_organism->GetPhenotype().SetToDie();
- return false;
+ return false; // no more, your died... (evil laugh)
}
}
}
Modified: development/source/cpu/cHardwareBase.h
===================================================================
--- development/source/cpu/cHardwareBase.h 2009-06-04 14:13:53 UTC (rev 3283)
+++ development/source/cpu/cHardwareBase.h 2009-06-04 15:16:11 UTC (rev 3284)
@@ -67,7 +67,7 @@
// -------- Instruction Costs ---------
int m_inst_cost;
tArray<int> m_inst_ft_cost;
- tArray<int> m_inst_energy_cost;
+ tArray<double> m_inst_energy_cost;
bool m_has_any_costs;
bool m_has_costs;
bool m_has_ft_costs;
Modified: development/source/main/cDeme.cc
===================================================================
--- development/source/main/cDeme.cc 2009-06-04 14:13:53 UTC (rev 3283)
+++ development/source/main/cDeme.cc 2009-06-04 15:16:11 UTC (rev 3284)
@@ -281,15 +281,15 @@
//reset remaining deme predicates
for (int i = 0; i < deme_pred_list.Size(); i++) {
- (*deme_pred_list[i]).Reset();
+ deme_pred_list[i]->Reset();
}
//reset remaining message predicates
for (int i = 0; i < message_pred_list.Size(); i++) {
- (*message_pred_list[i]).Reset();
+ message_pred_list[i]->Reset();
}
//reset remaining message predicates
for (int i = 0; i < movement_pred_list.Size(); i++) {
- (*movement_pred_list[i]).Reset();
+ movement_pred_list[i]->Reset();
}
if (resetResources) {
Modified: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc 2009-06-04 14:13:53 UTC (rev 3283)
+++ development/source/main/cPopulation.cc 2009-06-04 15:16:11 UTC (rev 3284)
@@ -346,6 +346,19 @@
// Loop through choosing the later placement of each child in the population.
bool parent_alive = true; // Will the parent live through this process?
for (int i = 0; i < child_array.GetSize(); i++) {
+/* if(merit_array[i].GetDouble() <= 0.0) {
+ // no weaklings!
+ if(child_array.GetSize() > 1) {
+ child_array.Swap(i, child_array.GetSize()-1);
+ child_array = child_array.Subset(0, child_array.GetSize()-2);
+ } else {
+ child_array.ResizeClear(0);
+ break;
+ }
+ --i;
+ continue;
+ }
+ */
target_cells[i] = PositionChild(parent_cell, m_world->GetConfig().ALLOW_PARENT.Get()).GetID();
// If we replaced the parent, make a note of this.
@@ -393,6 +406,12 @@
// If we're not about to kill the parent, do some extra work on it.
if (parent_alive == true) {
+ if(parent_phenotype.GetMerit().GetDouble() <= 0.0) {
+ // no weakling parents either!
+ parent_organism->GetPhenotype().SetToDie();
+ parent_alive = false;
+ }
+
// Reset inputs and re-calculate merit if required
if (m_world->GetConfig().RESET_INPUTS_ON_DIVIDE.Get() > 0){
environment.SetupInputs(ctx, parent_cell.m_inputs);
@@ -3732,11 +3751,11 @@
{
assert(step_size > 0.0);
assert(cell_id < cell_array.GetSize());
-
+
// If cell_id is negative, no cell could be found -- stop here.
if (cell_id < 0) return;
- cPopulationCell& cell = GetCell(cell_id);
+ cPopulationCell& cell = GetCell(cell_id);
assert(cell.IsOccupied()); // Unoccupied cell getting processor time!
cOrganism* cur_org = cell.GetOrganism();
Modified: development/source/tools/cProbSchedule.cc
===================================================================
--- development/source/tools/cProbSchedule.cc 2009-06-04 14:13:53 UTC (rev 3283)
+++ development/source/tools/cProbSchedule.cc 2009-06-04 15:16:11 UTC (rev 3284)
@@ -29,7 +29,7 @@
#include "cDeme.h"
#include "cMerit.h"
-// The larger merits cause problems here; things need to be re-thought out.
+// The larger merits cause problems here; avoid very large or very small merits
int cProbSchedule::GetNextID()
{
More information about the Avida-cvs
mailing list