[Avida-SVN] r3021 - in development/source: cpu main
brysonda at myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Thu Dec 11 18:33:03 PST 2008
Author: brysonda
Date: 2008-12-11 21:33:02 -0500 (Thu, 11 Dec 2008)
New Revision: 3021
Modified:
development/source/cpu/cHardwareBase.cc
development/source/cpu/cHardwareBase.h
development/source/cpu/cHardwareCPU.cc
development/source/cpu/cHardwareCPU.h
development/source/cpu/cHardwareTransSMT.cc
development/source/cpu/cHardwareTransSMT.h
development/source/main/cAvidaConfig.h
development/source/main/cOrganism.h
Log:
Implement all on copy mutation types in cHardwareCPU.
Modified: development/source/cpu/cHardwareBase.cc
===================================================================
--- development/source/cpu/cHardwareBase.cc 2008-12-11 20:02:47 UTC (rev 3020)
+++ development/source/cpu/cHardwareBase.cc 2008-12-12 02:33:02 UTC (rev 3021)
@@ -178,7 +178,7 @@
Return the number of mutations that occur on divide. AWC 06/29/06
Limit the number of mutations that occur to be less than or equal to maxmut (defaults to INT_MAX)
*/
-unsigned cHardwareBase::Divide_DoMutations(cAvidaContext& ctx, double mut_multiplier, const int maxmut)
+int cHardwareBase::Divide_DoMutations(cAvidaContext& ctx, double mut_multiplier, const int maxmut)
{
int totalMutations = 0;
cCPUMemory& offspring_genome = m_organism->ChildGenome();
@@ -338,19 +338,28 @@
return true;
}
+void cHardwareBase::doUniformCopyMutation(cAvidaContext& ctx, cHeadCPU& head)
+{
+ int mut = ctx.GetRandom().GetUInt((m_inst_set->GetSize() * 2) + 1);
+
+ if (mut < m_inst_set->GetSize()) head.SetInst(cInstruction(mut));
+ else if (mut == m_inst_set->GetSize()) head.RemoveInst();
+ else head.InsertInst(cInstruction(mut - m_inst_set->GetSize() - 1));
+}
+
// Slip Mutations
// As if the read head jumped from one random position of the offspring
// to another random position and continued reading to the end.
// This can cause large deletions or tandem duplications.
// Unlucky organisms might exceed the allowed length (randomly) if these mutations occur.
-bool cHardwareBase::doSlipMutation(cAvidaContext& ctx, cCPUMemory& genome)
+void cHardwareBase::doSlipMutation(cAvidaContext& ctx, cCPUMemory& genome, int from)
{
cGenome genome_copy = cGenome(genome);
// All combinations except beginning to past end allowed
- int from = ctx.GetRandom().GetInt(genome_copy.GetSize() + 1);
+ if (from < 0) from = ctx.GetRandom().GetInt(genome_copy.GetSize() + 1);
int to = (from == 0) ? ctx.GetRandom().GetInt(genome_copy.GetSize()) : ctx.GetRandom().GetInt(genome_copy.GetSize() + 1);
// Resize child genome
@@ -409,8 +418,6 @@
cout << "Parent: " << genome_copy.AsString() << endl;
cout << "Offspring: " << genome.AsString() << endl;
}
-
- return true;
}
Modified: development/source/cpu/cHardwareBase.h
===================================================================
--- development/source/cpu/cHardwareBase.h 2008-12-11 20:02:47 UTC (rev 3020)
+++ development/source/cpu/cHardwareBase.h 2008-12-12 02:33:02 UTC (rev 3021)
@@ -100,7 +100,7 @@
virtual bool SingleProcess(cAvidaContext& ctx, bool speculative = false) = 0;
virtual void ProcessBonusInst(cAvidaContext& ctx, const cInstruction& inst) = 0;
- unsigned Divide_DoMutations(cAvidaContext& ctx, double mut_multiplier = 1.0, const int maxmut = INT_MAX);
+ int Divide_DoMutations(cAvidaContext& ctx, double mut_multiplier = 1.0, const int maxmut = INT_MAX);
bool Divide_TestFitnessMeasures(cAvidaContext& ctx);
// -------- Helper methods --------
@@ -205,7 +205,8 @@
// -------- Mutation Helper Methods --------
bool doUniformMutation(cAvidaContext& ctx, cCPUMemory& genome);
- bool doSlipMutation(cAvidaContext& ctx, cCPUMemory& genome);
+ void doUniformCopyMutation(cAvidaContext& ctx, cHeadCPU& head);
+ void doSlipMutation(cAvidaContext& ctx, cCPUMemory& genome, int from = -1);
virtual int GetExecutedSize(const int parent_size);
@@ -227,15 +228,4 @@
};
-#ifdef ENABLE_UNIT_TESTS
-namespace nHardwareBase {
- /**
- * Run unit tests
- *
- * @param full Run full test suite; if false, just the fast tests.
- **/
- void UnitTests(bool full = false);
-}
-#endif
-
#endif
Modified: development/source/cpu/cHardwareCPU.cc
===================================================================
--- development/source/cpu/cHardwareCPU.cc 2008-12-11 20:02:47 UTC (rev 3020)
+++ development/source/cpu/cHardwareCPU.cc 2008-12-12 02:33:02 UTC (rev 3021)
@@ -536,6 +536,8 @@
m_promoters_enabled = m_world->GetConfig().PROMOTERS_ENABLED.Get();
m_constituative_regulation = m_world->GetConfig().CONSTITUTIVE_REGULATION.Get();
+ m_slip_read_head = !m_world->GetConfig().SLIP_COPY_MODE.Get();
+
m_memory = in_organism->GetGenome(); // Initialize memory...
Reset(ctx); // Setup the rest of the hardware...
}
@@ -4988,6 +4990,9 @@
GetRegister(dst) = read_inst;
ReadInst(read_inst);
+ if (m_slip_read_head && m_organism->TestCopySlip(ctx))
+ GetHead(head_id).Set(ctx.GetRandom().GetInt(GetHead(head_id).GetMemory().GetSize()));
+
GetHead(head_id).Advance();
return true;
}
@@ -5006,8 +5011,15 @@
active_head.SetInst(cInstruction(value));
active_head.SetFlagCopied();
+ if (m_organism->TestCopyIns(ctx)) active_head.InsertInst(m_inst_set->GetRandomInst(ctx));
+ if (m_organism->TestCopyDel(ctx)) active_head.RemoveInst();
+ if (m_organism->TestCopyUniform(ctx)) doUniformCopyMutation(ctx, active_head);
+ if (!m_slip_read_head && m_organism->TestCopySlip(ctx))
+ doSlipMutation(ctx, active_head.GetMemory(), active_head.GetPosition());
+
// Advance the head after write...
- active_head++;
+ active_head.Advance();
+
return true;
}
@@ -5023,23 +5035,32 @@
// Do mutations.
cInstruction read_inst = read_head.GetInst();
ReadInst(read_inst.GetOp());
+
if (m_organism->TestCopyMut(ctx)) {
read_inst = m_inst_set->GetRandomInst(ctx);
-// cpu_stats.mut_stats.copy_mut_count++;
write_head.SetFlagMutated();
write_head.SetFlagCopyMut();
}
-
-// cpu_stats.mut_stats.copies_exec++;
+
write_head.SetInst(read_inst);
write_head.SetFlagCopied(); // Set the copied flag...
+ if (m_organism->TestCopyIns(ctx)) write_head.InsertInst(m_inst_set->GetRandomInst(ctx));
+ if (m_organism->TestCopyDel(ctx)) write_head.RemoveInst();
+ if (m_organism->TestCopyUniform(ctx)) doUniformCopyMutation(ctx, write_head);
+ if (m_organism->TestCopySlip(ctx)) {
+ if (m_slip_read_head) {
+ read_head.Set(ctx.GetRandom().GetInt(read_head.GetMemory().GetSize()));
+ } else
+ doSlipMutation(ctx, write_head.GetMemory(), write_head.GetPosition());
+ }
+
read_head.Advance();
write_head.Advance();
//Slip mutations
if (m_organism->TestCopySlip(ctx)) {
- read_head.Set(ctx.GetRandom().GetInt(m_organism->GetGenome().GetSize()));
+
}
return true;
@@ -5066,6 +5087,16 @@
write_head.SetInst(read_inst);
write_head.SetFlagCopied(); // Set the copied flag...
+ if (ctx.GetRandom().P(m_organism->GetCopyInsProb() / reduction)) write_head.InsertInst(m_inst_set->GetRandomInst(ctx));
+ if (ctx.GetRandom().P(m_organism->GetCopyDelProb() / reduction)) write_head.RemoveInst();
+ if (ctx.GetRandom().P(m_organism->GetCopyUniformProb() / reduction)) doUniformCopyMutation(ctx, write_head);
+ if (ctx.GetRandom().P(m_organism->GetCopySlipProb() / reduction)) {
+ if (m_slip_read_head) {
+ read_head.Set(ctx.GetRandom().GetInt(read_head.GetMemory().GetSize()));
+ } else
+ doSlipMutation(ctx, write_head.GetMemory(), write_head.GetPosition());
+ }
+
read_head.Advance();
write_head.Advance();
return true;
Modified: development/source/cpu/cHardwareCPU.h
===================================================================
--- development/source/cpu/cHardwareCPU.h 2008-12-11 20:02:47 UTC (rev 3020)
+++ development/source/cpu/cHardwareCPU.h 2008-12-12 02:33:02 UTC (rev 3021)
@@ -149,6 +149,8 @@
bool m_promoters_enabled:1;
bool m_constituative_regulation:1;
+
+ bool m_slip_read_head:1;
};
// <-- Promoter model
Modified: development/source/cpu/cHardwareTransSMT.cc
===================================================================
--- development/source/cpu/cHardwareTransSMT.cc 2008-12-11 20:02:47 UTC (rev 3020)
+++ development/source/cpu/cHardwareTransSMT.cc 2008-12-12 02:33:02 UTC (rev 3021)
@@ -1154,7 +1154,7 @@
active_head.Adjust();
int value = Stack(src).Pop();
- if (value < 0 || value >= m_inst_set->GetSize()) value = NOPX;
+ if (value < 0 || value >= m_inst_set->GetSize()) value = 0;
active_head.SetInst(cInstruction(value));
active_head.SetFlagCopied();
Modified: development/source/cpu/cHardwareTransSMT.h
===================================================================
--- development/source/cpu/cHardwareTransSMT.h 2008-12-11 20:02:47 UTC (rev 3020)
+++ development/source/cpu/cHardwareTransSMT.h 2008-12-12 02:33:02 UTC (rev 3021)
@@ -69,7 +69,6 @@
static const int NUM_GLOBAL_STACKS = 1;
static const int NUM_STACKS = NUM_LOCAL_STACKS + NUM_GLOBAL_STACKS;
static const int NUM_NOPS = 4;
- static const int NOPX = 4;
static const int MAX_MEMSPACE_LABEL = 3;
static const int MAX_THREAD_LABEL = 3;
Modified: development/source/main/cAvidaConfig.h
===================================================================
--- development/source/main/cAvidaConfig.h 2008-12-11 20:02:47 UTC (rev 3020)
+++ development/source/main/cAvidaConfig.h 2008-12-12 02:33:02 UTC (rev 3021)
@@ -400,6 +400,7 @@
CONFIG_ADD_VAR(INJECT_MUT_PROB, double, 0.0, "Mutation rate (per site, applied on inject)");
CONFIG_ADD_VAR(SLIP_FILL_MODE, int, 0, "Fill insertions from slip mutations with 0=duplication, 1=nop-X, 2=random, 3=scrambled");
+ CONFIG_ADD_VAR(SLIP_COPY_MODE, int, 0, "How to handle 'on-copy' slip mutations:\n0 = actual read head slip\n1 = instant large mutation (obeys slip mode)");
CONFIG_ADD_VAR(PARENT_MUT_PROB, double, 0.0, "Per-site, in parent, on divide");
CONFIG_ADD_VAR(SPECIAL_MUT_LINE, int, -1, "If this is >= 0, ONLY this line is mutated");
CONFIG_ADD_VAR(META_COPY_MUT, double, 0.0, "Prob. of copy mutation rate changing (per gen)");
Modified: development/source/main/cOrganism.h
===================================================================
--- development/source/main/cOrganism.h 2008-12-11 20:02:47 UTC (rev 3020)
+++ development/source/main/cOrganism.h 2008-12-12 02:33:02 UTC (rev 3021)
@@ -337,6 +337,11 @@
bool TestParentMut(cAvidaContext& ctx) const { return m_mut_rates.TestParentMut(ctx); }
double GetCopyMutProb() const { return m_mut_rates.GetCopyMutProb(); }
+ double GetCopyInsProb() const { return m_mut_rates.GetCopyInsProb(); }
+ double GetCopyDelProb() const { return m_mut_rates.GetCopyDelProb(); }
+ double GetCopyUniformProb() const { return m_mut_rates.GetCopyUniformProb(); }
+ double GetCopySlipProb() const { return m_mut_rates.GetCopySlipProb(); }
+
void SetCopyMutProb(double _p) { return m_mut_rates.SetCopyMutProb(_p); }
void SetDivMutProb(double _p) { return m_mut_rates.SetDivMutProb(_p); }
More information about the Avida-cvs
mailing list