[Avida-SVN] r2222 - branches/energy/source/cpu
beckma24 at myxo.css.msu.edu
beckma24 at myxo.css.msu.edu
Tue Dec 4 05:47:44 PST 2007
Author: beckma24
Date: 2007-12-04 08:47:43 -0500 (Tue, 04 Dec 2007)
New Revision: 2222
Modified:
branches/energy/source/cpu/cHardwareCPU.cc
Log:
Fixed bug in sense3-and-rotate and sense-cell-data
Modified: branches/energy/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/energy/source/cpu/cHardwareCPU.cc 2007-12-04 12:53:55 UTC (rev 2221)
+++ branches/energy/source/cpu/cHardwareCPU.cc 2007-12-04 13:47:43 UTC (rev 2222)
@@ -103,7 +103,7 @@
tInstLibEntry<tMethod>("jump-b", &cHardwareCPU::Inst_JumpB),
tInstLibEntry<tMethod>("call", &cHardwareCPU::Inst_Call),
tInstLibEntry<tMethod>("return", &cHardwareCPU::Inst_Return),
-
+
tInstLibEntry<tMethod>("throw", &cHardwareCPU::Inst_Throw),
tInstLibEntry<tMethod>("throwif=0", &cHardwareCPU::Inst_ThrowIf0),
tInstLibEntry<tMethod>("throwif!=0", &cHardwareCPU::Inst_ThrowIfNot0),
@@ -203,9 +203,9 @@
tInstLibEntry<tMethod>("sense", &cHardwareCPU::Inst_SenseLog2), // If you add more sense instructions
tInstLibEntry<tMethod>("sense-unit", &cHardwareCPU::Inst_SenseUnit), // and want to keep stats, also add
tInstLibEntry<tMethod>("sense-m100", &cHardwareCPU::Inst_SenseMult100), // the names to cStats::cStats() @JEB
- // Data collection
+ // Data collection
tInstLibEntry<tMethod>("collect-cell-data", &cHardwareCPU::Inst_CollectCellData),
-
+
tInstLibEntry<tMethod>("donate-rnd", &cHardwareCPU::Inst_DonateRandom),
tInstLibEntry<tMethod>("donate-kin", &cHardwareCPU::Inst_DonateKin),
tInstLibEntry<tMethod>("donate-edt", &cHardwareCPU::Inst_DonateEditDist),
@@ -218,7 +218,7 @@
tInstLibEntry<tMethod>("IObuf-add1", &cHardwareCPU::Inst_IOBufAdd1),
tInstLibEntry<tMethod>("IObuf-add0", &cHardwareCPU::Inst_IOBufAdd0),
-
+
tInstLibEntry<tMethod>("rotate-l", &cHardwareCPU::Inst_RotateL),
tInstLibEntry<tMethod>("rotate-r", &cHardwareCPU::Inst_RotateR),
tInstLibEntry<tMethod>("rotate-left-one", &cHardwareCPU::Inst_RotateLeftOne),
@@ -231,14 +231,14 @@
tInstLibEntry<tMethod>("get-cell-x", &cHardwareCPU::Inst_GetCellX),
tInstLibEntry<tMethod>("get-cell-y", &cHardwareCPU::Inst_GetCellY),
tInstLibEntry<tMethod>("dist-from-diag", &cHardwareCPU::Inst_GetDistanceFromDiagonal),
-
+
// @WRE additions for movement
tInstLibEntry<tMethod>("tumble", &cHardwareCPU::Inst_Tumble),
tInstLibEntry<tMethod>("move", &cHardwareCPU::Inst_Move),
// Addition for follow-the-leader
- tInstLibEntry<tMethod>("sense3-and-rotate", &cHardwareCPU::Inst_Sense3andRotate),
- tInstLibEntry<tMethod>("sense-cell-data", &cHardwareCPU::Inst_SenseCellData),
-
+ tInstLibEntry<tMethod>("sense3-and-rotate", &cHardwareCPU::Inst_Sense3andRotate),
+ tInstLibEntry<tMethod>("sense-cell-data", &cHardwareCPU::Inst_SenseCellData),
+
// Threading instructions
tInstLibEntry<tMethod>("fork-th", &cHardwareCPU::Inst_ForkThread),
tInstLibEntry<tMethod>("forkl", &cHardwareCPU::Inst_ForkThreadLabel),
@@ -341,10 +341,10 @@
tInstLibEntry<tMethod>("repro-X", &cHardwareCPU::Inst_Repro),
tInstLibEntry<tMethod>("repro-Y", &cHardwareCPU::Inst_Repro),
tInstLibEntry<tMethod>("repro-Z", &cHardwareCPU::Inst_Repro),
-
+
tInstLibEntry<tMethod>("put-repro", &cHardwareCPU::Inst_TaskPutRepro),
tInstLibEntry<tMethod>("metabolize", &cHardwareCPU::Inst_TaskPutResetInputsRepro),
-
+
tInstLibEntry<tMethod>("sterilize", &cHardwareCPU::Inst_Sterilize),
tInstLibEntry<tMethod>("spawn-deme", &cHardwareCPU::Inst_SpawnDeme),
@@ -353,7 +353,7 @@
tInstLibEntry<tMethod>("kazi", &cHardwareCPU::Inst_Kazi),
tInstLibEntry<tMethod>("kazi5", &cHardwareCPU::Inst_Kazi5),
tInstLibEntry<tMethod>("die", &cHardwareCPU::Inst_Die),
-
+
// Sleep and time
tInstLibEntry<tMethod>("sleep", &cHardwareCPU::Inst_Sleep),
tInstLibEntry<tMethod>("sleep1", &cHardwareCPU::Inst_Sleep),
@@ -370,11 +370,11 @@
tInstLibEntry<tMethod>("regulate", &cHardwareCPU::Inst_Regulate),
tInstLibEntry<tMethod>("numberate", &cHardwareCPU::Inst_Numberate),
tInstLibEntry<tMethod>("bit-cons", &cHardwareCPU::Inst_BitConsensus),
-
+
// Energy usage
tInstLibEntry<tMethod>("double-energy-usage", &cHardwareCPU::Inst_DoubleEnergyUsage),
tInstLibEntry<tMethod>("half-energy-usage", &cHardwareCPU::Inst_HalfEnergyUsage),
-
+
// Messaging
tInstLibEntry<tMethod>("send-msg", &cHardwareCPU::Inst_SendMessage),
tInstLibEntry<tMethod>("send-msg-TX", &cHardwareCPU::Inst_SendMessage_TX),
@@ -382,10 +382,10 @@
tInstLibEntry<tMethod>("retrieve-msg", &cHardwareCPU::Inst_RetrieveMessage),
tInstLibEntry<tMethod>("retrieve-msg-RX-complete", &cHardwareCPU::Inst_RetrieveMessage_RXComplete),
tInstLibEntry<tMethod>("carrier-sense", &cHardwareCPU::Inst_CarrierSense),
-
+
// Placebo instructions
tInstLibEntry<tMethod>("skip", &cHardwareCPU::Inst_Skip),
-
+
// Must always be the last instruction in the array
tInstLibEntry<tMethod>("NULL", &cHardwareCPU::Inst_Nop, 0, "True no-operation instruction: does nothing"),
};
@@ -402,8 +402,8 @@
const int f_size = sizeof(s_f_array)/sizeof(tInstLibEntry<tMethod>);
static tMethod functions[f_size];
for (int i = 0; i < f_size; i++) functions[i] = s_f_array[i].GetFunction();
-
- const int def = 0;
+
+ const int def = 0;
const int null_inst = f_size - 1;
return new tInstLib<tMethod>(f_size, s_f_array, n_names, nop_mods, functions, def, null_inst);
@@ -442,7 +442,7 @@
m_has_ft_costs = hardware_cpu.m_has_ft_costs;
m_has_energy_costs = hardware_cpu.m_has_energy_costs;
#endif
-
+
}
@@ -477,18 +477,18 @@
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
-
+
// Promoter model
if (m_world->GetConfig().PROMOTERS_ENABLED.Get())
{
// Ideally, this shouldn't be hard-coded
cInstruction promoter_inst = m_world->GetHardwareManager().GetInstSet().GetInst(cStringUtil::Stringf("promoter"));
-
+
m_promoter_index = -1; // Meaning the last promoter was nothing
m_promoter_offset = 0;
m_promoter_regulation = 0;
@@ -534,7 +534,7 @@
void cHardwareCPU::SingleProcess(cAvidaContext& ctx)
{
-
+
int last_IP_pos = IP().GetPosition();
// Mark this organism as running...
@@ -548,7 +548,7 @@
// Count the cpu cycles used
phenotype.IncCPUCyclesUsed();
if (!m_world->GetConfig().NO_CPU_CYCLE_TIME.Get()) phenotype.IncTimeUsed();
-
+
const int num_threads = GetNumThreads();
// If we have threads turned on and we executed each thread in a single
@@ -576,11 +576,11 @@
// Test if costs have been paid and it is okay to execute this now...
bool exec = SingleProcess_PayCosts(ctx, cur_inst);
-
+
// If there are no active promoters and a certain mode is set, then don't execute any further instructions
if ((m_world->GetConfig().PROMOTERS_ENABLED.Get() == 1)
- && (m_world->GetConfig().NO_ACTIVE_PROMOTER_EFFECT.Get() == 2)
- && (m_promoter_index == -1) )
+ && (m_world->GetConfig().NO_ACTIVE_PROMOTER_EFFECT.Get() == 2)
+ && (m_promoter_index == -1) )
{
exec = false;
}
@@ -591,7 +591,7 @@
// execution, because this instruction reference may be invalid after
// certain classes of instructions (namely divide instructions) @DMB
const int time_cost = m_inst_set->GetAddlTimeCost(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)) );
@@ -601,7 +601,7 @@
if (m_world->GetConfig().PROMOTERS_ENABLED.Get() == 1) {
m_threads[m_cur_thread].IncPromoterInstExecuted();
}
-
+
if (exec == true) SingleProcess_ExecuteInst(ctx, cur_inst);
// Some instruction (such as jump) may turn m_advance_ip off. Usually
@@ -610,7 +610,7 @@
// Pay the time cost of the instruction now
phenotype.IncTimeUsed(time_cost);
-
+
// In the promoter model, we may force termination after a certain number of inst have been executed
if ( m_world->GetConfig().PROMOTERS_ENABLED.Get() == 1 )
{
@@ -620,11 +620,11 @@
if ( m_world->GetConfig().PROMOTER_INST_MAX.Get() && (m_threads[m_cur_thread].GetPromoterInstExecuted() >= m_world->GetConfig().PROMOTER_INST_MAX.Get()) )
Inst_Terminate(ctx);
}
-
+
} // if exec
-
+
} // Previous was executed once for each thread...
-
+
// Kill creatures who have reached their max num of instructions executed
const int max_executed = organism->GetMaxExecuted();
if ((max_executed > 0 && phenotype.GetTimeUsed() >= max_executed)
@@ -649,24 +649,24 @@
// If there is an execution error, execute a random instruction.
if (organism->TestExeErr()) actual_inst = m_inst_set->GetRandomInst(ctx);
#endif /* EXECUTION_ERRORS */
-
+
// Get a pointer to the corresponding method...
int inst_idx = m_inst_set->GetLibFunctionIndex(actual_inst);
// Mark the instruction as executed
IP().SetFlagExecuted();
-
+
#if INSTRUCTION_COUNT
// instruction execution count incremented
organism->GetPhenotype().IncCurInstCount(actual_inst.GetOp());
#endif
-
+
// And execute it.
const bool exec_success = (this->*(m_functions[inst_idx]))(ctx);
-
+
// NOTE: Organism may be dead now if instruction executed killed it (such as some divides, "die", or "kazi")
-
+
#if INSTRUCTION_COUNT
// Decrement if the instruction was not executed successfully.
if (exec_success == false) {
@@ -729,7 +729,7 @@
<< "F-Head:" << GetHead(nHardware::HEAD_FLOW).GetPosition() << " "
<< "RL:" << GetReadLabel().AsString() << " "
<< endl;
-
+
int number_of_stacks = GetNumStacks();
for (int stack_id = 0; stack_id < number_of_stacks; stack_id++) {
fp << ((m_threads[m_cur_thread].cur_stack == stack_id) ? '*' : ' ') << " Stack " << stack_id << ":" << setbase(16) << setfill('0');
@@ -740,7 +740,7 @@
fp << " Mem (" << GetMemory().GetSize() << "):"
<< " " << GetMemory().AsString()
<< endl;
-
+
if (m_world->GetConfig().PROMOTERS_ENABLED.Get())
{
fp << "Promoters: index=" << m_promoter_index << " offset=" << m_promoter_offset;
@@ -1216,7 +1216,7 @@
bool cHardwareCPU::Allocate_Random(cAvidaContext& ctx, const int old_size, const int new_size)
{
GetMemory().Resize(new_size);
-
+
for (int i = old_size; i < new_size; i++) {
GetMemory()[i] = m_inst_set->GetRandomInst(ctx);
}
@@ -1241,7 +1241,7 @@
}
if (allocated_size < 1) {
organism->Fault(FAULT_LOC_ALLOC, FAULT_TYPE_ERROR,
- cStringUtil::Stringf("Allocate of %d too small", allocated_size));
+ cStringUtil::Stringf("Allocate of %d too small", allocated_size));
return false;
}
@@ -1251,16 +1251,16 @@
// Make sure that the new size is in range.
if (new_size > MAX_CREATURE_SIZE || new_size < MIN_CREATURE_SIZE) {
organism->Fault(FAULT_LOC_ALLOC, FAULT_TYPE_ERROR,
- cStringUtil::Stringf("Invalid post-allocate size (%d)",
- new_size));
+ cStringUtil::Stringf("Invalid post-allocate size (%d)",
+ new_size));
return false;
}
const int max_alloc_size = (int) (old_size * m_world->GetConfig().CHILD_SIZE_RANGE.Get());
if (allocated_size > max_alloc_size) {
organism->Fault(FAULT_LOC_ALLOC, FAULT_TYPE_ERROR,
- cStringUtil::Stringf("Allocate too large (%d > %d)",
- allocated_size, max_alloc_size));
+ cStringUtil::Stringf("Allocate too large (%d > %d)",
+ allocated_size, max_alloc_size));
return false;
}
@@ -1268,8 +1268,8 @@
(int) (allocated_size * m_world->GetConfig().CHILD_SIZE_RANGE.Get());
if (old_size > max_old_size) {
organism->Fault(FAULT_LOC_ALLOC, FAULT_TYPE_ERROR,
- cStringUtil::Stringf("Allocate too small (%d > %d)",
- old_size, max_old_size));
+ cStringUtil::Stringf("Allocate too small (%d > %d)",
+ old_size, max_old_size));
return false;
}
@@ -1286,7 +1286,7 @@
}
m_mal_active = true;
-
+
return true;
}
@@ -1320,7 +1320,7 @@
// Handle Divide Mutations...
Divide_DoMutations(ctx, mut_multiplier);
-
+
// Many tests will require us to run the offspring through a test CPU;
// this is, for example, to see if mutations need to be reverted or if
// lineages need to be updated.
@@ -1340,7 +1340,7 @@
// Activate the child
bool parent_alive = organism->ActivateDivide(ctx);
-
+
// Do more work if the parent lives through the birth of the offspring
if (parent_alive) {
if (m_world->GetConfig().DIVIDE_METHOD.Get() == DIVIDE_METHOD_SPLIT) Reset();
@@ -1350,16 +1350,16 @@
}
/*
- Almost the same as Divide_Main, but resamples reverted offspring.
-
- RESAMPLING ONLY WORKS CORRECTLY WHEN ALL MUTIONS OCCUR ON DIVIDE!!
-
- AWC - 06/29/06
-*/
+ Almost the same as Divide_Main, but resamples reverted offspring.
+
+ RESAMPLING ONLY WORKS CORRECTLY WHEN ALL MUTIONS OCCUR ON DIVIDE!!
+
+ AWC - 06/29/06
+ */
bool cHardwareCPU::Divide_MainRS(cAvidaContext& ctx, const int div_point,
- const int extra_lines, double mut_multiplier)
+ const int extra_lines, double mut_multiplier)
{
-
+
//cStats stats = m_world->GetStats();
const int child_size = GetMemory().GetSize() - div_point - extra_lines;
@@ -1378,20 +1378,20 @@
unsigned
totalMutations = 0,
mutations = 0;
- //RScount = 0;
-
-
+ //RScount = 0;
+
+
bool
fitTest = false;
-
+
// Handle Divide Mutations...
/*
- Do mutations until one of these conditions are satisified:
- we have resampled X times
- we have an offspring with the same number of muations as the first offspring
- that is not reverted
- the parent is steralized (usually means an implicit mutation)
- */
+ Do mutations until one of these conditions are satisified:
+ we have resampled X times
+ we have an offspring with the same number of muations as the first offspring
+ that is not reverted
+ the parent is steralized (usually means an implicit mutation)
+ */
for(unsigned i = 0; i <= 100; i++){
if(i == 0){
mutations = totalMutations = Divide_DoMutations(ctx, mut_multiplier);
@@ -1400,23 +1400,23 @@
mutations = Divide_DoMutations(ctx, mut_multiplier);
m_world->GetStats().IncResamplings();
}
-
+
fitTest = Divide_TestFitnessMeasures(ctx);
if(!fitTest && mutations >= totalMutations) break;
-
+
}
// think about making this mutations == totalMuations - though this may be too hard...
/*
- if(RScount > 2)
- cerr << "Resampled " << RScount << endl;
- */
+ if(RScount > 2)
+ cerr << "Resampled " << RScount << endl;
+ */
//org could not be resampled beneath the hard cap -- it is then steraalized
if(fitTest/*RScount == 11*/) {
organism->GetPhenotype().ChildFertile() = false;
m_world->GetStats().IncFailedResamplings();
}
-
+
#if INSTRUCTION_COSTS
// reset first time instruction costs
for (int i = 0; i < inst_ft_cost.GetSize(); i++) {
@@ -1440,17 +1440,17 @@
}
/*
- Almost the same as Divide_Main, but only allows for one mutation
- on divde and resamples reverted offspring.
-
- RESAMPLING ONLY WORKS CORRECTLY WHEN ALL MUTIONS OCCUR ON DIVIDE!!
-
- AWC - 07/28/06
-*/
+ Almost the same as Divide_Main, but only allows for one mutation
+ on divde and resamples reverted offspring.
+
+ RESAMPLING ONLY WORKS CORRECTLY WHEN ALL MUTIONS OCCUR ON DIVIDE!!
+
+ AWC - 07/28/06
+ */
bool cHardwareCPU::Divide_Main1RS(cAvidaContext& ctx, const int div_point,
- const int extra_lines, double mut_multiplier)
+ const int extra_lines, double mut_multiplier)
{
-
+
//cStats stats = m_world->GetStats();
const int child_size = GetMemory().GetSize() - div_point - extra_lines;
@@ -1470,19 +1470,19 @@
totalMutations = 0,
mutations = 0;
// RScount = 0;
-
+
bool
fitTest = false;
-
-
+
+
// Handle Divide Mutations...
/*
- Do mutations until one of these conditions are satisified:
- we have resampled X times
- we have an offspring with the same number of muations as the first offspring
- that is not reverted
- the parent is steralized (usually means an implicit mutation)
- */
+ Do mutations until one of these conditions are satisified:
+ we have resampled X times
+ we have an offspring with the same number of muations as the first offspring
+ that is not reverted
+ the parent is steralized (usually means an implicit mutation)
+ */
for(unsigned i = 0; i < 100; i++){
if(!i){
mutations = totalMutations = Divide_DoMutations(ctx, mut_multiplier,1);
@@ -1491,23 +1491,23 @@
mutations = Divide_DoExactMutations(ctx, mut_multiplier,1);
m_world->GetStats().IncResamplings();
}
-
+
fitTest = Divide_TestFitnessMeasures(ctx);
//if(mutations > 1 ) cerr << "Too Many mutations!!!!!!!!!!!!!!!" << endl;
if(!fitTest && mutations >= totalMutations) break;
-
+
}
// think about making this mutations == totalMuations - though this may be too hard...
/*
- if(RScount > 2)
- cerr << "Resampled " << RScount << endl;
- */
+ if(RScount > 2)
+ cerr << "Resampled " << RScount << endl;
+ */
//org could not be resampled beneath the hard cap -- it is then steraalized
if(fitTest/*RScount == 11*/) {
organism->GetPhenotype().ChildFertile() = false;
m_world->GetStats().IncFailedResamplings();
}
-
+
#if INSTRUCTION_COSTS
// reset first time instruction costs
for (int i = 0; i < inst_ft_cost.GetSize(); i++) {
@@ -1531,17 +1531,17 @@
}
/*
- Almost the same as Divide_Main, but only allows for one mutation
- on divde and resamples reverted offspring.
-
- RESAMPLING ONLY WORKS CORRECTLY WHEN ALL MUTIONS OCCUR ON DIVIDE!!
-
- AWC - 07/28/06
-*/
+ Almost the same as Divide_Main, but only allows for one mutation
+ on divde and resamples reverted offspring.
+
+ RESAMPLING ONLY WORKS CORRECTLY WHEN ALL MUTIONS OCCUR ON DIVIDE!!
+
+ AWC - 07/28/06
+ */
bool cHardwareCPU::Divide_Main2RS(cAvidaContext& ctx, const int div_point,
- const int extra_lines, double mut_multiplier)
+ const int extra_lines, double mut_multiplier)
{
-
+
//cStats stats = m_world->GetStats();
const int child_size = GetMemory().GetSize() - div_point - extra_lines;
@@ -1561,19 +1561,19 @@
totalMutations = 0,
mutations = 0;
// RScount = 0;
-
+
bool
fitTest = false;
-
-
+
+
// Handle Divide Mutations...
/*
- Do mutations until one of these conditions are satisified:
- we have resampled X times
- we have an offspring with the same number of muations as the first offspring
- that is not reverted
- the parent is steralized (usually means an implicit mutation)
- */
+ Do mutations until one of these conditions are satisified:
+ we have resampled X times
+ we have an offspring with the same number of muations as the first offspring
+ that is not reverted
+ the parent is steralized (usually means an implicit mutation)
+ */
for(unsigned i = 0; i < 100; i++){
if(!i){
mutations = totalMutations = Divide_DoMutations(ctx, mut_multiplier,2);
@@ -1582,23 +1582,23 @@
Divide_DoExactMutations(ctx, mut_multiplier,mutations);
m_world->GetStats().IncResamplings();
}
-
+
fitTest = Divide_TestFitnessMeasures(ctx);
//if(mutations > 1 ) cerr << "Too Many mutations!!!!!!!!!!!!!!!" << endl;
if(!fitTest && mutations >= totalMutations) break;
-
+
}
// think about making this mutations == totalMuations - though this may be too hard...
/*
- if(RScount > 2)
- cerr << "Resampled " << RScount << endl;
- */
+ if(RScount > 2)
+ cerr << "Resampled " << RScount << endl;
+ */
//org could not be resampled beneath the hard cap -- it is then steraalized
if(fitTest/*RScount == 11*/) {
organism->GetPhenotype().ChildFertile() = false;
m_world->GetStats().IncFailedResamplings();
}
-
+
#if INSTRUCTION_COSTS
// reset first time instruction costs
for (int i = 0; i < inst_ft_cost.GetSize(); i++) {
@@ -1827,10 +1827,10 @@
{
// Only initialize this once to save some time...
static cInstruction catch_inst = GetInstSet().GetInst(cStringUtil::Stringf("catch"));
-
+
//Look for the label directly (no complement)
ReadLabel();
-
+
cHeadCPU search_head(IP());
int start_pos = search_head.GetPosition();
search_head++;
@@ -1842,7 +1842,7 @@
{
int catch_pos = search_head.GetPosition();
search_head++;
-
+
// Continue to examine the label after the catch
// (1) It ends (=> use the catch!)
// (2) It becomes longer than the throw label (=> use the catch!)
@@ -1871,7 +1871,7 @@
}
search_head.Advance();
}
-
+
return false;
}
@@ -1892,7 +1892,7 @@
{
// Only initialize this once to save some time...
static cInstruction label_inst = GetInstSet().GetInst(cStringUtil::Stringf("label"));
-
+
//Look for an EXACT label match after a 'label' instruction
ReadLabel();
@@ -1912,7 +1912,7 @@
if ( !m_inst_set->IsNop(search_head.GetInst()) ) break;
if ( GetLabel()[size_matched] != m_inst_set->GetNopMod( search_head.GetInst()) ) break;
if ( !m_inst_set->IsNop(search_head.GetInst()) ) break;
-
+
size_matched++;
search_head++;
}
@@ -1926,13 +1926,13 @@
// so we mark the catch as executed.
return true;
}
-
+
//If we advanced past NOPs during testing, retreat
if ( !m_inst_set->IsNop(search_head.GetInst()) ) search_head--;
}
search_head++;
}
-
+
return false;
}
@@ -2308,17 +2308,17 @@
{
const int op1 = REG_BX;
const int op2 = REG_AX;
-
+
const cHeadCPU from(this, GetRegister(op1));
cHeadCPU to(this, GetRegister(op2) + GetRegister(op1));
-// sCPUStats& cpu_stats = organism->CPUStats();
+ // sCPUStats& cpu_stats = organism->CPUStats();
if (organism->TestCopyMut(ctx)) {
to.SetInst(m_inst_set->GetRandomInst(ctx));
to.SetFlagMutated(); // Mark this instruction as mutated...
to.SetFlagCopyMut(); // Mark this instruction as copy mut...
- //organism->GetPhenotype().IsMutated() = true;
-// cpu_stats.mut_stats.copy_mut_count++;
+ //organism->GetPhenotype().IsMutated() = true;
+ // cpu_stats.mut_stats.copy_mut_count++;
} else {
to.SetInst(from.GetInst());
to.ClearFlagMutated(); // UnMark
@@ -2326,7 +2326,7 @@
}
to.SetFlagCopied(); // Set the copied flag.
-// cpu_stats.mut_stats.copies_exec++;
+ // cpu_stats.mut_stats.copies_exec++;
return true;
}
@@ -2334,7 +2334,7 @@
{
const int dst = FindModifiedRegister(REG_CX);
const int src = REG_BX;
-
+
const cHeadCPU from(this, GetRegister(src));
// Dis-allowing mutations on read, for the moment (write only...)
@@ -2348,26 +2348,26 @@
const int src = FindModifiedRegister(REG_CX);
const int op1 = REG_BX;
const int op2 = REG_AX;
-
+
cHeadCPU to(this, GetRegister(op2) + GetRegister(op1));
const int value = Mod(GetRegister(src), m_inst_set->GetSize());
-// sCPUStats& cpu_stats = organism->CPUStats();
-
+ // sCPUStats& cpu_stats = organism->CPUStats();
+
// Change value on a mutation...
if (organism->TestCopyMut(ctx)) {
to.SetInst(m_inst_set->GetRandomInst(ctx));
to.SetFlagMutated(); // Mark this instruction as mutated...
to.SetFlagCopyMut(); // Mark this instruction as copy mut...
- //organism->GetPhenotype().IsMutated() = true;
-// cpu_stats.mut_stats.copy_mut_count++;
+ //organism->GetPhenotype().IsMutated() = true;
+ // cpu_stats.mut_stats.copy_mut_count++;
} else {
to.SetInst(cInstruction(value));
to.ClearFlagMutated(); // UnMark
to.ClearFlagCopyMut(); // UnMark
}
-
+
to.SetFlagCopied(); // Set the copied flag.
-// cpu_stats.mut_stats.copies_exec++;
+ // cpu_stats.mut_stats.copies_exec++;
return true;
}
@@ -2385,15 +2385,15 @@
const int op1 = REG_AX;
cHeadCPU to(this, GetRegister(op1) + GetRegister(dst));
const int value = Mod(StackPop(), m_inst_set->GetSize());
-// sCPUStats& cpu_stats = organism->CPUStats();
+ // sCPUStats& cpu_stats = organism->CPUStats();
// Change value on a mutation...
if (organism->TestCopyMut(ctx)) {
to.SetInst(m_inst_set->GetRandomInst(ctx));
to.SetFlagMutated(); // Mark this instruction as mutated...
to.SetFlagCopyMut(); // Mark this instruction as copy mut...
- //organism->GetPhenotype().IsMutated() = true;
-// cpu_stats.mut_stats.copy_mut_count++;
+ //organism->GetPhenotype().IsMutated() = true;
+ // cpu_stats.mut_stats.copy_mut_count++;
} else {
to.SetInst(cInstruction(value));
to.ClearFlagMutated(); // UnMark
@@ -2401,7 +2401,7 @@
}
to.SetFlagCopied(); // Set the copied flag.
-// cpu_stats.mut_stats.copies_exec++;
+ // cpu_stats.mut_stats.copies_exec++;
return true;
}
@@ -2410,7 +2410,7 @@
const int dst = FindModifiedRegister(REG_CX);
const int op1 = REG_BX;
const int op2 = REG_AX;
-
+
cHeadCPU from(this, GetRegister(op1));
cHeadCPU to(this, GetRegister(op2) + GetRegister(op1));
@@ -2419,7 +2419,7 @@
to.SetInst(m_inst_set->GetRandomInst(ctx));
to.SetFlagMutated(); // Mark this instruction as mutated...
to.SetFlagCopyMut(); // Mark this instruction as copy mut...
- //organism->GetPhenotype().IsMutated() = true;
+ //organism->GetPhenotype().IsMutated() = true;
}
GetRegister(dst) = from.GetInst().GetOp() - to.GetInst().GetOp();
@@ -2431,7 +2431,7 @@
{
const int op1 = REG_BX;
const int op2 = REG_AX;
-
+
const cHeadCPU from(this, GetRegister(op1));
const cHeadCPU to(this, GetRegister(op2) + GetRegister(op1));
@@ -2462,11 +2462,11 @@
}
/*
- Divide with resampling -- Same as regular divide but on reversions will be
- resampled after they are reverted.
-
- AWC 06/29/06
-
+ Divide with resampling -- Same as regular divide but on reversions will be
+ resampled after they are reverted.
+
+ AWC 06/29/06
+
*/
bool cHardwareCPU::Inst_DivideRS(cAvidaContext& ctx)
@@ -2527,7 +2527,7 @@
static cInstruction transposon_inst = GetInstSet().GetInst(cStringUtil::Stringf("transposon"));
cCPUMemory& child_genome = organism->ChildGenome();
-
+
// Count the number of transposons that are marked as executed
int tr_count = 0;
for (int i=0; i < child_genome.GetSize(); i++)
@@ -2545,19 +2545,19 @@
}
-/*
- const tArray<cCodeLabel> tr = organism->GetPhenotype().GetActiveTransposons();
- cCPUMemory& child_genome = organism->ChildGenome();
-
- for (int i=0; i < tr.GetSize(); i++)
- {
- if (ctx.GetRandom().P(0.1))
- {
- const unsigned int mut_line = ctx.GetRandom().GetUInt(child_genome.GetSize() + 1);
- child_genome.Insert(mut_line, transposon_inst);
- }
- }
-*/
+ /*
+ const tArray<cCodeLabel> tr = organism->GetPhenotype().GetActiveTransposons();
+ cCPUMemory& child_genome = organism->ChildGenome();
+
+ for (int i=0; i < tr.GetSize(); i++)
+ {
+ if (ctx.GetRandom().P(0.1))
+ {
+ const unsigned int mut_line = ctx.GetRandom().GetUInt(child_genome.GetSize() + 1);
+ child_genome.Insert(mut_line, transposon_inst);
+ }
+ }
+ */
}
bool cHardwareCPU::Inst_Repro(cAvidaContext& ctx)
@@ -2565,14 +2565,14 @@
// const bool viable = Divide_CheckViable(ctx, div_point, child_size);
// these checks should be done, but currently they make some assumptions
// that crash when evaluating this kind of organism -- JEB
-
+
if (organism->GetPhenotype().GetCurBonus() < m_world->GetConfig().REQUIRED_BONUS.Get()) return false;
// Setup child
cCPUMemory& child_genome = organism->ChildGenome();
child_genome = GetMemory();
organism->GetPhenotype().SetLinesCopied(GetMemory().GetSize());
-
+
int lines_executed = 0;
for ( int i = 0; i < GetMemory().GetSize(); i++ ) {
if ( GetMemory().FlagExecuted(i)) lines_executed++;
@@ -2631,7 +2631,7 @@
const int reg_used = FindModifiedRegister(REG_BX);
const int value = GetRegister(reg_used);
- // GetRegister(reg_used) = 0;
+ // GetRegister(reg_used) = 0;
organism->DoOutput(ctx, value);
// Immediately attempt a repro
@@ -2645,7 +2645,7 @@
// Immediately attempt a repro
Inst_Repro(ctx);
-
+
// return value of put since successful repro would wipe state anyway
return return_value;
}
@@ -2664,7 +2664,7 @@
return true;
}
-
+
bool cHardwareCPU::Inst_Sterilize(cAvidaContext& ctx)
{
organism->GetPhenotype().IsFertile() = false;
@@ -2824,7 +2824,7 @@
organism->GetOrgInterface().ResetInputs(ctx); // Now re-randomize the inputs this organism sees
organism->ClearInput(); // Also clear their input buffers, or they can still claim
// rewards for numbers no longer in their environment!
-
+
const int reg_used_1 = FindModifiedRegister(REG_BX);
const int reg_used_2 = FindNextRegister(reg_used_1);
@@ -2905,39 +2905,39 @@
bool cHardwareCPU::Inst_TaskIO_Feedback(cAvidaContext& ctx)
{
const int reg_used = FindModifiedRegister(REG_BX);
-
+
//check cur_bonus before the output
double preOutputBonus = organism->GetPhenotype().GetCurBonus();
// Do the "put" component
const int value_out = GetRegister(reg_used);
organism->DoOutput(ctx, value_out); // Check for tasks completed.
-
+
//check cur_merit after the output
double postOutputBonus = organism->GetPhenotype().GetCurBonus();
//push the effect of the IO on merit (+,0,-) to the active stack
-
+
if (preOutputBonus > postOutputBonus){
StackPush(-1);
- }
+ }
else if (preOutputBonus == postOutputBonus){
StackPush(0);
- }
+ }
else if (preOutputBonus < postOutputBonus){
StackPush(1);
- }
+ }
else {
assert(0);
//Bollocks. There was an error.
- }
-
-
+ }
-
-
+
+
+
+
// Do the "get" component
const int value_in = organism->GetNextInput();
GetRegister(reg_used) = value_in;
@@ -2947,28 +2947,28 @@
bool cHardwareCPU::Inst_MatchStrings(cAvidaContext& ctx)
{
- if (m_executedmatchstrings)
- return false;
- organism->DoOutput(ctx, 357913941);
- m_executedmatchstrings = true;
- return true;
+ if (m_executedmatchstrings)
+ return false;
+ organism->DoOutput(ctx, 357913941);
+ m_executedmatchstrings = true;
+ return true;
}
bool cHardwareCPU::Inst_Sell(cAvidaContext& ctx)
{
- int search_label = GetLabel().AsInt(3) % MARKET_SIZE;
- int send_value = GetRegister(REG_BX);
- int sell_price = m_world->GetConfig().SELL_PRICE.Get();
- organism->SellValue(send_value, search_label, sell_price);
- return true;
+ int search_label = GetLabel().AsInt(3) % MARKET_SIZE;
+ int send_value = GetRegister(REG_BX);
+ int sell_price = m_world->GetConfig().SELL_PRICE.Get();
+ organism->SellValue(send_value, search_label, sell_price);
+ return true;
}
bool cHardwareCPU::Inst_Buy(cAvidaContext& ctx)
{
- int search_label = GetLabel().AsInt(3) % MARKET_SIZE;
- int buy_price = m_world->GetConfig().BUY_PRICE.Get();
- GetRegister(REG_BX) = organism->BuyValue(search_label, buy_price);
- return true;
+ int search_label = GetLabel().AsInt(3) % MARKET_SIZE;
+ int buy_price = m_world->GetConfig().BUY_PRICE.Get();
+ GetRegister(REG_BX) = organism->BuyValue(search_label, buy_price);
+ return true;
}
bool cHardwareCPU::Inst_Send(cAvidaContext& ctx)
@@ -3006,13 +3006,13 @@
// Returns the amount of a resource or resources
// specified by modifying NOPs into register BX
const tArray<double> & res_count = organism->GetOrgInterface().GetResources();
-
+
// Arbitrarily set to BX since the conditional instructions use this directly.
int reg_to_set = REG_BX;
-
+
// There are no resources, return
if (res_count.GetSize() == 0) return false;
-
+
// Only recalculate logs if these values have changed
static int last_num_resources = 0;
static int max_label_length = 0;
@@ -3020,16 +3020,16 @@
if ((last_num_resources != res_count.GetSize()))
{
- max_label_length = (int) ceil(log((double)res_count.GetSize())/log((double)num_nops));
- last_num_resources = res_count.GetSize();
+ max_label_length = (int) ceil(log((double)res_count.GetSize())/log((double)num_nops));
+ last_num_resources = res_count.GetSize();
}
-
+
// Convert modifying NOPs to the index of the resource.
// If there are fewer than the number of NOPs required
// to uniquely specify a resource, then add together
// a subset of resources (motivation: regulation can evolve
// to be more specific if there is an advantage)
-
+
// Find the maximum number of NOPs needed to specify this number of resources
// Note: It's a bit wasteful to recalculate this every time and organisms will
// definitely be confused if the number of resources changes during a run
@@ -3054,11 +3054,11 @@
int start_index = start_label.AsInt(num_nops);
int end_index = end_label.AsInt(num_nops);
-
+
// If the label refers to ONLY resources that
// do not exist, then the operation fails
if (start_index >= res_count.GetSize()) return false;
-
+
// Otherwise sum all valid resources that it might refer to
// (this will only be ONE if the label was of the maximum length).
int resource_result = 0;
@@ -3095,7 +3095,7 @@
resource_result = (int)(log(dresource_result)/log(base));
}
}
-
+
//Dump this value into an arbitrary register: BX
GetRegister(reg_to_set) = resource_result;
@@ -3111,7 +3111,7 @@
organism->GetPhenotype().IncSenseCount(sensed_index);
return true;
-
+
// Note that we are converting <double> resources to <int> register values
}
@@ -3129,14 +3129,14 @@
void cHardwareCPU::DoDonate(cOrganism* to_org)
{
assert(to_org != NULL);
-
+
const double merit_given = m_world->GetConfig().MERIT_GIVEN.Get();
const double merit_received = m_world->GetConfig().MERIT_RECEIVED.Get();
-
+
double cur_merit = organism->GetPhenotype().GetMerit().GetDouble();
cur_merit -= merit_given;
if(cur_merit < 0) cur_merit=0;
-
+
// Plug the current merit back into this organism and notify the scheduler.
organism->UpdateMerit(cur_merit);
@@ -3149,9 +3149,9 @@
void cHardwareCPU::DoEnergyDonate(cOrganism* to_org)
{
assert(to_org != NULL);
-
+
const double frac_energy_given = m_world->GetConfig().MERIT_GIVEN.Get();
-
+
double cur_energy = organism->GetPhenotype().GetStoredEnergy();
double energy_given = cur_energy * frac_energy_given;
@@ -3172,7 +3172,7 @@
}
organism->GetPhenotype().IncDonates();
organism->GetPhenotype().SetIsDonorRand();
-
+
// Get faced neighbor
cOrganism * neighbor = organism->GetNeighbor();
@@ -3191,10 +3191,10 @@
if (organism->GetPhenotype().GetCurNumDonates() > m_world->GetConfig().MAX_DONATES.Get()) {
return false;
}
-
+
organism->GetPhenotype().IncDonates();
organism->GetPhenotype().SetIsDonorRand();
-
+
// Turn to a random neighbor, get it, and turn back...
int neighbor_id = ctx.GetRandom().GetInt(organism->GetNeighborhoodSize());
for (int i = 0; i < neighbor_id; i++) organism->Rotate(1);
@@ -3207,16 +3207,16 @@
//print out how often random donations go to kin
/*
- static ofstream kinDistanceFile("kinDistance.dat");
- kinDistanceFile << (genotype->GetPhyloDistance(neighbor->GetGenotype())<=1) << " ";
- kinDistanceFile << (genotype->GetPhyloDistance(neighbor->GetGenotype())<=2) << " ";
- kinDistanceFile << (genotype->GetPhyloDistance(neighbor->GetGenotype())<=3) << " ";
- kinDistanceFile << genotype->GetPhyloDistance(neighbor->GetGenotype());
- kinDistanceFile << endl;
- */
+ static ofstream kinDistanceFile("kinDistance.dat");
+ kinDistanceFile << (genotype->GetPhyloDistance(neighbor->GetGenotype())<=1) << " ";
+ kinDistanceFile << (genotype->GetPhyloDistance(neighbor->GetGenotype())<=2) << " ";
+ kinDistanceFile << (genotype->GetPhyloDistance(neighbor->GetGenotype())<=3) << " ";
+ kinDistanceFile << genotype->GetPhyloDistance(neighbor->GetGenotype());
+ kinDistanceFile << endl;
+ */
neighbor->GetPhenotype().SetIsReceiverRand();
}
-
+
return true;
}
@@ -3229,8 +3229,8 @@
organism->GetPhenotype().IncDonates();
organism->GetPhenotype().SetIsDonorKin();
-
-
+
+
// Find the target as the first Kin found in the neighborhood.
const int num_neighbors = organism->GetNeighborhoodSize();
@@ -3274,7 +3274,7 @@
if (organism->GetPhenotype().GetCurNumDonates() > m_world->GetConfig().MAX_DONATES.Get()) {
return false;
}
-
+
organism->GetPhenotype().IncDonates();
organism->GetPhenotype().SetIsDonorEdit();
@@ -3325,63 +3325,63 @@
//in their genome (see Dawkins 1976, The Selfish Gene, for
//the history of the theory and the name 'green beard'
cPhenotype & phenotype = organism->GetPhenotype();
-
+
if (organism->GetPhenotype().GetCurNumDonates() > m_world->GetConfig().MAX_DONATES.Get()) {
return false;
}
-
+
phenotype.IncDonates();
phenotype.SetIsDonorGbg();
-
+
// Find the target as the first match found in the neighborhood.
-
+
//get the neighborhood size
const int num_neighbors = organism->GetNeighborhoodSize();
-
+
// Turn to face a random neighbor
int neighbor_id = ctx.GetRandom().GetInt(num_neighbors);
for (int i = 0; i < neighbor_id; i++) organism->Rotate(1);
cOrganism * neighbor = organism->GetNeighbor();
-
+
int max_id = neighbor_id + num_neighbors;
-
+
//we have not found a match yet
bool found = false;
-
+
// rotate through orgs in neighborhood
while (neighbor_id < max_id) {
- neighbor = organism->GetNeighbor();
-
- //if neighbor exists, do they have the green beard gene?
- if (neighbor != NULL) {
- const cGenome & neighbor_genome = neighbor->GetGenome();
-
- // for each instruction in the genome...
- for(int i=0;i<neighbor_genome.GetSize();i++){
-
- // ...see if it is donate-gbg
- if (neighbor_genome[i] == IP().GetInst()) {
- found = true;
- break;
- }
-
- }
- }
+ neighbor = organism->GetNeighbor();
+
+ //if neighbor exists, do they have the green beard gene?
+ if (neighbor != NULL) {
+ const cGenome & neighbor_genome = neighbor->GetGenome();
- // stop searching through the neighbors if we already found one
- if (found == true);{
- break;
+ // for each instruction in the genome...
+ for(int i=0;i<neighbor_genome.GetSize();i++){
+
+ // ...see if it is donate-gbg
+ if (neighbor_genome[i] == IP().GetInst()) {
+ found = true;
+ break;
+ }
+
}
+ }
+
+ // stop searching through the neighbors if we already found one
+ if (found == true);{
+ break;
+ }
+
+ organism->Rotate(1);
+ neighbor_id++;
+ }
- organism->Rotate(1);
- neighbor_id++;
- }
-
- if (found == false) neighbor = NULL;
-
+ if (found == false) neighbor = NULL;
+
// Put the facing back where it was.
for (int i = 0; i < neighbor_id; i++) organism->Rotate(-1);
-
+
// Donate only if we have found a close enough relative...
if (neighbor != NULL) {
DoDonate(neighbor);
@@ -3400,69 +3400,69 @@
//the history of the theory and the name 'green beard'
// cout << "i am about to donate to a green beard" << endl;
cPhenotype & phenotype = organism->GetPhenotype();
-
+
if (organism->GetPhenotype().GetCurNumDonates() > m_world->GetConfig().MAX_DONATES.Get()) {
return false;
}
-
+
phenotype.IncDonates();
phenotype.SetIsDonorTrueGb();
-
+
// Find the target as the first match found in the neighborhood.
-
+
//get the neighborhood size
const int num_neighbors = organism->GetNeighborhoodSize();
-
+
// Turn to face a random neighbor
int neighbor_id = ctx.GetRandom().GetInt(num_neighbors);
for (int i = 0; i < neighbor_id; i++) organism->Rotate(1);
cOrganism * neighbor = organism->GetNeighbor();
-
+
int max_id = neighbor_id + num_neighbors;
-
+
//we have not found a match yet
bool found = false;
-
+
// rotate through orgs in neighborhood
while (neighbor_id < max_id) {
- neighbor = organism->GetNeighbor();
- //if neighbor exists, AND if their parent attempted to donate,
- if (neighbor != NULL && neighbor->GetPhenotype().IsDonorTrueGbLast()) {
- const cGenome & neighbor_genome = neighbor->GetGenome();
-
- // for each instruction in the genome...
- for(int i=0;i<neighbor_genome.GetSize();i++){
-
- // ...see if it is donate-tgb, if so, we found a target
- if (neighbor_genome[i] == IP().GetInst()) {
- found = true;
- break;
- }
-
- }
- }
+ neighbor = organism->GetNeighbor();
+ //if neighbor exists, AND if their parent attempted to donate,
+ if (neighbor != NULL && neighbor->GetPhenotype().IsDonorTrueGbLast()) {
+ const cGenome & neighbor_genome = neighbor->GetGenome();
- // stop searching through the neighbors if we already found one
- if (found == true);{
- break;
+ // for each instruction in the genome...
+ for(int i=0;i<neighbor_genome.GetSize();i++){
+
+ // ...see if it is donate-tgb, if so, we found a target
+ if (neighbor_genome[i] == IP().GetInst()) {
+ found = true;
+ break;
+ }
+
}
+ }
+
+ // stop searching through the neighbors if we already found one
+ if (found == true);{
+ break;
+ }
+
+ organism->Rotate(1);
+ neighbor_id++;
+ }
- organism->Rotate(1);
- neighbor_id++;
- }
-
- if (found == false) neighbor = NULL;
-
+ if (found == false) neighbor = NULL;
+
// Put the facing back where it was.
for (int i = 0; i < neighbor_id; i++) organism->Rotate(-1);
-
+
// Donate only if we have found a close enough relative...
if (neighbor != NULL) {
DoDonate(neighbor);
neighbor->GetPhenotype().SetIsReceiverTrueGb();
}
-
+
return true;
}
@@ -3475,64 +3475,64 @@
//the history of the theory and the name 'green beard'
// cout << "i am about to donate to a green beard" << endl;
cPhenotype & phenotype = organism->GetPhenotype();
-
+
if (organism->GetPhenotype().GetCurNumDonates() > m_world->GetConfig().MAX_DONATES.Get()) {
return false;
}
-
-
+
+
phenotype.IncDonates();
phenotype.SetIsDonorThreshGb();
phenotype.IncNumThreshGbDonations();
-
+
// Find the target as the first match found in the neighborhood.
-
+
//get the neighborhood size
const int num_neighbors = organism->GetNeighborhoodSize();
-
+
// Turn to face a random neighbor
int neighbor_id = ctx.GetRandom().GetInt(num_neighbors);
for (int i = 0; i < neighbor_id; i++) organism->Rotate(1);
cOrganism * neighbor = organism->GetNeighbor();
-
+
int max_id = neighbor_id + num_neighbors;
-
+
//we have not found a match yet
bool found = false;
-
+
// rotate through orgs in neighborhood
while (neighbor_id < max_id) {
- neighbor = organism->GetNeighbor();
- //if neighbor exists, AND if their parent attempted to donate >= threshhold,
- if (neighbor != NULL && neighbor->GetPhenotype().GetNumThreshGbDonationsLast()>= m_world->GetConfig().MIN_GB_DONATE_THRESHOLD.Get() ) {
- const cGenome & neighbor_genome = neighbor->GetGenome();
-
- // for each instruction in the genome...
- for(int i=0;i<neighbor_genome.GetSize();i++){
-
- // ...see if it is donate-threshgb, if so, we found a target
- if (neighbor_genome[i] == IP().GetInst()) {
- found = true;
- break;
- }
-
- }
- }
+ neighbor = organism->GetNeighbor();
+ //if neighbor exists, AND if their parent attempted to donate >= threshhold,
+ if (neighbor != NULL && neighbor->GetPhenotype().GetNumThreshGbDonationsLast()>= m_world->GetConfig().MIN_GB_DONATE_THRESHOLD.Get() ) {
+ const cGenome & neighbor_genome = neighbor->GetGenome();
- // stop searching through the neighbors if we already found one
- if (found == true);{
- break;
+ // for each instruction in the genome...
+ for(int i=0;i<neighbor_genome.GetSize();i++){
+
+ // ...see if it is donate-threshgb, if so, we found a target
+ if (neighbor_genome[i] == IP().GetInst()) {
+ found = true;
+ break;
+ }
+
}
+ }
+
+ // stop searching through the neighbors if we already found one
+ if (found == true);{
+ break;
+ }
+
+ organism->Rotate(1);
+ neighbor_id++;
+ }
- organism->Rotate(1);
- neighbor_id++;
- }
-
- if (found == false) neighbor = NULL;
-
+ if (found == false) neighbor = NULL;
+
// Put the facing back where it was.
for (int i = 0; i < neighbor_id; i++) organism->Rotate(-1);
-
+
// Donate only if we have found a close enough relative...
if (neighbor != NULL) {
DoDonate(neighbor);
@@ -3540,7 +3540,7 @@
// cout << "************ neighbor->GetPhenotype().GetNumThreshGbDonationsLast() is " << neighbor->GetPhenotype().GetNumThreshGbDonationsLast() << endl;
}
-
+
return true;
}
@@ -3555,37 +3555,37 @@
// using this instruction. The threshold levels are multiples of
// the quanta value set in genesis, and the highest level that
// the donor qualifies for is the one used.
-
+
// (see Dawkins 1976, The Selfish Gene, for
// the history of the theory and the name 'green beard'
// cout << "i am about to donate to a green beard" << endl;
cPhenotype & phenotype = organism->GetPhenotype();
-
+
if (phenotype.GetCurNumDonates() > m_world->GetConfig().MAX_DONATES.Get()) {
return false;
}
-
+
phenotype.IncDonates();
phenotype.SetIsDonorQuantaThreshGb();
phenotype.IncNumQuantaThreshGbDonations();
//cout << endl << "quanta_threshgb attempt.. " ;
-
-
+
+
// Find the target as the first match found in the neighborhood.
-
+
//get the neighborhood size
const int num_neighbors = organism->GetNeighborhoodSize();
-
+
// Turn to face a random neighbor
int neighbor_id = ctx.GetRandom().GetInt(num_neighbors);
for (int i = 0; i < neighbor_id; i++) organism->Rotate(1);
cOrganism * neighbor = organism->GetNeighbor();
-
+
int max_id = neighbor_id + num_neighbors;
-
+
//we have not found a match yet
bool found = false;
-
+
// Get the quanta (step size) between threshold levels.
const int donate_quanta = m_world->GetConfig().DONATE_THRESH_QUANTA.Get();
@@ -3597,39 +3597,39 @@
//cout << " quanta thresh= " << quanta_donate_thresh;
// rotate through orgs in neighborhood
while (neighbor_id < max_id) {
- neighbor = organism->GetNeighbor();
- //if neighbor exists, AND if their parent attempted to donate >= threshhold,
- if (neighbor != NULL &&
- neighbor->GetPhenotype().GetNumQuantaThreshGbDonationsLast() >= quanta_donate_thresh) {
-
- const cGenome & neighbor_genome = neighbor->GetGenome();
-
- // for each instruction in the genome...
- for(int i=0;i<neighbor_genome.GetSize();i++){
-
- // ...see if it is donate-quantagb, if so, we found a target
- if (neighbor_genome[i] == IP().GetInst()) {
- found = true;
- break;
- }
-
- }
- }
+ neighbor = organism->GetNeighbor();
+ //if neighbor exists, AND if their parent attempted to donate >= threshhold,
+ if (neighbor != NULL &&
+ neighbor->GetPhenotype().GetNumQuantaThreshGbDonationsLast() >= quanta_donate_thresh) {
- // stop searching through the neighbors if we already found one
- if (found == true);{
- break;
+ const cGenome & neighbor_genome = neighbor->GetGenome();
+
+ // for each instruction in the genome...
+ for(int i=0;i<neighbor_genome.GetSize();i++){
+
+ // ...see if it is donate-quantagb, if so, we found a target
+ if (neighbor_genome[i] == IP().GetInst()) {
+ found = true;
+ break;
+ }
+
}
+ }
+
+ // stop searching through the neighbors if we already found one
+ if (found == true);{
+ break;
+ }
+
+ organism->Rotate(1);
+ neighbor_id++;
+ }
- organism->Rotate(1);
- neighbor_id++;
- }
-
- if (found == false) neighbor = NULL;
-
+ if (found == false) neighbor = NULL;
+
// Put the facing back where it was.
for (int i = 0; i < neighbor_id; i++) organism->Rotate(-1);
-
+
// Donate only if we have found a close enough relative...
if (neighbor != NULL) {
DoDonate(neighbor);
@@ -3637,7 +3637,7 @@
//cout << " ************ neighbor->GetPhenotype().GetNumQuantaThreshGbDonationsLast() is " << neighbor->GetPhenotype().GetNumQuantaThreshGbDonationsLast();
}
-
+
return true;
}
@@ -3648,7 +3648,7 @@
if (organism->GetPhenotype().GetCurNumDonates() > m_world->GetConfig().MAX_DONATES.Get()) {
return false;
}
-
+
organism->GetPhenotype().IncDonates();
organism->GetPhenotype().SetIsDonorNull();
@@ -3694,13 +3694,13 @@
bool cHardwareCPU::Inst_IOBufAdd1(cAvidaContext& ctx)
{
- organism->AddOutput(1);
- return true;
+ organism->AddOutput(1);
+ return true;
}
bool cHardwareCPU::Inst_IOBufAdd0(cAvidaContext& ctx)
{
- organism->AddOutput(0);
- return true;
+ organism->AddOutput(0);
+ return true;
}
bool cHardwareCPU::Inst_RotateL(cAvidaContext& ctx)
@@ -3772,8 +3772,8 @@
}
/**
- Rotate to facing specified by following label
-*/
+Rotate to facing specified by following label
+ */
bool cHardwareCPU::Inst_RotateLabel(cAvidaContext& ctx)
{
int standardNeighborhoodSize, actualNeighborhoodSize, newFacing, currentFacing;
@@ -3815,32 +3815,31 @@
// Addition for follow-the-leader
bool cHardwareCPU::Inst_Sense3andRotate(cAvidaContext& ctx)
{
- int left, right, center;
- cPopulationCell mycell;
-
- // Fill in left, right, center with m_cell_data via GetCellData()
- // GetRegister(out_reg) = m_world->GetPopulation().GetCell(cellID).GetCellData();
- mycell = m_world->GetPopulation().GetCell(organism->GetCellID());
- center = mycell.GetCellFaced().GetCellData();
- left = mycell.ConnectionList().GetLast()->GetCellData();
- right = mycell.ConnectionList().GetFirst()->GetCellData();
-
- // Register loading in future
- // Take differences
- // Issue appropriate rotate command
- if ((center >= left) && (center >= right)) { // do nothing
- } else if (left > right) {
- // Turn left
- mycell.ConnectionList().CircPrev();
- } else if (right > left) {
- // Turn right
- mycell.ConnectionList().CircNext();
- } else {
- // Turn right
- mycell.ConnectionList().CircNext();
- }
-
- return true;
+ int left_data, right_data, center_data;
+ cPopulationCell& mycell = m_world->GetPopulation().GetCell(organism->GetCellID());
+
+ // collect data
+ center_data = mycell.GetCellFaced().GetCellData();
+ mycell.ConnectionList().CircNext();
+ right_data = mycell.GetCellFaced().GetCellData();
+ mycell.ConnectionList().CircPrev();
+ mycell.ConnectionList().CircPrev();
+ left_data = mycell.GetCellFaced().GetCellData();
+ mycell.ConnectionList().CircNext();
+
+ // Register loading in future
+ // Take differences
+ // Issue appropriate rotate command
+ if (left_data >= center_data && left_data >= right_data) {
+ // Turn left
+ mycell.ConnectionList().CircPrev();
+ } else if (right_data >= center_data && right_data >= left_data) {
+ // Turn right
+ mycell.ConnectionList().CircNext();
+ } else {
+ // go straight
+ }
+ return true;
}
// More follow-the-leader; separate out sensing, @ LMG
@@ -3851,24 +3850,29 @@
// nop-B or none: faced (center) cell
bool cHardwareCPU::Inst_SenseCellData(cAvidaContext& ctx)
{
- int cell_value;
- cPopulationCell mycell;
+ int cell_value, left_data, right_data, center_data;
+ cPopulationCell& mycell = m_world->GetPopulation().GetCell(organism->GetCellID());
+ const int label = FindModifiedRegister(REG_BX);
+
+ //collect data
+ center_data = mycell.GetCellFaced().GetCellData();
+ mycell.ConnectionList().CircNext();
+ right_data = mycell.GetCellFaced().GetCellData();
+ mycell.ConnectionList().CircPrev();
+ mycell.ConnectionList().CircPrev();
+ left_data = mycell.GetCellFaced().GetCellData();
+ mycell.ConnectionList().CircNext();
- const int label = FindModifiedRegister(REG_BX);
-
- // Get the current cell ID
- mycell = m_world->GetPopulation().GetCell(organism->GetCellID());
-
- // changed to use registers enum
// Sense the appropriate cell according to the label
- if ( label == REG_AX) { cell_value = mycell.ConnectionList ().GetLast()->GetCellData(); } // nop-A, sense left
- else if ( label == REG_CX) { cell_value = mycell.ConnectionList().GetFirst()->GetCellData(); } // nop-C, sense right
- else { cell_value = mycell.GetCellFaced().GetCellData(); } // default, sense faced
-
- // cout << "Label = " << label << " Cell data = " << cell_value << endl;
-
- GetRegister(REG_BX) = cell_value;
- return true;
+ if ( label == REG_AX) {// nop-A, sense left
+ cell_value = left_data;
+ } else if ( label == REG_CX) { // nop-C, sense right
+ cell_value = right_data;
+ } else {// default, sense faced
+ cell_value = center_data;
+ }
+ GetRegister(REG_BX) = cell_value;
+ return true;
}
// @WRE addition for movement
@@ -3892,10 +3896,10 @@
{
// Declarations
int fromcellID, destcellID; //, actualNeighborhoodSize, fromFacing, destFacing, currentFacing;
-
+
// Get population
cPopulation& pop = m_world->GetPopulation();
-
+
// Get stepsize. Currently, all moves are one cell regardless of stepsize.
// This could be changed in the future.
const int stepsize = m_world->GetConfig().BIOMIMETIC_MOVEMENT_STEP.Get();
@@ -3925,7 +3929,7 @@
pop.SwapCells(pop.GetCell(fromcellID),pop.GetCell(destcellID));
// Swap inputs and facings between cells using helper function
pop.MoveOrganisms(ctx, pop.GetCell(fromcellID), pop.GetCell(destcellID));
-
+
// updates movement predicates
m_world->GetStats().Move(*organism);
@@ -4087,8 +4091,8 @@
}
/*
- Resample Divide -- AWC 06/29/06
-*/
+ Resample Divide -- AWC 06/29/06
+ */
bool cHardwareCPU::Inst_HeadDivideRS(cAvidaContext& ctx)
{
@@ -4104,8 +4108,8 @@
}
/*
- Resample Divide -- single mut on divide-- AWC 07/28/06
-*/
+ Resample Divide -- single mut on divide-- AWC 07/28/06
+ */
bool cHardwareCPU::Inst_HeadDivide1RS(cAvidaContext& ctx)
{
@@ -4121,8 +4125,8 @@
}
/*
- Resample Divide -- double mut on divide-- AWC 08/29/06
-*/
+ Resample Divide -- double mut on divide-- AWC 08/29/06
+ */
bool cHardwareCPU::Inst_HeadDivide2RS(cAvidaContext& ctx)
{
@@ -4203,20 +4207,20 @@
const int head_id = FindModifiedHead(nHardware::HEAD_READ);
GetHead(head_id).Adjust();
-// sCPUStats & cpu_stats = organism->CPUStats();
+ // sCPUStats & cpu_stats = organism->CPUStats();
// Mutations only occur on the read, for the moment.
int read_inst = 0;
if (organism->TestCopyMut(ctx)) {
read_inst = m_inst_set->GetRandomInst(ctx).GetOp();
-// cpu_stats.mut_stats.copy_mut_count++; // @CAO, hope this is good!
+ // cpu_stats.mut_stats.copy_mut_count++; // @CAO, hope this is good!
} else {
read_inst = GetHead(head_id).GetInst().GetOp();
}
GetRegister(dst) = read_inst;
ReadInst(read_inst);
-// cpu_stats.mut_stats.copies_exec++; // @CAO, this too..
+ // cpu_stats.mut_stats.copies_exec++; // @CAO, this too..
GetHead(head_id).Advance();
return true;
}
@@ -4245,7 +4249,7 @@
// For the moment, this cannot be nop-modified.
cHeadCPU& read_head = GetHead(nHardware::HEAD_READ);
cHeadCPU& write_head = GetHead(nHardware::HEAD_WRITE);
-// sCPUStats& cpu_stats = organism->CPUStats();
+ // sCPUStats& cpu_stats = organism->CPUStats();
read_head.Adjust();
write_head.Adjust();
@@ -4255,12 +4259,12 @@
ReadInst(read_inst.GetOp());
if (organism->TestCopyMut(ctx)) {
read_inst = m_inst_set->GetRandomInst(ctx);
-// cpu_stats.mut_stats.copy_mut_count++;
+ // cpu_stats.mut_stats.copy_mut_count++;
write_head.SetFlagMutated();
write_head.SetFlagCopyMut();
}
-// cpu_stats.mut_stats.copies_exec++;
+ // cpu_stats.mut_stats.copies_exec++;
write_head.SetInst(read_inst);
write_head.SetFlagCopied(); // Set the copied flag...
@@ -4268,7 +4272,7 @@
write_head.Advance();
//Slip mutations
- if (organism->TestCopySlip(ctx)) {
+ if (organism->TestCopySlip(ctx)) {
read_head.Set(ctx.GetRandom().GetInt(organism->GetGenome().GetSize()));
}
@@ -4280,7 +4284,7 @@
// For the moment, this cannot be nop-modified.
cHeadCPU & read_head = GetHead(nHardware::HEAD_READ);
cHeadCPU & write_head = GetHead(nHardware::HEAD_WRITE);
-// sCPUStats & cpu_stats = organism->CPUStats();
+ // sCPUStats & cpu_stats = organism->CPUStats();
read_head.Adjust();
write_head.Adjust();
@@ -4290,13 +4294,13 @@
ReadInst(read_inst.GetOp());
if ( ctx.GetRandom().P(organism->GetCopyMutProb() / reduction) ) {
read_inst = m_inst_set->GetRandomInst(ctx);
-// cpu_stats.mut_stats.copy_mut_count++;
+ // cpu_stats.mut_stats.copy_mut_count++;
write_head.SetFlagMutated();
write_head.SetFlagCopyMut();
//organism->GetPhenotype().IsMutated() = true;
}
-// cpu_stats.mut_stats.copies_exec++;
+ // cpu_stats.mut_stats.copies_exec++;
write_head.SetInst(read_inst);
write_head.SetFlagCopied(); // Set the copied flag...
@@ -4354,14 +4358,14 @@
}
/*
-This method causes an organism to sleep for ?BX? cycles
-*/
+ This method causes an organism to sleep for ?BX? cycles
+ */
bool cHardwareCPU::Inst_SleepVariableLenght(cAvidaContext& ctx) {
if(m_time_currently_sleeping < m_lenght_of_sleep) { // continue sleeping
m_time_currently_sleeping++;
} else if(m_lenght_of_sleep == -1) { //begin sleeping
- //set lenght of nap to ?BX?
+ //set lenght of nap to ?BX?
m_lenght_of_sleep = GetRegister(FindModifiedRegister(REG_BX));
//set time sleeping to zero
m_time_currently_sleeping = 0;
@@ -4437,7 +4441,7 @@
} else {
GetRegister(reg) = (int)floor((pos.first - pos.second)/2.0);
}
-// std::cerr<<"x = "<<pos.first<<" y = "<<pos.second<<" ans = "<<GetRegister(reg)<<std::endl;
+ // std::cerr<<"x = "<<pos.first<<" y = "<<pos.second<<" ans = "<<GetRegister(reg)<<std::endl;
return true;
}
@@ -4447,7 +4451,7 @@
{
// Promoters don't do anything themselves
return true;
-// std::cerr<<"x = "<<pos.first<<" y = "<<pos.second<<" ans = "<<GetRegister(reg)<<std::endl;
+ // std::cerr<<"x = "<<pos.first<<" y = "<<pos.second<<" ans = "<<GetRegister(reg)<<std::endl;
return true;
}
@@ -4474,7 +4478,7 @@
m_threads[m_cur_thread].ResetPromoterInstExecuted();
m_advance_ip = false;
const int reg_used = REG_BX; // register to put chosen promoter code in, for now always BX
-
+
// Search for an active promoter
int start_offset = m_promoter_offset;
int start_index = m_promoter_index;
@@ -4495,12 +4499,12 @@
// If we just checked the promoter that we were originally on, then there
// are no active promoters.
if ( (start_offset == m_promoter_offset) && (start_index == m_promoter_index) ) break;
-
+
// If we originally were not on a promoter, then stop once we check the
// first promoter and an offset of zero
if (start_index == -1)
{
- start_index = 0;
+ start_index = 0;
}
}
}
@@ -4531,7 +4535,7 @@
{
// We found an active match, offset to just after it.
// and put its bit code in BX for the organism to have
- // cHeadCPU will do the mod genome size for us
+ // cHeadCPU will do the mod genome size for us
IP().Set(m_promoters[m_promoter_index].m_pos + 1);
GetRegister(reg_used) = m_promoters[m_promoter_index].m_bit_code;
}
@@ -4592,7 +4596,7 @@
int state = code >> offset;
count += (state & 1);
}
-
+
return (count >= m_world->GetConfig().PROMOTER_EXE_THRESHOLD.Get());
}
@@ -4624,17 +4628,17 @@
code_size++;
}
- // move back one inst
+ // move back one inst
j += GetMemory().GetSize() + _dir;
j %= GetMemory().GetSize();
-
+
}
return code;
}
/*!
- Sets BX to 1 if >=50% of the bits in the specified register
- are 1's and zero otherwise.
+Sets BX to 1 if >=50% of the bits in the specified register
+are 1's and zero otherwise.
*/
bool cHardwareCPU::Inst_BitConsensus(cAvidaContext& ctx)
@@ -4670,15 +4674,15 @@
/*!
This method implements a transmission time for sent messages.
-The sender and all neighbor cells are blocked from sending until the message transmission is over.
-*/
+ The sender and all neighbor cells are blocked from sending until the message transmission is over.
+ */
bool cHardwareCPU::Inst_SendMessage_TX(cAvidaContext& ctx) { //carrier sense, multiple access
cPopulation& pop = m_world->GetPopulation();
int cell_id = organism->GetCellID();
cPopulationCell& sending_cell = pop.GetCell(cell_id);
-
+
if(sending_cell.IsTX()) { //if TX then fail
- // tell organism about failure?
+ // tell organism about failure?
m_world->GetStats().IncRadioBusy();
return false;
} else if(sending_cell.InTXRange()) { // if in range of TXer
@@ -4689,7 +4693,7 @@
const cOrgMessage& last_msg = organism->GetReceivedMessages().back();
last_msg.GetTXComplete(last_msg_update, last_msg_subupdate);
if(!m_world->GetStats().TimeHasPassed(last_msg_update, last_msg_subupdate)) { // if receiving a msg
- //actually receiving a msg
+ //actually receiving a msg
m_world->GetStats().IncRadioBusy();
return false;
}
@@ -4724,9 +4728,9 @@
/*
-This method implements a blocking receive.
-It is continously executed, paying all costs for every execution, until a message is received.
-*/
+ This method implements a blocking receive.
+ It is continously executed, paying all costs for every execution, until a message is received.
+ */
bool cHardwareCPU::Inst_ReceiveMsg_Blocking(cAvidaContext& ctx) {
const cOrgMessage* msg = organism->RetrieveMessage();
if(msg == 0) {
@@ -4763,7 +4767,7 @@
/*!
Same as RetrieveMessage except a message cannot be retrieved until its transmission time has passed.
-*/
+ */
bool cHardwareCPU::Inst_RetrieveMessage_RXComplete(cAvidaContext& ctx) {
const cOrgMessage* msg = organism->RetrieveMessage_RXComplete();
if(msg == 0)
More information about the Avida-cvs
mailing list