[Avida-SVN] r1832 - in branches/energy_dev/source: cpu main
beckma24 at myxo.css.msu.edu
beckma24 at myxo.css.msu.edu
Fri Jul 20 12:21:39 PDT 2007
Author: beckma24
Date: 2007-07-20 15:21:39 -0400 (Fri, 20 Jul 2007)
New Revision: 1832
Modified:
branches/energy_dev/source/cpu/cHardwareBase.cc
branches/energy_dev/source/cpu/cHardwareBase.h
branches/energy_dev/source/cpu/cHardwareCPU.cc
branches/energy_dev/source/cpu/cHardwareCPU.h
branches/energy_dev/source/cpu/cHardwareExperimental.cc
branches/energy_dev/source/cpu/cHardwareExperimental.h
branches/energy_dev/source/cpu/cHardwareGX.cc
branches/energy_dev/source/cpu/cHardwareGX.h
branches/energy_dev/source/cpu/cHardwareSMT.cc
branches/energy_dev/source/cpu/cHardwareSMT.h
branches/energy_dev/source/cpu/cHardwareTransSMT.cc
branches/energy_dev/source/cpu/cHardwareTransSMT.h
branches/energy_dev/source/main/cBirthChamber.cc
branches/energy_dev/source/main/cPhenotype.h
branches/energy_dev/source/main/cPopulation.cc
Log:
Added energy model to all hardware types. Moved SingleProcess_PayCosts to cHardwareBase class.
Modified: branches/energy_dev/source/cpu/cHardwareBase.cc
===================================================================
--- branches/energy_dev/source/cpu/cHardwareBase.cc 2007-07-19 21:44:58 UTC (rev 1831)
+++ branches/energy_dev/source/cpu/cHardwareBase.cc 2007-07-20 19:21:39 UTC (rev 1832)
@@ -36,7 +36,10 @@
#include "nMutation.h"
#include "cOrganism.h"
#include "cPhenotype.h"
+#include "cPopulation.h"
+#include "cPopulationCell.h"
#include "cRandom.h"
+#include "cStats.h"
#include "cTestCPU.h"
#include "cWorld.h"
#include "cWorldDriver.h"
@@ -718,3 +721,58 @@
assert(1);
return false;
}
+
+// This method will test to see if all costs have been paid associated
+// with executing an instruction and only return true when that instruction
+// should proceed.
+bool cHardwareBase::SingleProcess_PayCosts(cAvidaContext& ctx, const cInstruction& cur_inst)
+{
+#if INSTRUCTION_COSTS
+ assert(cur_inst.GetOp() < inst_cost.GetSize());
+
+ // check avaliable energy first
+ double energy_req = inst_energy_cost[cur_inst.GetOp()] * (organism->GetPhenotype().GetMerit().GetDouble() / 100.0); //compensate by factor of 100
+
+ if(m_world->GetConfig().ENERGY_ENABLED.Get() > 0 && energy_req > 0.0) {
+ if(organism->GetPhenotype().GetStoredEnergy() >= energy_req) {
+ inst_energy_cost[cur_inst.GetOp()] = 0;
+ //subtract energy used from current org energy.
+ organism->GetPhenotype().ReduceEnergy(energy_req);
+
+ // tracking sleeping organisms
+ cString instName = m_world->GetHardwareManager().GetInstSet().GetName(cur_inst);
+ int cellID = organism->GetCellID();
+ if( instName == cString("sleep") || instName == cString("sleep1") || instName == cString("sleep2") ||
+ instName == cString("sleep3") || instName == cString("sleep4")) {
+ cPopulation& pop = m_world->GetPopulation();
+ if(m_world->GetConfig().LOG_SLEEP_TIMES.Get() == 1) {
+ pop.AddBeginSleep(cellID,m_world->GetStats().GetUpdate());
+ }
+ pop.GetCell(cellID).GetOrganism()->SetSleeping(true);
+ pop.incNumAsleep();
+ }
+ } else { // not enough energy
+ return false;
+ }
+ }
+
+ // If first time cost hasn't been paid off...
+ if (m_has_ft_costs && inst_ft_cost[cur_inst.GetOp()] > 0) {
+ inst_ft_cost[cur_inst.GetOp()]--; // dec cost
+ return false;
+ }
+
+ // Next, look at the per use cost
+ if (m_has_costs && m_inst_set->GetCost(cur_inst) > 0) {
+ if (inst_cost[cur_inst.GetOp()] > 1) { // if isn't paid off (>1)
+ inst_cost[cur_inst.GetOp()]--; // dec cost
+ return false;
+ } else { // else, reset cost array
+ inst_cost[cur_inst.GetOp()] = m_inst_set->GetCost(cur_inst);
+ }
+ }
+
+ inst_energy_cost[cur_inst.GetOp()] = m_inst_set->GetEnergyCost(cur_inst); //reset instruction energy cost
+#endif
+ return true;
+}
Modified: branches/energy_dev/source/cpu/cHardwareBase.h
===================================================================
--- branches/energy_dev/source/cpu/cHardwareBase.h 2007-07-19 21:44:58 UTC (rev 1831)
+++ branches/energy_dev/source/cpu/cHardwareBase.h 2007-07-20 19:21:39 UTC (rev 1832)
@@ -58,6 +58,16 @@
cInstSet* m_inst_set; // Instruction set being used.
cHardwareTracer* m_tracer; // Set this if you want execution traced.
+ // Instruction costs...
+//#if INSTRUCTION_COSTS
+ tArray<int> inst_cost;
+ tArray<int> inst_ft_cost;
+ tArray<int> inst_energy_cost;
+ bool m_has_costs;
+ bool m_has_ft_costs;
+ bool m_has_energy_costs;
+//#endif
+
virtual int GetExecutedSize(const int parent_size);
virtual int GetCopiedSize(const int parent_size, const int child_size) = 0;
@@ -94,6 +104,7 @@
// -------- Core Functionality --------
virtual void Reset() = 0;
virtual void SingleProcess(cAvidaContext& ctx) = 0;
+ virtual bool SingleProcess_PayCosts(cAvidaContext& ctx, const cInstruction& cur_inst); //should be protected
virtual void ProcessBonusInst(cAvidaContext& ctx, const cInstruction& inst) = 0;
Modified: branches/energy_dev/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/energy_dev/source/cpu/cHardwareCPU.cc 2007-07-19 21:44:58 UTC (rev 1831)
+++ branches/energy_dev/source/cpu/cHardwareCPU.cc 2007-07-20 19:21:39 UTC (rev 1832)
@@ -403,15 +403,16 @@
, m_mal_active(hardware_cpu.m_mal_active)
, m_advance_ip(hardware_cpu.m_advance_ip)
, m_executedmatchstrings(hardware_cpu.m_executedmatchstrings)
+{
#if INSTRUCTION_COSTS
-, inst_cost(hardware_cpu.inst_cost)
-, inst_ft_cost(hardware_cpu.inst_ft_cost)
-, inst_energy_cost(hardware_cpu.inst_energy_cost)
-, m_has_costs(hardware_cpu.m_has_costs)
-, m_has_ft_costs(hardware_cpu.m_has_ft_costs)
- // TODO - m_has_energy_costs
+ inst_cost = hardware_cpu.inst_cost;
+ inst_ft_cost = hardware_cpu.inst_ft_cost;
+ inst_energy_cost = hardware_cpu.inst_energy_cost;
+ m_has_costs = hardware_cpu.m_has_costs;
+ m_has_ft_costs = hardware_cpu.m_has_ft_costs;
+ m_has_energy_costs = hardware_cpu.m_has_energy_costs;
#endif
-{
+
}
@@ -438,7 +439,7 @@
inst_energy_cost.Resize(num_inst_cost);
m_has_costs = false;
m_has_ft_costs = false;
- // TODO - m_has_energy_costs
+ m_has_energy_costs = false;
for (int i = 0; i < num_inst_cost; i++) {
inst_cost[i] = m_inst_set->GetCost(cInstruction(i));
@@ -448,10 +449,9 @@
if (!m_has_ft_costs && inst_ft_cost[i]) m_has_ft_costs = true;
inst_energy_cost[i] = m_inst_set->GetEnergyCost(cInstruction(i));
- // TODO - m_has_energy_costs if()
+ if(!m_has_energy_costs && inst_energy_cost[i]) m_has_energy_costs = true;
}
-#endif
-
+#endif
}
void cHardwareCPU::cLocalThread::operator=(const cLocalThread& in_thread)
@@ -579,65 +579,6 @@
CheckImplicitRepro(ctx);
}
-
-// This method will test to see if all costs have been paid associated
-// with executing an instruction and only return true when that instruction
-// should proceed.
-bool cHardwareCPU::SingleProcess_PayCosts(cAvidaContext& ctx, const cInstruction& cur_inst)
-{
-#if INSTRUCTION_COSTS
- assert(cur_inst.GetOp() < inst_cost.GetSize());
-
- // check avaliable energy first
- double energy_req = inst_energy_cost[cur_inst.GetOp()] * (organism->GetPhenotype().GetMerit().GetDouble() / 100.0); //compensate by factor of 100
-
- if(m_world->GetConfig().ENERGY_ENABLED.Get() == 1 && energy_req > 0.0) {
- if(organism->GetPhenotype().GetStoredEnergy() >= energy_req) {
- inst_energy_cost[cur_inst.GetOp()] = 0;
- //subtract energy used from current org energy.
- organism->GetPhenotype().ReduceEnergy(energy_req);
-
-
- // tracking sleeping organisms
- cString instName = m_world->GetHardwareManager().GetInstSet().GetName(cur_inst);
- int cellID = organism->GetCellID();
- if( instName == cString("sleep") || instName == cString("sleep1") || instName == cString("sleep2") ||
- instName == cString("sleep3") || instName == cString("sleep4")) {
- cPopulation& pop = m_world->GetPopulation();
- if(m_world->GetConfig().LOG_SLEEP_TIMES.Get() == 1) {
- pop.AddBeginSleep(cellID,m_world->GetStats().GetUpdate());
- }
- pop.GetCell(cellID).GetOrganism()->SetSleeping(true);
- pop.incNumAsleep(); //TODO - Fix me: this functions get called repeatedly
- }
-
- } else {
- // not enough energy
- return false;
- }
- }
-
- // If first time cost hasn't been paid off...
- if (m_has_ft_costs && inst_ft_cost[cur_inst.GetOp()] > 0) {
- inst_ft_cost[cur_inst.GetOp()]--; // dec cost
- return false;
- }
-
- // Next, look at the per use cost
- if (m_has_costs && m_inst_set->GetCost(cur_inst) > 0) {
- if (inst_cost[cur_inst.GetOp()] > 1) { // if isn't paid off (>1)
- inst_cost[cur_inst.GetOp()]--; // dec cost
- return false;
- } else { // else, reset cost array
- inst_cost[cur_inst.GetOp()] = m_inst_set->GetCost(cur_inst);
- }
- }
-
- inst_energy_cost[cur_inst.GetOp()] = m_inst_set->GetEnergyCost(cur_inst); //reset instruction energy cost
-#endif
- return true;
-}
-
// This method will handle the actual execution of an instruction
// within a single process, once that function has been finalized.
bool cHardwareCPU::SingleProcess_ExecuteInst(cAvidaContext& ctx, const cInstruction& cur_inst)
@@ -4122,7 +4063,7 @@
if(m_world->GetConfig().APPLY_ENERGY_METHOD.Get() == 2) {
organism->GetPhenotype().RefreshEnergy();
organism->GetPhenotype().ApplyToEnergyStore();
- double newMerit = cMerit::EnergyToMerit(organism->GetPhenotype().GetStoredEnergy(), m_world);
+ pop.UpdateMerit(organism->GetCellID(), cMerit::EnergyToMerit(organism->GetPhenotype().GetStoredEnergy(), m_world));
}
return true;
}
Modified: branches/energy_dev/source/cpu/cHardwareCPU.h
===================================================================
--- branches/energy_dev/source/cpu/cHardwareCPU.h 2007-07-19 21:44:58 UTC (rev 1831)
+++ branches/energy_dev/source/cpu/cHardwareCPU.h 2007-07-20 19:21:39 UTC (rev 1832)
@@ -137,19 +137,7 @@
bool m_mal_active; // Has an allocate occured since last divide?
bool m_advance_ip; // Should the IP advance after this instruction?
bool m_executedmatchstrings; // Have we already executed the match strings instruction?
-
- // Instruction costs...
-#if INSTRUCTION_COSTS
- tArray<int> inst_cost;
- tArray<int> inst_ft_cost;
- tArray<int> inst_energy_cost;
- bool m_has_costs;
- bool m_has_ft_costs;
- bool m_has_energy_costs;
-#endif
-
- bool SingleProcess_PayCosts(cAvidaContext& ctx, const cInstruction& cur_inst);
bool SingleProcess_ExecuteInst(cAvidaContext& ctx, const cInstruction& cur_inst);
// -------- Stack Manipulation... --------
Modified: branches/energy_dev/source/cpu/cHardwareExperimental.cc
===================================================================
--- branches/energy_dev/source/cpu/cHardwareExperimental.cc 2007-07-19 21:44:58 UTC (rev 1831)
+++ branches/energy_dev/source/cpu/cHardwareExperimental.cc 2007-07-20 19:21:39 UTC (rev 1832)
@@ -164,13 +164,15 @@
, m_mal_active(hardware_cpu.m_mal_active)
, m_advance_ip(hardware_cpu.m_advance_ip)
, m_executedmatchstrings(hardware_cpu.m_executedmatchstrings)
+{
#if INSTRUCTION_COSTS
-, inst_cost(hardware_cpu.inst_cost)
-, inst_ft_cost(hardware_cpu.inst_ft_cost)
-, m_has_costs(hardware_cpu.m_has_costs)
-, m_has_ft_costs(hardware_cpu.m_has_ft_costs)
+ inst_cost = hardware_cpu.inst_cost;
+ inst_ft_cost = hardware_cpu.inst_ft_cost;
+ inst_energy_cost = hardware_cpu.inst_energy_cost;
+ m_has_costs = hardware_cpu.m_has_costs;
+ m_has_ft_costs = hardware_cpu.m_has_ft_costs;
+ m_has_energy_costs = hardware_cpu.m_has_energy_costs;
#endif
-{
}
@@ -194,8 +196,10 @@
const int num_inst_cost = m_inst_set->GetSize();
inst_cost.Resize(num_inst_cost);
inst_ft_cost.Resize(num_inst_cost);
+ inst_energy_cost.Resize(num_inst_cost);
m_has_costs = false;
m_has_ft_costs = false;
+ m_has_energy_costs = false;
for (int i = 0; i < num_inst_cost; i++) {
inst_cost[i] = m_inst_set->GetCost(cInstruction(i));
@@ -203,9 +207,11 @@
inst_ft_cost[i] = m_inst_set->GetFTCost(cInstruction(i));
if (!m_has_ft_costs && inst_ft_cost[i]) m_has_ft_costs = true;
+
+ inst_energy_cost[i] = m_inst_set->GetEnergyCost(cInstruction(i));
+ if(!m_has_energy_costs && inst_energy_cost[i]) m_has_energy_costs = true;
}
#endif
-
}
void cHardwareExperimental::cLocalThread::operator=(const cLocalThread& in_thread)
@@ -314,7 +320,7 @@
// This method will test to see if all costs have been paid associated
// with executing an instruction and only return true when that instruction
// should proceed.
-bool cHardwareExperimental::SingleProcess_PayCosts(cAvidaContext& ctx, const cInstruction& cur_inst)
+/*bool cHardwareExperimental::SingleProcess_PayCosts(cAvidaContext& ctx, const cInstruction& cur_inst)
{
#if INSTRUCTION_COSTS
assert(cur_inst.GetOp() < inst_cost.GetSize());
@@ -337,7 +343,7 @@
#endif
return true;
-}
+}*/
// This method will handle the actuall execution of an instruction
// within single process, once that function has been finalized.
Modified: branches/energy_dev/source/cpu/cHardwareExperimental.h
===================================================================
--- branches/energy_dev/source/cpu/cHardwareExperimental.h 2007-07-19 21:44:58 UTC (rev 1831)
+++ branches/energy_dev/source/cpu/cHardwareExperimental.h 2007-07-20 19:21:39 UTC (rev 1832)
@@ -137,7 +137,7 @@
bool m_executedmatchstrings; // Have we already executed the match strings instruction?
// Instruction costs...
-#if INSTRUCTION_COSTS
+/*#if INSTRUCTION_COSTS
tArray<int> inst_cost;
tArray<int> inst_ft_cost;
bool m_has_costs;
@@ -145,7 +145,7 @@
#endif
- bool SingleProcess_PayCosts(cAvidaContext& ctx, const cInstruction& cur_inst);
+ bool SingleProcess_PayCosts(cAvidaContext& ctx, const cInstruction& cur_inst);*/
bool SingleProcess_ExecuteInst(cAvidaContext& ctx, const cInstruction& cur_inst);
// -------- Stack Manipulation... --------
Modified: branches/energy_dev/source/cpu/cHardwareGX.cc
===================================================================
--- branches/energy_dev/source/cpu/cHardwareGX.cc 2007-07-19 21:44:58 UTC (rev 1831)
+++ branches/energy_dev/source/cpu/cHardwareGX.cc 2007-07-20 19:21:39 UTC (rev 1832)
@@ -407,10 +407,20 @@
const int num_inst_cost = m_inst_set->GetSize();
inst_cost.Resize(num_inst_cost);
inst_ft_cost.Resize(num_inst_cost);
+ inst_energy_cost.Resize(num_inst_cost);
+ m_has_costs = false;
+ m_has_ft_costs = false;
+ m_has_energy_costs = false;
for (int i = 0; i < num_inst_cost; i++) {
inst_cost[i] = m_inst_set->GetCost(cInstruction(i));
+ if (!m_has_costs && inst_cost[i]) m_has_costs = true;
+
inst_ft_cost[i] = m_inst_set->GetFTCost(cInstruction(i));
+ if (!m_has_ft_costs && inst_ft_cost[i]) m_has_ft_costs = true;
+
+ inst_energy_cost[i] = m_inst_set->GetEnergyCost(cInstruction(i));
+ if(!m_has_energy_costs && inst_energy_cost[i]) m_has_energy_costs = true;
}
#endif
}
@@ -577,7 +587,7 @@
// This method will test to see if all costs have been paid associated
// with executing an instruction and only return true when that instruction
// should proceed.
-bool cHardwareGX::SingleProcess_PayCosts(cAvidaContext& ctx, const cInstruction& cur_inst)
+/*bool cHardwareGX::SingleProcess_PayCosts(cAvidaContext& ctx, const cInstruction& cur_inst)
{
#if INSTRUCTION_COSTS
assert(cur_inst.GetOp() < inst_cost.GetSize());
@@ -600,7 +610,7 @@
#endif
return true;
-}
+}*/
/*! This method executes one instruction for one programid. */
Modified: branches/energy_dev/source/cpu/cHardwareGX.h
===================================================================
--- branches/energy_dev/source/cpu/cHardwareGX.h 2007-07-19 21:44:58 UTC (rev 1831)
+++ branches/energy_dev/source/cpu/cHardwareGX.h 2007-07-20 19:21:39 UTC (rev 1832)
@@ -260,13 +260,13 @@
bool m_reset_heads; // Flas to make it easy for instructions to reset heads back (force task modularity).
// Instruction costs...
-#if INSTRUCTION_COSTS
+/*#if INSTRUCTION_COSTS
tArray<int> inst_cost;
tArray<int> inst_ft_cost;
#endif
- bool SingleProcess_PayCosts(cAvidaContext& ctx, const cInstruction& cur_inst);
+ bool SingleProcess_PayCosts(cAvidaContext& ctx, const cInstruction& cur_inst);*/
bool SingleProcess_ExecuteInst(cAvidaContext& ctx, const cInstruction& cur_inst);
// -------- Stack Manipulation... --------
Modified: branches/energy_dev/source/cpu/cHardwareSMT.cc
===================================================================
--- branches/energy_dev/source/cpu/cHardwareSMT.cc 2007-07-19 21:44:58 UTC (rev 1831)
+++ branches/energy_dev/source/cpu/cHardwareSMT.cc 2007-07-20 19:21:39 UTC (rev 1832)
@@ -172,17 +172,22 @@
const int num_inst_cost = m_inst_set->GetSize();
inst_cost.Resize(num_inst_cost);
inst_ft_cost.Resize(num_inst_cost);
+ inst_energy_cost.Resize(num_inst_cost);
m_has_costs = false;
m_has_ft_costs = false;
-
+ m_has_energy_costs = false;
+
for (int i = 0; i < num_inst_cost; i++) {
inst_cost[i] = m_inst_set->GetCost(cInstruction(i));
if (!m_has_costs && inst_cost[i]) m_has_costs = true;
inst_ft_cost[i] = m_inst_set->GetFTCost(cInstruction(i));
if (!m_has_ft_costs && inst_ft_cost[i]) m_has_ft_costs = true;
+
+ inst_energy_cost[i] = m_inst_set->GetEnergyCost(cInstruction(i));
+ if(!m_has_energy_costs && inst_energy_cost[i]) m_has_energy_costs = true;
}
-#endif
+#endif
organism->NetReset();
}
@@ -232,12 +237,18 @@
const cInstruction& cur_inst = IP().GetInst();
// Test if costs have been paid and it is okay to execute this now...
- const bool exec = SingleProcess_PayCosts(ctx, cur_inst);
+ bool exec = SingleProcess_PayCosts(ctx, cur_inst);
// Now execute the instruction...
if (exec == true) {
- SingleProcess_ExecuteInst(ctx, cur_inst);
-
+
+ // Prob of exec (moved from SingleProcess_PayCosts so that we advance IP after a fail)
+ if ( m_inst_set->GetProbFail(cur_inst) > 0.0 ) {
+ exec = !( ctx.GetRandom().P(m_inst_set->GetProbFail(cur_inst)) );
+ }
+
+ if (exec == true) SingleProcess_ExecuteInst(ctx, cur_inst);
+
// Some instruction (such as jump) may turn advance_ip off. Ususally
// we now want to move to the next instruction in the memory.
if (AdvanceIP() == true) IP().Advance();
@@ -259,7 +270,7 @@
// This method will test to see if all costs have been paid associated
// with executing an instruction and only return true when that instruction
// should proceed.
-bool cHardwareSMT::SingleProcess_PayCosts(cAvidaContext& ctx, const cInstruction& cur_inst)
+/*bool cHardwareSMT::SingleProcess_PayCosts(cAvidaContext& ctx, const cInstruction& cur_inst)
{
#if INSTRUCTION_COSTS
assert(cur_inst.GetOp() < inst_cost.GetSize());
@@ -286,7 +297,7 @@
}
#endif
return true;
-}
+}*/
// This method will handle the actual execution of an instruction
// within single process, once that function has been finalized.
Modified: branches/energy_dev/source/cpu/cHardwareSMT.h
===================================================================
--- branches/energy_dev/source/cpu/cHardwareSMT.h 2007-07-19 21:44:58 UTC (rev 1831)
+++ branches/energy_dev/source/cpu/cHardwareSMT.h 2007-07-20 19:21:39 UTC (rev 1832)
@@ -121,20 +121,18 @@
// Threads
tManagedPointerArray<cLocalThread> m_threads;
tHashTable<int, int> m_thread_lbls;
- int m_cur_thread;
-
- // Instruction costs...
-#if INSTRUCTION_COSTS
+ int m_cur_thread;
+ int m_cur_child;
+
+ // Instruction costs...
+/*#if INSTRUCTION_COSTS
tArray<int> inst_cost;
tArray<int> inst_ft_cost;
bool m_has_costs;
bool m_has_ft_costs;
#endif
-
- int m_cur_child;
-
- bool SingleProcess_PayCosts(cAvidaContext& ctx, const cInstruction& cur_inst);
+ bool SingleProcess_PayCosts(cAvidaContext& ctx, const cInstruction& cur_inst);*/
bool SingleProcess_ExecuteInst(cAvidaContext& ctx, const cInstruction& cur_inst);
Modified: branches/energy_dev/source/cpu/cHardwareTransSMT.cc
===================================================================
--- branches/energy_dev/source/cpu/cHardwareTransSMT.cc 2007-07-19 21:44:58 UTC (rev 1831)
+++ branches/energy_dev/source/cpu/cHardwareTransSMT.cc 2007-07-20 19:21:39 UTC (rev 1832)
@@ -169,17 +169,22 @@
const int num_inst_cost = m_inst_set->GetSize();
inst_cost.Resize(num_inst_cost);
inst_ft_cost.Resize(num_inst_cost);
+ inst_energy_cost.Resize(num_inst_cost);
m_has_costs = false;
m_has_ft_costs = false;
-
+ m_has_energy_costs = false;
+
for (int i = 0; i < num_inst_cost; i++) {
inst_cost[i] = m_inst_set->GetCost(cInstruction(i));
if (!m_has_costs && inst_cost[i]) m_has_costs = true;
inst_ft_cost[i] = m_inst_set->GetFTCost(cInstruction(i));
if (!m_has_ft_costs && inst_ft_cost[i]) m_has_ft_costs = true;
+
+ inst_energy_cost[i] = m_inst_set->GetEnergyCost(cInstruction(i));
+ if(!m_has_energy_costs && inst_energy_cost[i]) m_has_energy_costs = true;
}
-#endif
+#endif
organism->ClearParasites();
organism->NetReset();
@@ -230,11 +235,16 @@
const cInstruction& cur_inst = IP().GetInst();
// Test if costs have been paid and it is okay to execute this now...
- const bool exec = SingleProcess_PayCosts(ctx, cur_inst);
+ bool exec = SingleProcess_PayCosts(ctx, cur_inst);
// Now execute the instruction...
if (exec == true) {
- SingleProcess_ExecuteInst(ctx, cur_inst);
+ // Prob of exec (moved from SingleProcess_PayCosts so that we advance IP after a fail)
+ if ( m_inst_set->GetProbFail(cur_inst) > 0.0 ) {
+ exec = !( ctx.GetRandom().P(m_inst_set->GetProbFail(cur_inst)) );
+ }
+
+ if (exec == true) SingleProcess_ExecuteInst(ctx, cur_inst);
// Some instruction (such as jump) may turn advance_ip off. Ususally
// we now want to move to the next instruction in the memory.
@@ -257,7 +267,7 @@
// This method will test to see if all costs have been paid associated
// with executing an instruction and only return true when that instruction
// should proceed.
-bool cHardwareTransSMT::SingleProcess_PayCosts(cAvidaContext& ctx, const cInstruction& cur_inst)
+/*bool cHardwareTransSMT::SingleProcess_PayCosts(cAvidaContext& ctx, const cInstruction& cur_inst)
{
#if INSTRUCTION_COSTS
assert(cur_inst.GetOp() < inst_cost.GetSize());
@@ -284,7 +294,7 @@
}
#endif
return true;
-}
+}*/
// This method will handle the actual execution of an instruction
// within single process, once that function has been finalized.
Modified: branches/energy_dev/source/cpu/cHardwareTransSMT.h
===================================================================
--- branches/energy_dev/source/cpu/cHardwareTransSMT.h 2007-07-19 21:44:58 UTC (rev 1831)
+++ branches/energy_dev/source/cpu/cHardwareTransSMT.h 2007-07-20 19:21:39 UTC (rev 1832)
@@ -121,19 +121,17 @@
tManagedPointerArray<cLocalThread> m_threads;
tHashTable<int, int> m_thread_lbls;
int m_cur_thread;
-
+ int m_cur_child;
+
// Instruction costs...
-#if INSTRUCTION_COSTS
+/*#if INSTRUCTION_COSTS
tArray<int> inst_cost;
tArray<int> inst_ft_cost;
bool m_has_costs;
bool m_has_ft_costs;
#endif
- int m_cur_child;
-
-
- bool SingleProcess_PayCosts(cAvidaContext& ctx, const cInstruction& cur_inst);
+ bool SingleProcess_PayCosts(cAvidaContext& ctx, const cInstruction& cur_inst);*/
bool SingleProcess_ExecuteInst(cAvidaContext& ctx, const cInstruction& cur_inst);
Modified: branches/energy_dev/source/main/cBirthChamber.cc
===================================================================
--- branches/energy_dev/source/main/cBirthChamber.cc 2007-07-19 21:44:58 UTC (rev 1831)
+++ branches/energy_dev/source/main/cBirthChamber.cc 2007-07-20 19:21:39 UTC (rev 1832)
@@ -158,7 +158,7 @@
merit_array.Resize(1);
if(m_world->GetConfig().ENERGY_ENABLED.Get() == 1) {
- double energy_cap = (double) m_world->GetConfig().ENERGY_CAP.Get();
+// double energy_cap = (double) m_world->GetConfig().ENERGY_CAP.Get();
// calculate energy to be given to child
double child_energy = parent.GetPhenotype().ExtractParentEnergy();
Modified: branches/energy_dev/source/main/cPhenotype.h
===================================================================
--- branches/energy_dev/source/main/cPhenotype.h 2007-07-19 21:44:58 UTC (rev 1831)
+++ branches/energy_dev/source/main/cPhenotype.h 2007-07-20 19:21:39 UTC (rev 1832)
@@ -372,8 +372,8 @@
bool CopyTrue() const { assert(initialized == true); return copy_true; }
bool DivideSex() const { assert(initialized == true); return divide_sex; }
int MateSelectID() const { assert(initialized == true); return mate_select_id; }
- int CrossNum() const { assert(initialized == true); return cross_num; }
- bool ChildFertile() const { assert(initialized == true); return child_fertile;}
+ int CrossNum() const { assert(initialized == true); return cross_num; }
+ bool ChildFertile() const { assert(initialized == true); return child_fertile;}
int GetChildCopiedSize() const { assert(initialized == true); return child_copied_size; }
Modified: branches/energy_dev/source/main/cPopulation.cc
===================================================================
--- branches/energy_dev/source/main/cPopulation.cc 2007-07-19 21:44:58 UTC (rev 1831)
+++ branches/energy_dev/source/main/cPopulation.cc 2007-07-20 19:21:39 UTC (rev 1832)
@@ -232,12 +232,7 @@
tArray<cOrganism*> child_array;
tArray<cMerit> merit_array;
-
- //for energy model
-/* 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();
-*/
-
+
// Update the parent's phenotype.
// This needs to be done before the parent goes into the birth chamber
// or the merit doesn't get passed onto the child correctly
@@ -410,19 +405,19 @@
// Setup the inputs in the target cell.
environment.SetupInputs(ctx, target_cell.input_array);
-
- // Precalculate the merit if requested
- if (m_world->GetConfig().PRECALC_MERIT.Get() > 0){
- cCPUTestInfo test_info;
- cTestCPU* test_cpu = m_world->GetHardwareManager().CreateTestCPU();
- test_info.UseManualInputs(target_cell.input_array); // Test using what the environment will be
- test_cpu->TestGenome(ctx, test_info, in_organism->GetHardware().GetMemory()); // Use the true genome
- in_organism->GetPhenotype().SetMerit(test_info.GetTestPhenotype().GetMerit()); // Update merit
- delete test_cpu;
- }
+
+ // Precalculate the merit if requested
+ if (m_world->GetConfig().PRECALC_MERIT.Get() > 0){
+ cCPUTestInfo test_info;
+ cTestCPU* test_cpu = m_world->GetHardwareManager().CreateTestCPU();
+ test_info.UseManualInputs(target_cell.input_array); // Test using what the environment will be
+ test_cpu->TestGenome(ctx, test_info, in_organism->GetHardware().GetMemory()); // Use the true genome
+ in_organism->GetPhenotype().SetMerit(test_info.GetTestPhenotype().GetMerit()); // Update merit
+ delete test_cpu;
+ }
// Update the archive...
-
-
+
+
in_genotype->AddOrganism();
if (old_genotype != NULL) {
@@ -448,27 +443,27 @@
// Statistics...
m_world->GetStats().RecordBirth(target_cell.GetID(), in_genotype->GetID(),
in_organism->GetPhenotype().ParentTrue());
-
- // @MRR Do coalescence clade set up for new organisms.
- CCladeSetupOrganism(in_organism );
-
+
+ // @MRR Do coalescence clade set up for new organisms.
+ CCladeSetupOrganism(in_organism );
+
//count how many times MERIT_BONUS_INST (rewarded instruction) is in the genome
//only relevant if merit is proportional to # times MERIT_BONUS_INST is in the genome
int rewarded_instruction = m_world->GetConfig().MERIT_BONUS_INST.Get();
int num_rewarded_instructions = 0;
int genome_length = in_organism->GetGenome().GetSize();
-
+
if(rewarded_instruction == -1){
//no key instruction, so no bonus
in_organism->GetPhenotype().SetCurBonusInstCount(0);
- }
+ }
else{
for(int i = 1; i <= genome_length; i++){
if(in_organism->GetGenome()[i-1].GetOp() == rewarded_instruction){
- num_rewarded_instructions++;
+ num_rewarded_instructions++;
}
}
- in_organism->GetPhenotype().SetCurBonusInstCount(num_rewarded_instructions);
+ in_organism->GetPhenotype().SetCurBonusInstCount(num_rewarded_instructions);
}
}
More information about the Avida-cvs
mailing list