[Avida-SVN] r1598 - in development/source: cpu main
dknoester at myxo.css.msu.edu
dknoester at myxo.css.msu.edu
Wed May 23 21:29:44 PDT 2007
Author: dknoester
Date: 2007-05-24 00:29:43 -0400 (Thu, 24 May 2007)
New Revision: 1598
Modified:
development/source/cpu/cHardwareGX.cc
development/source/cpu/cHardwareGX.h
development/source/main/cOrganism.cc
development/source/main/cOrganism.h
Log:
Added per-programid input and output buffers to remove crosstalk during task checking.
Modified: development/source/cpu/cHardwareGX.cc
===================================================================
--- development/source/cpu/cHardwareGX.cc 2007-05-23 18:45:49 UTC (rev 1597)
+++ development/source/cpu/cHardwareGX.cc 2007-05-24 04:29:43 UTC (rev 1598)
@@ -25,6 +25,7 @@
#include "cHardwareGX.h"
#include "cAvidaContext.h"
#include "cCPUTestInfo.h"
+#include "cEnvironment.h"
#include "functions.h"
#include "cGenomeUtil.h"
#include "cGenotype.h"
@@ -2143,7 +2144,8 @@
{
// Randomize the inputs so they can't save numbers
organism->GetOrgInterface().ResetInputs(ctx); // Now re-randomize the inputs this organism sees
- organism->ClearInput(); // Also clear their input buffers, or they can still claim
+ m_current->m_inputBuffer.Clear();
+ //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);
@@ -2192,7 +2194,8 @@
{
bool return_value = Inst_TaskPut(ctx); // Do a normal put
organism->GetOrgInterface().ResetInputs(ctx); // Now re-randomize the inputs this organism sees
- organism->ClearInput(); // Also clear their input buffers, or they can still claim
+ m_current->m_inputBuffer.Clear();
+ //organism->ClearInput(); // Also clear their input buffers, or they can still claim
// rewards for numbers no longer in their environment!
return return_value;
}
@@ -2203,7 +2206,7 @@
// Do the "put" component
const int value_out = GetRegister(reg_used);
- organism->DoOutput(ctx, value_out); // Check for tasks completed.
+ organism->DoOutput(ctx, m_current->m_inputBuffer, m_current->m_outputBuffer, value_out); // Check for tasks completed.
// Do the "get" component
const int value_in = organism->GetNextInput();
@@ -2221,33 +2224,26 @@
// Do the "put" component
const int value_out = GetRegister(reg_used);
- organism->DoOutput(ctx, value_out); // Check for tasks completed.
-
+ organism->DoOutput(ctx, m_current->m_inputBuffer, m_current->m_outputBuffer, 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;
@@ -3742,6 +3738,8 @@
, m_cpu_cycles_used(0)
, m_gx_hardware(hardware)
, m_unique_id(hardware->m_last_unique_id_assigned++)
+, m_inputBuffer(m_gx_hardware->m_world->GetEnvironment().GetInputSize())
+, m_outputBuffer(m_gx_hardware->m_world->GetEnvironment().GetOutputSize())
{
assert(m_gx_hardware!=0);
for(int i=0; i<NUM_HEADS; ++i) {
Modified: development/source/cpu/cHardwareGX.h
===================================================================
--- development/source/cpu/cHardwareGX.h 2007-05-23 18:45:49 UTC (rev 1597)
+++ development/source/cpu/cHardwareGX.h 2007-05-24 04:29:43 UTC (rev 1598)
@@ -60,8 +60,8 @@
#include "tInstLib.h"
#include "defs.h"
#include "nHardware.h"
+#include "tBuffer.h"
-
class cInjectGenotype;
class cInstLib;
class cInstSet;
@@ -218,6 +218,9 @@
cCPUStack m_stack; //!< This cProgramid's stack (no global stack).
cHeadProgramid m_heads[NUM_HEADS]; //!< This cProgramid's heads.
int m_regs[NUM_REGISTERS]; //!< This cProgramid's registers.
+
+ tBuffer<int> m_inputBuffer; //!< This programid's input buffer.
+ tBuffer<int> m_outputBuffer; //!< This programid's output buffer.
};
protected:
Modified: development/source/main/cOrganism.cc
===================================================================
--- development/source/main/cOrganism.cc 2007-05-23 18:45:49 UTC (rev 1597)
+++ development/source/main/cOrganism.cc 2007-05-24 04:29:43 UTC (rev 1598)
@@ -154,18 +154,35 @@
void cOrganism::DoInput(const int value)
{
- m_input_buf.Add(value);
- m_phenotype.TestInput(m_input_buf, m_output_buf);
+ DoInput(m_input_buf, m_output_buf, value);
}
+
+void cOrganism::DoInput(tBuffer<int>& input_buffer, tBuffer<int>& output_buffer, const int value)
+{
+ input_buffer.Add(value);
+ m_phenotype.TestInput(input_buffer, output_buffer);
+}
+
+
+
void cOrganism::DoOutput(cAvidaContext& ctx, const int value, const bool on_divide)
{
- assert(m_interface);
+ DoOutput(ctx, m_input_buf, m_output_buf, value, on_divide);
+}
+
+
+void cOrganism::DoOutput(cAvidaContext& ctx,
+ tBuffer<int>& input_buffer,
+ tBuffer<int>& output_buffer,
+ const int value,
+ const bool on_divide)
+{
const tArray<double> & resource_count = m_interface->GetResources();
-
+
tList<tBuffer<int> > other_input_list;
tList<tBuffer<int> > other_output_list;
-
+
// If tasks require us to consider neighbor inputs, collect them...
if (m_world->GetEnvironment().UseNeighborInput()) {
const int num_neighbors = m_interface->GetNumNeighbors();
@@ -173,11 +190,11 @@
m_interface->Rotate();
cOrganism * cur_neighbor = m_interface->GetNeighbor();
if (cur_neighbor == NULL) continue;
-
+
other_input_list.Push( &(cur_neighbor->m_input_buf) );
}
}
-
+
// If tasks require us to consider neighbor outputs, collect them...
if (m_world->GetEnvironment().UseNeighborOutput()) {
const int num_neighbors = m_interface->GetNumNeighbors();
@@ -185,36 +202,37 @@
m_interface->Rotate();
cOrganism * cur_neighbor = m_interface->GetNeighbor();
if (cur_neighbor == NULL) continue;
-
+
other_output_list.Push( &(cur_neighbor->m_output_buf) );
}
}
bool net_valid = false;
if (m_net) net_valid = NetValidate(ctx, value);
-
+
// Do the testing of tasks performed...
-
+
// if on IO add value to m_output_buf, if on divide don't need to
- if (!on_divide) m_output_buf.Add(value);
+ if(!on_divide) output_buffer.Add(value);
tArray<double> res_change(resource_count.GetSize());
tArray<int> insts_triggered;
bool clear_input = false;
-
+
tBuffer<int>* received_messages_point = &m_received_messages;
if (!m_world->GetConfig().SAVE_RECEIVED.Get()) received_messages_point = NULL;
- cTaskContext taskctx(m_interface, m_input_buf, m_output_buf, other_input_list, other_output_list, net_valid, 0, on_divide, received_messages_point);
+ cTaskContext taskctx(m_interface, input_buffer, output_buffer, other_input_list,
+ other_output_list, net_valid, 0, on_divide, received_messages_point);
m_phenotype.TestOutput(ctx, taskctx, resource_count, res_change, insts_triggered);
m_interface->UpdateResources(res_change);
-
+
for (int i = 0; i < insts_triggered.GetSize(); i++) {
const int cur_inst = insts_triggered[i];
m_hardware->ProcessBonusInst(ctx, cInstruction(cur_inst));
}
- if (clear_input) m_input_buf.Clear();
+ if(clear_input) input_buffer.Clear();
}
Modified: development/source/main/cOrganism.h
===================================================================
--- development/source/main/cOrganism.h 2007-05-23 18:45:49 UTC (rev 1597)
+++ development/source/main/cOrganism.h 2007-05-24 04:29:43 UTC (rev 1598)
@@ -200,7 +200,10 @@
// -------- Input and Output Methods --------
void DoInput(const int value);
+ void DoInput(tBuffer<int>& input_buffer, tBuffer<int>& output_buffer, const int value);
void DoOutput(cAvidaContext& ctx, const int value, const bool on_divide = false);
+ void DoOutput(cAvidaContext& ctx, tBuffer<int>& input_buffer,
+ tBuffer<int>& output_buffer, const int value, const bool on_divide=false);
void ClearInput() { m_input_buf.Clear(); }
void AddOutput(int val) { m_output_buf.Add(val); }
More information about the Avida-cvs
mailing list