[Avida-cvs] [avida-svn] r610 - in development/source: cpu main
brysonda@myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Thu Apr 13 19:33:03 PDT 2006
Author: brysonda
Date: 2006-04-13 22:33:03 -0400 (Thu, 13 Apr 2006)
New Revision: 610
Modified:
development/source/cpu/cHardware4Stack.cc
development/source/cpu/cHardware4Stack.h
development/source/cpu/cHardwareBase.h
development/source/cpu/cHardwareCPU.cc
development/source/cpu/cHardwareCPU.h
development/source/cpu/cHardwareSMT.cc
development/source/cpu/cHardwareSMT.h
development/source/cpu/cTestCPUInterface.cc
development/source/cpu/cTestCPUInterface.h
development/source/main/cOrgInterface.h
development/source/main/cOrganism.cc
development/source/main/cOrganism.h
development/source/main/cPopulation.cc
development/source/main/cPopulation.h
development/source/main/cPopulationInterface.cc
development/source/main/cPopulationInterface.h
Log:
Implement SMT::InjectHost. Add SMT::MemorySpaceExists to support InjectHost. Change InjectThread signature in preparation for semantic change. Rename ActivateInject (parasite into host) to ActivateParasite so that it is distinguishable from ActivateInject (organism into population).
Modified: development/source/cpu/cHardware4Stack.cc
===================================================================
--- development/source/cpu/cHardware4Stack.cc 2006-04-13 13:36:10 UTC (rev 609)
+++ development/source/cpu/cHardware4Stack.cc 2006-04-14 02:33:03 UTC (rev 610)
@@ -862,8 +862,7 @@
int inject_signal = false;
- if(injected_code.GetSize()>0)
- inject_signal = organism->InjectParasite(injected_code);
+ if (injected_code.GetSize() > 0) inject_signal = organism->InjectParasite(injected_code);
//************* CALL GOES HERE ******************//
// spin around randomly (caution: possible organism dizziness)
Modified: development/source/cpu/cHardware4Stack.h
===================================================================
--- development/source/cpu/cHardware4Stack.h 2006-04-13 13:36:10 UTC (rev 609)
+++ development/source/cpu/cHardware4Stack.h 2006-04-14 02:33:03 UTC (rev 610)
@@ -227,8 +227,8 @@
// -------- Parasite Stuff --------
int TestParasite() const;
- bool InjectHost(const cCodeLabel& in_label, const cGenome & injection);
- int InjectThread(const cCodeLabel&, const cGenome&) { return -1; }
+ bool InjectHost(const cCodeLabel& in_label, const cGenome& injection);
+ bool InjectThread(const cCodeLabel& in_label) { return false; }
// -------- Accessors --------
Modified: development/source/cpu/cHardwareBase.h
===================================================================
--- development/source/cpu/cHardwareBase.h 2006-04-13 13:36:10 UTC (rev 609)
+++ development/source/cpu/cHardwareBase.h 2006-04-14 02:33:03 UTC (rev 610)
@@ -115,7 +115,7 @@
// -------- Parasite Stuff --------
virtual int TestParasite() const = 0;
virtual bool InjectHost(const cCodeLabel& in_label, const cGenome& injection) = 0;
- virtual int InjectThread(const cCodeLabel& in_label, const cGenome& injection) = 0;
+ virtual bool InjectThread(const cCodeLabel& in_label) = 0;
// -------- Accessors --------
Modified: development/source/cpu/cHardwareCPU.cc
===================================================================
--- development/source/cpu/cHardwareCPU.cc 2006-04-13 13:36:10 UTC (rev 609)
+++ development/source/cpu/cHardwareCPU.cc 2006-04-14 02:33:03 UTC (rev 610)
@@ -965,22 +965,17 @@
return true; // (inject succeeds!)
}
-int cHardwareCPU::InjectThread(const cCodeLabel & in_label, const cGenome & injection)
+bool cHardwareCPU::InjectThread(const cCodeLabel& in_label)
{
// Make sure the genome will be below max size after injection.
- const int new_size = injection.GetSize() + GetMemory().GetSize();
- if (new_size > MAX_CREATURE_SIZE) return 1; // (inject fails)
-
- const int inject_line = FindFullLabel(in_label).GetPosition();
-
- // Abort if no compliment is found.
- if (inject_line == -1) return 2; // (inject fails)
-
- // Inject the code!
- InjectCodeThread(injection, inject_line+1);
-
- return 0; // (inject succeeds!)
+ if(ForkThread())
+ {
+ organism->GetPhenotype().IsMultiThread() = true;
+ return true;
+ }
+
+ return false;
}
void cHardwareCPU::InjectCode(const cGenome & inject_code, const int line_num)
@@ -1001,53 +996,14 @@
// Adjust all of the heads to take into account the new mem size.
- for (int i=0; i < nHardware::NUM_HEADS; i++) {
- if (!GetHead(i).TestParasite() &&
- GetHead(i).GetPosition() > line_num)
+ for (int i = 0; i < nHardware::NUM_HEADS; i++) {
+ if (!GetHead(i).TestParasite() && GetHead(i).GetPosition() > line_num)
GetHead(i).Jump(inject_size);
}
}
void cHardwareCPU::InjectCodeThread(const cGenome & inject_code, const int line_num)
{
- assert(line_num >= 0);
- assert(line_num <= memory.GetSize());
- assert(memory.GetSize() + inject_code.GetSize() < MAX_CREATURE_SIZE);
-
- if(ForkThread())
- {
- // Inject the new code.
- const int inject_size = inject_code.GetSize();
- memory.Insert(line_num, inject_code);
-
- // Set instruction flags on the injected code
- for (int i = line_num; i < line_num + inject_size; i++) {
- memory.SetFlagInjected(i);
- }
- organism->GetPhenotype().IsModified() = true;
- organism->GetPhenotype().IsMultiThread() = true;
-
- // Adjust all of the heads to take into account the new mem size.
-
- int currthread = GetCurThread();
- SetThread(0);
- for (int i=0; i<GetNumThreads()-2; i++)
- {
- for (int j=0; j < nHardware::NUM_HEADS; j++)
- {
- if (!GetHead(i).TestParasite() && GetHead(i).GetPosition() > line_num)
- GetHead(i).Jump(inject_size);
- }
- NextThread();
- }
- SetThread(currthread);
-
- }
- else
- {
- //Some kind of error message should go here...but what?
- }
-
}
void cHardwareCPU::Mutate(cAvidaContext& ctx, int mut_point)
@@ -2708,16 +2664,9 @@
// Search for the label in the host...
GetLabel().Rotate(1, nHardwareCPU::NUM_NOPS);
- const int inject_signal =
- host_organism->GetHardware().InjectThread(GetLabel(), inject_code);
- if (inject_signal == 1) {
- Fault(FAULT_LOC_INJECT, FAULT_TYPE_WARNING, "inject: host too large.");
- return false; // Inject failed.
+ if (host_organism->GetHardware().InjectHost(GetLabel(), inject_code)) {
+ host_organism->GetHardware().InjectThread(GetLabel());
}
- if (inject_signal == 2) {
- Fault(FAULT_LOC_INJECT, FAULT_TYPE_WARNING, "inject: target not in host.");
- return false; // Inject failed.
- }
// Set the relevent flags.
organism->GetPhenotype().IsModifier() = true;
Modified: development/source/cpu/cHardwareCPU.h
===================================================================
--- development/source/cpu/cHardwareCPU.h 2006-04-13 13:36:10 UTC (rev 609)
+++ development/source/cpu/cHardwareCPU.h 2006-04-14 02:33:03 UTC (rev 610)
@@ -160,7 +160,7 @@
// -------- Parasite Stuff --------
int TestParasite() const;
bool InjectHost(const cCodeLabel& in_label, const cGenome& injection);
- int InjectThread(const cCodeLabel& in_label, const cGenome& injection);
+ bool InjectThread(const cCodeLabel& in_label);
// -------- Accessors --------
Modified: development/source/cpu/cHardwareSMT.cc
===================================================================
--- development/source/cpu/cHardwareSMT.cc 2006-04-13 13:36:10 UTC (rev 609)
+++ development/source/cpu/cHardwareSMT.cc 2006-04-14 02:33:03 UTC (rev 610)
@@ -368,9 +368,15 @@
}
-int cHardwareSMT::FindMemorySpaceLabel(int mem_space)
+bool cHardwareSMT::MemorySpaceExists(const cCodeLabel& label)
{
- cCodeLabel& label = GetLabel();
+ int null;
+ if (label.GetSize() == 0 || m_mem_lbls.Find(label.AsInt(nHardwareSMT::NUM_NOPS), null)) return true;
+ return false;
+}
+
+int cHardwareSMT::FindMemorySpaceLabel(const cCodeLabel& label, int mem_space)
+{
if (label.GetSize() == 0) return 0;
int hash_key = label.AsInt(nHardwareSMT::NUM_NOPS);
@@ -704,7 +710,6 @@
}
m_mem_array[mem_space_used].Resize(end_pos);
-
cCPUMemory injected_code = m_mem_array[mem_space_used];
Inject_DoMutations(ctx, mut_multiplier, injected_code);
@@ -712,7 +717,7 @@
bool inject_signal = false;
if (injected_code.GetSize() > 0) inject_signal = organism->InjectParasite(injected_code);
- //reset the memory space which was injected
+ // reset the memory space that was injected
m_mem_array[mem_space_used] = cGenome("a");
for (int x = 0; x < nHardware::NUM_HEADS; x++) GetHead(x).Reset(IP().GetMemSpace(), this);
@@ -726,8 +731,15 @@
//This is the code run by the TARGET of an injection. This RECIEVES the infection.
bool cHardwareSMT::InjectHost(const cCodeLabel& in_label, const cGenome& inject_code)
{
- // @DMB - Need to discuss how InjectHost should work with extensible memory spaces...
- return false;
+ // Inject fails if the memory space is already in use.
+ if (MemorySpaceExists(in_label)) return false;
+
+ // Otherwise create the memory space and copy in the genome
+ int mem_space_used = FindMemorySpaceLabel(GetLabel(), -1);
+ assert(mem_space_used == -1);
+ m_mem_array[mem_space_used] = inject_code;
+
+ return true;
}
void cHardwareSMT::Mutate(cAvidaContext& ctx, int mut_point)
@@ -908,19 +920,18 @@
void cHardwareSMT::ReadLabel(int max_size)
{
int count = 0;
- cHeadMultiMem* inst_ptr = &( IP() );
+ cHeadMultiMem& inst_ptr = IP();
GetLabel().Clear();
- while (m_inst_set->IsNop(inst_ptr->GetNextInst()) &&
- (count < max_size)) {
+ while (m_inst_set->IsNop(inst_ptr.GetNextInst()) && (count < max_size)) {
count++;
- inst_ptr->Advance();
- GetLabel().AddNop(m_inst_set->GetNopMod(inst_ptr->GetInst()));
+ inst_ptr.Advance();
+ GetLabel().AddNop(m_inst_set->GetNopMod(inst_ptr.GetInst()));
// If this is the first line of the template, mark it executed.
if (GetLabel().GetSize() <= m_world->GetConfig().MAX_LABEL_EXE_SIZE.Get()) {
- inst_ptr->SetFlagExecuted();
+ inst_ptr.SetFlagExecuted();
}
}
}
@@ -1632,7 +1643,7 @@
if (GetLabel().GetSize() == 0) {
GetHead(nHardware::HEAD_FLOW).Set(0, 0);
} else {
- int mem_space_used = FindMemorySpaceLabel(-1);
+ int mem_space_used = FindMemorySpaceLabel(GetLabel(), -1);
if (mem_space_used == -1) return false;
GetHead(nHardware::HEAD_FLOW).Set(0, mem_space_used);
}
Modified: development/source/cpu/cHardwareSMT.h
===================================================================
--- development/source/cpu/cHardwareSMT.h 2006-04-13 13:36:10 UTC (rev 609)
+++ development/source/cpu/cHardwareSMT.h 2006-04-14 02:33:03 UTC (rev 610)
@@ -136,7 +136,8 @@
int FindNextStack(int default_stack);
int FindPreviousStack(int default_stack);
int FindComplementStack(int base_stack);
- int FindMemorySpaceLabel(int mem_space);
+ int FindMemorySpaceLabel(const cCodeLabel& label, int mem_space);
+ bool MemorySpaceExists(const cCodeLabel& label);
void Fault(int fault_loc, int fault_type, cString fault_desc="");
bool Allocate_Necro(const int new_size);
@@ -224,8 +225,8 @@
// -------- Parasite Stuff --------
int TestParasite() const;
- bool InjectHost(const cCodeLabel& in_label, const cGenome & injection);
- int InjectThread(const cCodeLabel&, const cGenome&) { return -1; }
+ bool InjectHost(const cCodeLabel& in_label, const cGenome& inject_code);
+ bool InjectThread(const cCodeLabel& in_label) { return false; }
// -------- Accessors --------
Modified: development/source/cpu/cTestCPUInterface.cc
===================================================================
--- development/source/cpu/cTestCPUInterface.cc 2006-04-13 13:36:10 UTC (rev 609)
+++ development/source/cpu/cTestCPUInterface.cc 2006-04-14 02:33:03 UTC (rev 610)
@@ -73,7 +73,7 @@
{
}
-bool cTestCPUInterface::SendMessage(cOrgMessage & mess)
+bool cTestCPUInterface::SendMessage(cOrgMessage& mess)
{
return false;
}
@@ -83,7 +83,7 @@
return m_testcpu->GetReceiveValue();
}
-bool cTestCPUInterface::InjectParasite(cOrganism * parent, const cGenome & injected_code)
+bool cTestCPUInterface::InjectParasite(cOrganism* parent, const cGenome& injected_code)
{
return false;
}
Modified: development/source/cpu/cTestCPUInterface.h
===================================================================
--- development/source/cpu/cTestCPUInterface.h 2006-04-13 13:36:10 UTC (rev 609)
+++ development/source/cpu/cTestCPUInterface.h 2006-04-14 02:33:03 UTC (rev 610)
@@ -14,10 +14,6 @@
#include "cOrgInterface.h"
#endif
-class cOrganism;
-class cGenome;
-template <class T> class tArray;
-class cOrgMessage;
class cTestCPU;
#ifndef NULL
Modified: development/source/main/cOrgInterface.h
===================================================================
--- development/source/main/cOrgInterface.h 2006-04-13 13:36:10 UTC (rev 609)
+++ development/source/main/cOrgInterface.h 2006-04-14 02:33:03 UTC (rev 610)
@@ -11,12 +11,14 @@
#define cOrgInterface_h
class cAvidaContext;
+class cCodeLabel;
+class cGenome;
class cOrganism;
+class cOrgMessage;
class cOrgSinkMessage;
-class cGenome;
template <class T> class tArray;
-class cOrgMessage;
+
class cOrgInterface
{
private:
Modified: development/source/main/cOrganism.cc
===================================================================
--- development/source/main/cOrganism.cc 2006-04-13 13:36:10 UTC (rev 609)
+++ development/source/main/cOrganism.cc 2006-04-14 02:33:03 UTC (rev 610)
@@ -57,7 +57,7 @@
, is_running(false)
{
// Initialization of structures...
- hardware = m_world->GetHardwareManager().Create(this);
+ m_hardware = m_world->GetHardwareManager().Create(this);
cpu_stats.Setup();
if (m_world->GetConfig().DEATH_METHOD.Get() > 0) {
@@ -80,7 +80,7 @@
cOrganism::~cOrganism()
{
assert(is_running == false);
- delete hardware;
+ delete m_hardware;
delete m_interface;
if (m_net != NULL) delete m_net;
}
@@ -164,7 +164,7 @@
for (int i = 0; i < insts_triggered.GetSize(); i++) {
const int cur_inst = insts_triggered[i];
- hardware->ProcessBonusInst(ctx, cInstruction(cur_inst) );
+ m_hardware->ProcessBonusInst(ctx, cInstruction(cur_inst) );
}
}
@@ -330,7 +330,7 @@
for (int i = 0; i < insts_triggered.GetSize(); i++) {
const int cur_inst = insts_triggered[i];
- hardware->ProcessBonusInst(ctx, cInstruction(cur_inst) );
+ m_hardware->ProcessBonusInst(ctx, cInstruction(cur_inst) );
}
}
@@ -355,37 +355,15 @@
return m_interface->InjectParasite(this, injected_code);
}
-bool cOrganism::InjectHost(const cCodeLabel & label, const cGenome & injected_code)
+bool cOrganism::InjectHost(const cCodeLabel& label, const cGenome& injected_code)
{
- return hardware->InjectHost(label, injected_code);
+ return m_hardware->InjectHost(label, injected_code);
}
-void cOrganism::AddParasite(cInjectGenotype * in_genotype)
-{
- parasites.push_back(in_genotype);
-}
-
-cInjectGenotype & cOrganism::GetParasite(int x)
-{
- return *parasites[x];
-}
-
-int cOrganism::GetNumParasites()
-{
- return parasites.size();
-}
-
-void cOrganism::ClearParasites()
-{
- parasites.clear();
-}
-
int cOrganism::OK()
{
- if (!hardware->OK()) return false;
- if (!phenotype.OK()) return false;
-
- return true;
+ if (m_hardware->OK() && phenotype.OK()) return true;
+ return false;
}
@@ -414,7 +392,7 @@
void cOrganism::PrintStatus(ostream& fp, const cString & next_name)
{
fp << "---------------------------" << endl;
- hardware->PrintStatus(fp);
+ m_hardware->PrintStatus(fp);
phenotype.PrintStatus(fp);
fp << "---------------------------" << endl;
fp << "ABOUT TO EXECUTE: " << next_name << endl;
Modified: development/source/main/cOrganism.h
===================================================================
--- development/source/main/cOrganism.h 2006-04-13 13:36:10 UTC (rev 609)
+++ development/source/main/cOrganism.h 2006-04-14 02:33:03 UTC (rev 610)
@@ -12,7 +12,6 @@
#define cOrganism_h
#include <fstream>
-#include <deque>
#ifndef cCPUMemory_h
#include "cCPUMemory.h"
@@ -41,6 +40,9 @@
#ifndef cOrgSourceMessage_h
#include "cOrgSourceMessage.h"
#endif
+#ifndef tArray_h
+#include "tArray.h"
+#endif
#ifndef tBuffer_h
#include "tBuffer.h"
#endif
@@ -57,6 +59,7 @@
**/
class cAvidaContext;
+class cCodeLabel;
class cHardwareBase;
class cGenotype;
class cInjectGenotype;
@@ -70,15 +73,14 @@
{
protected:
cWorld* m_world;
- cHardwareBase* hardware; // The actual machinary running this organism.
- cGenotype* genotype; // Information about organisms with this genome.
- cPhenotype phenotype; // Descriptive attributes of organism.
- const cGenome initial_genome; // Initial genome; can never be changed!
- std::deque<cInjectGenotype*> parasites; // List of all parasites associated with
- // this organism.
- cMutationRates mut_rates; // Rate of all possible mutations.
- cLocalMutations mut_info; // Info about possible mutations;
- cOrgInterface* m_interface; // Interface back to the population.
+ cHardwareBase* m_hardware; // The actual machinary running this organism.
+ cGenotype* genotype; // Information about organisms with this genome.
+ cPhenotype phenotype; // Descriptive attributes of organism.
+ const cGenome initial_genome; // Initial genome; can never be changed!
+ tArray<cInjectGenotype*> m_parasites; // List of all parasites associated with this organism.
+ cMutationRates mut_rates; // Rate of all possible mutations.
+ cLocalMutations mut_info; // Info about possible mutations;
+ cOrgInterface* m_interface; // Interface back to the population.
// Input and Output with the environment
int input_pointer;
@@ -132,7 +134,7 @@
cOrganism(cWorld* world, cAvidaContext& ctx, const cGenome& in_genome);
~cOrganism();
- cHardwareBase& GetHardware() { return *hardware; }
+ cHardwareBase& GetHardware() { return *m_hardware; }
cOrganism* GetNeighbor() { assert(m_interface); return m_interface->GetNeighbor(); }
int GetNeighborhoodSize() { assert(m_interface); return m_interface->GetNumNeighbors(); }
void Rotate(int direction) { assert(m_interface); m_interface->Rotate(direction); }
@@ -168,12 +170,12 @@
int NetLast() { return m_net->last_seq; }
void NetReset();
- bool InjectParasite(const cGenome & genome);
- bool InjectHost(const cCodeLabel & in_label, const cGenome & genome);
- void AddParasite(cInjectGenotype * cur);
- cInjectGenotype & GetParasite(int x);
- int GetNumParasites();
- void ClearParasites();
+ bool InjectParasite(const cGenome& genome);
+ bool InjectHost(const cCodeLabel& in_label, const cGenome& genome);
+ void AddParasite(cInjectGenotype* cur) { m_parasites.Push(cur); }
+ cInjectGenotype& GetParasite(int x) { return *m_parasites[x]; }
+ int GetNumParasites() { return m_parasites.GetSize(); }
+ void ClearParasites() { m_parasites.Resize(0); }
int OK();
Modified: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc 2006-04-13 13:36:10 UTC (rev 609)
+++ development/source/main/cPopulation.cc 2006-04-14 02:33:03 UTC (rev 610)
@@ -382,35 +382,32 @@
return parent_alive;
}
-bool cPopulation::ActivateInject(cOrganism & parent, const cGenome & injected_code)
+bool cPopulation::ActivateParasite(cOrganism& parent, const cGenome& injected_code)
{
assert(&parent != NULL);
- if(injected_code.GetSize() ==0)
- return false;
+ if (injected_code.GetSize() == 0) return false;
cHardwareBase& parent_cpu = parent.GetHardware();
- cInjectGenotype * parent_genotype = parent_cpu.GetCurThreadOwner();
+ cInjectGenotype* parent_genotype = parent_cpu.GetCurThreadOwner();
const int parent_id = parent.GetOrgInterface().GetCellID();
assert(parent_id >= 0 && parent_id < cell_array.GetSize());
- cPopulationCell & parent_cell = cell_array[ parent_id ];
+ cPopulationCell& parent_cell = cell_array[ parent_id ];
int num_neighbors = parent.GetNeighborhoodSize();
- cOrganism * target_organism =
+ cOrganism* target_organism =
parent_cell.connection_list.GetPos(m_world->GetRandom().GetUInt(num_neighbors))->GetOrganism();
- if(target_organism==NULL)
- return false;
+ if (target_organism == NULL) return false;
cHardwareBase& child_cpu = target_organism->GetHardware();
- if(child_cpu.GetNumThreads() == m_world->GetConfig().MAX_CPU_THREADS.Get())
- return false;
+ if (child_cpu.GetNumThreads() == m_world->GetConfig().MAX_CPU_THREADS.Get()) return false;
- cInjectGenotype * child_genotype = parent_genotype;
+ cInjectGenotype* child_genotype = parent_genotype; // @DMB - uh, WTF? This is not creating a copy. Should it?
- if(target_organism->InjectHost(parent_cpu.GetLabel(), injected_code)) {
+ if (target_organism->InjectHost(parent_cpu.GetLabel(), injected_code)) {
// If the parent genotype is not correct for the child, adjust it.
if (parent_genotype == NULL || parent_genotype->GetGenome() != injected_code) {
child_genotype = m_world->GetClassificationManager().GetInjectGenotype(injected_code, parent_genotype);
@@ -419,8 +416,6 @@
target_organism->AddParasite(child_genotype);
child_genotype->AddParasite();
child_cpu.SetThreadOwner(child_genotype);
- //if(parent_genotype!=NULL)
- // parent_genotype->RemoveParasite();
m_world->GetClassificationManager().AdjustInjectGenotype(*child_genotype);
}
else
@@ -429,7 +424,7 @@
return true;
}
-bool cPopulation::ActivateInject(const int cell_id, const cGenome & injected_code)
+bool cPopulation::ActivateInject(const int cell_id, const cGenome& injected_code)
{
cInjectGenotype * child_genotype = m_world->GetClassificationManager().GetInjectGenotype(injected_code);
cHardwareBase& child_cpu = cell_array[cell_id].GetOrganism()->GetHardware();
Modified: development/source/main/cPopulation.h
===================================================================
--- development/source/main/cPopulation.h 2006-04-13 13:36:10 UTC (rev 609)
+++ development/source/main/cPopulation.h 2006-04-14 02:33:03 UTC (rev 610)
@@ -39,7 +39,7 @@
#endif
class cAvidaContext;
-class cSchedule;
+class cCodeLabel;
class cChangeList;
class cEnvironment;
class cGenome;
@@ -47,7 +47,9 @@
class cLineage;
class cOrganism;
class cPopulationCell;
+class cSchedule;
+
class cPopulation
{
private:
@@ -117,8 +119,8 @@
// Activate the offspring of an organism in the population
bool ActivateOffspring(cAvidaContext& ctx, cGenome& child_genome, cOrganism& parent_organism);
-
- bool ActivateInject(cOrganism& parent, const cGenome& injected_code);
+ bool ActivateParasite(cOrganism& parent, const cGenome& injected_code);
+
bool ActivateInject(const int cell_id, const cGenome& injected_code);
// Inject an organism from the outside world.
Modified: development/source/main/cPopulationInterface.cc
===================================================================
--- development/source/main/cPopulationInterface.cc 2006-04-13 13:36:10 UTC (rev 609)
+++ development/source/main/cPopulationInterface.cc 2006-04-14 02:33:03 UTC (rev 610)
@@ -30,13 +30,13 @@
bool cPopulationInterface::Divide(cAvidaContext& ctx, cOrganism* parent, cGenome& child_genome)
{
assert(parent != NULL);
- assert(m_world->GetPopulation().GetCell(cell_id).GetOrganism() == parent);
+ assert(m_world->GetPopulation().GetCell(m_cell_id).GetOrganism() == parent);
return m_world->GetPopulation().ActivateOffspring(ctx, child_genome, *parent);
}
cOrganism * cPopulationInterface::GetNeighbor()
{
- cPopulationCell & cell = m_world->GetPopulation().GetCell(cell_id);
+ cPopulationCell & cell = m_world->GetPopulation().GetCell(m_cell_id);
assert(cell.IsOccupied());
return cell.ConnectionList().GetFirst()->GetOrganism();
@@ -44,7 +44,7 @@
int cPopulationInterface::GetNumNeighbors()
{
- cPopulationCell & cell = m_world->GetPopulation().GetCell(cell_id);
+ cPopulationCell & cell = m_world->GetPopulation().GetCell(m_cell_id);
assert(cell.IsOccupied());
return cell.ConnectionList().GetSize();
@@ -52,7 +52,7 @@
void cPopulationInterface::Rotate(int direction)
{
- cPopulationCell & cell = m_world->GetPopulation().GetCell(cell_id);
+ cPopulationCell & cell = m_world->GetPopulation().GetCell(m_cell_id);
assert(cell.IsOccupied());
if (direction >= 0) cell.ConnectionList().CircNext();
@@ -61,7 +61,7 @@
double cPopulationInterface::TestFitness()
{
- cPopulationCell & cell = m_world->GetPopulation().GetCell(cell_id);
+ cPopulationCell & cell = m_world->GetPopulation().GetCell(m_cell_id);
assert(cell.IsOccupied());
return cell.GetOrganism()->GetGenotype()->GetTestFitness();
@@ -69,52 +69,52 @@
int cPopulationInterface::GetInput()
{
- cPopulationCell & cell = m_world->GetPopulation().GetCell(cell_id);
+ cPopulationCell & cell = m_world->GetPopulation().GetCell(m_cell_id);
assert(cell.IsOccupied());
return cell.GetInput();
}
int cPopulationInterface::GetInputAt(int& input_pointer)
{
- cPopulationCell& cell = m_world->GetPopulation().GetCell(cell_id);
+ cPopulationCell& cell = m_world->GetPopulation().GetCell(m_cell_id);
assert(cell.IsOccupied());
return cell.GetInputAt(input_pointer);
}
int cPopulationInterface::Debug()
{
- cPopulationCell & cell = m_world->GetPopulation().GetCell(cell_id);
+ cPopulationCell & cell = m_world->GetPopulation().GetCell(m_cell_id);
assert(cell.IsOccupied());
return cell.GetOrganism()->GetGenotype()->GetID();
}
const tArray<double> & cPopulationInterface::GetResources()
{
- return m_world->GetPopulation().GetCellResources(cell_id);
+ return m_world->GetPopulation().GetCellResources(m_cell_id);
}
void cPopulationInterface::UpdateResources(const tArray<double> & res_change)
{
- return m_world->GetPopulation().UpdateCellResources(res_change, cell_id);
+ return m_world->GetPopulation().UpdateCellResources(res_change, m_cell_id);
}
void cPopulationInterface::Die()
{
- cPopulationCell & cell = m_world->GetPopulation().GetCell(cell_id);
+ cPopulationCell & cell = m_world->GetPopulation().GetCell(m_cell_id);
m_world->GetPopulation().KillOrganism(cell);
}
void cPopulationInterface::Kaboom()
{
- cPopulationCell & cell = m_world->GetPopulation().GetCell(cell_id);
+ cPopulationCell & cell = m_world->GetPopulation().GetCell(m_cell_id);
m_world->GetPopulation().Kaboom(cell);
}
bool cPopulationInterface::SendMessage(cOrgMessage & mess)
{
- mess.SetSenderID(cell_id);
+ mess.SetSenderID(m_cell_id);
mess.SetTime(m_world->GetStats().GetUpdate());
- cPopulationCell& cell = m_world->GetPopulation().GetCell(cell_id);
+ cPopulationCell& cell = m_world->GetPopulation().GetCell(m_cell_id);
if(cell.ConnectionList().GetFirst() == NULL)
return false;
mess.SetRecipientID(cell.ConnectionList().GetFirst()->GetID());
@@ -123,7 +123,7 @@
cOrgSinkMessage* cPopulationInterface::NetReceive()
{
- cPopulationCell& cell = m_world->GetPopulation().GetCell(cell_id);
+ cPopulationCell& cell = m_world->GetPopulation().GetCell(m_cell_id);
assert(cell.IsOccupied());
const int num_neighbors = cell.ConnectionList().GetSize();
@@ -146,7 +146,7 @@
int cPopulationInterface::ReceiveValue()
{
- cPopulationCell & cell = m_world->GetPopulation().GetCell(cell_id);
+ cPopulationCell & cell = m_world->GetPopulation().GetCell(m_cell_id);
assert(cell.IsOccupied());
const int num_neighbors = cell.ConnectionList().GetSize();
@@ -164,16 +164,16 @@
return 0;
}
-bool cPopulationInterface::InjectParasite(cOrganism * parent, const cGenome & injected_code)
+bool cPopulationInterface::InjectParasite(cOrganism* parent, const cGenome& injected_code)
{
assert(parent != NULL);
- assert(m_world->GetPopulation().GetCell(cell_id).GetOrganism() == parent);
+ assert(m_world->GetPopulation().GetCell(m_cell_id).GetOrganism() == parent);
- return m_world->GetPopulation().ActivateInject(*parent, injected_code);
+ return m_world->GetPopulation().ActivateParasite(*parent, injected_code);
}
bool cPopulationInterface::UpdateMerit(double new_merit)
{
- return m_world->GetPopulation().UpdateMerit(cell_id, new_merit);
+ return m_world->GetPopulation().UpdateMerit(m_cell_id, new_merit);
}
Modified: development/source/main/cPopulationInterface.h
===================================================================
--- development/source/main/cPopulationInterface.h 2006-04-13 13:36:10 UTC (rev 609)
+++ development/source/main/cPopulationInterface.h 2006-04-14 02:33:03 UTC (rev 610)
@@ -22,26 +22,24 @@
#endif
class cPopulation;
-class cOrganism;
-class cGenome;
-template <class T> class tArray;
-class cOrgMessage;
-class cPopulationInterface : public cOrgInterface {
+
+class cPopulationInterface : public cOrgInterface
+{
private:
cWorld* m_world;
- int cell_id;
+ int m_cell_id;
cPopulationInterface(); // @not_implemented
cPopulationInterface(const cPopulationInterface&); // @not_implemented
cPopulationInterface operator=(const cPopulationInterface&); // @not_implemented
public:
- cPopulationInterface(cWorld* world) : m_world(world), cell_id(-1) { ; }
+ cPopulationInterface(cWorld* world) : m_world(world), m_cell_id(-1) { ; }
virtual ~cPopulationInterface() { ; }
- int GetCellID() { return cell_id; }
- void SetCellID(int in_id) { cell_id = in_id; }
+ int GetCellID() { return m_cell_id; }
+ void SetCellID(int in_id) { m_cell_id = in_id; }
bool Divide(cAvidaContext& ctx, cOrganism* parent, cGenome& child_genome);
cOrganism* GetNeighbor();
More information about the Avida-cvs
mailing list