[Avida-SVN] r2275 - in development/source: cpu main
barrick at myxo.css.msu.edu
barrick at myxo.css.msu.edu
Thu Jan 24 11:51:49 PST 2008
Author: barrick
Date: 2008-01-24 14:51:49 -0500 (Thu, 24 Jan 2008)
New Revision: 2275
Modified:
development/source/cpu/cHardwareBase.h
development/source/cpu/cHardwareCPU.cc
development/source/cpu/cHardwareExperimental.cc
development/source/main/cPopulation.cc
development/source/main/cPopulation.h
Log:
Fixed InjectChild to not create zombie genotypes.
Fixed error that had promoters only checking first 7 of 8 possible execution windows.
Modified: development/source/cpu/cHardwareBase.h
===================================================================
--- development/source/cpu/cHardwareBase.h 2008-01-24 19:47:31 UTC (rev 2274)
+++ development/source/cpu/cHardwareBase.h 2008-01-24 19:51:49 UTC (rev 2275)
@@ -74,9 +74,10 @@
bool Divide_CheckViable(cAvidaContext& ctx, const int parent_size, const int child_size);
public: //@JEB
unsigned Divide_DoMutations(cAvidaContext& ctx, double mut_multiplier = 1.0, const int maxmut = INT_MAX);
+ bool Divide_TestFitnessMeasures(cAvidaContext& ctx);
+
protected:
unsigned Divide_DoExactMutations(cAvidaContext& ctx, double mut_multiplier = 1.0, const int pointmut = INT_MAX);
- bool Divide_TestFitnessMeasures(cAvidaContext& ctx);
void TriggerMutations_Body(cAvidaContext& ctx, int type, cCPUMemory& target_memory, cHeadCPU& cur_head);
bool TriggerMutations_ScopeGenome(cAvidaContext& ctx, const cMutation* cur_mut,
Modified: development/source/cpu/cHardwareCPU.cc
===================================================================
--- development/source/cpu/cHardwareCPU.cc 2008-01-24 19:47:31 UTC (rev 2274)
+++ development/source/cpu/cHardwareCPU.cc 2008-01-24 19:51:49 UTC (rev 2275)
@@ -4368,9 +4368,6 @@
m_promoter_index = -1;
IP().Set(0);
GetRegister(reg_used) = 0;
-
- // @JEB HACK! -- All kinds of bad stuff happens if execution length is zero. For now:
- if (m_world->GetConfig().NO_ACTIVE_PROMOTER_EFFECT.Get() == 2) GetMemory().SetFlagExecuted(0);
}
// Death to organisms that refuse to use promoters!
else if (m_world->GetConfig().NO_ACTIVE_PROMOTER_EFFECT.Get() == 1)
@@ -4484,7 +4481,7 @@
// Move offset, rolling over when there are not enough bits before we would have to wrap around left
m_promoter_offset+=m_world->GetConfig().PROMOTER_EXE_LENGTH.Get();
- if (m_promoter_offset + m_world->GetConfig().PROMOTER_EXE_LENGTH.Get() >= m_world->GetConfig().PROMOTER_CODE_SIZE.Get())
+ if (m_promoter_offset + m_world->GetConfig().PROMOTER_EXE_LENGTH.Get() > m_world->GetConfig().PROMOTER_CODE_SIZE.Get())
{
m_promoter_offset = 0;
}
Modified: development/source/cpu/cHardwareExperimental.cc
===================================================================
--- development/source/cpu/cHardwareExperimental.cc 2008-01-24 19:47:31 UTC (rev 2274)
+++ development/source/cpu/cHardwareExperimental.cc 2008-01-24 19:51:49 UTC (rev 2275)
@@ -1526,7 +1526,7 @@
// Move offset, rolling over when there are not enough bits before we would have to wrap around left
const int promoter_exe_length = m_world->GetConfig().PROMOTER_EXE_LENGTH.Get();
m_promoter_offset += promoter_exe_length;
- if (m_promoter_offset + promoter_exe_length >= m_world->GetConfig().PROMOTER_CODE_SIZE.Get()) m_promoter_offset = 0;
+ if (m_promoter_offset + promoter_exe_length > m_world->GetConfig().PROMOTER_CODE_SIZE.Get()) m_promoter_offset = 0;
}
}
Modified: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc 2008-01-24 19:47:31 UTC (rev 2274)
+++ development/source/main/cPopulation.cc 2008-01-24 19:51:49 UTC (rev 2275)
@@ -421,9 +421,7 @@
{
assert(in_organism != NULL);
assert(in_organism->GetGenome().GetSize() >= 1);
-// assert(in_organism->GetGenome().GetSize() >= 1);
-
in_organism->SetOrgInterface(new cPopulationInterface(m_world));
// If the organism does not have a genotype, give it one! No parent
@@ -2989,39 +2987,28 @@
// This function injects the child genome of an organism into the population at cell_id.
// Takes care of divide mutations.
-void cPopulation::InjectChild(int cell_id, cOrganism& orig_org)
+void cPopulation::InjectChild(int cell_id, cOrganism& parent)
{
assert(cell_id >= 0 && cell_id < cell_array.GetSize());
cAvidaContext& ctx = m_world->GetDefaultContext();
-
+
// Do mutations on the child genome, but restore it to its current state afterward.
- cGenome save_child = orig_org.ChildGenome();
- orig_org.GetHardware().Divide_DoMutations(ctx);
-
- tArray<cOrganism*> child_array;
- tArray<cMerit> merit_array;
- birth_chamber.SubmitOffspring(ctx, orig_org.ChildGenome(), orig_org, child_array, merit_array);
- //@JEB for now we force asex for an injected child, sex will probably mess up CompeteOrganisms...
- assert(child_array.GetSize() == 1);
- cOrganism * new_organism = child_array[0];
- orig_org.ChildGenome() = save_child;
-
- // Set the genotype...
- //new_organism->SetGenotype(orig_org.GetGenotype());
+ cGenome save_child = parent.ChildGenome();
+ parent.GetHardware().Divide_DoMutations(ctx);
+ cGenome child_genome = parent.ChildGenome();
+ parent.GetHardware().Divide_TestFitnessMeasures(ctx);
+ parent.ChildGenome() = save_child;
+ cOrganism* new_organism = new cOrganism(m_world, ctx, child_genome);
+ // Set the genotype...
+ assert(parent.GetGenotype());
+ cGenotype* new_genotype = m_world->GetClassificationManager().GetGenotypeInjected(child_genome, parent.GetGenotype()->GetLineageLabel());
+ new_organism->SetGenotype(new_genotype);
+
// Setup the phenotype...
- orig_org.GetPhenotype().SetLinesCopied(new_organism->ChildGenome().GetSize());
- new_organism->GetPhenotype().SetMerit(merit_array[0]);
- new_organism->GetPhenotype().SetupOffspring(orig_org.GetPhenotype(), new_organism->GetGenome());
+ new_organism->GetPhenotype().SetupOffspring(parent.GetPhenotype(),child_genome);
- // Do lineage tracking for the new organisms.
- LineageSetupOrganism(new_organism, orig_org.GetLineage(),
- orig_org.GetLineageLabel(), orig_org.GetGenotype());
-
- //By default, store the parent cclade, this may get modified in ActivateOrgansim (@MRR)
- new_organism->SetCCladeLabel(orig_org.GetCCladeLabel());
-
// Prep the cell..
if (m_world->GetConfig().BIRTH_METHOD.Get() == POSITION_CHILD_FULL_SOUP_ELDEST &&
cell_array[cell_id].IsOccupied() == true) {
@@ -3036,14 +3023,12 @@
new_organism->MutationRates().Copy(cell_array[cell_id].MutationRates());
} else {
// Update the mutation rates of each child from its parent.
- new_organism->MutationRates().Copy(orig_org.MutationRates());
+ new_organism->MutationRates().Copy(parent.MutationRates());
}
// Activate the organism in the population...
-// cGenotype* child_genotype = new_organism->GetGenotype();
-// child_genotype->DecDeferAdjust();
-// m_world->GetClassificationManager().AdjustGenotype(*child_genotype);
- ActivateOrganism(ctx, new_organism, cell_array[cell_id]);
+ ActivateOrganism(ctx, new_organism, cell_array[cell_id]);
+
}
@@ -3472,7 +3457,8 @@
cout << "Competed: Min fitness = " << lowest_fitness << ", Avg fitness = " << average_fitness << " Max fitness = " << highest_fitness << endl;
cout << "Copied : Min fitness = " << lowest_fitness_copied << ", Avg fitness = " << average_fitness_copied << ", Max fitness = " << highest_fitness_copied << endl;
cout << "Copied : Different organisms = " << different_orgs_copied << endl;
-
+ if (m_world->GetVerbosity() >= VERBOSE_DETAILS) cout << "Genotype Count: " << m_world->GetClassificationManager().GetGenotypeCount() << endl;
+
// copy stats to cStats, so that these can be remembered and printed
m_world->GetStats().SetCompetitionTrialFitnesses(avg_trial_fitnesses);
m_world->GetStats().SetCompetitionFitness(average_fitness);
Modified: development/source/main/cPopulation.h
===================================================================
--- development/source/main/cPopulation.h 2008-01-24 19:47:31 UTC (rev 2274)
+++ development/source/main/cPopulation.h 2008-01-24 19:51:49 UTC (rev 2275)
@@ -135,7 +135,7 @@
void InjectGenotype(int cell_id, cGenotype* genotype);
void InjectGenome(int cell_id, const cGenome& genome, int lineage_label);
void InjectClone(int cell_id, cOrganism& orig_org);
- void InjectChild(int cell_id, cOrganism& orig_org);
+ void InjectChild(int cell_id, cOrganism& parent);
void LineageSetupOrganism(cOrganism* organism, cLineage* lineage, int lin_label, cGenotype* parent_genotype = NULL);
void CCladeSetupOrganism(cOrganism* organism);
More information about the Avida-cvs
mailing list