[Avida-SVN] r2441 - in development/source: actions cpu main
covertar at myxo.css.msu.edu
covertar at myxo.css.msu.edu
Sun Mar 9 10:28:06 PDT 2008
Author: covertar
Date: 2008-03-09 13:28:06 -0400 (Sun, 09 Mar 2008)
New Revision: 2441
Modified:
development/source/actions/PopulationActions.cc
development/source/cpu/cHardwareBase.cc
development/source/cpu/cHardwareCPU.cc
development/source/main/cOrganism.cc
development/source/main/cOrganism.h
development/source/main/cPopulation.cc
Log:
Minor clean-ups to resampling code
Added SetMigrationRate action to alter migration rate during
experiments.
Modified: development/source/actions/PopulationActions.cc
===================================================================
--- development/source/actions/PopulationActions.cc 2008-03-08 22:14:02 UTC (rev 2440)
+++ development/source/actions/PopulationActions.cc 2008-03-09 17:28:06 UTC (rev 2441)
@@ -805,7 +805,26 @@
}
};
+class cActionSetMigrationRate : public cAction
+{
+private:
+ double m_rate;
+public:
+ cActionSetMigrationRate(cWorld* world, const cString& args) : cAction(world, args), m_rate(0.0)
+ {
+ cString largs(args);
+ if(largs.GetSize()) m_rate = largs.PopWord().AsDouble();
+ }
+
+ static const cString GetDescription() { return "Arguments: [double rate=0.0]"; }
+
+ void Process(cAvidaContext& ctx)
+ {
+ m_world->GetConfig().MIGRATION_RATE.Set(m_rate);
+ }
+};
+
class cActionSetMutProb : public cAction
{
private:
@@ -1647,6 +1666,7 @@
action_lib->Register<cActionKillRectangle>("KillRectangle");
action_lib->Register<cActionSerialTransfer>("SerialTransfer");
+ action_lib->Register<cActionSetMigrationRate>("SetMigrationRate");
action_lib->Register<cActionSetMutProb>("SetMutProb");
action_lib->Register<cActionModMutProb>("ModMutProb");
action_lib->Register<cActionZeroMuts>("ZeroMuts");
Modified: development/source/cpu/cHardwareBase.cc
===================================================================
--- development/source/cpu/cHardwareBase.cc 2008-03-08 22:14:02 UTC (rev 2440)
+++ development/source/cpu/cHardwareBase.cc 2008-03-09 17:28:06 UTC (rev 2441)
@@ -397,30 +397,14 @@
organism->GetPhenotype().SetDivType(mut_multiplier);
// Divide Mutations
- if (organism->TestDivideMut(ctx) && totalMutations < maxmut) {
+ if (totalMutations < maxmut) {
const unsigned int mut_line = ctx.GetRandom().GetUInt(child_genome.GetSize());
child_genome[mut_line] = m_inst_set->GetRandomInst(ctx);
// ++cpu_stats.mut_stats.divide_mut_count;
totalMutations++;
//cerr << "Mutating HERE!!!! BAD!!!!!" << endl;
}
-
- // Divide Insertions
- if (organism->TestDivideIns(ctx) && child_genome.GetSize() < MAX_CREATURE_SIZE && totalMutations < maxmut) {
- const unsigned int mut_line = ctx.GetRandom().GetUInt(child_genome.GetSize() + 1);
- child_genome.Insert(mut_line, m_inst_set->GetRandomInst(ctx));
-// ++cpu_stats.mut_stats.divide_insert_mut_count;
- totalMutations++;
- }
-
- // Divide Deletions
- if (organism->TestDivideDel(ctx) && child_genome.GetSize() > MIN_CREATURE_SIZE && totalMutations < maxmut) {
- const unsigned int mut_line = ctx.GetRandom().GetUInt(child_genome.GetSize());
- child_genome.Remove(mut_line);
-// ++cpu_stats.mut_stats.divide_delete_mut_count;
- totalMutations++;
- }
-
+
// Divide Mutations (per site)
if (organism->GetDivMutProb() > 0 && totalMutations < maxmut) {
//int num_mut = ctx.GetRandom().GetRandBinomial(child_genome.GetSize(),
@@ -433,85 +417,11 @@
child_genome[site] = m_inst_set->GetRandomInst(ctx);
// ++cpu_stats.mut_stats.div_mut_count;
totalMutations++;
- //cerr << "OK to mutate here " << totalMutations << endl;
+ cerr << "Resampling here " << totalMutations << endl;
}
}
}
-
-
- // Need to come back and fix tese last two - per site instructions
- // Insert Mutations (per site)
- if (organism->GetInsMutProb() > 0 && totalMutations < maxmut) {
- int num_mut = ctx.GetRandom().GetRandBinomial(child_genome.GetSize(),
- organism->GetInsMutProb());
-
- // If would make creature to big, insert up to MAX_CREATURE_SIZE
- if (num_mut + child_genome.GetSize() > MAX_CREATURE_SIZE) {
- num_mut = MAX_CREATURE_SIZE - child_genome.GetSize();
- }
- // If we have lines to insert...
- if (num_mut > 0) {
- // Build a list of the sites where mutations occured
- static int mut_sites[MAX_CREATURE_SIZE];
- for (int i = 0; i < num_mut; i++) {
- mut_sites[i] = ctx.GetRandom().GetUInt(child_genome.GetSize() + 1);
- }
- // Sort the list
- qsort( (void*)mut_sites, num_mut, sizeof(int), &IntCompareFunction );
- // Actually do the mutations (in reverse sort order)
- for (int i = num_mut-1; i >= 0; i--) {
- child_genome.Insert(mut_sites[i], m_inst_set->GetRandomInst(ctx));
-// cpu_stats.mut_stats.insert_mut_count++;
- totalMutations++; //Unlike the others we can't be sure this was done only on divide -- AWC 06/29/06
- }
- }
- }
-
-
- // Delete Mutations (per site)
- if (organism->GetDelMutProb() > 0 && totalMutations < maxmut) {
- int num_mut = ctx.GetRandom().GetRandBinomial(child_genome.GetSize(),
- organism->GetDelMutProb());
- // If would make creature too small, delete down to MIN_CREATURE_SIZE
- if (child_genome.GetSize() - num_mut < MIN_CREATURE_SIZE) {
- num_mut = child_genome.GetSize() - MIN_CREATURE_SIZE;
- }
-
- // If we have lines to delete...
- for (int i = 0; i < num_mut; i++) {
- int site = ctx.GetRandom().GetUInt(child_genome.GetSize());
- child_genome.Remove(site);
-// cpu_stats.mut_stats.delete_mut_count++;
- totalMutations++;
- }
- }
-
- // Mutations in the parent's genome
- if (organism->GetParentMutProb() > 0 && totalMutations < maxmut) {
- for (int i = 0; i < GetMemory().GetSize(); i++) {
- if (organism->TestParentMut(ctx)) {
- GetMemory()[i] = m_inst_set->GetRandomInst(ctx);
-// cpu_stats.mut_stats.parent_mut_line_count++;
- totalMutations++; //Unlike the others we can't be sure this was done only on divide -- AWC 06/29/06
-
- }
- }
- }
-
-
- // Count up mutated lines
-// for (int i = 0; i < GetMemory().GetSize(); i++) {
-// if (GetMemory().FlagPointMut(i)) {
-// cpu_stats.mut_stats.point_mut_line_count++;
-// }
-// }
-// for (int i = 0; i < child_genome.GetSize(); i++) {
-// if (child_genome.FlagCopyMut(i)) {
-// cpu_stats.mut_stats.copy_mut_line_count++;
-// }
-// }
-
return totalMutations;
}
@@ -616,18 +526,17 @@
bool revert = false;
bool sterilize = false;
-
- //if you?r suppose to be dead, you really are going to be dead
- if(!test_info.IsViable()){
+
+ // If implicit mutations are turned off, make sure this won't spawn one.
+ if (organism->GetFailImplicit() > 0) {
+ if (test_info.GetMaxDepth() > 0) sterilize = true;
+ }
+
+ if(organism->GetFailImplicit() > 1 && !test_info.IsViable()){
//if (test_info.GetMaxDepth() > 0) sterilize = true;
sterilize = true;
}
- // If implicit mutations are turned off, make sure this won't spawn one.
- if (organism->GetFailImplicit() == true) {
- if (test_info.GetMaxDepth() > 0) sterilize = true;
- }
-
if (child_fitness == 0.0) {
// Fatal mutation... test for reversion.
if (ctx.GetRandom().P(organism->GetRevertFatal())) revert = true;
Modified: development/source/cpu/cHardwareCPU.cc
===================================================================
--- development/source/cpu/cHardwareCPU.cc 2008-03-08 22:14:02 UTC (rev 2440)
+++ development/source/cpu/cHardwareCPU.cc 2008-03-09 17:28:06 UTC (rev 2441)
@@ -1334,7 +1334,7 @@
// 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);
+ Divide_TestFitnessMeasures1(ctx);
#if INSTRUCTION_COSTS
// reset first time instruction costs
@@ -1411,7 +1411,7 @@
m_world->GetStats().IncResamplings();
}
- fitTest = Divide_TestFitnessMeasures(ctx);
+ fitTest = Divide_TestFitnessMeasures1(ctx);
if(!fitTest && mutations >= totalMutations) break;
Modified: development/source/main/cOrganism.cc
===================================================================
--- development/source/main/cOrganism.cc 2008-03-08 22:14:02 UTC (rev 2440)
+++ development/source/main/cOrganism.cc 2008-03-09 17:28:06 UTC (rev 2441)
@@ -479,7 +479,7 @@
bool cOrganism::GetTestOnDivide() const { return m_interface->TestOnDivide(); }
-bool cOrganism::GetFailImplicit() const { return m_world->GetConfig().FAIL_IMPLICIT.Get(); }
+int cOrganism::GetFailImplicit() const { return m_world->GetConfig().FAIL_IMPLICIT.Get(); }
bool cOrganism::GetRevertFatal() const { return m_world->GetConfig().REVERT_FATAL.Get(); }
bool cOrganism::GetRevertNeg() const { return m_world->GetConfig().REVERT_DETRIMENTAL.Get(); }
Modified: development/source/main/cOrganism.h
===================================================================
--- development/source/main/cOrganism.h 2008-03-08 22:14:02 UTC (rev 2440)
+++ development/source/main/cOrganism.h 2008-03-09 17:28:06 UTC (rev 2441)
@@ -299,7 +299,7 @@
// -------- Configuration Convenience Methods --------
bool GetTestOnDivide() const;
- bool GetFailImplicit() const;
+ int GetFailImplicit() const;
bool GetRevertFatal() const;
bool GetRevertNeg() const;
Modified: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc 2008-03-08 22:14:02 UTC (rev 2440)
+++ development/source/main/cPopulation.cc 2008-03-09 17:28:06 UTC (rev 2441)
@@ -2198,6 +2198,8 @@
//@AWC -- decide wether the child will migrate to another deme -- if migrating we ignore the birth method.
if ((m_world->GetConfig().MIGRATION_RATE.Get() > 0.0) //@AWC -- Pedantic test to maintain consistancy.
&& m_world->GetRandom().P(m_world->GetConfig().MIGRATION_RATE.Get())){
+
+ //cerr << "Attempting to migrate with rate " << m_world->GetConfig().MIGRATION_RATE.Get() << "!" << endl;
int deme_id = parent_cell.GetDemeID();
More information about the Avida-cvs
mailing list