[Avida-SVN] r3556 - development/source/main

dk at myxo.css.msu.edu dk at myxo.css.msu.edu
Tue Dec 15 13:42:24 PST 2009


Author: dk
Date: 2009-12-15 16:42:24 -0500 (Tue, 15 Dec 2009)
New Revision: 3556

Modified:
   development/source/main/cAvidaConfig.h
   development/source/main/cPopulationInterface.cc
   development/source/main/cPopulationInterface.h
Log:
HGT refactoring.

Modified: development/source/main/cAvidaConfig.h
===================================================================
--- development/source/main/cAvidaConfig.h	2009-12-15 21:18:26 UTC (rev 3555)
+++ development/source/main/cAvidaConfig.h	2009-12-15 21:42:24 UTC (rev 3556)
@@ -664,7 +664,7 @@
 	// -------- 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_SELECTION, int, 0, "Method used to select fragments for HGT mutation (0=random [default]\n1=trimmed selection).");
+	CONFIG_ADD_VAR(HGT_FRAGMENT_SELECTION, int, 0, "Method used to select fragments for HGT mutation (0=random [default]\n1=trimmed selection\n2=random placement).");
 	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).");

Modified: development/source/main/cPopulationInterface.cc
===================================================================
--- development/source/main/cPopulationInterface.cc	2009-12-15 21:18:26 UTC (rev 3555)
+++ development/source/main/cPopulationInterface.cc	2009-12-15 21:42:24 UTC (rev 3556)
@@ -651,6 +651,10 @@
 			HGTTrimmedFragmentSelection(ctx, offspring, cell.GetFragments(), selected, location);
 			break;
 		}
+		case 2: { // random selection and random placement
+			HGTRandomFragmentPlacement(ctx, offspring, cell.GetFragments(), selected, location);
+			break;
+		}
 		default: { // error
 			m_world->GetDriver().RaiseFatalException(1, "HGT_FRAGMENT_SELECTION is set to an invalid value.");
 			break;
@@ -682,7 +686,7 @@
 																											substring_match& location) {
 	// randomly select the genome fragment for HGT:
 	selected=fragments.begin();
-	std::advance(selected, ctx.GetRandom().GetInt(fragments.size()));
+	std::advance(selected, ctx.GetRandom().GetUInt(fragments.size()));
 
 	// find the location within the offspring's genome that best matches the selected fragment:
 	location = cGenomeUtil::FindUnbiasedCircularMatch(ctx, offspring, *selected);
@@ -703,7 +707,7 @@
 																											 substring_match& location) {
 	// randomly select the genome fragment for HGT:
 	selected=fragments.begin();
-	std::advance(selected, ctx.GetRandom().GetInt(fragments.size()));
+	std::advance(selected, ctx.GetRandom().GetUInt(fragments.size()));
 	
 	// copy the selected fragment, trimming redundant instructions at the end:
 	cGenome trimmed(*selected);
@@ -714,3 +718,25 @@
 	// find the location within the offspring's genome that best matches the selected fragment:
 	location = cGenomeUtil::FindUnbiasedCircularMatch(ctx, offspring, trimmed);
 }
+
+
+/*! Random selection of the fragment used for HGT mutation, located at a random position.
+ 
+ Here we select a random fragment and a random location for that fragment within the offspring.
+ The beginning of the fragment location is selected at random, while the end is selected a
+ random distance (up to the length of the selected fragment * 2) instructions away.
+ */
+void cPopulationInterface::HGTRandomFragmentPlacement(cAvidaContext& ctx, const cGenome& offspring,
+																fragment_list_type& fragments, fragment_list_type::iterator& selected,
+																substring_match& location) {
+	// randomly select the genome fragment for HGT:
+	selected=fragments.begin();
+	std::advance(selected, ctx.GetRandom().GetUInt(fragments.size()));
+
+	// select a random location within the offspring's genome for this fragment to be
+	// inserted:
+	location.begin = ctx.GetRandom().GetUInt(offspring.GetSize());
+	location.end = location.begin + ctx.GetRandom().GetUInt(selected->GetSize()*2);
+	location.size = offspring.GetSize();
+	location.resize(offspring.GetSize());
+}

Modified: development/source/main/cPopulationInterface.h
===================================================================
--- development/source/main/cPopulationInterface.h	2009-12-15 21:18:26 UTC (rev 3555)
+++ development/source/main/cPopulationInterface.h	2009-12-15 21:42:24 UTC (rev 3556)
@@ -149,7 +149,7 @@
 	//! Perform an HGT mutation on this offspring.
 	void DoHGTMutation(cAvidaContext& ctx, cGenome& offspring);
 protected:
-	//! Random selection of the fragment used for HGT mutation.
+	//! Random selection of the fragment used for HGT mutation, located at the best match.
 	void HGTRandomFragmentSelection(cAvidaContext& ctx, const cGenome& offspring,
 																	fragment_list_type& fragments, fragment_list_type::iterator& selected,
 																	substring_match& location);
@@ -157,6 +157,10 @@
 	void HGTTrimmedFragmentSelection(cAvidaContext& ctx, const cGenome& offspring,
 																	 fragment_list_type& fragments, fragment_list_type::iterator& selected,
 																	 substring_match& location);	
+	//! Random selection of the fragment used for HGT mutation, located at a random position.
+	void HGTRandomFragmentPlacement(cAvidaContext& ctx, const cGenome& offspring,
+																	fragment_list_type& fragments, fragment_list_type::iterator& selected,
+																	substring_match& location);	
 };
 
 




More information about the Avida-cvs mailing list