[Avida-SVN] r2271 - development/source/cpu
brysonda at myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Wed Jan 23 19:47:12 PST 2008
Author: brysonda
Date: 2008-01-23 22:47:12 -0500 (Wed, 23 Jan 2008)
New Revision: 2271
Modified:
development/source/cpu/cHardwareExperimental.cc
development/source/cpu/cHardwareExperimental.h
Log:
Add the repro instruction into cHardwareExperimental.
Modified: development/source/cpu/cHardwareExperimental.cc
===================================================================
--- development/source/cpu/cHardwareExperimental.cc 2008-01-24 03:10:50 UTC (rev 2270)
+++ development/source/cpu/cHardwareExperimental.cc 2008-01-24 03:47:12 UTC (rev 2271)
@@ -144,10 +144,13 @@
tInstLibEntry<tMethod>("bit-cons", &cHardwareExperimental::Inst_BitConsensus),
tInstLibEntry<tMethod>("bit-cons-24", &cHardwareExperimental::Inst_BitConsensus24),
tInstLibEntry<tMethod>("execurate", &cHardwareExperimental::Inst_Execurate),
- tInstLibEntry<tMethod>("execurate-24", &cHardwareExperimental::Inst_Execurate24)
- };
+ tInstLibEntry<tMethod>("execurate-24", &cHardwareExperimental::Inst_Execurate24),
+
+ tInstLibEntry<tMethod>("repro", &cHardwareExperimental::Inst_Repro)
+};
+
const int n_size = sizeof(s_n_array)/sizeof(cNOPEntry);
static cString n_names[n_size];
@@ -1641,3 +1644,63 @@
return true;
}
+
+bool cHardwareExperimental::Inst_Repro(cAvidaContext& ctx)
+{
+ // 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;
+
+ // Since the divide will now succeed, set up the information to be sent
+ // to the new organism
+ cGenome & child_genome = organism->ChildGenome();
+ child_genome = m_memory;
+ organism->GetPhenotype().SetLinesCopied(child_genome.GetSize());
+
+ int lines_executed = 0;
+ for (int i = 0; i < m_memory.GetSize(); i++) if (m_memory.FlagExecuted(i)) lines_executed++;
+ organism->GetPhenotype().SetLinesExecuted(lines_executed);
+
+
+ // Perform Copy Mutations...
+ if (organism->GetCopyMutProb() > 0) { // Skip this if no mutations....
+ for (int i = 0; i < GetMemory().GetSize(); i++) {
+ if (organism->TestCopyMut(ctx)) child_genome[i] = m_inst_set->GetRandomInst(ctx);
+ }
+ }
+
+ // Handle Divide Mutations...
+ Divide_DoMutations(ctx);
+
+ // 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.
+ Divide_TestFitnessMeasures(ctx);
+
+#if INSTRUCTION_COSTS
+ // reset first time instruction costs
+ for (int i = 0; i < inst_ft_cost.GetSize(); i++) {
+ inst_ft_cost[i] = m_inst_set->GetFTCost(cInstruction(i));
+ }
+#endif
+
+ m_mal_active = false;
+ if (m_world->GetConfig().DIVIDE_METHOD.Get() == DIVIDE_METHOD_SPLIT) {
+ m_advance_ip = false;
+ }
+
+ // 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();
+ }
+
+ return true;
+}
+
+
Modified: development/source/cpu/cHardwareExperimental.h
===================================================================
--- development/source/cpu/cHardwareExperimental.h 2008-01-24 03:10:50 UTC (rev 2270)
+++ development/source/cpu/cHardwareExperimental.h 2008-01-24 03:47:12 UTC (rev 2271)
@@ -374,6 +374,9 @@
bool Inst_Execurate(cAvidaContext& ctx);
bool Inst_Execurate24(cAvidaContext& ctx);
+
+
+ bool Inst_Repro(cAvidaContext& ctx);
};
More information about the Avida-cvs
mailing list