[Avida-SVN] r3484 - in branches/tcmalloc-1.4: Avida.xcodeproj source/cpu source/main source/platform/tcmalloc source/tools
brysonda at myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Wed Oct 14 15:25:30 PDT 2009
Author: brysonda
Date: 2009-10-14 18:25:29 -0400 (Wed, 14 Oct 2009)
New Revision: 3484
Modified:
branches/tcmalloc-1.4/Avida.xcodeproj/project.pbxproj
branches/tcmalloc-1.4/source/cpu/cHardwareBase.cc
branches/tcmalloc-1.4/source/cpu/cHardwareCPU.cc
branches/tcmalloc-1.4/source/cpu/cHardwareExperimental.cc
branches/tcmalloc-1.4/source/cpu/cHardwareExperimental.h
branches/tcmalloc-1.4/source/cpu/cTestCPUInterface.h
branches/tcmalloc-1.4/source/main/avida.cc
branches/tcmalloc-1.4/source/main/cAvidaConfig.cc
branches/tcmalloc-1.4/source/main/cAvidaConfig.h
branches/tcmalloc-1.4/source/main/cGenomeUtil.cc
branches/tcmalloc-1.4/source/main/cGenomeUtil.h
branches/tcmalloc-1.4/source/main/cOrgInterface.h
branches/tcmalloc-1.4/source/main/cOrganism.cc
branches/tcmalloc-1.4/source/main/cOrganism.h
branches/tcmalloc-1.4/source/main/cPopulation.cc
branches/tcmalloc-1.4/source/main/cPopulationInterface.cc
branches/tcmalloc-1.4/source/main/cPopulationInterface.h
branches/tcmalloc-1.4/source/platform/tcmalloc/tcmalloc.cc
branches/tcmalloc-1.4/source/tools/cInitFile.cc
branches/tcmalloc-1.4/source/tools/cInitFile.h
Log:
Merge r3460:3483 from development into branches/tcmalloc-1.4
Modified: branches/tcmalloc-1.4/Avida.xcodeproj/project.pbxproj
===================================================================
--- branches/tcmalloc-1.4/Avida.xcodeproj/project.pbxproj 2009-10-14 20:58:19 UTC (rev 3483)
+++ branches/tcmalloc-1.4/Avida.xcodeproj/project.pbxproj 2009-10-14 22:25:29 UTC (rev 3484)
@@ -287,7 +287,7 @@
isa = PBXContainerItemProxy;
containerPortal = DCC30C4D0762532C008F7A48 /* Project object */;
proxyType = 1;
- remoteGlobalIDString = 7022469C107FC4F10079CD25 /* tcmalloc-1.4 */;
+ remoteGlobalIDString = 7022469C107FC4F10079CD25;
remoteInfo = "tcmalloc-1.4";
};
7023ECA60C0A436000362B9C /* PBXContainerItemProxy */ = {
Modified: branches/tcmalloc-1.4/source/cpu/cHardwareBase.cc
===================================================================
--- branches/tcmalloc-1.4/source/cpu/cHardwareBase.cc 2009-10-14 20:58:19 UTC (rev 3483)
+++ branches/tcmalloc-1.4/source/cpu/cHardwareBase.cc 2009-10-14 22:25:29 UTC (rev 3484)
@@ -238,8 +238,15 @@
m_organism->GetDivSlipProb() / mut_multiplier);
for (int i = 0; i < num_mut; i++) doSlipMutation(ctx, offspring_genome);
}
+
+ // HGT Mutations - NOT COUNTED
+ // These are location-dependent, hence they are implemented in cPopulationInterface.
+ if(m_world->GetConfig().ENABLE_HGT.Get()
+ && (m_world->GetConfig().HGT_MUTATION_P.Get() > 0.0)
+ && (ctx.GetRandom().P(m_world->GetConfig().HGT_MUTATION_P.Get()))) {
+ m_organism->GetOrgInterface().DoHGTMutation(ctx, offspring_genome);
+ }
-
// Divide Mutations
if (m_organism->TestDivideMut(ctx) && totalMutations < maxmut) {
const unsigned int mut_line = ctx.GetRandom().GetUInt(offspring_genome.GetSize());
Modified: branches/tcmalloc-1.4/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/tcmalloc-1.4/source/cpu/cHardwareCPU.cc 2009-10-14 20:58:19 UTC (rev 3483)
+++ branches/tcmalloc-1.4/source/cpu/cHardwareCPU.cc 2009-10-14 22:25:29 UTC (rev 3484)
@@ -6194,7 +6194,6 @@
} else
doSlipMutation(ctx, m_memory, write_head.GetPosition());
}
- m_organism->AttemptHGTInsertion(ctx);
read_head.Advance();
write_head.Advance();
Modified: branches/tcmalloc-1.4/source/cpu/cHardwareExperimental.cc
===================================================================
--- branches/tcmalloc-1.4/source/cpu/cHardwareExperimental.cc 2009-10-14 20:58:19 UTC (rev 3483)
+++ branches/tcmalloc-1.4/source/cpu/cHardwareExperimental.cc 2009-10-14 22:25:29 UTC (rev 3484)
@@ -39,6 +39,7 @@
#include "nMutation.h"
#include "cOrganism.h"
#include "cPhenotype.h"
+#include "cStateGrid.h"
#include "cStringUtil.h"
#include "cTestCPU.h"
#include "cWorldDriver.h"
@@ -191,7 +192,14 @@
tInstLibEntry<tMethod>("execurate", &cHardwareExperimental::Inst_Execurate),
tInstLibEntry<tMethod>("execurate-24", &cHardwareExperimental::Inst_Execurate24),
-
+
+ // State Grid instructions
+ tInstLibEntry<tMethod>("sg-move", &cHardwareExperimental::Inst_SGMove),
+ tInstLibEntry<tMethod>("sg-rotate-l", &cHardwareExperimental::Inst_SGRotateL),
+ tInstLibEntry<tMethod>("sg-rotate-r", &cHardwareExperimental::Inst_SGRotateR),
+ tInstLibEntry<tMethod>("sg-sense", &cHardwareExperimental::Inst_SGSense),
+
+
// DEPRECATED Instructions
tInstLibEntry<tMethod>("set-flow", &cHardwareExperimental::Inst_SetFlow, 0, "Set flow-head to position in ?CX?")
};
@@ -2072,3 +2080,88 @@
}
+bool cHardwareExperimental::Inst_SGMove(cAvidaContext& ctx)
+{
+ assert(m_ext_mem.GetSize() > 3);
+
+ const cStateGrid& sg = m_organism->GetStateGrid();
+
+ int& x = m_ext_mem[0];
+ int& y = m_ext_mem[1];
+
+ const int facing = m_ext_mem[2];
+
+ // State grid is treated as a 2-dimensional toroidal grid with size [0, width) and [0, height)
+ switch (facing) {
+ case 0: // N
+ if (++y == sg.GetHeight()) y = 0;
+ break;
+
+ case 1: // NE
+ if (++x == sg.GetWidth()) x = 0;
+ if (++y == sg.GetHeight()) y = 0;
+ break;
+
+ case 2: // E
+ if (++x == sg.GetWidth()) x = 0;
+ break;
+
+ case 3: // SE
+ if (++x == sg.GetWidth()) x = 0;
+ if (--y == -1) y = sg.GetHeight() - 1;
+ break;
+
+ case 4: // S
+ if (--y == -1) y = sg.GetHeight() - 1;
+ break;
+
+ case 5: // SW
+ if (--x == -1) x = sg.GetWidth() - 1;
+ if (--y == -1) y = sg.GetHeight() - 1;
+ break;
+
+ case 6: // W
+ if (--x == -1) x = sg.GetWidth() - 1;
+ break;
+
+ case 7: // NW
+ if (--x == -1) x = sg.GetWidth() - 1;
+ if (++y == sg.GetHeight()) y = 0;
+ break;
+
+ default:
+ assert(facing >= 0 && facing <= 7);
+ }
+
+ // Increment state observed count
+ m_ext_mem[3 + sg.GetStateAt(x, y)]++;
+
+ // Save this location in the movement history
+ m_ext_mem.Push(sg.GetIDFor(x, y));
+ return true;
+}
+
+bool cHardwareExperimental::Inst_SGRotateL(cAvidaContext& ctx)
+{
+ assert(m_ext_mem.GetSize() > 3);
+ if (--m_ext_mem[2] < 0) m_ext_mem[2] = 7;
+ return true;
+}
+
+bool cHardwareExperimental::Inst_SGRotateR(cAvidaContext& ctx)
+{
+ assert(m_ext_mem.GetSize() > 3);
+ if (++m_ext_mem[2] > 7) m_ext_mem[2] = 0;
+ return true;
+}
+
+bool cHardwareExperimental::Inst_SGSense(cAvidaContext& ctx)
+{
+ const cStateGrid& sg = m_organism->GetStateGrid();
+ const int reg_used = FindModifiedRegister(REG_BX);
+ setInternalValue(m_threads[m_cur_thread].reg[reg_used], sg.SenseStateAt(m_ext_mem[0], m_ext_mem[1]));
+ return true;
+}
+
+
+
Modified: branches/tcmalloc-1.4/source/cpu/cHardwareExperimental.h
===================================================================
--- branches/tcmalloc-1.4/source/cpu/cHardwareExperimental.h 2009-10-14 20:58:19 UTC (rev 3483)
+++ branches/tcmalloc-1.4/source/cpu/cHardwareExperimental.h 2009-10-14 22:25:29 UTC (rev 3484)
@@ -474,6 +474,12 @@
// Replication
bool Inst_Repro(cAvidaContext& ctx);
+
+ // State Grid Navigation
+ bool Inst_SGMove(cAvidaContext& ctx);
+ bool Inst_SGRotateL(cAvidaContext& ctx);
+ bool Inst_SGRotateR(cAvidaContext& ctx);
+ bool Inst_SGSense(cAvidaContext& ctx);
};
Modified: branches/tcmalloc-1.4/source/cpu/cTestCPUInterface.h
===================================================================
--- branches/tcmalloc-1.4/source/cpu/cTestCPUInterface.h 2009-10-14 20:58:19 UTC (rev 3483)
+++ branches/tcmalloc-1.4/source/cpu/cTestCPUInterface.h 2009-10-14 22:25:29 UTC (rev 3484)
@@ -112,6 +112,9 @@
void CreateLinkByXY(int x, int y, double weight=1.0) { }
//! Link this organism's cell to the cell with index idx.
void CreateLinkByIndex(int idx, double weight=1.0) { }
+
+ //! HGT mutation (does nothing).
+ void DoHGTMutation(cAvidaContext& ctx, cGenome& offspring) { }
};
Modified: branches/tcmalloc-1.4/source/main/avida.cc
===================================================================
--- branches/tcmalloc-1.4/source/main/avida.cc 2009-10-14 20:58:19 UTC (rev 3483)
+++ branches/tcmalloc-1.4/source/main/avida.cc 2009-10-14 22:25:29 UTC (rev 3484)
@@ -155,6 +155,7 @@
bool flag_review = false;
bool flag_verbosity = false; int val_verbosity = 0;
bool flag_seed = false; int val_seed = 0;
+ bool flag_warn_default = false;
// Then scan through and process the rest of the args.
while (arg_num < argc) {
@@ -189,6 +190,7 @@
<< " -set <name> <value> Override values in avida.cfg" << endl
<< " -v[ersion] Prints the version number" << endl
<< " -v0 -v1 -v2 -v3 -v4 Set output verbosity to 0..4" << endl
+ << " -w[arn] Warn when default config settings are used." << endl
<< endl;
exit(0);
@@ -206,6 +208,8 @@
flag_analyze = true;
} else if (cur_arg == "-interactive" || cur_arg == "-i") {
flag_interactive = true;
+ } else if (cur_arg == "-warn" || cur_arg == "-w") {
+ flag_warn_default = true;
} else if (cur_arg == "-load" || cur_arg == "-l") {
if (arg_num + 1 == argc || args[arg_num + 1][0] == '-') {
cerr << "Error: Must include a filename to load from." << endl;
@@ -261,7 +265,7 @@
delete [] args;
// Load configuration file
- cfg->Load(config_filename, defs, crash_if_not_found);
+ cfg->Load(config_filename, defs, crash_if_not_found, flag_warn_default);
// Process Command Line Flags
Modified: branches/tcmalloc-1.4/source/main/cAvidaConfig.cc
===================================================================
--- branches/tcmalloc-1.4/source/main/cAvidaConfig.cc 2009-10-14 20:58:19 UTC (rev 3483)
+++ branches/tcmalloc-1.4/source/main/cAvidaConfig.cc 2009-10-14 22:25:29 UTC (rev 3484)
@@ -62,7 +62,7 @@
}
-void cAvidaConfig::Load(const cString& filename, const tDictionary<cString>& mappings, bool crash_if_not_found)
+void cAvidaConfig::Load(const cString& filename, const tDictionary<cString>& mappings, bool crash_if_not_found, bool warn_default)
{
// Load the contents from the file.
cInitFile init_file(filename, mappings);
@@ -103,7 +103,7 @@
while ((cur_entry = entry_it.Next()) != NULL) {
const cString keyword = cur_entry->GetName();
const cString default_val = cur_entry->GetDefault();
- cur_entry->LoadString( init_file.ReadString(keyword, default_val) );
+ cur_entry->LoadString( init_file.ReadString(keyword, default_val, warn_default) );
}
}
Modified: branches/tcmalloc-1.4/source/main/cAvidaConfig.h
===================================================================
--- branches/tcmalloc-1.4/source/main/cAvidaConfig.h 2009-10-14 20:58:19 UTC (rev 3483)
+++ branches/tcmalloc-1.4/source/main/cAvidaConfig.h 2009-10-14 22:25:29 UTC (rev 3484)
@@ -306,6 +306,7 @@
CONFIG_ADD_VAR(NUM_DEMES, int, 1, "Number of independent groups in the\npopulation (default=1).");
CONFIG_ADD_VAR(DEMES_COMPETITION_STYLE, int, 0, "Select how the demes compete\n0=Fitness proportional\n1=Tournament");
CONFIG_ADD_VAR(DEMES_TOURNAMENT_SIZE, int, 0, "Number of demes that participate in a tournament");
+ CONFIG_ADD_VAR(DEMES_OVERRIDE_FITNESS, int, 0, "Whether the calculated fitness is used\n0=yes (default)\n1=no (all fitnesses=1)");
CONFIG_ADD_VAR(DEMES_USE_GERMLINE, int, 0, "Whether demes use a distinct germline (default=0).");
CONFIG_ADD_VAR(DEMES_PREVENT_STERILE, int, 0, "Whether to prevent sterile demes from\nreplicating (default=0 or no).");
CONFIG_ADD_VAR(DEMES_RESET_RESOURCES, int, 0, "Reset resources in demes on replication. \n0 = reset both demes \n1 = reset target deme \n2 = deme resources remain unchanged\n");
@@ -660,16 +661,16 @@
CONFIG_ADD_VAR(DEME_NETWORK_REQUIRES_CONNECTEDNESS, int, 1, "Whether the deme's network must be connected before an actual fitness is calculated.");
CONFIG_ADD_VAR(DEME_NETWORK_TOPOLOGY_FITNESS, int, 0, "Network measure used to determine fitness; see cDemeTopologyNetwork.h.");
- // -------- Horizontal gene transfer config options --------
+ // -------- Horizontal Gene Transfer (HGT) config options --------
CONFIG_ADD_GROUP(HGT_GROUP, "Horizontal gene transfer settings");
CONFIG_ADD_VAR(ENABLE_HGT, int, 0, "Whether HGT is enabled; 0=false (default),\n 1=true.");
CONFIG_ADD_VAR(HGT_FRAGMENT_SIZE_MEAN, double, 10, "Mean size of fragments (drawn from a normal\ndist., default=10).");
CONFIG_ADD_VAR(HGT_FRAGMENT_SIZE_VARIANCE, double, 2, "Variance of fragments (drawn from a normal\ndist., default=2).");
CONFIG_ADD_VAR(HGT_MAX_FRAGMENTS_PER_CELL, int, 100, "Max. allowed number of fragments\nper cell (default=100).");
CONFIG_ADD_VAR(HGT_DIFFUSION_METHOD, int, 0, "Method to use for diffusion of genome\nfragments (0=none [default]).");
- CONFIG_ADD_VAR(HGT_INSERTION_PROB, double, 0.0, "Probability that a genome fragment\nwill be inserted during a copy (default=0.0).");
- CONFIG_ADD_VAR(HGT_LOOKAHEAD_LENGTH, int, 4, "Number of instructions forward from the\nread head that will be used to calculate\nthe liklihood of HGT.");
-
+ CONFIG_ADD_VAR(HGT_MUTATION_P, double, 0.0, "Probability that an HGT mutation will occur on divide (default=0.0).");
+ CONFIG_ADD_VAR(HGT_INSERTION_MUT_P, double, 0.5, "Probability that an HGT mutation will result in an insertion (default=0.5); replacement if false.");
+
CONFIG_ADD_GROUP(INST_RES_GROUP, "Resource-Dependent Instructions Settings");
CONFIG_ADD_VAR(INST_RES, cString, "", "Resource upon which the execution of certain instruction depends");
CONFIG_ADD_VAR(INST_RES_FLOOR, double, 0.0, "Assumed lower level of resource in environment. Used for probability dist.");
@@ -684,7 +685,7 @@
inline void Load(const cString& filename) { Load(filename, false); }
void Load(const cString& filename, bool crash_if_not_found);
- void Load(const cString& filename, const tDictionary<cString>& mappings, bool crash_if_not_found = false);
+ void Load(const cString& filename, const tDictionary<cString>& mappings, bool crash_if_not_found = false, bool warn_default = true);
void Print(const cString& filename);
void Status();
void PrintReview();
Modified: branches/tcmalloc-1.4/source/main/cGenomeUtil.cc
===================================================================
--- branches/tcmalloc-1.4/source/main/cGenomeUtil.cc 2009-10-14 20:58:19 UTC (rev 3483)
+++ branches/tcmalloc-1.4/source/main/cGenomeUtil.cc 2009-10-14 22:25:29 UTC (rev 3484)
@@ -30,6 +30,8 @@
#include "cInitFile.h"
#include "cInstSet.h"
#include "functions.h"
+#include <algorithm>
+#include <strings.h>
using namespace std;
@@ -242,6 +244,84 @@
}
+/*! Return all matches of substring within base.
+
+ The return value here is somewhat incomplete. Eventually, the idea is that the
+ list of matches include the starting position of the match, the overall length (extent)
+ of the match, and the cost of the match. Right now, however, it only includes the cost.
+
+ \todo Convert this over to using two rows instead of len(substring)+1 rows (easy, but I'm being lazy).
+ */
+cGenomeUtil::substring_match_list_type cGenomeUtil::FindSubstringMatches(const cGenome& base, const cGenome& substring) {
+ substring_match_list_type ssml(base.GetSize());
+ const int rows=substring.GetSize()+1;
+ const int cols=base.GetSize()+1;
+ int costmat[rows][cols];
+ bzero(costmat, sizeof(int)*rows*cols);
+
+ // initialize the first row, first column, and match list starts.
+ for(int i=0; i<rows; ++i) { costmat[i][0] = i; }
+ for(int j=0; j<cols; ++j) { costmat[0][j] = 0; }
+ // for(int j=0; j<base.GetSize(); ++j) { ssml[j].start = j; ssml[j].extent = 0; }
+
+ // now do all the rest...
+ for(int i=1; i<rows; ++i) {
+ for(int j=1; j<cols; ++j) {
+ // we're only doing cost at the moment, so we can get away with something simple (i know, i know; space & time, etc., etc.):
+ int l[3] = { costmat[i-1][j-1], costmat[i-1][j], costmat[i][j-1] };
+ costmat[i][j] = *std::min_element(l,l+3) + (substring[i-1] == base[j-1]);
+// if we need to know the relationship among all three elements for tracking extents,
+// then this may be a good starting point:
+// A=above left, B=above, C=left
+// if(costmat[i-1][j-1] < costmat[i-1][j]) {
+// // A < B
+// if(costmat[i-1][j-1] < costmat[i][j-1]) {
+// // A < C --> A < (B,C)
+// costmat[i][j] = costmat[i-1][j-1];
+// ++ssml[j-1].extent;
+// } else {
+// // A >= C --> C <= (A,B)
+// costmat[i][j] = costmat[i][j-1];
+// ++ssml[j-1].extent;
+// }
+// } else {
+// // A >= B
+// if(costmat[i-1][j] < costmat[i][j-1]) {
+// // B < C --> B <= (A,C)
+// costmat[i][j] = costmat[i-1][j];
+// // extent unchanged
+// } else {
+// // B >= C --> C <= (A,B)
+// costmat[i][j] = costmat[i][j-1];
+// ++ssml[j-1].extent;
+// }
+// }
+//
+// // add the cost of a mismatch:
+// costmat[i][j] += (substring[j] == base[i]);
+ }
+ }
+
+ // copy match costs from the last row, skipping the null column (it can't ever be least):
+ for(int j=0; j<base.GetSize(); ++j) {
+ ssml[j].cost = costmat[rows-1][j+1];
+ ssml[j].position = j;
+ }
+
+ return ssml;
+}
+
+
+/*! Return the best match of substring within base.
+
+ \todo Ties for the value of the best match should be broken randomly.
+ */
+cGenomeUtil::substring_match cGenomeUtil::FindBestSubstringMatch(const cGenome& base, const cGenome& substring) {
+ substring_match_list_type ssml = FindSubstringMatches(base, substring);
+ return *std::min_element(ssml.begin(), ssml.end());
+}
+
+
cGenome cGenomeUtil::Crop(const cGenome & in_genome, int start, int end)
{
assert(end > start); // Must have a positive length clip!
Modified: branches/tcmalloc-1.4/source/main/cGenomeUtil.h
===================================================================
--- branches/tcmalloc-1.4/source/main/cGenomeUtil.h 2009-10-14 20:58:19 UTC (rev 3483)
+++ branches/tcmalloc-1.4/source/main/cGenomeUtil.h 2009-10-14 22:25:29 UTC (rev 3484)
@@ -29,6 +29,7 @@
#ifndef cGenome_h
#include "cGenome.h"
#endif
+#include <vector>
class cAvidaContext;
class cInstruction;
@@ -57,6 +58,24 @@
static int FindSlidingDistance(const cGenome& gen1, const cGenome& gen2);
static int FindEditDistance(const cGenome& gen1, const cGenome& gen2);
+ //! Substring match record.
+ struct substring_match {
+ //! Default constructor.
+ substring_match() : position(0), extent(0), cost(0) { }
+ //! Operator< overload.
+ bool operator<(const substring_match& sm) { return cost < sm.cost; }
+ int position; //!< Final position in the base string of this match.
+ int extent; //!< Length of the match in the base string.
+ int cost; //!< Cost (edit distance) of this match.
+ };
+
+ //! Type for a list of substring matches.
+ typedef std::vector<substring_match> substring_match_list_type;
+ //! Return all matches of substring within base.
+ static substring_match_list_type FindSubstringMatches(const cGenome& base, const cGenome& substring);
+ //! Return the best match of substring within base.
+ static substring_match FindBestSubstringMatch(const cGenome& base, const cGenome& substring);
+
// ===== Construction methods =====
static cGenome Crop(const cGenome& genome, int start, int end);
static cGenome Cut(const cGenome& genome, int start, int end);
Modified: branches/tcmalloc-1.4/source/main/cOrgInterface.h
===================================================================
--- branches/tcmalloc-1.4/source/main/cOrgInterface.h 2009-10-14 20:58:19 UTC (rev 3483)
+++ branches/tcmalloc-1.4/source/main/cOrgInterface.h 2009-10-14 22:25:29 UTC (rev 3484)
@@ -117,6 +117,7 @@
virtual void CreateLinkByFacing(double weight=1.0) = 0;
virtual void CreateLinkByXY(int x, int y, double weight=1.0) = 0;
virtual void CreateLinkByIndex(int idx, double weight=1.0) = 0;
+ virtual void DoHGTMutation(cAvidaContext& ctx, cGenome& offspring) = 0;
};
#endif
Modified: branches/tcmalloc-1.4/source/main/cOrganism.cc
===================================================================
--- branches/tcmalloc-1.4/source/main/cOrganism.cc 2009-10-14 20:58:19 UTC (rev 3483)
+++ branches/tcmalloc-1.4/source/main/cOrganism.cc 2009-10-14 22:25:29 UTC (rev 3484)
@@ -1231,48 +1231,3 @@
return val;
}
-
-/*! Tests for and attempts to perform an insertion of an HGT genome fragment
- into this organism's genome. Returns true if a genome fragment was inserted,
- false otherwise.
- */
-bool cOrganism::AttemptHGTInsertion(cAvidaContext& ctx) {
- if(!m_world->GetConfig().ENABLE_HGT.Get()
- || (m_world->GetConfig().HGT_INSERTION_PROB.Get()==0.0)) {
- return false;
- }
-
- int cellid = GetCellID();
- if(cellid == -1) { return false; } // test cpu, nothing to do.
- cPopulationCell& cell = m_world->GetPopulation().GetCell(cellid);
-
- // need to calculate the probability of inserting any of the fragments that live in
- // this organism's cell. this P() is partially based on the instructions near the
- // read head, so let's grab that fragment:
- cGenome nearby = m_hardware->GetGenomeFragment(m_world->GetConfig().HGT_LOOKAHEAD_LENGTH.Get());
-
- // get the list of genome fragments currently in this cell:
- typedef cPopulationCell::fragment_list_type fragment_list_type;
- fragment_list_type& fragments = cell.GetFragments();
-
- // now, the probability of selecting a fragment for insertion is a combination
- // of how long it's been in contact with this organism, a background rate, and
- // the similarity of this fragment to the nearby fragment. the oldest genomes
- // have the greatest chance of being inserted, because they've gone through this
- // loop multiple times.
- //
- // when a fragment is inserted, we also need to adjust the amount of hgt resource
- // present in the population, and do some stat tracking.
- for(fragment_list_type::iterator i=fragments.begin(); i!=fragments.end(); ++i) {
- int d = std::max(cGenomeUtil::FindHammingDistance(nearby, *i), 1);
- if(m_world->GetRandom().P(m_world->GetConfig().HGT_INSERTION_PROB.Get() / d)) {
- m_hardware->InsertGenomeFragment(*i);
- m_world->GetPopulation().AdjustHGTResource(-i->GetSize());
- m_world->GetStats().GenomeFragmentInserted(this, *i);
- fragments.erase(i);
- return true;
- }
- }
-
- return false;
-}
Modified: branches/tcmalloc-1.4/source/main/cOrganism.h
===================================================================
--- branches/tcmalloc-1.4/source/main/cOrganism.h 2009-10-14 20:58:19 UTC (rev 3483)
+++ branches/tcmalloc-1.4/source/main/cOrganism.h 2009-10-14 22:25:29 UTC (rev 3484)
@@ -646,11 +646,6 @@
/*! The main DoOutput function. The DoOutputs above all forward to this function. */
void doOutput(cAvidaContext& ctx, tBuffer<int>& input_buffer, tBuffer<int>& output_buffer, const bool on_divide);
-
- // -------- HGT methods --------
-public:
- //! Tests for and attempts to perform an insertion of an HGT genome fragment into this organism's genome.
- bool AttemptHGTInsertion(cAvidaContext& ctx);
};
Modified: branches/tcmalloc-1.4/source/main/cPopulation.cc
===================================================================
--- branches/tcmalloc-1.4/source/main/cPopulation.cc 2009-10-14 20:58:19 UTC (rev 3483)
+++ branches/tcmalloc-1.4/source/main/cPopulation.cc 2009-10-14 22:25:29 UTC (rev 3484)
@@ -294,7 +294,7 @@
// if HGT is on, make sure there's a resource for it:
if(m_world->GetConfig().ENABLE_HGT.Get() && (m_hgt_resid == -1)) {
- m_world->GetDriver().RaiseFatalException(-1, "HGT is enabled, but no HGT resource is defined; add hgt=1 to a single resource in the environment file.");
+ m_world->GetDriver().NotifyWarning("HGT is enabled, but no HGT resource is defined; add hgt=1 to a single resource in the environment file.");
}
}
@@ -1282,6 +1282,14 @@
return;
}
+ // to facilitate control runs, sometimes we want to know what the fitness values
+ // are, but we don't want competition to depend on them.
+ if(m_world->GetConfig().DEMES_OVERRIDE_FITNESS.Get()) {
+ for(int i=0; i<static_cast<int>(fitness.size()); ++i) {
+ fitness[i] = 1.0;
+ }
+ }
+
// Number of demes (at index) which should wind up in the next generation.
std::vector<unsigned int> deme_counts(deme_array.GetSize(), 0);
@@ -5893,7 +5901,9 @@
/*! Modify current level of the HGT resource.
*/
void cPopulation::AdjustHGTResource(double delta) {
- resource_count.Modify(m_hgt_resid, delta);
+ if(m_hgt_resid != -1) {
+ resource_count.Modify(m_hgt_resid, delta);
+ }
}
/*! Mix all organisms in the population.
Modified: branches/tcmalloc-1.4/source/main/cPopulationInterface.cc
===================================================================
--- branches/tcmalloc-1.4/source/main/cPopulationInterface.cc 2009-10-14 20:58:19 UTC (rev 3483)
+++ branches/tcmalloc-1.4/source/main/cPopulationInterface.cc 2009-10-14 22:25:29 UTC (rev 3484)
@@ -28,6 +28,7 @@
#include "cDeme.h"
#include "cEnvironment.h"
#include "cGenotype.h"
+#include "cGenomeUtil.h"
#include "cHardwareManager.h"
#include "cOrganism.h"
#include "cOrgSinkMessage.h"
@@ -38,6 +39,8 @@
#include "cTestCPU.h"
#include <cassert>
+#include <algorithm>
+#include <iterator>
#ifndef NULL
#define NULL 0
@@ -620,3 +623,72 @@
cPopulationCell& that_cell = deme->GetCell(idx % deme->GetSize());
deme->GetNetwork().Connect(*this_cell, that_cell, weight);
}
+
+
+/*! Perform an HGT mutation on this offspring.
+
+ HGT mutations are location-dependent, hence they are implemented here as opposed to
+ the CPU or organism.
+
+ If this method is called, an HGT mutation of some kind is imminent. All that's left
+ is to actually *do* the mutation. We only do *one* HGT mutation each time this method
+ is called.
+
+ \todo HGT should prefer more similar and older fragments.
+ \todo Enable replacement mutations.
+ */
+void cPopulationInterface::DoHGTMutation(cAvidaContext& ctx, cGenome& offspring) {
+ // get this organism's cell:
+ cPopulationCell& cell = m_world->GetPopulation().GetCell(m_cell_id);
+
+ // do we have any fragments available?
+ if(cell.CountGenomeFragments() == 0) { return; }
+
+ // randomly select the genome fragment for HGT:
+ typedef cPopulationCell::fragment_list_type fragment_list_type;
+ fragment_list_type& fragments = cell.GetFragments();
+ fragment_list_type::iterator f=fragments.begin();
+ std::advance(f, ctx.GetRandom().GetInt(fragments.size()));
+
+ // find the location within this organism's genome that best matches the selected fragment:
+ cGenomeUtil::substring_match ssm = cGenomeUtil::FindBestSubstringMatch(cell.GetOrganism()->GetGenome(), *f);
+
+ // there are (currently) two supported types of HGT mutations: insertions & replacements.
+ // which one are we doing?
+ if(ctx.GetRandom().P(m_world->GetConfig().HGT_INSERTION_MUT_P.Get())) {
+ // insertion: insert the fragment at the final location of the match:
+ offspring.Insert(ssm.position, *f);
+ } else {
+ // replacement: replace up to fragment size instructions in the genome.
+
+ // replacement counts forward, so let's get the starting index of where the
+ // fragment needs to go. *inclusive* of the final match position (so +1), and
+ // a floor at 0.
+ int start = std::max(ssm.position-f->GetSize()+1, 0);
+
+ offspring.Replace(start, ssm.position-start+1, *f);
+ }
+
+ // resource utilization, cleanup, and stats tracking:
+ m_world->GetPopulation().AdjustHGTResource(-f->GetSize());
+ m_world->GetStats().GenomeFragmentInserted(cell.GetOrganism(), *f);
+ fragments.erase(f);
+
+ // old code from a previous version of hgt, kept around for reference:
+ // // calculate the best match for each fragment:
+ // cGenomeUtil::substring_match_list_type match_list;
+ // for(fragment_list_type::iterator i=fragments.begin(); i!=fragments.end(); ++i) {
+ // match_list.push_back(cGenomeUtil::FindBestSubstringMatch(cell.GetOrganism()->GetGenome(), *i));
+ // }
+
+ // for(fragment_list_type::iterator i=fragments.begin(); i!=fragments.end(); ++i) {
+ // int d = std::max(cGenomeUtil::FindHammingDistance(nearby, *i), 1);
+ // if(m_world->GetRandom().P(m_world->GetConfig().HGT_INSERTION_PROB.Get() / d)) {
+ // m_hardware->InsertGenomeFragment(*i);
+ // m_world->GetPopulation().AdjustHGTResource(-i->GetSize());
+ // m_world->GetStats().GenomeFragmentInserted(this, *i);
+ // fragments.erase(i);
+ // return true;
+ // }
+ // }
+}
Modified: branches/tcmalloc-1.4/source/main/cPopulationInterface.h
===================================================================
--- branches/tcmalloc-1.4/source/main/cPopulationInterface.h 2009-10-14 20:58:19 UTC (rev 3483)
+++ branches/tcmalloc-1.4/source/main/cPopulationInterface.h 2009-10-14 22:25:29 UTC (rev 3484)
@@ -36,12 +36,13 @@
#include "cWorldDriver.h"
#endif
+class cAvidaContext;
class cDeme;
+class cGenome;
class cPopulation;
class cPopulationCell;
class cOrgMessage;
-
class cPopulationInterface : public cOrgInterface
{
private:
@@ -137,6 +138,11 @@
protected:
//! Internal-use method to consolidate message-sending code.
bool SendMessage(cOrgMessage& msg, cPopulationCell& rcell);
+
+ // -------- HGT support --------
+public:
+ //! Perform an HGT mutation on this offspring.
+ void DoHGTMutation(cAvidaContext& ctx, cGenome& offspring);
};
Modified: branches/tcmalloc-1.4/source/platform/tcmalloc/tcmalloc.cc
===================================================================
--- branches/tcmalloc-1.4/source/platform/tcmalloc/tcmalloc.cc 2009-10-14 20:58:19 UTC (rev 3483)
+++ branches/tcmalloc-1.4/source/platform/tcmalloc/tcmalloc.cc 2009-10-14 22:25:29 UTC (rev 3484)
@@ -438,7 +438,7 @@
class PageHeapAllocator {
private:
// How much to allocate from system at a time
- static const int kAllocIncrement = 128 << 10;
+ static const unsigned int kAllocIncrement = 128 << 10;
// Aligned size of T
static const size_t kAlignedSize
@@ -842,8 +842,8 @@
span->free = 0;
Event(span, 'A', n);
+ ASSERT(((int)span->length - 1) >= 0);
const unsigned int extra = span->length - n;
- ASSERT(extra >= 0);
if (extra > 0) {
Span* leftover = NewSpan(span->start + n, extra);
leftover->free = 1;
@@ -1372,7 +1372,7 @@
}
race_counter = t;
}
- ASSERT(t >= 0);
+// ASSERT(t >= 0);
ASSERT(t < kNumClasses);
if (t == locked_size_class) return false;
return central_cache[t].ShrinkCache(locked_size_class, force);
Modified: branches/tcmalloc-1.4/source/tools/cInitFile.cc
===================================================================
--- branches/tcmalloc-1.4/source/tools/cInitFile.cc 2009-10-14 20:58:19 UTC (rev 3483)
+++ branches/tcmalloc-1.4/source/tools/cInitFile.cc 2009-10-14 22:25:29 UTC (rev 3484)
@@ -249,7 +249,7 @@
}
-cString cInitFile::ReadString(const cString& name, cString def) const
+cString cInitFile::ReadString(const cString& name, cString def, bool warn_default) const
{
// See if we definately can't find the keyword.
if (name == "") return def;
@@ -257,8 +257,10 @@
// Search for the keyword.
cString cur_line;
if (Find(cur_line, name, 0) == false) {
- m_errors.PushRear(new cString(cStringUtil::Stringf("%s not in '%s', defaulting to: %s",
- (const char*)name, (const char*)m_filename, (const char*)def)));
+ if (warn_default) {
+ m_errors.PushRear(new cString(cStringUtil::Stringf("%s not in '%s', defaulting to: %s",
+ (const char*)name, (const char*)m_filename, (const char*)def)));
+ }
return def;
}
Modified: branches/tcmalloc-1.4/source/tools/cInitFile.h
===================================================================
--- branches/tcmalloc-1.4/source/tools/cInitFile.h 2009-10-14 20:58:19 UTC (rev 3483)
+++ branches/tcmalloc-1.4/source/tools/cInitFile.h 2009-10-14 22:25:29 UTC (rev 3484)
@@ -133,7 +133,7 @@
* one to set standard values that are used if the user does not override
* them.
**/
- cString ReadString(const cString& name, cString def = "") const;
+ cString ReadString(const cString& name, cString def = "", bool warn_default = true) const;
/**
* Looks over all lines loaded into the file, and warns if any of them
More information about the Avida-cvs
mailing list