[Avida-SVN] r3566 - in branches/biounit/source: actions cpu main
brysonda at myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Fri Dec 18 12:52:40 PST 2009
Author: brysonda
Date: 2009-12-18 15:52:40 -0500 (Fri, 18 Dec 2009)
New Revision: 3566
Modified:
branches/biounit/source/actions/PopulationActions.cc
branches/biounit/source/cpu/cHardwareBase.h
branches/biounit/source/cpu/cHardwareCPU.cc
branches/biounit/source/cpu/cHardwareCPU.h
branches/biounit/source/cpu/cHardwareExperimental.cc
branches/biounit/source/cpu/cHardwareExperimental.h
branches/biounit/source/cpu/cHardwareGX.cc
branches/biounit/source/cpu/cHardwareGX.h
branches/biounit/source/cpu/cHardwareSMT.cc
branches/biounit/source/cpu/cHardwareSMT.h
branches/biounit/source/cpu/cHardwareTransSMT.cc
branches/biounit/source/cpu/cHardwareTransSMT.h
branches/biounit/source/cpu/cTestCPUInterface.cc
branches/biounit/source/cpu/cTestCPUInterface.h
branches/biounit/source/main/cOrgInterface.h
branches/biounit/source/main/cOrganism.cc
branches/biounit/source/main/cOrganism.h
branches/biounit/source/main/cPopulation.cc
branches/biounit/source/main/cPopulation.h
branches/biounit/source/main/cPopulationInterface.cc
branches/biounit/source/main/cPopulationInterface.h
Log:
Parasites should now be properly tracked via biogroup based genotypes.
Modified: branches/biounit/source/actions/PopulationActions.cc
===================================================================
--- branches/biounit/source/actions/PopulationActions.cc 2009-12-18 17:03:43 UTC (rev 3565)
+++ branches/biounit/source/actions/PopulationActions.cc 2009-12-18 20:52:40 UTC (rev 3566)
@@ -427,7 +427,7 @@
{
private:
cString m_filename;
- cCodeLabel m_label;
+ cString m_label;
int m_cell_start;
int m_cell_end;
public:
@@ -435,7 +435,7 @@
{
cString largs(args);
m_filename = largs.PopWord();
- m_label.ReadString(largs.PopWord());
+ m_label = largs.PopWord();
if (largs.GetSize()) m_cell_start = largs.PopWord().AsInt();
if (largs.GetSize()) m_cell_end = largs.PopWord().AsInt();
@@ -485,7 +485,7 @@
private:
cString m_filename_genome;
cString m_filename_parasite;
- cCodeLabel m_label;
+ cString m_label;
int m_cell_start;
int m_cell_end;
double m_merit;
@@ -498,7 +498,7 @@
cString largs(args);
m_filename_genome = largs.PopWord();
m_filename_parasite = largs.PopWord();
- m_label.ReadString(largs.PopWord());
+ m_label = largs.PopWord();
if (largs.GetSize()) m_cell_start = largs.PopWord().AsInt();
if (largs.GetSize()) m_cell_end = largs.PopWord().AsInt();
if (largs.GetSize()) m_merit = largs.PopWord().AsDouble();
Modified: branches/biounit/source/cpu/cHardwareBase.h
===================================================================
--- branches/biounit/source/cpu/cHardwareBase.h 2009-12-18 17:03:43 UTC (rev 3565)
+++ branches/biounit/source/cpu/cHardwareBase.h 2009-12-18 20:52:40 UTC (rev 3566)
@@ -173,7 +173,7 @@
// -------- Parasite Stuff --------
- virtual bool InjectHost(const cCodeLabel& in_label, const cGenome& injection) = 0;
+ virtual bool ParasiteInfectHost(cBioUnit* bu) = 0;
// -------- Mutation --------
Modified: branches/biounit/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/biounit/source/cpu/cHardwareCPU.cc 2009-12-18 17:03:43 UTC (rev 3565)
+++ branches/biounit/source/cpu/cHardwareCPU.cc 2009-12-18 20:52:40 UTC (rev 3566)
@@ -218,8 +218,6 @@
tInstLibEntry<tMethod>("divideRS", &cHardwareCPU::Inst_DivideRS, nInstFlag::STALL),
tInstLibEntry<tMethod>("c-alloc", &cHardwareCPU::Inst_CAlloc),
tInstLibEntry<tMethod>("c-divide", &cHardwareCPU::Inst_CDivide, nInstFlag::STALL),
- tInstLibEntry<tMethod>("inject", &cHardwareCPU::Inst_Inject, nInstFlag::STALL),
- tInstLibEntry<tMethod>("inject-r", &cHardwareCPU::Inst_InjectRand, nInstFlag::STALL),
tInstLibEntry<tMethod>("transposon", &cHardwareCPU::Inst_Transposon),
tInstLibEntry<tMethod>("search-f", &cHardwareCPU::Inst_SearchF),
tInstLibEntry<tMethod>("search-b", &cHardwareCPU::Inst_SearchB),
@@ -1241,47 +1239,7 @@
}
-bool cHardwareCPU::InjectHost(const cCodeLabel & in_label, const cGenome & injection)
-{
- // Make sure the genome will be below max size after injection.
-
- const int new_size = injection.GetSize() + m_memory.GetSize();
- if (new_size > MAX_CREATURE_SIZE) return false; // (inject fails)
-
- const int inject_line = FindLabelFull(in_label).GetPosition();
-
- // Abort if no compliment is found.
- if (inject_line == -1) return false; // (inject fails)
-
- // Inject the code!
- InjectCode(injection, inject_line+1);
-
- return true; // (inject succeeds!)
-}
-void cHardwareCPU::InjectCode(const cGenome & inject_code, const int line_num)
-{
- assert(line_num >= 0);
- assert(line_num <= m_memory.GetSize());
- assert(m_memory.GetSize() + inject_code.GetSize() < MAX_CREATURE_SIZE);
-
- // Inject the new code.
- const int inject_size = inject_code.GetSize();
- m_memory.Insert(line_num, inject_code);
-
- // Set instruction flags on the injected code
- for (int i = line_num; i < line_num + inject_size; i++) {
- m_memory.SetFlagInjected(i);
- }
- m_organism->GetPhenotype().IsModified() = true;
-
- // Adjust all of the heads to take into account the new mem size.
- for (int i = 0; i < NUM_HEADS; i++) {
- if (getHead(i).GetPosition() > line_num) getHead(i).Jump(inject_size);
- }
-}
-
-
void cHardwareCPU::ReadInst(const int in_inst)
{
if (m_inst_set->IsNop( cInstruction(in_inst) )) {
@@ -3272,129 +3230,10 @@
return true;
}
-// The inject instruction can be used instead of a divide command, paired
-// with an allocate. Note that for an inject to work, one needs to have a
-// broad range for sizes allowed to be allocated.
-//
-// This command will cut out from read-head to write-head.
-// It will then look at the template that follows the command and inject it
-// into the complement template found in a neighboring organism.
-bool cHardwareCPU::Inst_Inject(cAvidaContext& ctx)
-{
- AdjustHeads();
- const int start_pos = getHead(nHardware::HEAD_READ).GetPosition();
- const int end_pos = getHead(nHardware::HEAD_WRITE).GetPosition();
- const int inject_size = end_pos - start_pos;
-
- // Make sure the creature will still be above the minimum size,
- if (inject_size <= 0) {
- m_organism->Fault(FAULT_LOC_INJECT, FAULT_TYPE_ERROR, "inject: no code to inject");
- return false; // (inject fails)
- }
- if (start_pos < MIN_CREATURE_SIZE) {
- m_organism->Fault(FAULT_LOC_INJECT, FAULT_TYPE_ERROR, "inject: new size too small");
- return false; // (inject fails)
- }
-
- // Since its legal to cut out the injected piece, do so.
- cGenome inject_code(cGenomeUtil::Crop(m_memory, start_pos, end_pos));
- m_memory.Remove(start_pos, inject_size);
- AdjustHeads();
-
- // If we don't have a host, stop here.
- cOrganism * host_organism = m_organism->GetNeighbor();
- if (host_organism == NULL) return false;
-
- // Scan for the label to match...
- ReadLabel();
-
- // If there is no label, abort.
- if (GetLabel().GetSize() == 0) {
- m_organism->Fault(FAULT_LOC_INJECT, FAULT_TYPE_ERROR, "inject: label required");
- return false; // (inject fails)
- }
-
- // Search for the label in the host...
- GetLabel().Rotate(1, NUM_NOPS);
-
- const bool inject_signal = host_organism->GetHardware().InjectHost(GetLabel(), inject_code);
- if (inject_signal) {
- m_organism->Fault(FAULT_LOC_INJECT, FAULT_TYPE_WARNING, "inject: host too large.");
- return false; // Inject failed.
- }
-
- // Set the relevent flags.
- m_organism->GetPhenotype().IsModifier() = true;
-
- return inject_signal;
-}
-bool cHardwareCPU::Inst_InjectRand(cAvidaContext& ctx)
-{
- // Rotate to a random facing and then run the normal inject instruction
- const int num_neighbors = m_organism->GetNeighborhoodSize();
- m_organism->Rotate(ctx.GetRandom().GetUInt(num_neighbors));
- Inst_Inject(ctx);
- return true;
-}
-// The inject instruction can be used instead of a divide command, paired
-// with an allocate. Note that for an inject to work, one needs to have a
-// broad range for sizes allowed to be allocated.
-//
-// This command will cut out from read-head to write-head.
-// It will then look at the template that follows the command and inject it
-// into the complement template found in a neighboring organism.
-
-bool cHardwareCPU::Inst_InjectThread(cAvidaContext& ctx)
-{
- AdjustHeads();
- const int start_pos = getHead(nHardware::HEAD_READ).GetPosition();
- const int end_pos = getHead(nHardware::HEAD_WRITE).GetPosition();
- const int inject_size = end_pos - start_pos;
-
- // Make sure the creature will still be above the minimum size,
- if (inject_size <= 0) {
- m_organism->Fault(FAULT_LOC_INJECT, FAULT_TYPE_ERROR, "inject: no code to inject");
- return false; // (inject fails)
- }
- if (start_pos < MIN_CREATURE_SIZE) {
- m_organism->Fault(FAULT_LOC_INJECT, FAULT_TYPE_ERROR, "inject: new size too small");
- return false; // (inject fails)
- }
-
- // Since its legal to cut out the injected piece, do so.
- cGenome inject_code( cGenomeUtil::Crop(m_memory, start_pos, end_pos) );
- m_memory.Remove(start_pos, inject_size);
-
- // If we don't have a host, stop here.
- cOrganism * host_organism = m_organism->GetNeighbor();
- if (host_organism == NULL) return false;
-
- // Scan for the label to match...
- ReadLabel();
-
- // If there is no label, abort.
- if (GetLabel().GetSize() == 0) {
- m_organism->Fault(FAULT_LOC_INJECT, FAULT_TYPE_ERROR, "inject: label required");
- return false; // (inject fails)
- }
-
- // Search for the label in the host...
- GetLabel().Rotate(1, NUM_NOPS);
-
- if (host_organism->GetHardware().InjectHost(GetLabel(), inject_code)) {
- if (ForkThread()) m_organism->GetPhenotype().IsMultiThread() = true;
- }
-
- // Set the relevent flags.
- m_organism->GetPhenotype().IsModifier() = true;
-
- return true;
-}
-
bool cHardwareCPU::Inst_TaskGet(cAvidaContext& ctx)
{
const int reg_used = FindModifiedRegister(REG_CX);
Modified: branches/biounit/source/cpu/cHardwareCPU.h
===================================================================
--- branches/biounit/source/cpu/cHardwareCPU.h 2009-12-18 17:03:43 UTC (rev 3565)
+++ branches/biounit/source/cpu/cHardwareCPU.h 2009-12-18 20:52:40 UTC (rev 3566)
@@ -246,8 +246,6 @@
void Divide_DoTransposons(cAvidaContext& ctx);
void InheritState(cHardwareBase& in_hardware);
- void InjectCode(const cGenome& injection, const int line_num);
-
bool HeadCopy_ErrorCorrect(cAvidaContext& ctx, double reduction);
bool Inst_HeadDivideMut(cAvidaContext& ctx, double mut_multiplier = 1);
@@ -313,7 +311,7 @@
bool ThreadSelect(const cCodeLabel& in_label) { return false; } // Labeled threads not supported
inline void ThreadPrev(); // Shift the current thread in use.
inline void ThreadNext();
- cBioUnit* ThreadGetOwner() { return m_organism; } // @TODO - note cHardwareCPU does not implement parasites
+ cBioUnit* ThreadGetOwner() { return m_organism; }
int GetNumThreads() const { return m_threads.GetSize(); }
int GetCurThread() const { return m_cur_thread; }
@@ -321,7 +319,7 @@
const cLocalThread& GetThread(int _index) const { return m_threads[_index]; }
// -------- Parasite Stuff --------
- bool InjectHost(const cCodeLabel& in_label, const cGenome& injection);
+ bool ParasiteInfectHost(cBioUnit* bu) { return false; }
// Non-Standard Methods
@@ -475,9 +473,6 @@
bool Inst_CDivide(cAvidaContext& ctx);
bool Inst_MaxAlloc(cAvidaContext& ctx);
bool Inst_MaxAllocMoveWriteHead(cAvidaContext& ctx);
- bool Inst_Inject(cAvidaContext& ctx);
- bool Inst_InjectRand(cAvidaContext& ctx);
- bool Inst_InjectThread(cAvidaContext& ctx);
bool Inst_Transposon(cAvidaContext& ctx);
bool Inst_ReproDeme(cAvidaContext& ctx);
bool Inst_Repro(cAvidaContext& ctx);
Modified: branches/biounit/source/cpu/cHardwareExperimental.cc
===================================================================
--- branches/biounit/source/cpu/cHardwareExperimental.cc 2009-12-18 17:03:43 UTC (rev 3565)
+++ branches/biounit/source/cpu/cHardwareExperimental.cc 2009-12-18 20:52:40 UTC (rev 3566)
@@ -803,47 +803,6 @@
}
-bool cHardwareExperimental::InjectHost(const cCodeLabel & in_label, const cGenome & injection)
-{
- // Make sure the genome will be below max size after injection.
-
- const int new_size = injection.GetSize() + m_memory.GetSize();
- if (new_size > MAX_CREATURE_SIZE) return false; // (inject fails)
-
- const int inject_line = FindLabelFull(in_label).GetPosition();
-
- // Abort if no compliment is found.
- if (inject_line == -1) return false; // (inject fails)
-
- // Inject the code!
- InjectCode(injection, inject_line+1);
-
- return true; // (inject succeeds!)
-}
-
-void cHardwareExperimental::InjectCode(const cGenome & inject_code, const int line_num)
-{
- assert(line_num >= 0);
- assert(line_num <= m_memory.GetSize());
- assert(m_memory.GetSize() + inject_code.GetSize() < MAX_CREATURE_SIZE);
-
- // Inject the new code.
- const int inject_size = inject_code.GetSize();
- m_memory.Insert(line_num, inject_code);
-
- // Set instruction flags on the injected code
- for (int i = line_num; i < line_num + inject_size; i++) {
- m_memory.SetFlagInjected(i);
- }
- m_organism->GetPhenotype().IsModified() = true;
-
- // Adjust all of the heads to take into account the new mem size.
- for (int i = 0; i < NUM_HEADS; i++) {
- if (getHead(i).GetPosition() > line_num) getHead(i).Jump(inject_size);
- }
-}
-
-
void cHardwareExperimental::ReadInst(const int in_inst)
{
if (m_inst_set->IsLabel(cInstruction(in_inst))) {
Modified: branches/biounit/source/cpu/cHardwareExperimental.h
===================================================================
--- branches/biounit/source/cpu/cHardwareExperimental.h 2009-12-18 17:03:43 UTC (rev 3565)
+++ branches/biounit/source/cpu/cHardwareExperimental.h 2009-12-18 20:52:40 UTC (rev 3566)
@@ -287,7 +287,7 @@
bool ThreadSelect(const cCodeLabel& in_label) { return false; } // Labeled threads not supported
inline void ThreadPrev(); // Shift the current thread in use.
inline void ThreadNext();
- cBioUnit* ThreadGetOwner() { return m_organism; } // @TODO - cHardwareExperimental not implement parasites
+ cBioUnit* ThreadGetOwner() { return m_organism; }
int GetNumThreads() const { return m_threads.GetSize(); }
int GetCurThread() const { return m_cur_thread; }
@@ -295,7 +295,7 @@
// -------- Parasite Stuff --------
- bool InjectHost(const cCodeLabel& in_label, const cGenome& injection);
+ bool ParasiteInfectHost(cBioUnit* bu) { return false; }
// -------- Non-Standard Methods --------
@@ -369,10 +369,6 @@
bool Divide_Main(cAvidaContext& ctx, const int divide_point, const int extra_lines=0, double mut_multiplier=1);
- // -------- Parasite Stuff --------
- void InjectCode(const cGenome& injection, const int line_num);
-
-
// ---------- Utility Functions -----------
inline unsigned int BitCount(unsigned int value) const;
inline void setInternalValue(sInternalValue& dest, int value, bool from_env = false);
Modified: branches/biounit/source/cpu/cHardwareGX.cc
===================================================================
--- branches/biounit/source/cpu/cHardwareGX.cc 2009-12-18 17:03:43 UTC (rev 3565)
+++ branches/biounit/source/cpu/cHardwareGX.cc 2009-12-18 20:52:40 UTC (rev 3566)
@@ -173,8 +173,6 @@
tInstLibEntry<tMethod>("if-n-cpy", &cHardwareGX::Inst_IfNCpy),
tInstLibEntry<tMethod>("allocate", &cHardwareGX::Inst_Allocate),
tInstLibEntry<tMethod>("c-alloc", &cHardwareGX::Inst_CAlloc),
- tInstLibEntry<tMethod>("inject", &cHardwareGX::Inst_Inject),
- tInstLibEntry<tMethod>("inject-r", &cHardwareGX::Inst_InjectRand),
tInstLibEntry<tMethod>("search-f", &cHardwareGX::Inst_SearchF),
tInstLibEntry<tMethod>("search-b", &cHardwareGX::Inst_SearchB),
tInstLibEntry<tMethod>("mem-size", &cHardwareGX::Inst_MemSize),
@@ -933,35 +931,9 @@
}
-/*! Inject a genome fragment into this CPU. This works a little differently in
-cHardwareGX, in that we don't insert a genome fragment into a preexisting genome,
-but instead ust create a new cProgramid with the genome-to-be-injected.
-*/
-bool cHardwareGX::InjectHost(const cCodeLabel & in_label, const cGenome & injection)
-{
- InjectCode(injection, -1);
- return true;
-}
-/*! Inject a genome fragment into this CPU. This works differently in
-cHardwareGX -- We just insert a new cProgramid.
-*/
-void cHardwareGX::InjectCode(const cGenome & inject_code, const int line_num)
-{
- programid_ptr injected = new cProgramid(inject_code, this);
- // Set instruction flags on the injected code
- for(int i=0; i<injected->m_memory.GetSize(); ++i) {
- injected->m_memory.SetFlagInjected(i);
- }
-
- AddProgramid(injected);
-
- m_organism->GetPhenotype().IsModified() = true;
-}
-
-
void cHardwareGX::ReadInst(const int in_inst)
{
if(m_inst_set->IsNop(cInstruction(in_inst))) {
@@ -2147,75 +2119,8 @@
return true;
}
-// The inject instruction can be used instead of a divide command, paired
-// with an allocate. Note that for an inject to work, one needs to have a
-// broad range for sizes allowed to be allocated.
-//
-// This command will cut out from read-head to write-head.
-// It will then look at the template that follows the command and inject it
-// into the complement template found in a neighboring organism.
-bool cHardwareGX::Inst_Inject(cAvidaContext& ctx)
-{
- AdjustHeads();
- const int start_pos = GetHead(nHardware::HEAD_READ).GetPosition();
- const int end_pos = GetHead(nHardware::HEAD_WRITE).GetPosition();
- const int inject_size = end_pos - start_pos;
-
- // Make sure the creature will still be above the minimum size,
- if (inject_size <= 0) {
- m_organism->Fault(FAULT_LOC_INJECT, FAULT_TYPE_ERROR, "inject: no code to inject");
- return false; // (inject fails)
- }
- if (start_pos < MIN_CREATURE_SIZE) {
- m_organism->Fault(FAULT_LOC_INJECT, FAULT_TYPE_ERROR, "inject: new size too small");
- return false; // (inject fails)
- }
-
- // Since its legal to cut out the injected piece, do so.
- cGenome inject_code( cGenomeUtil::Crop(GetMemory(), start_pos, end_pos) );
- GetMemory().Remove(start_pos, inject_size);
-
- // If we don't have a host, stop here.
- cOrganism * host_organism = m_organism->GetNeighbor();
- if (host_organism == NULL) return false;
-
- // Scan for the label to match...
- ReadLabel();
-
- // If there is no label, abort.
- if (GetLabel().GetSize() == 0) {
- m_organism->Fault(FAULT_LOC_INJECT, FAULT_TYPE_ERROR, "inject: label required");
- return false; // (inject fails)
- }
-
- // Search for the label in the host...
- GetLabel().Rotate(1, NUM_NOPS);
-
- const bool inject_signal = host_organism->GetHardware().InjectHost(GetLabel(), inject_code);
- if (inject_signal) {
- m_organism->Fault(FAULT_LOC_INJECT, FAULT_TYPE_WARNING, "inject: host too large.");
- return false; // Inject failed.
- }
-
- // Set the relevent flags.
- m_organism->GetPhenotype().IsModifier() = true;
-
- return inject_signal;
-}
-
-bool cHardwareGX::Inst_InjectRand(cAvidaContext& ctx)
-{
- // Rotate to a random facing and then run the normal inject instruction
- const int num_neighbors = m_organism->GetNeighborhoodSize();
- m_organism->Rotate(ctx.GetRandom().GetUInt(num_neighbors));
- Inst_Inject(ctx);
- return true;
-}
-
-
-
bool cHardwareGX::Inst_TaskGet(cAvidaContext& ctx)
{
const int reg_used = FindModifiedRegister(REG_CX);
Modified: branches/biounit/source/cpu/cHardwareGX.h
===================================================================
--- branches/biounit/source/cpu/cHardwareGX.h 2009-12-18 17:03:43 UTC (rev 3565)
+++ branches/biounit/source/cpu/cHardwareGX.h 2009-12-18 20:52:40 UTC (rev 3566)
@@ -300,7 +300,6 @@
int calcExecutedSize(const int parent_size);
int calcCopiedSize(const int parent_size, const int child_size);
bool Divide_Main(cAvidaContext& ctx);
- void InjectCode(const cGenome& injection, const int line_num);
bool HeadCopy_ErrorCorrect(cAvidaContext& ctx, double reduction);
void ReadInst(const int in_inst);
@@ -361,16 +360,16 @@
/* cHardwareGX does not support threads (at least, not as in other CPUs). */
virtual bool ThreadSelect(const int thread_id) { return false; }
virtual bool ThreadSelect(const cCodeLabel& in_label) { return false; }
- virtual void ThreadPrev() { }
- virtual void ThreadNext() { }
- virtual cBioUnit* ThreadGetOwner() { return m_organism; } // @TODO - cHardwareGX does not support parasites
+ virtual void ThreadPrev() { ; }
+ virtual void ThreadNext() { ; }
+ virtual cBioUnit* ThreadGetOwner() { return m_organism; }
- virtual int GetNumThreads() const { return -1; }
+ virtual int GetNumThreads() const { return 1; }
virtual int GetCurThread() const { return -1; }
virtual int GetCurThreadID() const { return -1; }
// -------- Parasite Stuff --------
- bool InjectHost(const cCodeLabel& in_label, const cGenome& injection);
+ bool ParasiteInfectHost(cBioUnit* bu) { return false; }
// -------- Input/Output Buffers --------
@@ -488,8 +487,6 @@
bool Inst_Allocate(cAvidaContext& ctx);
bool Inst_CAlloc(cAvidaContext& ctx);
bool Inst_MaxAlloc(cAvidaContext& ctx);
- bool Inst_Inject(cAvidaContext& ctx);
- bool Inst_InjectRand(cAvidaContext& ctx);
bool Inst_Repro(cAvidaContext& ctx);
Modified: branches/biounit/source/cpu/cHardwareSMT.cc
===================================================================
--- branches/biounit/source/cpu/cHardwareSMT.cc 2009-12-18 17:03:43 UTC (rev 3565)
+++ branches/biounit/source/cpu/cHardwareSMT.cc 2009-12-18 20:52:40 UTC (rev 3566)
@@ -166,6 +166,8 @@
for(int i = 0; i < NUM_STACKS; i++) {
Stack(i).Clear();
}
+
+ m_organism->ClearParasites();
}
void cHardwareSMT::cLocalThread::Reset(cHardwareBase* in_hardware, int mem_space)
@@ -632,7 +634,7 @@
bool inject_signal = false;
if (injected_code.GetSize() > 0) {
cBioUnit* parent = (m_threads[m_cur_thread].owner) ? m_threads[m_cur_thread].owner : m_organism;
- inject_signal = m_organism->InjectParasite(parent, GetLabel(), injected_code);
+ inject_signal = m_organism->InjectParasite(parent, GetLabel().AsString(), injected_code);
}
// reset the memory space that was injected
@@ -646,20 +648,40 @@
return inject_signal;
}
-//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)
+bool cHardwareSMT::ParasiteInfectHost(cBioUnit* bu)
{
- // Inject fails if the memory space is already in use or thread exists
- if (MemorySpaceExists(in_label) || FindThreadLabel(in_label) != -1) return false;
-
- // Otherwise create the memory space and copy in the genome
- int mem_space_used = FindMemorySpaceLabel(in_label, -1);
- assert(mem_space_used != -1);
- m_mem_array[mem_space_used] = inject_code;
+ assert(bu->GetMetaGenome().GetHardwareType() == GetType() && bu->GetMetaGenome().GetInstSetID() == GetInstSetID());
- // Create a thread for this parasite
- if (!ThreadCreate(in_label, mem_space_used)) return false; // Partially failed injection, could not create thread
-
+ cCodeLabel label;
+ label.ReadString(bu->GetUnitSourceArgs());
+
+ // Inject fails if the memory space is already in use
+ if (label.GetSize() == 0 || MemorySpaceExists(label)) return false;
+
+ int thread_id = m_threads.GetSize();
+
+ // Check for existing thread
+ int hash_key = label.AsInt(NUM_NOPS);
+ if (m_thread_lbls.Find(hash_key, thread_id)) {
+ if (m_threads[thread_id].running) return false; // Thread exists, and is running... call fails
+ } else {
+ // Check for thread cap
+ if (thread_id == m_world->GetConfig().MAX_CPU_THREADS.Get()) return false;
+
+ // Add new thread entry
+ m_threads.Resize(thread_id + 1);
+ m_thread_lbls.Add(hash_key, thread_id);
+ }
+
+ // Create the memory space and copy in the parasite
+ int mem_space = FindMemorySpaceLabel(label, -1);
+ assert(mem_space != -1);
+ m_mem_array[mem_space] = bu->GetMetaGenome().GetGenome();
+
+ // Setup the thread
+ m_threads[thread_id].Reset(this, mem_space);
+ m_threads[thread_id].owner = bu;
+
return true;
}
@@ -721,6 +743,7 @@
// Setup this thread into the current selected memory space (Flow Head)
m_threads[thread_id].Reset(this, mem_space);
+ m_threads[thread_id].owner = m_threads[m_cur_thread].owner;
return (thread_id + 1);
}
Modified: branches/biounit/source/cpu/cHardwareSMT.h
===================================================================
--- branches/biounit/source/cpu/cHardwareSMT.h 2009-12-18 17:03:43 UTC (rev 3565)
+++ branches/biounit/source/cpu/cHardwareSMT.h 2009-12-18 20:52:40 UTC (rev 3566)
@@ -263,7 +263,7 @@
// -------- Parasite Stuff --------
- bool InjectHost(const cCodeLabel& in_label, const cGenome& inject_code);
+ bool ParasiteInfectHost(cBioUnit* bu);
private:
Modified: branches/biounit/source/cpu/cHardwareTransSMT.cc
===================================================================
--- branches/biounit/source/cpu/cHardwareTransSMT.cc 2009-12-18 17:03:43 UTC (rev 3565)
+++ branches/biounit/source/cpu/cHardwareTransSMT.cc 2009-12-18 20:52:40 UTC (rev 3566)
@@ -177,7 +177,7 @@
read_label.Clear();
next_label.Clear();
running = true;
- owner = NULL;
+ owner = NULL;
}
cBioUnit* cHardwareTransSMT::ThreadGetOwner()
@@ -635,7 +635,7 @@
bool inject_signal = false;
if (injected_code.GetSize() > 0) {
cBioUnit* parent = (m_threads[m_cur_thread].owner) ? m_threads[m_cur_thread].owner : m_organism;
- inject_signal = m_organism->InjectParasite(parent, GetLabel(), injected_code);
+ inject_signal = m_organism->InjectParasite(parent, GetLabel().AsString(), injected_code);
}
// reset the memory space that was injected
@@ -651,22 +651,40 @@
return inject_signal;
}
-//This is the code run by the TARGET of an injection. This RECIEVES the infection.
-bool cHardwareTransSMT::InjectHost(const cCodeLabel& in_label, const cGenome& inject_code)
+
+bool cHardwareTransSMT::ParasiteInfectHost(cBioUnit* bu)
{
- // Inject fails if the memory space is already in use or thread exists
- if (MemorySpaceExists(in_label) || FindThreadLabel(in_label) != -1)
- {
- return false;
+ assert(bu->GetMetaGenome().GetHardwareType() == GetType() && bu->GetMetaGenome().GetInstSetID() == GetInstSetID());
+
+ cCodeLabel label;
+ label.ReadString(bu->GetUnitSourceArgs());
+
+ // Inject fails if the memory space is already in use
+ if (label.GetSize() == 0 || MemorySpaceExists(label)) return false;
+
+ int thread_id = m_threads.GetSize();
+
+ // Check for existing thread
+ int hash_key = label.AsInt(NUM_NOPS);
+ if (m_thread_lbls.Find(hash_key, thread_id)) {
+ if (m_threads[thread_id].running) return false; // Thread exists, and is running... call fails
+ } else {
+ // Check for thread cap
+ if (thread_id == m_world->GetConfig().MAX_CPU_THREADS.Get()) return false;
+
+ // Add new thread entry
+ m_threads.Resize(thread_id + 1);
+ m_thread_lbls.Add(hash_key, thread_id);
}
- // Otherwise create the memory space and copy in the genome
- int mem_space_used = FindMemorySpaceLabel(in_label, -1);
- assert(mem_space_used != -1);
- m_mem_array[mem_space_used] = inject_code;
+ // Create the memory space and copy in the parasite
+ int mem_space = FindMemorySpaceLabel(label, -1);
+ assert(mem_space != -1);
+ m_mem_array[mem_space] = bu->GetMetaGenome().GetGenome();
- // Create a thread for this parasite
- if (!ThreadCreate(in_label, mem_space_used)) return false; // Partially failed injection, could not create thread
+ // Setup the thread
+ m_threads[thread_id].Reset(this, mem_space);
+ m_threads[thread_id].owner = bu;
return true;
}
@@ -729,6 +747,7 @@
// Setup this thread into the current selected memory space (Flow Head)
m_threads[thread_id].Reset(this, mem_space);
+ m_threads[thread_id].owner = m_threads[m_cur_thread].owner;
return thread_id;
}
Modified: branches/biounit/source/cpu/cHardwareTransSMT.h
===================================================================
--- branches/biounit/source/cpu/cHardwareTransSMT.h 2009-12-18 17:03:43 UTC (rev 3565)
+++ branches/biounit/source/cpu/cHardwareTransSMT.h 2009-12-18 20:52:40 UTC (rev 3566)
@@ -261,7 +261,7 @@
// -------- Parasite Stuff --------
- bool InjectHost(const cCodeLabel& in_label, const cGenome& inject_code);
+ bool ParasiteInfectHost(cBioUnit* bu);
private:
Modified: branches/biounit/source/cpu/cTestCPUInterface.cc
===================================================================
--- branches/biounit/source/cpu/cTestCPUInterface.cc 2009-12-18 17:03:43 UTC (rev 3565)
+++ branches/biounit/source/cpu/cTestCPUInterface.cc 2009-12-18 20:52:40 UTC (rev 3566)
@@ -128,7 +128,7 @@
return m_testcpu->GetReceiveValue();
}
-bool cTestCPUInterface::InjectParasite(cOrganism* host, cBioUnit* parent, const cCodeLabel& label, const cGenome& injected_code)
+bool cTestCPUInterface::InjectParasite(cOrganism* host, cBioUnit* parent, const cString& label, const cGenome& injected_code)
{
return false;
}
Modified: branches/biounit/source/cpu/cTestCPUInterface.h
===================================================================
--- branches/biounit/source/cpu/cTestCPUInterface.h 2009-12-18 17:03:43 UTC (rev 3565)
+++ branches/biounit/source/cpu/cTestCPUInterface.h 2009-12-18 20:52:40 UTC (rev 3566)
@@ -89,7 +89,7 @@
int ReceiveValue();
void SellValue(const int data, const int label, const int sell_price, const int org_id);
int BuyValue(const int label, const int buy_price);
- bool InjectParasite(cOrganism* host, cBioUnit* parent, const cCodeLabel& label, const cGenome& injected_code);
+ bool InjectParasite(cOrganism* host, cBioUnit* parent, const cString& label, const cGenome& injected_code);
bool UpdateMerit(double new_merit);
bool TestOnDivide() { return false; }
int GetFacing() { return 0; }
Modified: branches/biounit/source/main/cOrgInterface.h
===================================================================
--- branches/biounit/source/main/cOrgInterface.h 2009-12-18 17:03:43 UTC (rev 3565)
+++ branches/biounit/source/main/cOrgInterface.h 2009-12-18 20:52:40 UTC (rev 3566)
@@ -36,13 +36,13 @@
class cAvidaContext;
class cBioUnit;
-class cCodeLabel;
class cDeme;
class cGenome;
class cMetaGenome;
class cOrganism;
class cOrgMessage;
class cOrgSinkMessage;
+class cString;
template <class T> class tArray;
@@ -101,7 +101,7 @@
virtual int ReceiveValue() = 0;
virtual void SellValue(const int data, const int label, const int sell_price, const int org_id) = 0;
virtual int BuyValue(const int label, const int buy_price) = 0;
- virtual bool InjectParasite(cOrganism* host, cBioUnit* parent, const cCodeLabel& label, const cGenome& injected_code) = 0;
+ virtual bool InjectParasite(cOrganism* host, cBioUnit* parent, const cString& label, const cGenome& injected_code) = 0;
virtual bool UpdateMerit(double new_merit) = 0;
virtual bool TestOnDivide() = 0;
virtual bool SendMessage(cOrgMessage& msg) = 0;
Modified: branches/biounit/source/main/cOrganism.cc
===================================================================
--- branches/biounit/source/main/cOrganism.cc 2009-12-18 17:03:43 UTC (rev 3565)
+++ branches/biounit/source/main/cOrganism.cc 2009-12-18 20:52:40 UTC (rev 3566)
@@ -216,6 +216,7 @@
if(m_net) delete m_net;
if(m_msg) delete m_msg;
if(m_opinion) delete m_opinion;
+ for (int i = 0; i < m_parasites.GetSize(); i++) delete m_parasites[i];
}
cOrganism::cNetSupport::~cNetSupport()
@@ -650,32 +651,23 @@
}
-bool cOrganism::InjectParasite(cBioUnit* parent, const cCodeLabel& label, const cGenome& injected_code)
+bool cOrganism::InjectParasite(cBioUnit* parent, const cString& label, const cGenome& injected_code)
{
assert(m_interface);
return m_interface->InjectParasite(this, parent, label, injected_code);
}
-bool cOrganism::InjectHost(cBioUnit* parent, eBioUnitSource src, const cCodeLabel& label, const cGenome& injected_code)
+bool cOrganism::ParasiteInfectHost(cBioUnit* parasite)
{
- cInjectGenotype* child_genotype = parent_genotype;
+ if (!m_hardware->ParasiteInfectHost(parasite)) return false;
- // 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);
- }
-
- target_organism->AddParasite(child_genotype);
- child_genotype->AddParasite();
- child_cpu.ThreadSetOwner(child_genotype);
-
-
- return m_hardware->InjectHost(label, injected_code);
+ m_parasites.Push(parasite);
+ return true;
}
void cOrganism::ClearParasites()
{
- for (int i = 0; i < m_parasites.GetSize(); i++) m_parasites[i]->RemoveParasite();
+ for (int i = 0; i < m_parasites.GetSize(); i++) delete m_parasites[i];
m_parasites.Resize(0);
}
Modified: branches/biounit/source/main/cOrganism.h
===================================================================
--- branches/biounit/source/main/cOrganism.h 2009-12-18 17:03:43 UTC (rev 3565)
+++ branches/biounit/source/main/cOrganism.h 2009-12-18 20:52:40 UTC (rev 3566)
@@ -80,7 +80,6 @@
class cAvidaContext;
class cBioGroup;
-class cCodeLabel;
class cEnvironment;
class cGenotype;
class cHardwareBase;
@@ -329,9 +328,8 @@
// -------- Parasite Interactions --------
- bool InjectParasite(cBioUnit* parent, const cCodeLabel& label, const cGenome& genome);
- bool InjectHost(cBioUnit* parent, eBioUnitSource src, const cCodeLabel& in_label, const cGenome& genome);
- void AddParasite(cBioUnit* cur) { m_parasites.Push(cur); }
+ bool InjectParasite(cBioUnit* parent, const cString& label, const cGenome& genome);
+ bool ParasiteInfectHost(cBioUnit* parasite);
int GetNumParasites() const { return m_parasites.GetSize(); }
void ClearParasites();
Modified: branches/biounit/source/main/cPopulation.cc
===================================================================
--- branches/biounit/source/main/cPopulation.cc 2009-12-18 17:03:43 UTC (rev 3565)
+++ branches/biounit/source/main/cPopulation.cc 2009-12-18 20:52:40 UTC (rev 3566)
@@ -46,6 +46,7 @@
#include "cIntegratedSchedule.h"
#include "cLineage.h"
#include "cOrganism.h"
+#include "cParasite.h"
#include "cPhenotype.h"
#include "cPopulationCell.h"
#include "cProbSchedule.h"
@@ -523,7 +524,7 @@
return parent_alive;
}
-bool cPopulation::ActivateParasite(cOrganism* host, cBioUnit* parent, const cCodeLabel& label, const cGenome& injected_code)
+bool cPopulation::ActivateParasite(cOrganism* host, cBioUnit* parent, const cString& label, const cGenome& injected_code)
{
assert(parent != NULL);
@@ -608,10 +609,21 @@
// Attempt actual parasite injection
- if (!target_organism->InjectHost(parent, SRC_PARASITE_INJECT, label, injected_code)) return false;
+
+ cMetaGenome mg(parent->GetMetaGenome().GetHardwareType(), parent->GetMetaGenome().GetInstSetID(), injected_code);
+ cParasite* parasite = new cParasite(mg, parent->GetPhenotype().GetGeneration(), SRC_PARASITE_INJECT, label);
+
+ if (!target_organism->ParasiteInfectHost(parasite)) {
+ delete parasite;
+ return false;
+ }
+ // Classify the parasite
+ tArray<const tArray<cBioGroup*>*> pgrps(1);
+ pgrps[0] = &parent->GetBioGroups();
+ parasite->SelfClassify(pgrps);
- // Handle post injection actions
+ // Handle post injection actions
if (m_world->GetConfig().INJECT_STERILIZES_HOST.Get()) target_organism->GetPhenotype().Sterilize();
return true;
@@ -883,7 +895,6 @@
deme_array[in_cell.GetDemeID()].OrganismDeath(in_cell);
}
genotype->RemoveOrganism();
- organism->ClearParasites();
// If HGT is turned on, this organism's genome needs to be split up into fragments
// and deposited in its cell. We then also have to add the size of this genome to
@@ -5078,15 +5089,19 @@
}
}
-void cPopulation::InjectParasite(const cCodeLabel& label, const cGenome& injected_code, int cell_id)
+void cPopulation::InjectParasite(const cString& label, const cGenome& injected_code, int cell_id)
{
cOrganism* target_organism = cell_array[cell_id].GetOrganism();
-
if (target_organism == NULL) return;
- if (target_organism->GetHardware().GetNumThreads() == m_world->GetConfig().MAX_CPU_THREADS.Get()) return;
+ cMetaGenome mg(target_organism->GetHardware().GetType(), target_organism->GetHardware().GetInstSetID(), injected_code);
+ cParasite* parasite = new cParasite(mg, 0, SRC_PARASITE_FILE_LOAD, label);
- target_organism->InjectHost(NULL, SRC_PARASITE_FILE_LOAD, label, injected_code);
+ if (target_organism->ParasiteInfectHost(parasite)) {
+ m_world->GetClassificationManager().ClassifyNewBioUnit(parasite);
+ } else {
+ delete parasite;
+ }
}
Modified: branches/biounit/source/main/cPopulation.h
===================================================================
--- branches/biounit/source/main/cPopulation.h 2009-12-18 17:03:43 UTC (rev 3565)
+++ branches/biounit/source/main/cPopulation.h 2009-12-18 20:52:40 UTC (rev 3566)
@@ -138,11 +138,11 @@
// Activate the offspring of an organism in the population
bool ActivateOffspring(cAvidaContext& ctx, const cMetaGenome& offspring_genome, cOrganism* parent_organism);
- bool ActivateParasite(cOrganism* host, cBioUnit* parent, const cCodeLabel& label, const cGenome& injected_code);
+ bool ActivateParasite(cOrganism* host, cBioUnit* parent, const cString& label, const cGenome& injected_code);
// Inject an organism from the outside world.
void Inject(const cGenome& genome, eBioUnitSource src, int cell_id = -1, double merit = -1, int lineage_label = 0, double neutral_metric = 0);
- void InjectParasite(const cCodeLabel& label, const cGenome& injected_code, int cell_id);
+ void InjectParasite(const cString& label, const cGenome& injected_code, int cell_id);
// Deactivate an organism in the population (required for deactivations)
void KillOrganism(cPopulationCell& in_cell);
Modified: branches/biounit/source/main/cPopulationInterface.cc
===================================================================
--- branches/biounit/source/main/cPopulationInterface.cc 2009-12-18 17:03:43 UTC (rev 3565)
+++ branches/biounit/source/main/cPopulationInterface.cc 2009-12-18 20:52:40 UTC (rev 3566)
@@ -266,7 +266,7 @@
return value;
}
-bool cPopulationInterface::InjectParasite(cOrganism* host, cBioUnit* parent, const cCodeLabel& label, const cGenome& injected_code)
+bool cPopulationInterface::InjectParasite(cOrganism* host, cBioUnit* parent, const cString& label, const cGenome& injected_code)
{
assert(parent != NULL);
assert(m_world->GetPopulation().GetCell(m_cell_id).GetOrganism() == host);
Modified: branches/biounit/source/main/cPopulationInterface.h
===================================================================
--- branches/biounit/source/main/cPopulationInterface.h 2009-12-18 17:03:43 UTC (rev 3565)
+++ branches/biounit/source/main/cPopulationInterface.h 2009-12-18 20:52:40 UTC (rev 3566)
@@ -110,7 +110,7 @@
int ReceiveValue();
void SellValue(const int data, const int label, const int sell_price, const int org_id);
int BuyValue(const int label, const int buy_price);
- bool InjectParasite(cOrganism* host, cBioUnit* parent, const cCodeLabel& label, const cGenome& injected_code);
+ bool InjectParasite(cOrganism* host, cBioUnit* parent, const cString& label, const cGenome& injected_code);
bool UpdateMerit(double new_merit);
bool TestOnDivide();
//! Send a message to the faced organism.
More information about the Avida-cvs
mailing list