[Avida-SVN] r1403 - in trunk/source: actions analyze cpu main tools
covertar at myxo.css.msu.edu
covertar at myxo.css.msu.edu
Thu Mar 15 13:26:51 PDT 2007
Author: covertar
Date: 2007-03-15 16:26:51 -0400 (Thu, 15 Mar 2007)
New Revision: 1403
Modified:
trunk/source/actions/CMakeLists.txt
trunk/source/actions/LandscapeActions.cc
trunk/source/actions/cActionLibrary.cc
trunk/source/analyze/cAnalyze.cc
trunk/source/analyze/cAnalyze.h
trunk/source/analyze/cAnalyzeGenotype.h
trunk/source/cpu/cHardwareBase.cc
trunk/source/cpu/cHardwareBase.h
trunk/source/cpu/cHardwareCPU.cc
trunk/source/cpu/cHardwareCPU.h
trunk/source/cpu/cHardwareSMT.cc
trunk/source/main/cAvidaConfig.cc
trunk/source/main/cAvidaConfig.h
trunk/source/main/cLandscape.cc
trunk/source/main/cLandscape.h
trunk/source/main/cPopulationCell.cc
trunk/source/tools/tList.h
Log:
Updates to resampling
fixed landscapeings missing genotype id
added lineage actions to make marginal effects matricies
fixes to tList.h
back-ported dave's analyze config options
Modified: trunk/source/actions/CMakeLists.txt
===================================================================
--- trunk/source/actions/CMakeLists.txt 2007-03-15 17:38:10 UTC (rev 1402)
+++ trunk/source/actions/CMakeLists.txt 2007-03-15 20:26:51 UTC (rev 1403)
@@ -8,6 +8,7 @@
PopulationActions.cc
PrintActions.cc
SaveLoadActions.cc
+ LineageActions.cc
)
ADD_LIBRARY(actions ${libactions_a_SOURCES})
Modified: trunk/source/actions/LandscapeActions.cc
===================================================================
--- trunk/source/actions/LandscapeActions.cc 2007-03-15 17:38:10 UTC (rev 1402)
+++ trunk/source/actions/LandscapeActions.cc 2007-03-15 20:26:51 UTC (rev 1403)
@@ -226,7 +226,7 @@
tListIterator<cAnalyzeGenotype> batch_it(m_world->GetAnalyze().GetCurrentBatch().List());
cAnalyzeGenotype* genotype = NULL;
while (genotype = batch_it.Next()) {
- land = new cLandscape(m_world, genotype->GetGenome(), inst_set);
+ land = new cLandscape(m_world, genotype->GetGenome(), inst_set, genotype->GetID());
land->SetDistance(m_dist);
m_batch.PushRear(land);
jobqueue.AddJob(new tAnalyzeJob<cLandscape>(land, &cLandscape::Process));
@@ -237,7 +237,7 @@
m_world->GetDriver().NotifyComment("Full Landscaping...");
land = new cLandscape(m_world, m_world->GetClassificationManager().GetBestGenotype()->GetGenome(),
- m_world->GetHardwareManager().GetInstSet());
+ m_world->GetHardwareManager().GetInstSet(), m_world->GetClassificationManager().GetBestGenotype()->GetID());
m_batch.PushRear(land);
land->SetDistance(m_dist);
land->Process(ctx);
@@ -829,7 +829,7 @@
tListIterator<cAnalyzeGenotype> batch_it(m_world->GetAnalyze().GetCurrentBatch().List());
cAnalyzeGenotype* genotype = NULL;
while (genotype = batch_it.Next()) {
- cLandscape* land = new cLandscape(m_world, genotype->GetGenome(), inst_set);
+ cLandscape* land = new cLandscape(m_world, genotype->GetGenome(), inst_set, genotype->GetID());
if (m_sample_size) {
land->SetTrials(m_sample_size);
jobqueue.AddJob(new tAnalyzeJob<cLandscape>(land, &cLandscape::TestPairs));
Modified: trunk/source/actions/cActionLibrary.cc
===================================================================
--- trunk/source/actions/cActionLibrary.cc 2007-03-15 17:38:10 UTC (rev 1402)
+++ trunk/source/actions/cActionLibrary.cc 2007-03-15 20:26:51 UTC (rev 1403)
@@ -15,6 +15,7 @@
#include "PopulationActions.h"
#include "PrintActions.h"
#include "SaveLoadActions.h"
+#include "LineageActions.h"
cActionLibrary* cActionLibrary::ConstructDefaultActionLibrary()
@@ -27,6 +28,7 @@
RegisterPopulationActions(actlib);
RegisterPrintActions(actlib);
RegisterSaveLoadActions(actlib);
+ RegisterLineageActions(actlib);
return actlib;
}
Modified: trunk/source/analyze/cAnalyze.cc
===================================================================
--- trunk/source/analyze/cAnalyze.cc 2007-03-15 17:38:10 UTC (rev 1402)
+++ trunk/source/analyze/cAnalyze.cc 2007-03-15 20:26:51 UTC (rev 1403)
@@ -6821,6 +6821,50 @@
}
}
+void cAnalyze::ConfigGet(cString cur_string)
+{
+ cString cvar = cur_string.PopWord();
+ cString var = cur_string.PopWord();
+
+ cerr << cvar << " | " << var << " | " << cur_string << endl;
+
+ if (cvar.GetSize() == 0 || var.GetSize() == 0) {
+ cerr << "Error: Missing variable in CONFIG_GET command" << endl;
+ return;
+ }
+
+ cString& cur_variable = GetVariable(var);
+
+ // Get Config Variable
+ if (!m_world->GetConfig().Get(cvar, cur_variable)) {
+ cerr << "Error: Configuration Variable '" << var << "' was not found." << endl;
+ return;
+ }
+
+ if (m_world->GetVerbosity() >= VERBOSE_ON)
+ cout << "Setting variable " << var << " to " << cur_variable << endl;
+}
+
+void cAnalyze::ConfigSet(cString cur_string)
+{
+ cString cvar = cur_string.PopWord();
+
+ if (cvar.GetSize() == 0) {
+ cerr << "Error: No variable provided in CONFIG_SET command" << endl;
+ return;
+ }
+
+ // Get Config Variable
+ cString val = cur_string.PopWord();
+ if (!m_world->GetConfig().Set(cvar, val)) {
+ cerr << "Error: Configuration Variable '" << cvar << "' was not found." << endl;
+ return;
+ }
+
+ if (m_world->GetVerbosity() >= VERBOSE_ON)
+ cout << "Setting configuration variable " << cvar << " to " << val << endl;
+}
+
void cAnalyze::BatchSet(cString cur_string)
{
int next_batch = 0;
@@ -7747,6 +7791,8 @@
// Control commands...
AddLibraryDef("SET", &cAnalyze::VarSet);
+ AddLibraryDef("CONFIG_GET", &cAnalyze::ConfigGet);
+ AddLibraryDef("CONFIG_SET", &cAnalyze::ConfigSet);
AddLibraryDef("SET_BATCH", &cAnalyze::BatchSet);
AddLibraryDef("NAME_BATCH", &cAnalyze::BatchName);
AddLibraryDef("TAG_BATCH", &cAnalyze::BatchTag);
Modified: trunk/source/analyze/cAnalyze.h
===================================================================
--- trunk/source/analyze/cAnalyze.h 2007-03-15 17:38:10 UTC (rev 1402)
+++ trunk/source/analyze/cAnalyze.h 2007-03-15 20:26:51 UTC (rev 1403)
@@ -208,6 +208,8 @@
// Control...
void VarSet(cString cur_string);
+ void ConfigGet(cString cur_string);
+ void ConfigSet(cString cur_string);
void BatchSet(cString cur_string);
void BatchName(cString cur_string);
void BatchTag(cString cur_string);
Modified: trunk/source/analyze/cAnalyzeGenotype.h
===================================================================
--- trunk/source/analyze/cAnalyzeGenotype.h 2007-03-15 17:38:10 UTC (rev 1402)
+++ trunk/source/analyze/cAnalyzeGenotype.h 2007-03-15 20:26:51 UTC (rev 1403)
@@ -151,6 +151,7 @@
cAnalyzeGenotype(const cAnalyzeGenotype & _gen);
~cAnalyzeGenotype();
+ cInstSet& GetInstSet() {return inst_set;}
const cStringList & GetSpecialArgs() { return special_args; }
void SetSpecialArgs(const cStringList & _args) { special_args = _args; }
@@ -315,6 +316,10 @@
equality of two references means that they refer to the same object.
*/
bool operator==(const cAnalyzeGenotype &in) const { return &in == this; }
+
+
+ //added for compatability with tArray - needed for some of AC's actions
+ cAnalyzeGenotype& operator=(const cAnalyzeGenotype &in) { cAnalyzeGenotype *temp = new cAnalyzeGenotype(in); return *temp;}
};
#ifdef ENABLE_UNIT_TESTS
Modified: trunk/source/cpu/cHardwareBase.cc
===================================================================
--- trunk/source/cpu/cHardwareBase.cc 2007-03-15 17:38:10 UTC (rev 1402)
+++ trunk/source/cpu/cHardwareBase.cc 2007-03-15 20:26:51 UTC (rev 1403)
@@ -8,6 +8,8 @@
*
*/
+//class cGenotype;
+
#include "cHardwareBase.h"
#include "cAvidaContext.h"
@@ -26,10 +28,10 @@
#include "cWorld.h"
#include "cWorldDriver.h"
#include "nHardware.h"
+#include "cGenotype.h"
#include "functions.h"
-
int cHardwareBase::GetExecutedSize(const int parent_size)
{
int executed_size = 0;
@@ -55,8 +57,7 @@
organism->Fault(FAULT_LOC_DIVIDE, FAULT_TYPE_ERROR,
cStringUtil::Stringf("Invalid offspring length (%d)", child_size));
return false; // (divide fails)
- }
- if (parent_size < min_size || parent_size > max_size) {
+ } if (parent_size < min_size || parent_size > max_size) {
organism->Fault(FAULT_LOC_DIVIDE, FAULT_TYPE_ERROR,
cStringUtil::Stringf("Invalid post-divide length (%d)",parent_size));
return false; // (divide fails)
@@ -243,6 +244,59 @@
return totalMutations;
}
+unsigned cHardwareBase::Divide_Do2SiteMutations(cAvidaContext& ctx, double mut_multiplier, const int maxmut)
+{
+ int totalMutations = 0;
+ //cerr << "Maxmut: " << maxmut << endl;
+ sCPUStats& cpu_stats = organism->CPUStats();
+ cCPUMemory& child_genome = organism->ChildGenome();
+
+ organism->GetPhenotype().SetDivType(mut_multiplier);
+
+ // Divide Mutations (per site)
+ if (organism->GetDivMutProb() > 0 && totalMutations < maxmut) {
+ int num_mut = ctx.GetRandom().GetRandBinomial(2,
+ organism->GetDivMutProb() / mut_multiplier);
+ // If we have lines to mutate...
+ if (num_mut > 0 && totalMutations < maxmut) {
+ if(num_mut == 1){
+ int site = ctx.GetRandom().GetUInt(2);
+ if(site == 0)
+ child_genome[23] = m_inst_set->GetRandomInst(ctx);
+ else
+ child_genome[27] = m_inst_set->GetRandomInst(ctx);
+
+ totalMutations++;
+ ++cpu_stats.mut_stats.div_mut_count;
+ }
+ else if(num_mut == 2){
+ child_genome[23] = m_inst_set->GetRandomInst(ctx);
+ child_genome[27] = m_inst_set->GetRandomInst(ctx);
+
+ totalMutations += 2;
+ cpu_stats.mut_stats.div_mut_count += 2;
+
+ }
+
+
+
+ }
+ }
+ // 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;
+}
+
/*
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 equat to maxmut (defaults to INT_MAX)
@@ -411,8 +465,21 @@
bool revert = false;
bool sterilize = false;
+ //if you're suppose to be dead, you really are going to be dead
+ if(!test_info.IsViable()){
+ if (test_info.GetMaxDepth() > 0) sterilize = true;
+ }
+
+ if(organism->GetGenotype()->GetID() == 866367){
+ cerr << "----------------------------------------------------------------" << endl;
+ cerr << "Fail implicit: " << organism->GetFailImplicit() << endl;
+ cerr << "Max Depth: " << test_info.GetMaxDepth() << endl;
+ cerr << "Viable: " << test_info.IsViable() << endl;
+ cerr << "Steralize1: " << sterilize;
+ }
+
// If implicit mutations are turned off, make sure this won't spawn one.
- if (organism->GetFailImplicit() == true) {
+ if (organism->GetFailImplicit() == true ) {
if (test_info.GetMaxDepth() > 0) sterilize = true;
}
@@ -439,11 +506,108 @@
if (sterilize == true) {
organism->GetPhenotype().ChildFertile() = false;
+ if(organism->GetGenotype()->GetID() == 866367){
+ cerr << "Steralized!" << endl;
+ }
+
}
return (!sterilize) && revert;
}
+// test whether the offspring creature contains an advantageous mutation.
+/*
+ Return true iff only a reversion is performed -- returns false is steralized regardless of weather or
+ not a reversion is performed. AWC 06/29/06
+*/
+bool cHardwareBase::Divide_TestFitnessMeasures1(cAvidaContext& ctx, double& fit_ratio)
+{
+ cPhenotype & phenotype = organism->GetPhenotype();
+ phenotype.CopyTrue() = ( organism->ChildGenome() == organism->GetGenome() );
+ phenotype.ChildFertile() = true;
+
+ // Only continue if we're supposed to do a fitness test on divide...
+ if (organism->GetTestOnDivide() == false) return false;
+
+ // If this was a perfect copy, then we don't need to worry about any other
+ // tests... Theoretically, we need to worry about the parent changing,
+ // but as long as the child is always compared to the original genotype,
+ // this won't be an issue.
+ if (phenotype.CopyTrue() == true) return false;
+
+ const double parent_fitness = organism->GetTestFitness(ctx);
+ const double neut_min = parent_fitness * (1.0 - organism->GetNeutralMin());//nHardware::FITNESS_NEUTRAL_MIN;
+ const double neut_max = parent_fitness * (1.0 + organism->GetNeutralMax());//nHardware::FITNESS_NEUTRAL_MAX;
+
+ cTestCPU* testcpu = m_world->GetHardwareManager().CreateTestCPU();
+ cCPUTestInfo test_info;
+ test_info.UseRandomInputs();
+ testcpu->TestGenome(ctx, test_info, organism->ChildGenome());
+ const double child_fitness = test_info.GetGenotypeFitness();
+ delete testcpu;
+
+ bool revert = false;
+ bool sterilize = false;
+
+ //if you're suppose to be dead, you really are going to be dead
+ if(!test_info.IsViable()){
+ //if (test_info.GetMaxDepth() > 0) sterilize = true;
+ sterilize = true;
+ }
+
+// if(organism->GetGenotype()->GetID() == 866367){
+// cerr << "----------------------------------------------------------------" << endl;
+// cerr << "Fail implicit: " << organism->GetFailImplicit() << endl;
+// cerr << "Max Depth: " << test_info.GetMaxDepth() << endl;
+// cerr << "Viable: " << test_info.IsViable() << endl;
+// cerr << "Steralize1: " << sterilize;
+// }
+
+ // If implicit mutations are turned off, make sure this won't spawn one.
+ if (organism->GetFailImplicit() == true ) {
+ if (test_info.GetMaxDepth() > 0) sterilize = true;
+ //cerr << "Max Depth: " << test_info.GetMaxDepth() << endl;
+ }
+
+ if (child_fitness == 0.0) {
+ // Fatal mutation... test for reversion.
+ if (ctx.GetRandom().P(organism->GetRevertFatal())) revert = true;
+ if (ctx.GetRandom().P(organism->GetSterilizeFatal())) sterilize = true;
+ } else if (child_fitness < neut_min) {
+ if (ctx.GetRandom().P(organism->GetRevertNeg())) revert = true;
+ if (ctx.GetRandom().P(organism->GetSterilizeNeg())) sterilize = true;
+ } else if (child_fitness <= neut_max) {
+ if (ctx.GetRandom().P(organism->GetRevertNeut())) revert = true;
+ if (ctx.GetRandom().P(organism->GetSterilizeNeut())) sterilize = true;
+ } else {
+ if (ctx.GetRandom().P(organism->GetRevertPos())) revert = true;
+ if (ctx.GetRandom().P(organism->GetSterilizePos())) sterilize = true;
+
+ //hack to force deleterious reversons to be replaced with neutral mutants
+ if (organism->GetRevertNeg() == 1.0) fit_ratio = child_fitness / parent_fitness;
+ }
+
+ // Ideally, we won't have reversions and sterilizations turned on at the
+ // same time, but if we do, give revert the priority.
+ if (revert == true) {
+ organism->ChildGenome() = organism->GetGenome();
+ cerr << "Reverted!" << endl;
+ }
+ cerr << test_info.GetMaxDepth() << endl;
+
+ if (sterilize == true) {
+ organism->GetPhenotype().ChildFertile() = false;
+
+ // if(organism->GetGenotype()->GetID() == 866367){
+ cerr << "Steralized!" << endl;
+ //}
+
+ }
+
+ return (!sterilize) && revert;
+}
+
+
int cHardwareBase::PointMutate(cAvidaContext& ctx, const double mut_rate)
{
cCPUMemory& memory = GetMemory();
Modified: trunk/source/cpu/cHardwareBase.h
===================================================================
--- trunk/source/cpu/cHardwareBase.h 2007-03-15 17:38:10 UTC (rev 1402)
+++ trunk/source/cpu/cHardwareBase.h 2007-03-15 20:26:51 UTC (rev 1403)
@@ -29,6 +29,7 @@
class cOrganism;
class cString;
class cWorld;
+class cGenotype;
//class cStats; //AWC 06/29/06
class cHardwareBase
@@ -44,8 +45,10 @@
bool Divide_CheckViable(cAvidaContext& ctx, const int parent_size, const int child_size);
unsigned Divide_DoMutations(cAvidaContext& ctx, double mut_multiplier = 1.0, const int maxmut = INT_MAX);
+ unsigned Divide_Do2SiteMutations(cAvidaContext& ctx, double mut_multiplier = 1.0, const int maxmut = INT_MAX);
unsigned Divide_DoExactMutations(cAvidaContext& ctx, double mut_multiplier = 1.0, const int pointmut = INT_MAX);
bool Divide_TestFitnessMeasures(cAvidaContext& ctx);
+ bool Divide_TestFitnessMeasures1(cAvidaContext& ctx, double& fit_ratio);
void TriggerMutations_Body(cAvidaContext& ctx, int type, cCPUMemory& target_memory, cHeadCPU& cur_head);
bool TriggerMutations_ScopeGenome(cAvidaContext& ctx, const cMutation* cur_mut,
Modified: trunk/source/cpu/cHardwareCPU.cc
===================================================================
--- trunk/source/cpu/cHardwareCPU.cc 2007-03-15 17:38:10 UTC (rev 1402)
+++ trunk/source/cpu/cHardwareCPU.cc 2007-03-15 20:26:51 UTC (rev 1403)
@@ -240,6 +240,8 @@
"Allocate maximum allowed space"),
cInstEntryCPU("h-divide", &cHardwareCPU::Inst_HeadDivide, true,
"Divide code between read and write heads."),
+ cInstEntryCPU("h-divide2Sites", &cHardwareCPU::Inst_2SitesHeadDivide, true,
+ "Divide code between read and write heads, but mutate only at sites 23 and 27."),
cInstEntryCPU("h-divide1RS", &cHardwareCPU::Inst_HeadDivide1RS, true,
"Divide code between read and write heads, at most one mutation on divide, resample if reverted."),
cInstEntryCPU("h-divide2RS", &cHardwareCPU::Inst_HeadDivide2RS, true,
@@ -1234,6 +1236,57 @@
}
/*
+ Divide only 2 sites in a length 50 ancestor... AWC 02/19/07
+ */
+bool cHardwareCPU::Divide_2SitesMain(cAvidaContext& ctx, const int div_point,
+ const int extra_lines, double mut_multiplier)
+{
+ const int child_size = GetMemory().GetSize() - div_point - extra_lines;
+
+ // Make sure this divide will produce a viable offspring.
+ const bool viable = Divide_CheckViable(ctx, div_point, child_size);
+ if (viable == false) 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 = cGenomeUtil::Crop(m_memory, div_point, div_point+child_size);
+
+ // Cut off everything in this memory past the divide point.
+ GetMemory().Resize(div_point);
+
+ // Handle Divide Mutations...
+ Divide_Do2SiteMutations(ctx, mut_multiplier);
+
+ // 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, and do more work if the parent lives through the
+ // birth.
+ bool parent_alive = organism->ActivateDivide(ctx);
+ if (parent_alive) {
+ if (m_world->GetConfig().DIVIDE_METHOD.Get() == DIVIDE_METHOD_SPLIT) Reset();
+ }
+
+ return true;
+}
+
+
+/*
Almost the same as Divide_Main, but resamples reverted offspring.
RESAMPLING ONLY WORKS CORRECTLY WHEN ALL MUTIONS OCCUR ON DIVIDE!!
@@ -1358,6 +1411,8 @@
bool
fitTest = false;
+ double
+ fitRatio = 1.0;
// Handle Divide Mutations...
/*
@@ -1374,12 +1429,17 @@
else{
mutations = Divide_DoExactMutations(ctx, mut_multiplier,1);
m_world->GetStats().IncResamplings();
+ //cerr << "****************ERROR: resampling!" << endl;
}
- fitTest = Divide_TestFitnessMeasures(ctx);
- //if(mutations > 1 ) cerr << "Too Many mutations!!!!!!!!!!!!!!!" << endl;
- if(!fitTest && mutations >= totalMutations) break;
+ fitTest = Divide_TestFitnessMeasures1(ctx, fitRatio);
+ //this is a hack to make sure that deletrious mutants are replaced with neutral mutants
+ if(i){
+ if(/*fitRatio <= 1.0 && */!fitTest && mutations >= totalMutations) break;
+ }else if(!fitTest && mutations >= totalMutations) break;
+ fitRatio = 1.0;
+
}
// think about making this mutations == totalMuations - though this may be too hard...
/*
@@ -1449,7 +1509,6 @@
bool
fitTest = false;
-
// Handle Divide Mutations...
/*
Do mutations until one of these conditions are satisified:
@@ -2430,7 +2489,7 @@
}
}
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.
@@ -3096,6 +3155,19 @@
return ret_val;
}
+bool cHardwareCPU::Inst_2SitesHeadDivide(cAvidaContext& ctx)
+{
+ AdjustHeads();
+ const int divide_pos = GetHead(nHardware::HEAD_READ).GetPosition();
+ int child_end = GetHead(nHardware::HEAD_WRITE).GetPosition();
+ if (child_end == 0) child_end = GetMemory().GetSize();
+ const int extra_lines = GetMemory().GetSize() - child_end;
+ bool ret_val = Divide_2SitesMain(ctx, divide_pos, extra_lines,1);
+ // Re-adjust heads.
+ AdjustHeads();
+ return ret_val;
+}
+
bool cHardwareCPU::Inst_HeadDivide(cAvidaContext& ctx)
{
return Inst_HeadDivideMut(ctx, 1);
Modified: trunk/source/cpu/cHardwareCPU.h
===================================================================
--- trunk/source/cpu/cHardwareCPU.h 2007-03-15 17:38:10 UTC (rev 1402)
+++ trunk/source/cpu/cHardwareCPU.h 2007-03-15 20:26:51 UTC (rev 1403)
@@ -171,6 +171,7 @@
int GetCopiedSize(const int parent_size, const int child_size);
bool Divide_Main(cAvidaContext& ctx, const int divide_point, const int extra_lines=0, double mut_multiplier=1);
+ bool Divide_2SitesMain(cAvidaContext& ctx, const int divide_point, const int extra_lines=0, double mut_multiplier=1); //AWC 02/19/07
bool Divide_MainRS(cAvidaContext& ctx, const int divide_point, const int extra_lines=0, double mut_multiplier=1); //AWC 06/29/06
bool Divide_Main1RS(cAvidaContext& ctx, const int divide_point, const int extra_lines=0, double mut_multiplier=1); //AWC 07/28/06
bool Divide_Main2RS(cAvidaContext& ctx, const int divide_point, const int extra_lines=0, double mut_multiplier=1); //AWC 07/28/06
@@ -419,6 +420,7 @@
bool Inst_IfLabel(cAvidaContext& ctx);
bool Inst_IfLabel2(cAvidaContext& ctx);
bool Inst_HeadDivide(cAvidaContext& ctx);
+ bool Inst_2SitesHeadDivide(cAvidaContext& ctx);
bool Inst_HeadDivideRS(cAvidaContext& ctx); //AWC 06/29/06
bool Inst_HeadDivide1RS(cAvidaContext& ctx); //AWC 07/28/06
bool Inst_HeadDivide2RS(cAvidaContext& ctx); //AWC 08/29/06
Modified: trunk/source/cpu/cHardwareSMT.cc
===================================================================
--- trunk/source/cpu/cHardwareSMT.cc 2007-03-15 17:38:10 UTC (rev 1402)
+++ trunk/source/cpu/cHardwareSMT.cc 2007-03-15 20:26:51 UTC (rev 1403)
@@ -953,7 +953,7 @@
// Handle Divide Mutations...
Divide_DoMutations(ctx, mut_multiplier);
-
+
// 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.
Modified: trunk/source/main/cAvidaConfig.cc
===================================================================
--- trunk/source/main/cAvidaConfig.cc 2007-03-15 17:38:10 UTC (rev 1402)
+++ trunk/source/main/cAvidaConfig.cc 2007-03-15 20:26:51 UTC (rev 1403)
@@ -406,3 +406,40 @@
return cfg;
}
+bool cAvidaConfig::Get(const cString& entry, cString& ret) const
+{
+ // Loop through all groups, then all entries, searching for the specified entry.
+ tConstListIterator<cBaseConfigGroup> group_it(group_list);
+ const cBaseConfigGroup* cur_group;
+ while ((cur_group = group_it.Next()) != NULL) {
+ // Loop through entries for this group...
+ tConstListIterator<cBaseConfigEntry> entry_it(cur_group->GetEntryList());
+ const cBaseConfigEntry* cur_entry;
+ while ((cur_entry = entry_it.Next()) != NULL) {
+ if (cur_entry->GetName() == entry) {
+ ret = cur_entry->AsString();
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+bool cAvidaConfig::Set(const cString& entry, const cString& val)
+{
+ // Loop through all groups, then all entries, searching for the specified entry.
+ tListIterator<cBaseConfigGroup> group_it(group_list);
+ cBaseConfigGroup* cur_group;
+ while ((cur_group = group_it.Next()) != NULL) {
+ // Loop through entries for this group...
+ tListIterator<cBaseConfigEntry> entry_it(cur_group->GetEntryList());
+ cBaseConfigEntry* cur_entry;
+ while ((cur_entry = entry_it.Next()) != NULL) {
+ if (cur_entry->GetName() == entry) {
+ cur_entry->LoadString(val);
+ return true;
+ }
+ }
+ }
+ return false;
+}
Modified: trunk/source/main/cAvidaConfig.h
===================================================================
--- trunk/source/main/cAvidaConfig.h 2007-03-15 17:38:10 UTC (rev 1402)
+++ trunk/source/main/cAvidaConfig.h 2007-03-15 20:26:51 UTC (rev 1403)
@@ -63,8 +63,8 @@
} \
TYPE Get() const { return value; } /* 8 */ \
void Set(TYPE in_value) { value = in_value; } \
- cString AsString() { return cStringUtil::Convert(value); } /* 9 */ \
-} NAME /* 10 */ \
+ cString AsString() const { return cStringUtil::Convert(value); } /* 9 */ \
+} NAME /* 10 */ \
// Now we're going to make another macro to deal with groups. This time its
@@ -102,13 +102,13 @@
virtual void LoadString(const cString & str_value) = 0;
- const cString & GetName() { return config_name; }
+ const cString & GetName() const { return config_name; }
const cString & GetType() { return type; }
const cString & GetDefault() { return default_value; }
const cString & GetDesc() { return description; }
bool GetUseOveride() { return use_overide; }
- virtual cString AsString() = 0;
+ virtual cString AsString() const = 0;
};
// The cBaseConfigGroup class is a bass class for objects that collect the
@@ -123,9 +123,10 @@
: group_name(_name), description(_desc) { global_group_list.PushRear(this); }
~cBaseConfigGroup() { ; }
- const cString & GetName() { return group_name; }
- const cString & GetDesc() { return description; }
+ const cString & GetName() const { return group_name; }
+ const cString & GetDesc() const { return description; }
tList<cBaseConfigEntry> & GetEntryList() { return entry_list; }
+ const tList<cBaseConfigEntry> & GetEntryList() const { return entry_list; }
void AddEntry(cBaseConfigEntry * _entry) { entry_list.PushRear(_entry); }
};
@@ -275,12 +276,18 @@
CONFIG_ADD_VAR(SAVE_RECEIVED, bool, 0, "Enable storage of all inputs bought from other orgs");
CONFIG_ADD_VAR(BUY_PRICE, int, 0, "price offered by organisms attempting to buy");
CONFIG_ADD_VAR(SELL_PRICE, int, 0, "price offered by organisms attempting to sell");
+ CONFIG_ADD_VAR(ANALYZE_OPTION_1, cString, "0", "String variable accessible from analysis scripts");
+ CONFIG_ADD_VAR(ANALYZE_OPTION_2, cString, "0", "String variable accessible from analysis scripts");
#endif
void Load(const cString& filename);
void Print(const cString& filename);
void Status();
+
+ bool Get(const cString& entry, cString& ret) const;
+ bool Set(const cString& entry, const cString& val);
+
void GenerateOverides();
};
Modified: trunk/source/main/cLandscape.cc
===================================================================
--- trunk/source/main/cLandscape.cc 2007-03-15 17:38:10 UTC (rev 1402)
+++ trunk/source/main/cLandscape.cc 2007-03-15 20:26:51 UTC (rev 1403)
@@ -24,9 +24,9 @@
#include "cWorld.h"
-cLandscape::cLandscape(cWorld* world, const cGenome & in_genome, const cInstSet & in_inst_set)
+cLandscape::cLandscape(cWorld* world, const cGenome & in_genome, const cInstSet & in_inst_set, const int& genotypeID)
: m_world(world), inst_set(in_inst_set), base_genome(1), peak_genome(1), trials(1), m_min_found(0),
- m_max_trials(0), site_count(NULL)
+ m_max_trials(0), site_count(NULL), m_genotypeID(genotypeID)
{
Reset(in_genome);
}
@@ -777,6 +777,7 @@
void cLandscape::PrintStats(cDataFile& df, int update)
{
+ df.Write(m_genotypeID, "Genotype ID");
df.Write(update, "Update");
df.Write(GetProbDead(), "Probability Lethal");
df.Write(GetProbNeg(), "Probability Deleterious");
Modified: trunk/source/main/cLandscape.h
===================================================================
--- trunk/source/main/cLandscape.h 2007-03-15 17:38:10 UTC (rev 1402)
+++ trunk/source/main/cLandscape.h 2007-03-15 20:26:51 UTC (rev 1403)
@@ -17,6 +17,10 @@
#ifndef cGenome_h
#include "cGenome.h"
#endif
+//dont really need this.
+//#ifndef cGenotype.h
+//#include "cGenotype.h"
+//#endif
#ifndef cString_h
#include "cString.h"
#endif
@@ -76,6 +80,8 @@
double total_entropy;
double complexity;
+ int m_genotypeID;
+
cCPUTestInfo test_info; // Info used for all cpu calculations.
double neut_min; // These two variables are a range around the base
double neut_max; // fitness to be counted as neutral mutations.
@@ -97,7 +103,7 @@
cLandscape& operator=(const cLandscape&); // @not_implemented
public:
- cLandscape(cWorld* world, const cGenome& in_genome, const cInstSet& in_inst_set);
+ cLandscape(cWorld* world, const cGenome& in_genome, const cInstSet& in_inst_set, const int& genotypeID = -1);
~cLandscape();
void Reset(const cGenome& in_genome);
Modified: trunk/source/main/cPopulationCell.cc
===================================================================
--- trunk/source/main/cPopulationCell.cc 2007-03-15 17:38:10 UTC (rev 1402)
+++ trunk/source/main/cPopulationCell.cc 2007-03-15 20:26:51 UTC (rev 1403)
@@ -75,13 +75,13 @@
{
// @CAO Note, this breaks avida if new_facing is not in connection_list
-#ifdef DEBUG
+ //#ifdef DEBUG
int scan_count = 0;
-#endif
- while (connection_list.GetFirst() != &new_facing) {
+ //#endif
+ while (connection_list.GetFirst() != &new_facing && ++scan_count < connection_list.GetSize()) {
connection_list.CircNext();
#ifdef DEBUG
- assert(++scan_count < connection_list.GetSize());
+ assert(scan_count < connection_list.GetSize());
#endif
}
}
Modified: trunk/source/tools/tList.h
===================================================================
--- trunk/source/tools/tList.h 2007-03-15 17:38:10 UTC (rev 1402)
+++ trunk/source/tools/tList.h 2007-03-15 20:26:51 UTC (rev 1403)
@@ -80,9 +80,14 @@
const tList<T> & GetConstList() { return list; }
const tListNode<T> * GetConstNode() { return node; }
+
+ T * _NextData();
+ T * _PrevData();
+
public:
- explicit tListIterator(tList<T> & _list);
+ explicit tListIterator(tList<T> & _list);
explicit tListIterator(tList<T> & _list, tListNode<T> * start_node);
+ tListIterator(const tListIterator<T> & _it);
~tListIterator();
void Set(tListNode<T> * in_node) { node = in_node; }
@@ -95,7 +100,12 @@
const T * GetConst() { return Get(); }
const T * NextConst() { return Next(); }
const T * PrevConst() { return Prev(); }
-
+
+ T * NextData() {return _NextData();}
+ T * PrevData() {return _PrevData();}
+
+ // const T * NextData() {return _NextData();}
+ //const T * PrevData() {return _PrevData();}
bool Find(T * test_data);
bool AtRoot() const;
@@ -208,6 +218,32 @@
delete out_node;
return out_data;
}
+
+ //same as remove node but we're deleting the data...
+ void EraseNode(tListNode<T> * out_node) {
+ // Make sure we're not trying to delete the root node!
+ if (out_node == &root) return;
+
+ // Adjust any iterators on the deleted node.
+ tListNode< tBaseIterator<T> > * test_it = it_root.next;
+ while (test_it != &it_root) {
+ // If this iterator is on this node, move it back one.
+ if (test_it->data->GetConstNode() == out_node) {
+ test_it->data->PrevConst();
+ }
+ test_it = test_it->next;
+ }
+
+ // Save the data and patch up the linked list.
+ T * out_data = out_node->data;
+ out_node->prev->next = out_node->next;
+ out_node->next->prev = out_node->prev;
+
+ // Cleanup and return
+ size--;
+ delete out_node;
+ delete out_data;
+ }
// To be called from iterator constructor only!
void AddIterator(tBaseIterator<T> * new_it) const {
@@ -236,6 +272,7 @@
T * PopRear() { return RemoveNode(root.prev); }
void Clear() { while (size > 0) Pop(); }
+ void EraseList() { while (size > 0) EraseNode(root.next); }
void Append(const tList<T> & in_list) {
tListNode<T> * cur_node = in_list.root.next;
@@ -297,6 +334,12 @@
if (&(other.list) != this) return NULL; // @CAO make this an assert?
return RemoveNode(other.node);
}
+
+ //same as Remove but we delete the data ...
+ void Erase(tListIterator<T> & other) {
+ if (&(other.list) != this) return NULL; // @CAO make this an assert?
+ EraseNode(other.node);
+ }
T * Insert(tListIterator<T> & list_it, T * in_data) {
tListNode<T> * cur_node = list_it.node;
@@ -330,6 +373,18 @@
//return false;
return NULL;
}
+
+ //same as remove but we delete teh data instead...
+ void Erase(T * other) {
+ tListNode<T> * test = root.next;
+ while (test != &root) {
+ if (test->data == other) {
+ EraseNode(test);
+ }
+ test = test->next;
+ }
+ }
+
int GetSize() const { return size; }
@@ -543,6 +598,13 @@
list.AddIterator(this);
}
+template <class T> tListIterator<T>::tListIterator(const tListIterator<T> & _it)
+: list(_it.list), node(_it.node)
+{
+ list.AddIterator(this);
+}
+
+
template <class T> tListIterator<T>::tListIterator(tList<T> & _list,
tListNode<T> * start_node)
: list(_list), node(start_node)
@@ -560,6 +622,14 @@
node = &(list.root);
}
+template <class T> T * tListIterator<T>::_NextData(){
+ return node->next->data;
+}
+
+template <class T> T * tListIterator<T>::_PrevData(){
+ return node->prev->data;
+}
+
template <class T> T * tListIterator<T>::Get()
{
return node->data;
More information about the Avida-cvs
mailing list