[Avida-SVN] r3121 - in development: . Avida.xcodeproj source/actions source/analyze source/classification source/cpu source/main source/tools
jbarrick at myxo.css.msu.edu
jbarrick at myxo.css.msu.edu
Fri Jan 16 10:41:15 PST 2009
Author: jbarrick
Date: 2009-01-16 13:41:14 -0500 (Fri, 16 Jan 2009)
New Revision: 3121
Added:
development/source/classification/cMutationSteps.cc
development/source/classification/cMutationSteps.h
Modified:
development/Avida.xcodeproj/project.pbxproj
development/CMakeLists.txt
development/source/actions/SaveLoadActions.cc
development/source/analyze/cAnalyze.cc
development/source/analyze/cAnalyzeGenotype.cc
development/source/analyze/cAnalyzeGenotype.h
development/source/classification/cClassificationManager.cc
development/source/classification/cClassificationManager.h
development/source/cpu/cCPUMemory.h
development/source/cpu/cHardwareBase.cc
development/source/main/cAvidaConfig.h
development/source/main/cGenome.cc
development/source/main/cGenome.h
development/source/main/cPopulation.cc
development/source/tools/cStringUtil.cc
development/source/tools/cStringUtil.h
Log:
* Added support (cMutationStep) for logging mutations that happen on divide, outputting, and loading in analyze mode.
* New slip mode for inserting nop-C
* Cleaned up abortive genome alignment code.
Modified: development/Avida.xcodeproj/project.pbxproj
===================================================================
--- development/Avida.xcodeproj/project.pbxproj 2009-01-16 16:22:13 UTC (rev 3120)
+++ development/Avida.xcodeproj/project.pbxproj 2009-01-16 18:41:14 UTC (rev 3121)
@@ -23,6 +23,7 @@
/* End PBXAggregateTarget section */
/* Begin PBXBuildFile section */
+ 10479F2E0F1BC54B00AF9F6A /* cMutationSteps.cc in Sources */ = {isa = PBXBuildFile; fileRef = 10479F2C0F1BC54B00AF9F6A /* cMutationSteps.cc */; };
2A57A3FF0D6B954D00FC54C7 /* cProbDemeProbSchedule.cc in Sources */ = {isa = PBXBuildFile; fileRef = 2A57A3FD0D6B954D00FC54C7 /* cProbDemeProbSchedule.cc */; };
2A57A4000D6B954D00FC54C7 /* cProbDemeProbSchedule.h in Headers */ = {isa = PBXBuildFile; fileRef = 2A57A3FE0D6B954D00FC54C7 /* cProbDemeProbSchedule.h */; };
5629D8110C3EE14800C5F152 /* cTextWindow.cc in Sources */ = {isa = PBXBuildFile; fileRef = 5629D80D0C3EE13500C5F152 /* cTextWindow.cc */; };
@@ -371,6 +372,8 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
+ 10479F2C0F1BC54B00AF9F6A /* cMutationSteps.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = cMutationSteps.cc; sourceTree = "<group>"; };
+ 10479F2D0F1BC54B00AF9F6A /* cMutationSteps.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cMutationSteps.h; sourceTree = "<group>"; };
1097463D0AE9606E00929ED6 /* cDeme.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cDeme.cc; sourceTree = "<group>"; };
1097463E0AE9606E00929ED6 /* cDeme.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cDeme.h; sourceTree = "<group>"; };
2A57A3FD0D6B954D00FC54C7 /* cProbDemeProbSchedule.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cProbDemeProbSchedule.cc; sourceTree = "<group>"; };
@@ -1374,6 +1377,8 @@
70F7DC9F09293E6F009E311D /* cGenotype.h */,
70F7DAEF09290468009E311D /* cClassificationManager.h */,
70F7DAF009290468009E311D /* cClassificationManager.cc */,
+ 10479F2D0F1BC54B00AF9F6A /* cMutationSteps.h */,
+ 10479F2C0F1BC54B00AF9F6A /* cMutationSteps.cc */,
);
path = classification;
sourceTree = "<group>";
@@ -2102,6 +2107,7 @@
D7FB16D60ED62684002E939E /* cOrgMessage.cc in Sources */,
70AD4FA00F194F4D00AA50AC /* cGenotypeData.cc in Sources */,
700D9C470F1A8F34002CC711 /* cModularityAnalysis.cc in Sources */,
+ 10479F2E0F1BC54B00AF9F6A /* cMutationSteps.cc in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Modified: development/CMakeLists.txt
===================================================================
--- development/CMakeLists.txt 2009-01-16 16:22:13 UTC (rev 3120)
+++ development/CMakeLists.txt 2009-01-16 18:41:14 UTC (rev 3121)
@@ -153,6 +153,7 @@
${CLASSIFICATION_DIR}/cInjectGenotypeControl.cc
${CLASSIFICATION_DIR}/cInjectGenotypeQueue.cc
${CLASSIFICATION_DIR}/cLineage.cc
+ ${CLASSIFICATION_DIR}/cMutationSteps.cc
${CLASSIFICATION_DIR}/cSpecies.cc
${CLASSIFICATION_DIR}/cSpeciesControl.cc
${CLASSIFICATION_DIR}/cSpeciesQueue.cc
Modified: development/source/actions/SaveLoadActions.cc
===================================================================
--- development/source/actions/SaveLoadActions.cc 2009-01-16 16:22:13 UTC (rev 3120)
+++ development/source/actions/SaveLoadActions.cc 2009-01-16 18:41:14 UTC (rev 3121)
@@ -171,13 +171,19 @@
class cActionSavePopulation : public cAction
{
private:
+ bool m_print_mut_steps;
cString m_filename;
public:
- cActionSavePopulation(cWorld* world, const cString& args) : cAction(world, args), m_filename("")
+ cActionSavePopulation(cWorld* world, const cString& args) : cAction(world, args), m_print_mut_steps(0), m_filename("")
{
cString largs(args);
if (largs.GetSize()) m_filename = largs.PopWord();
+ if (m_filename == "mut_steps") {
+ m_print_mut_steps = 1;
+ m_filename = "";
+ if (largs.GetSize()) m_filename = largs.PopWord();
+ }
}
static const cString GetDescription() { return "Arguments: [string fname='']"; }
@@ -186,7 +192,7 @@
{
cString filename(m_filename);
if (filename == "") filename.Set("detail-%d.pop", m_world->GetStats().GetUpdate());
- m_world->GetClassificationManager().DumpDetailedSummary(m_world->GetDataFileOFStream(filename));
+ m_world->GetClassificationManager().DumpDetailedSummary(m_world->GetDataFileOFStream(filename), m_print_mut_steps);
m_world->GetDataFileManager().Remove(filename);
}
};
@@ -264,15 +270,23 @@
{
private:
int m_backdist;
+ bool m_print_mut_steps;
cString m_filename;
+
public:
cActionSaveHistoricPopulation(cWorld* world, const cString& args)
- : cAction(world, args), m_backdist(-1), m_filename("")
+ : cAction(world, args), m_backdist(-1), m_print_mut_steps(0), m_filename("")
{
cString largs(args);
if (largs.GetSize()) m_backdist = largs.PopWord().AsInt();
if (largs.GetSize()) m_filename = largs.PopWord();
+ if (m_filename == "mut_steps") {
+ m_print_mut_steps = 1;
+ m_filename = "";
+ if (largs.GetSize()) m_filename = largs.PopWord();
+ }
+
}
static const cString GetDescription() { return "Arguments: [int back_dist=-1] [string fname='']"; }
@@ -281,7 +295,7 @@
{
cString filename(m_filename);
if (filename == "") filename.Set("historic-%d.pop", m_world->GetStats().GetUpdate());
- m_world->GetClassificationManager().DumpHistoricSummary(m_world->GetDataFileOFStream(filename), m_backdist);
+ m_world->GetClassificationManager().DumpHistoricSummary(m_world->GetDataFileOFStream(filename), m_backdist, m_print_mut_steps);
m_world->GetDataFileManager().Remove(filename);
}
};
Modified: development/source/analyze/cAnalyze.cc
===================================================================
--- development/source/analyze/cAnalyze.cc 2009-01-16 16:22:13 UTC (rev 3120)
+++ development/source/analyze/cAnalyze.cc 2009-01-16 18:41:14 UTC (rev 3121)
@@ -901,7 +901,7 @@
}
const cString filetype = input_file.GetFiletype();
- if (filetype != "population_data" && // Depricated
+ if (filetype != "population_data" && // Deprecated
filetype != "genotype_data") {
cerr << "Error: Cannot load files of type \"" << filetype << "\"." << endl;
if (exit_on_error) exit(1);
@@ -6217,7 +6217,6 @@
{
// Align does not need any args yet.
(void) cur_string;
- int perform_slow_alignment = (cur_string.GetSize()) ? cur_string.PopWord().AsInt() : 0;
cout << "Aligning sequences..." << endl;
@@ -6243,28 +6242,7 @@
int num_del = 0;
// Compare each string to the previous.
- if (perform_slow_alignment == 0) {
- cStringUtil::EditDistance(sequences[i], sequences[i-1], diff_info, '_');
- }
- else
- if (perform_slow_alignment == 1) {
- cStringUtil::GapMinimizingEditDistance(sequences[i], sequences[i-1], diff_info, '_');
- }
- else {
- cString best_diff_info;
- int min_dist = -1;
- for (int j=0; j<i; j++) {
- cString test_diff_info;
- int test_dist = cStringUtil::GapMinimizingEditDistance(sequences[i], sequences[j], test_diff_info, '_');
- if (min_dist == -1 || test_dist < min_dist) {
- min_dist = test_dist;
- best_diff_info = test_diff_info;
- if (min_dist == 0) j=i;
- }
- }
-
- diff_info = best_diff_info;
- }
+ cStringUtil::EditDistance(sequences[i], sequences[i-1], diff_info, '_');
while (diff_info.GetSize() != 0) {
cString cur_mut = diff_info.Pop(',');
Modified: development/source/analyze/cAnalyzeGenotype.cc
===================================================================
--- development/source/analyze/cAnalyzeGenotype.cc 2009-01-16 16:22:13 UTC (rev 3120)
+++ development/source/analyze/cAnalyzeGenotype.cc 2009-01-16 18:41:14 UTC (rev 3121)
@@ -295,9 +295,12 @@
ADD_GDATA(double (), "phen_likely_freq", "Freq of Most Likely Phenotype", GetLikelyFrequency, SetNULL, 0, 0, 0);
ADD_GDATA(double (), "phen_likely_fitness","Fitness of Most Likely Phenotype", GetLikelyFitness, SetNULL, 0, 0, 0);
+ // @JEB There is a difference between these two. parent_muts is based on an alignment. mut_steps is based on recorded mutations during run.
ADD_GDATA(const cString& (), "parent_muts", "Mutations from Parent", GetParentMuts, SetParentMuts, 0, "(none)", "");
+ ADD_GDATA(const cString (), "mut_steps", "Mutation Steps from Parent", GetMutSteps, SetMutSteps, 0, "", "");
+
ADD_GDATA(const cString& (), "task_order", "Task Performance Order", GetTaskOrder, SetTaskOrder, 0, "(none)", "");
- ADD_GDATA(cString (), "sequence", "Genome Sequence", GetSequence, SetSequence, 0, "(N/A)", "");
+ ADD_GDATA(cString (), "sequence", "Genome Sequence", GetSequence, SetSequence, 0, "(N/A)", "");
ADD_GDATA(const cString& (), "alignment", "Aligned Sequence", GetAlignedSequence, SetAlignedSequence, 0, "(N/A)", "");
ADD_GDATA(cString (), "executed_flags", "Executed Flags", GetExecutedFlags, SetNULL, 0, "(N/A)", "");
@@ -328,8 +331,8 @@
ADD_GDATA(int (), "dom_depth", "Tree Depth of Dominant Genotype", GetDepth, SetDepth, 0, 0, 0);
ADD_GDATA(int (), "dom_id", "Dominant Genotype ID", GetID, SetID, 0, 0, 0);
ADD_GDATA(cString (), "dom_sequence", "Dominant Genotype Sequence", GetSequence, SetSequence, 0, "(N/A)", "");
+
-
return dcm;
#undef ADD_GDATA
}
@@ -612,6 +615,7 @@
efficiency_ratio = GetEfficiency() / parent_genotype->GetEfficiency();
comp_merit_ratio = GetCompMerit() / parent_genotype->GetCompMerit();
parent_dist = cStringUtil::EditDistance(genome.AsString(), parent_genotype->GetGenome().AsString(), parent_muts);
+
ancestor_dist = parent_genotype->GetAncestorDist() + parent_dist;
}
Modified: development/source/analyze/cAnalyzeGenotype.h
===================================================================
--- development/source/analyze/cAnalyzeGenotype.h 2009-01-16 16:22:13 UTC (rev 3120)
+++ development/source/analyze/cAnalyzeGenotype.h 2009-01-16 18:41:14 UTC (rev 3121)
@@ -302,6 +302,8 @@
void SetLineageLabel(int _label) { lineage_label = _label; }
void SetParentMuts(const cString & in_muts) { parent_muts = in_muts; }
+ void SetMutSteps(const cString in_muts) { genome.GetMutationSteps().Set(in_muts); }
+
void SetTaskOrder(const cString & in_order) { task_order = in_order; }
// A set of NULL accessors to simplyfy automated accesses.
@@ -352,6 +354,7 @@
int GetDepth() const { return depth; }
const cString& GetParentMuts() const { return parent_muts; }
+ const cString GetMutSteps() const { const cMutationSteps& ms = genome.GetMutationSteps(); return ms.AsString(); }
// Knockout accessors
int GetKO_DeadCount() const;
Modified: development/source/classification/cClassificationManager.cc
===================================================================
--- development/source/classification/cClassificationManager.cc 2009-01-16 16:22:13 UTC (rev 3120)
+++ development/source/classification/cClassificationManager.cc 2009-01-16 18:41:14 UTC (rev 3121)
@@ -669,26 +669,26 @@
return true;
}
-bool cClassificationManager::DumpDetailedSummary(ofstream& fp)
+bool cClassificationManager::DumpDetailedSummary(ofstream& fp, bool print_mut_steps)
{
m_genotype_ctl->Reset(0);
- DumpDetailHeading(fp);
+ DumpDetailHeading(fp, print_mut_steps);
for (int i = 0; i < m_genotype_ctl->GetSize(); i++) {
- DumpDetailedEntry(m_genotype_ctl->Get(0), fp);
+ DumpDetailedEntry(m_genotype_ctl->Get(0), fp, print_mut_steps);
m_genotype_ctl->Next(0);
}
return true;
}
-bool cClassificationManager::DumpHistoricSummary(ofstream& fp, int back_dist)
+bool cClassificationManager::DumpHistoricSummary(ofstream& fp, int back_dist, bool print_mut_steps)
{
// Calculate the update we should start printing from...
int start_update = 0;
if (back_dist > 0) start_update = m_world->GetStats().GetUpdate() - back_dist;
// Loop through all defunct genotypes that we're saving.
- DumpDetailHeading(fp);
+ DumpDetailHeading(fp, print_mut_steps);
m_genotype_ctl->ResetHistoric(0);
for (int i = 0; i < m_genotype_ctl->GetHistoricCount(); i++) {
// Get the next genotype. Only print it if its in range...
@@ -697,7 +697,7 @@
m_genotype_ctl->Next(0);
continue;
}
- DumpDetailedEntry(cur_genotype, fp);
+ DumpDetailedEntry(cur_genotype, fp, print_mut_steps);
// Move to the next genotype...
m_genotype_ctl->Next(0);
@@ -730,11 +730,12 @@
return true;
}
-void cClassificationManager::DumpDetailHeading (ofstream& fp)
+void cClassificationManager::DumpDetailHeading (ofstream& fp, bool print_mut_steps)
{
fp << "#filetype genotype_data" << endl
- << "#format id parent_id parent_dist num_cpus total_cpus length merit gest_time fitness update_born update_dead depth sequence" << endl
- << endl
+ << "#format id parent_id parent_dist num_cpus total_cpus length merit gest_time fitness update_born update_dead depth sequence";
+ if (print_mut_steps) { fp << " mut_steps"; }
+ fp << endl << endl
<< "# 1: ID" << endl
<< "# 2: parent ID" << endl
<< "# 3: parent distance" << endl
@@ -747,7 +748,9 @@
<< "# 10: update born" << endl
<< "# 11: update deactivated" << endl
<< "# 12: depth in phylogentic tree" << endl
- << "# 13: genome of organism" << endl << endl;
+ << "# 13: genome of organism" << endl;
+ if (print_mut_steps) { fp << "# 14: mutation steps from parent" << endl; }
+ fp << endl;
}
void cClassificationManager::DumpDetailSexHeading (ofstream& fp)
@@ -771,7 +774,7 @@
<< "# 14: genome of organism" << endl << endl;
}
-void cClassificationManager::DumpDetailedEntry(cGenotype* genotype, ofstream& fp)
+void cClassificationManager::DumpDetailedEntry(cGenotype* genotype, ofstream& fp, bool print_mut_steps)
{
fp << genotype->GetID() << " " // 1
<< genotype->GetParentID() << " " // 2
@@ -786,8 +789,9 @@
<< genotype->GetUpdateBorn() << " " // 10
<< genotype->GetUpdateDeactivated() << " " // 11
<< genotype->GetDepth() << " " // 12
- << genotype->GetGenome().AsString() << " " // 13
- << endl;
+ << genotype->GetGenome().AsString() << " "; // 13
+ if (print_mut_steps) { fp << genotype->GetGenome().GetMutationSteps().AsString() << " "; } // 14
+ fp << endl;
}
void cClassificationManager::DumpDetailedSexEntry(cGenotype * genotype, ofstream& fp)
Modified: development/source/classification/cClassificationManager.h
===================================================================
--- development/source/classification/cClassificationManager.h 2009-01-16 16:22:13 UTC (rev 3120)
+++ development/source/classification/cClassificationManager.h 2009-01-16 18:41:14 UTC (rev 3121)
@@ -105,7 +105,7 @@
// Private Helper Functions
void AddGenotype(cGenotype* in_genotype, int list_num = -1);
void AddInjectGenotype(cInjectGenotype* in_inject_genotype, int in_list_num = -1);
- void DumpDetailHeading(std::ofstream& fp);
+ void DumpDetailHeading(std::ofstream& fp, bool print_mut_steps = false);
void DumpDetailSexHeading (std::ofstream& fp);
unsigned int FindCRC(const cGenome& in_genome) const;
unsigned int FindInjectCRC(const cGenome& in_genome) const;
@@ -155,11 +155,11 @@
// Genotype Output
bool DumpTextSummary(std::ofstream& fp);
bool PrintGenotypes(std::ofstream& fp, cString & data_fields, int historic);
- bool DumpDetailedSummary(std::ofstream& fp);
+ bool DumpDetailedSummary(std::ofstream& fp, bool print_mut_steps = false);
bool DumpDetailedSexSummary(std::ofstream& fp);
- bool DumpHistoricSummary(std::ofstream& fp, int back_dist);
+ bool DumpHistoricSummary(std::ofstream& fp, int back_dist, bool print_mut_steps = false);
bool DumpHistoricSexSummary(std::ofstream& fp);
- void DumpDetailedEntry(cGenotype* genotype, std::ofstream& fp);
+ void DumpDetailedEntry(cGenotype* genotype, std::ofstream& fp, bool print_mut_steps = false);
void DumpDetailedSexEntry(cGenotype* genotype, std::ofstream& fp);
Added: development/source/classification/cMutationSteps.cc
===================================================================
--- development/source/classification/cMutationSteps.cc (rev 0)
+++ development/source/classification/cMutationSteps.cc 2009-01-16 18:41:14 UTC (rev 3121)
@@ -0,0 +1,95 @@
+/*
+ * cMutationSteps.cc
+ * Avida
+ *
+ * Copyright 1999-2009 Michigan State University. All rights reserved.
+ * Copyright 1999-2003 California Institute of Technology.
+ *
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; version 2
+ * of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "cMutationSteps.h"
+
+cMutationSteps::cMutationSteps(const cMutationSteps& in_ms) : tList<cMutationStep>()
+{
+ tConstListIterator<cMutationStep> mutation_it(in_ms);
+ while (cMutationStep* mut = mutation_it.Next()) {
+ this->PushRear(mut->copy());
+ }
+}
+
+void cMutationSteps::operator=(const cMutationSteps& in_ms)
+{
+ tConstListIterator<cMutationStep> mutation_it(in_ms);
+ while (cMutationStep* mut = mutation_it.Next()) {
+ this->PushRear(mut->copy());
+ }
+}
+
+cMutationSteps::~cMutationSteps()
+{
+ tListIterator<cMutationStep> mutation_it(*this);
+ while (cMutationStep* mut = mutation_it.Next()) {
+ delete mut;
+ }
+}
+
+void cMutationSteps::Clear()
+{
+ tListIterator<cMutationStep> mutation_it(*this);
+ while (cMutationStep* mut = mutation_it.Next()) {
+ delete mut;
+ }
+ tList<cMutationStep>::Clear();
+}
+
+void cMutationSteps::AddSubstitutionMutation(int _pos, char _from, char _to)
+{
+ cMutationStep* mut = new cSubstitutionMutationStep(_pos, _from, _to);
+ this->PushRear(mut);
+}
+
+void cMutationSteps::AddDeletionMutation(int _pos, char _from)
+{
+ cMutationStep* mut = new cDeletionMutationStep(_pos, _from);
+ this->PushRear(mut);
+}
+
+void cMutationSteps::AddInsertionMutation(int _pos, int _to)
+{
+ cMutationStep* mut = new cInsertionMutationStep(_pos, _to);
+ this->PushRear(mut);
+}
+
+void cMutationSteps::AddSlipMutation(int _start, int _end)
+{
+ cMutationStep* mut = new cSlipMutationStep(_start, _end);
+ this->PushRear(mut);
+}
+
+cString cMutationSteps::AsString() const
+{
+ if (m_loaded_string.GetSize() > 0) return m_loaded_string;
+
+ cString return_string;
+ tConstListIterator<cMutationStep> mutation_it(*this);
+ while (cMutationStep* mut = mutation_it.Next()) {
+ if (return_string.GetSize() > 0) { return_string += ","; }
+ return_string += mut->AsString();
+ }
+ return return_string;
+}
Added: development/source/classification/cMutationSteps.h
===================================================================
--- development/source/classification/cMutationSteps.h (rev 0)
+++ development/source/classification/cMutationSteps.h 2009-01-16 18:41:14 UTC (rev 3121)
@@ -0,0 +1,115 @@
+/*
+ * cMutationSteps.h
+ * Avida
+ *
+ * Copyright 1999-2009 Michigan State University. All rights reserved.
+ * Copyright 1999-2003 California Institute of Technology.
+ *
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; version 2
+ * of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef cMutationSteps_h
+#define cMutationSteps_h
+
+#ifndef cString_h
+#include "cString.h"
+#endif
+
+#ifndef tList_h
+#include "tList.h"
+#endif
+
+
+class cMutationStep {
+public:
+ virtual ~cMutationStep() {};
+ virtual cMutationStep* copy() const = 0;
+ virtual cString AsString() = 0;
+};
+
+class cSubstitutionMutationStep : public cMutationStep {
+public:
+ int m_pos;
+ char m_from;
+ char m_to;
+ cSubstitutionMutationStep(const cSubstitutionMutationStep& _in) : cMutationStep(), m_pos(_in.m_pos), m_from(_in.m_from), m_to(_in.m_to) {}
+ void operator=(const cSubstitutionMutationStep& _in) { m_pos=_in.m_pos; m_from=_in.m_from; m_to=_in.m_to; };
+ cSubstitutionMutationStep(int _pos, char _from, char _to) { m_pos = _pos; m_from = _from; m_to = _to; }
+ ~cSubstitutionMutationStep() {};
+ cMutationStep* copy() const { return new cSubstitutionMutationStep(*this); }
+ cString AsString() { cString s; s.Set("M%c%i%c", m_from, m_pos, m_to); return s; }
+};
+
+class cDeletionMutationStep : public cMutationStep {
+public:
+ int m_pos;
+ char m_from;
+ cDeletionMutationStep(const cDeletionMutationStep& _in) : cMutationStep(), m_pos(_in.m_pos), m_from(_in.m_from) {}
+ void operator=(const cDeletionMutationStep& _in) { m_pos=_in.m_pos; m_from=_in.m_from; };
+ cDeletionMutationStep(int _pos, char _from) { m_pos = _pos; m_from = _from; }
+ ~cDeletionMutationStep() {};
+ cMutationStep* copy() const { return new cDeletionMutationStep(*this); }
+ cString AsString() { cString s; s.Set("D%i%c", m_pos, m_from); return s; }
+};
+
+class cInsertionMutationStep : public cMutationStep{
+public:
+ int m_pos;
+ char m_to;
+ cInsertionMutationStep(const cInsertionMutationStep& _in) : cMutationStep(), m_pos(_in.m_pos), m_to(_in.m_to) {}
+ void operator=(const cInsertionMutationStep& _in) { m_pos=_in.m_pos; m_to=_in.m_to; };
+ cInsertionMutationStep(int _pos, int _to) { m_pos = _pos; m_to = _to; };
+ ~cInsertionMutationStep() {};
+ cMutationStep* copy() const { return new cInsertionMutationStep(*this); }
+ cString AsString() { cString s; s.Set("I%i%c", m_pos, m_to); return s; }
+};
+
+class cSlipMutationStep : public cMutationStep {
+public:
+ int m_start;
+ int m_end;
+ cSlipMutationStep(const cSlipMutationStep& _in) : cMutationStep(), m_start(_in.m_start), m_end(_in.m_end) {}
+ void operator=(const cSlipMutationStep& _in) { m_start=_in.m_start; m_end=_in.m_end; };
+ cSlipMutationStep(int _start, int _end) { m_start = _start; m_end = _end; };
+ ~cSlipMutationStep() {};
+ cMutationStep* copy() const { return new cSlipMutationStep(*this); }
+ cString AsString() { cString s; s.Set("S%i-%i", m_start, m_end); return s; }
+};
+
+
+class cMutationSteps : public tList<cMutationStep> {
+private:
+ cString m_loaded_string;
+public:
+ cMutationSteps() {};
+ cMutationSteps(const cMutationSteps& in_ms);
+ void operator=(const cMutationSteps& in_ms);
+ ~cMutationSteps();
+ void Clear();
+
+ void AddSubstitutionMutation(int _pos, char _from, char _to);
+ void AddDeletionMutation(int _pos, char _from);
+ void AddInsertionMutation(int _pos, int _to);
+ void AddSlipMutation(int _start, int _end);
+
+ void Set(const cString& in_mut_steps) { m_loaded_string = in_mut_steps; }
+ // need to implement for reading, right now, we fake it.
+ cString AsString() const;
+};
+
+
+#endif
Modified: development/source/cpu/cCPUMemory.h
===================================================================
--- development/source/cpu/cCPUMemory.h 2009-01-16 16:22:13 UTC (rev 3120)
+++ development/source/cpu/cCPUMemory.h 2009-01-16 18:41:14 UTC (rev 3121)
@@ -47,7 +47,6 @@
static const unsigned char MASK_UNUSED = 0x80; // unused bit
tArray<unsigned char> flag_array;
-
// A collection of sloppy instructions to perform oft-used functions that
// will need to be cleaned up after this is run.
@@ -73,6 +72,7 @@
genome[i].SetOp(0);
flag_array[i] = 0;
}
+ m_mutation_steps.Clear();
}
void ClearFlags() { flag_array.SetAll(0); }
void Reset(int new_size); // Reset size, clearing contents...
Modified: development/source/cpu/cHardwareBase.cc
===================================================================
--- development/source/cpu/cHardwareBase.cc 2009-01-16 16:22:13 UTC (rev 3120)
+++ development/source/cpu/cHardwareBase.cc 2009-01-16 18:41:14 UTC (rev 3121)
@@ -191,7 +191,9 @@
// Divide Mutations
if (m_organism->TestDivideMut(ctx) && totalMutations < maxmut) {
const unsigned int mut_line = ctx.GetRandom().GetUInt(offspring_genome.GetSize());
+ char before_mutation = offspring_genome[mut_line].GetSymbol();
offspring_genome[mut_line] = m_inst_set->GetRandomInst(ctx);
+ offspring_genome.GetMutationSteps().AddSubstitutionMutation(mut_line, before_mutation, offspring_genome[mut_line].GetSymbol());
totalMutations++;
}
@@ -199,12 +201,14 @@
if (m_organism->TestDivideIns(ctx) && offspring_genome.GetSize() < MAX_CREATURE_SIZE && totalMutations < maxmut) {
const unsigned int mut_line = ctx.GetRandom().GetUInt(offspring_genome.GetSize() + 1);
offspring_genome.Insert(mut_line, m_inst_set->GetRandomInst(ctx));
+ offspring_genome.GetMutationSteps().AddInsertionMutation(mut_line, offspring_genome[mut_line].GetSymbol());
totalMutations++;
}
// Divide Deletions
if (m_organism->TestDivideDel(ctx) && offspring_genome.GetSize() > MIN_CREATURE_SIZE && totalMutations < maxmut) {
const unsigned int mut_line = ctx.GetRandom().GetUInt(offspring_genome.GetSize());
+ offspring_genome.GetMutationSteps().AddDeletionMutation(mut_line, offspring_genome[mut_line].GetSymbol());
offspring_genome.Remove(mut_line);
totalMutations++;
}
@@ -226,7 +230,9 @@
if (num_mut > 0 && totalMutations < maxmut) {
for (int i = 0; i < num_mut && totalMutations < maxmut; i++) {
int site = ctx.GetRandom().GetUInt(offspring_genome.GetSize());
+ char before_mutation = offspring_genome[site].GetSymbol();
offspring_genome[site] = m_inst_set->GetRandomInst(ctx);
+ offspring_genome.GetMutationSteps().AddSubstitutionMutation(site, before_mutation, offspring_genome[site].GetSymbol());
totalMutations++;
}
}
@@ -237,7 +243,7 @@
if (m_organism->GetDivInsProb() > 0 && totalMutations < maxmut) {
int num_mut = ctx.GetRandom().GetRandBinomial(offspring_genome.GetSize(), m_organism->GetDivInsProb());
- // If would make creature to big, insert up to MAX_CREATURE_SIZE
+ // If would make creature too big, insert up to MAX_CREATURE_SIZE
if (num_mut + offspring_genome.GetSize() > MAX_CREATURE_SIZE) {
num_mut = MAX_CREATURE_SIZE - offspring_genome.GetSize();
}
@@ -252,6 +258,7 @@
// Actually do the mutations (in reverse sort order)
for (int i = mut_sites.GetSize() - 1; i >= 0; i--) {
offspring_genome.Insert(mut_sites[i], m_inst_set->GetRandomInst(ctx));
+ offspring_genome.GetMutationSteps().AddInsertionMutation(mut_sites[i], offspring_genome[mut_sites[i]].GetSymbol());
}
totalMutations += num_mut;
@@ -270,7 +277,9 @@
// If we have lines to delete...
for (int i = 0; i < num_mut; i++) {
- offspring_genome.Remove(ctx.GetRandom().GetUInt(offspring_genome.GetSize()));
+ int site = ctx.GetRandom().GetUInt(offspring_genome.GetSize());
+ offspring_genome.GetMutationSteps().AddDeletionMutation(site, offspring_genome[site].GetSymbol());
+ offspring_genome.Remove(site);
}
totalMutations += num_mut;
@@ -372,19 +381,22 @@
copied_so_far.SetAll(false);
for (int i = 0; i < insertion_length; i++) {
switch (m_world->GetConfig().SLIP_FILL_MODE.Get()) {
+ //Duplication
case 0:
genome[from + i] = genome_copy[to + i];
- break;
-
+ break;
+
+ //Empty (nop-X)
case 1:
genome[from + i] = m_inst_set->GetInst("nop-X");
- break;
-
+ break;
+
+ //Random
case 2:
genome[from + i] = m_inst_set->GetRandomInst(ctx);
- break;
+ break;
- //Randomized order of instructions
+ //Scrambled order
case 3:
{
int copy_index = m_world->GetRandom().GetInt(insertion_length - i);
@@ -401,7 +413,12 @@
genome[from + i] = genome[to + copy_index];
copied_so_far[copy_index] = true;
}
- break;
+ break;
+
+ //Empty (nop-C)
+ case 4:
+ genome[from + i] = m_inst_set->GetInst("nop-C");
+ break;
default:
m_world->GetDriver().RaiseException("Unknown SLIP_FILL_MODE\n");
@@ -412,6 +429,7 @@
// Deletion / remaining genome
if (insertion_length < 0) insertion_length = 0;
for (int i = insertion_length; i < genome_copy.GetSize() - to; i++) genome[from + i] = genome_copy[to + i];
+ genome.GetMutationSteps().AddSlipMutation(from, to);
if (m_world->GetVerbosity() >= VERBOSE_DETAILS) {
cout << "SLIP MUTATION from " << from << " to " << to << endl;
Modified: development/source/main/cAvidaConfig.h
===================================================================
--- development/source/main/cAvidaConfig.h 2009-01-16 16:22:13 UTC (rev 3120)
+++ development/source/main/cAvidaConfig.h 2009-01-16 18:41:14 UTC (rev 3121)
@@ -361,7 +361,7 @@
CONFIG_ADD_VAR(SAME_LENGTH_SEX, int, 0, "0 = recombine with any genome\n1 = only recombine w/ same length");
CONFIG_ADD_GROUP(DIVIDE_GROUP, "Divide Restrictions");
- CONFIG_ADD_VAR(CHILD_SIZE_RANGE, double, 2.0, "Maximal differential between child and parent sizes.");
+ CONFIG_ADD_VAR(CHILD_SIZE_RANGE, double, 2.0, "Maximal differential between child and parent sizes.\n(Checked BEFORE mutations applied on divide.)");
CONFIG_ADD_VAR(MIN_COPIED_LINES, double, 0.5, "Code fraction which must be copied before divide.");
CONFIG_ADD_VAR(MIN_EXE_LINES, double, 0.5, "Code fraction which must be executed before divide.");
CONFIG_ADD_VAR(MIN_GENOME_SIZE, int, 0, "Minimum number of instructions allowed in a genome. 0 = OFF");
@@ -391,7 +391,7 @@
CONFIG_ADD_VAR(DIV_INS_PROB, double, 0.0, "Insertion rate (per site, applied on divide)");
CONFIG_ADD_VAR(DIV_DEL_PROB, double, 0.0, "Deletion rate (per site, applied on divide)");
CONFIG_ADD_VAR(DIV_UNIFORM_PROB, double, 0.0, "Uniform mutation probability (per site, applied on divide)\n- Randomly applies any of the three classes of mutations (ins, del, point).");
- CONFIG_ADD_VAR(DIV_SLIP_PROB, double, 0.0, "Slip rate");
+ CONFIG_ADD_VAR(DIV_SLIP_PROB, double, 0.0, "Slip rate (per site, applied on divide)");
CONFIG_ADD_VAR(DIVIDE_MUT_PROB, double, 0.0, "Mutation rate (per divide)");
CONFIG_ADD_VAR(DIVIDE_INS_PROB, double, 0.05, "Insertion rate (per divide)");
@@ -403,7 +403,7 @@
CONFIG_ADD_VAR(INJECT_DEL_PROB, double, 0.0, "Deletion rate (per site, applied on inject)");
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_FILL_MODE, int, 0, "Fill insertions from slip mutations with 0=duplication, 1=nop-X, 2=random, 3=scrambled, 4=nop-C");
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");
Modified: development/source/main/cGenome.cc
===================================================================
--- development/source/main/cGenome.cc 2009-01-16 16:22:13 UTC (rev 3120)
+++ development/source/main/cGenome.cc 2009-01-16 18:41:14 UTC (rev 3121)
@@ -35,7 +35,7 @@
}
cGenome::cGenome(const cGenome & in_genome)
- : genome(in_genome.GetSize()), active_size(in_genome.GetSize())
+ : genome(in_genome.GetSize()), active_size(in_genome.GetSize()), m_mutation_steps(in_genome.GetMutationSteps())
{
for (int i = 0; i < active_size; i++) genome[i] = in_genome[i];
}
@@ -84,6 +84,8 @@
for (int i = 0; i < active_size; i++) {
genome[i] = other_genome[i];
}
+
+ m_mutation_steps = other_genome.m_mutation_steps;
}
Modified: development/source/main/cGenome.h
===================================================================
--- development/source/main/cGenome.h 2009-01-16 16:22:13 UTC (rev 3120)
+++ development/source/main/cGenome.h 2009-01-16 18:41:14 UTC (rev 3121)
@@ -31,6 +31,9 @@
#ifndef cInstruction_h
#include "cInstruction.h"
#endif
+#ifndef cMutationSteps_h
+#include "cMutationSteps.h"
+#endif
#ifndef cString_h
#include "cString.h"
#endif
@@ -48,6 +51,7 @@
protected:
tArray<cInstruction> genome;
int active_size;
+ cMutationSteps m_mutation_steps;
public:
//! Default constructor.
@@ -74,6 +78,10 @@
int GetSize() const { return active_size; }
cString AsString() const;
+
+ cMutationSteps& GetMutationSteps() { return m_mutation_steps; }
+ const cMutationSteps& GetMutationSteps() const { return m_mutation_steps; }
+
};
Modified: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc 2009-01-16 16:22:13 UTC (rev 3120)
+++ development/source/main/cPopulation.cc 2009-01-16 18:41:14 UTC (rev 3121)
@@ -403,6 +403,9 @@
GetCell(target_cells[i]).Rotate(parent_cell);
}
}
+
+ // Purge the mutations since last division
+ parent_organism.ChildGenome().GetMutationSteps().Clear();
}
// Do any statistics on the parent that just gave birth...
Modified: development/source/tools/cStringUtil.cc
===================================================================
--- development/source/tools/cStringUtil.cc 2009-01-16 16:22:13 UTC (rev 3120)
+++ development/source/tools/cStringUtil.cc 2009-01-16 18:41:14 UTC (rev 3121)
@@ -184,144 +184,6 @@
return value;
}
-
-int cStringUtil::GapMinimizingEditDistance(const cString & string1, const cString & string2,
- cString & info, const char gap)
-{
- const int size1 = string1.GetSize();
- const int size2 = string2.GetSize();
-
- if (!size1) return size2;
- if (!size2) return size1;
-
- // Note: For both matrices, the first and last cols/rows
- // are for alignments to an end gap.
- tMatrix<double> dist_matrix(size2+2, size1+2);
-
- // Keep track of changes in a mut_matrix.
- // N=None, M=Mutations, I=Insertion, D=Deletion
- tMatrix<char> mut_matrix(size2+2, size1+2);
-
- // Initialize the last row and col to record the difference from nothing.
- for (int i = 0; i < size1+1; i++) {
- dist_matrix(size2+1,i) = (double) (size1+1 - i);
- mut_matrix(size2+1,i) = 'I';
- }
- for (int i = 0; i < size2+1; i++) {
- dist_matrix(i,size1+1) = (double) (size2+1 - i);
- mut_matrix(i,size1+1) = 'D';
- }
- mut_matrix(size2+1,size1+1) = 'N';
- dist_matrix(size2+1,size1+1) = (double) 0;
-
- for (int i = size2; i >= 0; i--) {
- // Move down the cur_row and fill it out.
- for (int j = size1; j >= 0; j--) {
- // Otherwise, set the current position to the minimal of the three
- // numbers above (insertion), to the left (deletion), or upper left
- // (mutation/match) plus one if the aligned positions do not match.
-
- char c1 = (j-1 >= 0) ? string1[j-1] : '\0';
- char c2 = (i-1 >= 0) ? string2[i-1] : '\0';
-
- bool matched = (c1 == c2);
- if (j-1 < 0 && i-1 <= 0) matched = 0;
- double match_dist = dist_matrix(i+1,j+1) + ((matched) ? 0 : 1);
-
- double ins_dist = dist_matrix(i+1,j) + 1;
- if (mut_matrix(i+1,j) != 'D') ins_dist += 0.0001;
- double del_dist = dist_matrix(i,j+1) + 1;
- if (mut_matrix(i,j+1) != 'I') del_dist += 0.0001;
-
- if (ins_dist <= del_dist && ins_dist <= match_dist) { // Insertion!
- dist_matrix(i,j) = ins_dist;
- mut_matrix(i,j) = 'D';
- } else if (match_dist <= del_dist) { // Mutation!
- dist_matrix(i,j) = match_dist;
- mut_matrix(i,j) = (matched) ? 'N' : 'M';
-
- } else { // Deletion!
- dist_matrix(i,j) = del_dist;
- mut_matrix(i,j) = 'I';
- }
- }
- }
- mut_matrix(size2+1,size1+1) = 'N';
- dist_matrix(size2+1,size1+1) = (double) 0;
-
- /* For debugging, print out matrices
- for (int i = 0; i <= size2+1; i++) {
- for (int j = 0; j <=size1+1; j++) {
- cout << dist_matrix(i,j) << " ";
- }
- cout << endl;
- }
-
- for (int i = 0; i <= size2+1; i++) {
- for (int j = 0; j <=size1+1; j++) {
- cout << mut_matrix(i,j) << " ";
- }
- cout << endl;
- }
- */
-
- // Construct the list of changes
- int pos1 = 0;
- int pos2 = 0;
- info = "";
-
- // We don't start at 0,0 (which would be an initial gap to an initial gap alignment)
- // Choose whether there are initial gaps.
- cString mut_string;
- bool first_time = true;
- while (pos1 < size1+1 || pos2 < size2+1) {
- if (mut_matrix(pos2, pos1) == 'N') {
- pos1++; pos2++;
- continue;
- }
-
- // There is a mutation here; determine the type...
- const char old_char = (pos2-1 < size2 && pos2>0) ? string2[pos2-1] : '\0';
- const char new_char = (pos1-1 < size1 && pos1>0) ? string1[pos1-1] : '\0';
-
- if (mut_matrix(pos2, pos1) == 'M') {
- mut_string.Set("M%d%c%c", pos2-1, old_char, new_char);
-
- // "Mutations" in the initial column are really alignments
- // with gaps so we must substitute insertions or deletions.
- if (pos1==0) {
- mut_string.Set("D%d%c", pos1, new_char);
- }
- if (pos2==0) {
- mut_string.Set("I%d%c", pos2, new_char);
- }
- pos1++; pos2++;
- }
- else if (mut_matrix(pos2, pos1) == 'D') {
- mut_string.Set("D%d%c", pos2-1, old_char);
- pos2++;
- }
- else { // if (mut_matrix(pos2+1, pos1+1) == 'I') {
- mut_string.Set("I%d%c", pos1-1, new_char);
- pos1++;
- }
-
- if (first_time) {
- first_time = false;
- continue;
- }
-
- /* For debugging, print out mutations found
- cout << mut_string << endl;
- */
- if (info.GetSize() > 0) mut_string.Insert(",");
- info += mut_string;
- }
-
- // Now that we are done, return the bottom-right corner of the chart.
- return (int) dist_matrix(0, 0);
-}
-
int cStringUtil::EditDistance(const cString & string1, const cString & string2,
cString & info, const char gap)
{
Modified: development/source/tools/cStringUtil.h
===================================================================
--- development/source/tools/cStringUtil.h 2009-01-16 16:22:13 UTC (rev 3120)
+++ development/source/tools/cStringUtil.h 2009-01-16 18:41:14 UTC (rev 3121)
@@ -65,7 +65,6 @@
**/
static int EditDistance(const cString& string1, const cString& string2);
static int EditDistance(const cString& string1, const cString& string2, cString& info, const char gap = ' ');
- static int GapMinimizingEditDistance(const cString& string1, const cString& string2, cString& info, const char gap = ' ');
/**
* Various, overloaded conversion functions for use in templates. Note
More information about the Avida-cvs
mailing list