[Avida-SVN] r3558 - in branches/parasites: . documentation source/actions source/cpu source/main source/tools tests/default_transsmt_100u

brysonda at myxo.css.msu.edu brysonda at myxo.css.msu.edu
Wed Dec 16 07:51:37 PST 2009


Author: brysonda
Date: 2009-12-16 10:51:37 -0500 (Wed, 16 Dec 2009)
New Revision: 3558

Modified:
   branches/parasites/Avida.vcproj
   branches/parasites/documentation/actions.html
   branches/parasites/documentation/environment.html
   branches/parasites/documentation/svn.html
   branches/parasites/source/actions/PopulationActions.cc
   branches/parasites/source/cpu/cHardwareExperimental.cc
   branches/parasites/source/cpu/cHardwareExperimental.h
   branches/parasites/source/main/cAvidaConfig.h
   branches/parasites/source/main/cEnvironment.cc
   branches/parasites/source/main/cGenome.cc
   branches/parasites/source/main/cGenome.h
   branches/parasites/source/main/cGenomeUtil.cc
   branches/parasites/source/main/cGenomeUtil.h
   branches/parasites/source/main/cPopulationCell.cc
   branches/parasites/source/main/cPopulationInterface.cc
   branches/parasites/source/main/cPopulationInterface.h
   branches/parasites/source/main/cReactionProcess.h
   branches/parasites/source/main/cStats.cc
   branches/parasites/source/main/cStats.h
   branches/parasites/source/tools/cBitArray.h
   branches/parasites/tests/default_transsmt_100u/test_list
Log:
Merge r3507:3557 from development into branches/parasites

Modified: branches/parasites/Avida.vcproj
===================================================================
--- branches/parasites/Avida.vcproj	2009-12-15 22:39:52 UTC (rev 3557)
+++ branches/parasites/Avida.vcproj	2009-12-16 15:51:37 UTC (rev 3558)
@@ -297,6 +297,38 @@
 				>
 			</File>
 			<File
+				RelativePath=".\source\main\cBirthDemeHandler.h"
+				>
+			</File>
+			<File
+				RelativePath=".\source\main\cBirthGenomeSizeHandler.h"
+				>
+			</File>
+			<File
+				RelativePath=".\source\main\cBirthGlobalHandler.h"
+				>
+			</File>
+			<File
+				RelativePath=".\source\main\cBirthGridLocalHandler.h"
+				>
+			</File>
+			<File
+				RelativePath=".\source\main\cBirthMateSelectHandler.h"
+				>
+			</File>
+			<File
+				RelativePath=".\source\main\cBirthNeighborhoodHandler.h"
+				>
+			</File>
+			<File
+				RelativePath=".\source\main\cBirthSelectionHandler.h"
+				>
+			</File>
+			<File
+				RelativePath=".\source\tools\cBitArray.h"
+				>
+			</File>
+			<File
 				RelativePath=".\source\tools\cBlockStruct.h"
 				>
 			</File>
@@ -377,10 +409,26 @@
 				>
 			</File>
 			<File
+				RelativePath=".\source\main\cDemeNetwork.h"
+				>
+			</File>
+			<File
+				RelativePath=".\source\main\cDemeNetworkUtils.h"
+				>
+			</File>
+			<File
+				RelativePath=".\source\main\cDemePredicate.h"
+				>
+			</File>
+			<File
 				RelativePath=".\source\tools\cDemeProbSchedule.h"
 				>
 			</File>
 			<File
+				RelativePath=".\source\main\cDemeTopologyNetwork.h"
+				>
+			</File>
+			<File
 				RelativePath=".\source\tools\cDoubleSum.h"
 				>
 			</File>
@@ -1173,6 +1221,38 @@
 				>
 			</File>
 			<File
+				RelativePath=".\source\main\cBirthDemeHandler.cc"
+				>
+			</File>
+			<File
+				RelativePath=".\source\main\cBirthGenomeSizeHandler.cc"
+				>
+			</File>
+			<File
+				RelativePath=".\source\main\cBirthGlobalHandler.cc"
+				>
+			</File>
+			<File
+				RelativePath=".\source\main\cBirthGridLocalHandler.cc"
+				>
+			</File>
+			<File
+				RelativePath=".\source\main\cBirthMateSelectHandler.cc"
+				>
+			</File>
+			<File
+				RelativePath=".\source\main\cBirthNeighborhoodHandler.cc"
+				>
+			</File>
+			<File
+				RelativePath=".\source\main\cBirthSelectionHandler.cc"
+				>
+			</File>
+			<File
+				RelativePath=".\source\tools\cBitArray.cc"
+				>
+			</File>
+			<File
 				RelativePath=".\source\tools\cBlockStruct.cc"
 				>
 			</File>
@@ -1245,11 +1325,15 @@
 				>
 			</File>
 			<File
+				RelativePath=".\source\main\cDemeNetwork.cc"
+				>
+			</File>
+			<File
 				RelativePath=".\source\tools\cDemeProbSchedule.cc"
 				>
 			</File>
 			<File
-				RelativePath=".\source\tools\cDoubleSum.cc"
+				RelativePath=".\source\main\cDemeTopologyNetwork.cc"
 				>
 			</File>
 			<File

Modified: branches/parasites/documentation/actions.html
===================================================================
--- branches/parasites/documentation/actions.html	2009-12-15 22:39:52 UTC (rev 3557)
+++ branches/parasites/documentation/actions.html	2009-12-16 15:51:37 UTC (rev 3558)
@@ -9,7 +9,7 @@
 
 <div class="revision">
 Revised 2006-09-03 DMB
-<br>Generated Thu Sep  3 20:49:10 2009 by make_actions_html</div>
+<br>Generated Mon Nov 16 13:42:09 2009 by make_actions_html</div>
 
 <p>
 <a href="index.html">Return to the Index</a> &nbsp;|&nbsp;
@@ -74,10 +74,14 @@
       <a href="#ConnectCells">ConnectCells</a><br>
       <a href="#copy_deme">copy_deme</a><br>
       <a href="#CopyDeme">CopyDeme</a><br>
+      <a href="#CountMultipleOpinions">CountMultipleOpinions</a><br>
+      <a href="#CountOpinions">CountOpinions</a><br>
       <a href="#DecayPoints">DecayPoints</a><br>
       <a href="#DelayedDemeEvent">DelayedDemeEvent</a><br>
       <a href="#DelayedDemeEventsPerSlots">DelayedDemeEventsPerSlots</a><br>
       <a href="#DeletionLandscape">DeletionLandscape</a><br>
+      <a href="#DemeBalanceTwoTasks">DemeBalanceTwoTasks</a><br>
+      <a href="#DemeReactionDiversity">DemeReactionDiversity</a><br>
       <a href="#DemeResourceThresholdPredicate">DemeResourceThresholdPredicate</a><br>
       <a href="#Desynchronization">Desynchronization</a><br>
       <a href="#detail_parasite_pop">detail_parasite_pop</a><br>
@@ -86,6 +90,8 @@
       <a href="#DiffuseHGTGenomeFragments">DiffuseHGTGenomeFragments</a><br>
       <a href="#DisconnectCells">DisconnectCells</a><br>
       <a href="#disconnect_cells">disconnect_cells</a><br>
+      <a href="#DistributeData">DistributeData</a><br>
+      <a href="#DistributeDataEfficiently">DistributeDataEfficiently</a><br>
       <a href="#DivideDemes">DivideDemes</a><br>
       <a href="#DumpCellDataGrid">DumpCellDataGrid</a><br>
       <a href="#dump_donor_grid">dump_donor_grid</a><br>
@@ -95,6 +101,7 @@
       <a href="#dump_fitness_grid">dump_fitness_grid</a><br>
       <a href="#DumpFitnessGrid">DumpFitnessGrid</a><br>
       <a href="#dump_genotype_grid">dump_genotype_grid</a><br>
+      <a href="#DumpGenotypeColorGrid">DumpGenotypeColorGrid</a><br>
       <a href="#DumpGenotypeIDGrid">DumpGenotypeIDGrid</a><br>
       <a href="#dump_historic_pop">dump_historic_pop</a><br>
       <a href="#dump_historic_sex_pop">dump_historic_sex_pop</a><br>
@@ -164,17 +171,18 @@
       <a href="#KillRate">KillRate</a><br>
       <a href="#KillRectangle">KillRectangle</a><br>
       <a href="#kill_rectangle">kill_rectangle</a><br>
+      <a href="#KillWithinRadiusBelowResourceThreshold">KillWithinRadiusBelowResourceThreshold</a><br>
       <a href="#LoadClone">LoadClone</a><br>
       <a href="#load_clone">load_clone</a><br>
       <a href="#load_dump_file">load_dump_file</a><br>
       <a href="#LoadPopulation">LoadPopulation</a><br>
       <a href="#LoadStructuredPopulation">LoadStructuredPopulation</a><br>
       <a href="#MigrateDemes">MigrateDemes</a><br>
+    <td valign="top">
       <a href="#MixPopulation">MixPopulation</a><br>
       <a href="#ModMutProb">ModMutProb</a><br>
       <a href="#MutationalNeighborhood">MutationalNeighborhood</a><br>
       <a href="#new_trial">new_trial</a><br>
-    <td valign="top">
       <a href="#NewTrial">NewTrial</a><br>
       <a href="#outflow_scaled_resource">outflow_scaled_resource</a><br>
       <a href="#OutflowScaledResource">OutflowScaledResource</a><br>
@@ -186,6 +194,7 @@
       <a href="#Pred_DemeEventNUniqueIndividualsMovedIntoTarget">Pred_DemeEventNUniqueIndividualsMovedIntoTarget</a><br>
       <a href="#PredictNuLandscape">PredictNuLandscape</a><br>
       <a href="#PredictWLandscape">PredictWLandscape</a><br>
+      <a href="#PrintAveNumTasks">PrintAveNumTasks</a><br>
       <a href="#print_average_data">print_average_data</a><br>
       <a href="#PrintAverageData">PrintAverageData</a><br>
       <a href="#PrintAvgDemeTasksExeData">PrintAvgDemeTasksExeData</a><br>
@@ -197,6 +206,7 @@
       <a href="#PrintCellData">PrintCellData</a><br>
       <a href="#PrintCellVisitsData">PrintCellVisitsData</a><br>
       <a href="#PrintCompetitionData">PrintCompetitionData</a><br>
+      <a href="#PrintConsensusData">PrintConsensusData</a><br>
       <a href="#print_count_data">print_count_data</a><br>
       <a href="#PrintCountData">PrintCountData</a><br>
       <a href="#PrintCurrentMeanDemeDensity">PrintCurrentMeanDemeDensity</a><br>
@@ -287,13 +297,14 @@
       <a href="#PrintMutationRateData">PrintMutationRateData</a><br>
       <a href="#PrintNewReactionData">PrintNewReactionData</a><br>
       <a href="#PrintNewTasksData">PrintNewTasksData</a><br>
+      <a href="#PrintNewTasksDataPlus">PrintNewTasksDataPlus</a><br>
       <a href="#print_number_phenotypes">print_number_phenotypes</a><br>
       <a href="#PrintNumOrgsInDeme">PrintNumOrgsInDeme</a><br>
       <a href="#PrintNumOrgsKilledData">PrintNumOrgsKilledData</a><br>
+    <td valign="top">
       <a href="#PrintOpinionsSetPerDeme">PrintOpinionsSetPerDeme</a><br>
       <a href="#PrintParasiteData">PrintParasiteData</a><br>
       <a href="#PrintPerDemeGenPerFounderData">PrintPerDemeGenPerFounderData</a><br>
-    <td valign="top">
       <a href="#PrintPerDemeReactionData">PrintPerDemeReactionData</a><br>
       <a href="#PrintPerDemeTasksData">PrintPerDemeTasksData</a><br>
       <a href="#PrintPerDemeTasksExeData">PrintPerDemeTasksExeData</a><br>
@@ -314,6 +325,7 @@
       <a href="#PrintSenseData">PrintSenseData</a><br>
       <a href="#PrintSenseExeData">PrintSenseExeData</a><br>
       <a href="#PrintShadedAltruists">PrintShadedAltruists</a><br>
+      <a href="#PrintSimpleConsensusData">PrintSimpleConsensusData</a><br>
       <a href="#PrintSleepData">PrintSleepData</a><br>
       <a href="#print_species_abundance_histogram">print_species_abundance_histogram</a><br>
       <a href="#PrintSpeciesAbundanceHistogram">PrintSpeciesAbundanceHistogram</a><br>
@@ -341,6 +353,7 @@
       <a href="#PrintViableTasksData">PrintViableTasksData</a><br>
       <a href="#RandomLandscape">RandomLandscape</a><br>
       <a href="#rate_kill">rate_kill</a><br>
+      <a href="#ReplaceFromGermline">ReplaceFromGermline</a><br>
       <a href="#replicate_demes">replicate_demes</a><br>
       <a href="#ReplicateDemes">ReplicateDemes</a><br>
       <a href="#reset_demes">reset_demes</a><br>
@@ -408,6 +421,7 @@
       <a href="#ToggleFitnessValley">ToggleFitnessValley</a><br>
       <a href="#ToggleRewardInstruction">ToggleRewardInstruction</a><br>
       <a href="#TrackAllMessages">TrackAllMessages</a><br>
+      <a href="#UnitFitness">UnitFitness</a><br>
       <a href="#VERBOSE">VERBOSE</a><br>
       <a href="#zero_muts">zero_muts</a><br>
       <a href="#ZeroMuts">ZeroMuts</a><br>
@@ -1048,7 +1062,7 @@
 </li>
 <li><p>
   <strong><a name="AssignRandomCellData">AssignRandomCellData</a></strong>
-  <i>No Arguments</i>
+  <i>[num_cells=deme_size]</i>
   </p>
   <p>
   
@@ -1182,6 +1196,20 @@
   </p>
 </li>
 <li><p>
+  <strong><a name="CountMultipleOpinions">CountMultipleOpinions</a></strong>
+  </p>
+  <p>
+  
+  </p>
+</li>
+<li><p>
+  <strong><a name="CountOpinions">CountOpinions</a></strong>
+  </p>
+  <p>
+  
+  </p>
+</li>
+<li><p>
   <strong><a name="DecayPoints">DecayPoints</a></strong>
   </p>
   <p>
@@ -1191,6 +1219,20 @@
   </p>
 </li>
 <li><p>
+  <strong><a name="DemeBalanceTwoTasks">DemeBalanceTwoTasks</a></strong>
+  </p>
+  <p>
+  
+  </p>
+</li>
+<li><p>
+  <strong><a name="DemeReactionDiversity">DemeReactionDiversity</a></strong>
+  </p>
+  <p>
+  
+  </p>
+</li>
+<li><p>
   <strong><a name="DemeResourceThresholdPredicate">DemeResourceThresholdPredicate</a></strong>
   </p>
   <p>
@@ -1230,6 +1272,20 @@
   </p>
 </li>
 <li><p>
+  <strong><a name="DistributeData">DistributeData</a></strong>
+  </p>
+  <p>
+  
+  </p>
+</li>
+<li><p>
+  <strong><a name="DistributeDataEfficiently">DistributeDataEfficiently</a></strong>
+  </p>
+  <p>
+  
+  </p>
+</li>
+<li><p>
   <strong><a name="DivideDemes">DivideDemes</a></strong>
   <i>No arguments (yet!)</i>
   </p>
@@ -1419,7 +1475,7 @@
 </li>
 <li><p>
   <strong><a name="IteratedConsensus">IteratedConsensus</a></strong>
-  <i>[int compete_period=100 [int replace_number=0]]</i>
+  <i>[int compete_period=100 [int replace_number=1 [int kill=1 [int restrict_range=1]]]]</i>
   </p>
   <p>
   
@@ -1555,6 +1611,14 @@
   </p>
 </li>
 <li><p>
+  <strong><a name="KillWithinRadiusBelowResourceThreshold">KillWithinRadiusBelowResourceThreshold</a></strong>
+  <i>[int numradii=0, int radius=0, string resource name, double threshold=0]</i>
+  </p>
+  <p>
+  
+  </p>
+</li>
+<li><p>
   <strong><a name="MigrateDemes">MigrateDemes</a></strong>
   <i>&lt;string resource name&gt;&lt;double failure_percent&gt;</i>
   </p>
@@ -1630,6 +1694,13 @@
   </p>
 </li>
 <li><p>
+  <strong><a name="ReplaceFromGermline">ReplaceFromGermline</a></strong>
+  </p>
+  <p>
+  
+  </p>
+</li>
+<li><p>
   <strong><a name="replicate_demes">replicate_demes</a></strong>
   <i>[string trigger=full_deme]</i>
   </p>
@@ -1813,6 +1884,13 @@
   </p>
 </li>
 <li><p>
+  <strong><a name="UnitFitness">UnitFitness</a></strong>
+  </p>
+  <p>
+  
+  </p>
+</li>
+<li><p>
   <strong><a name="zero_muts">zero_muts</a></strong>
   <i>No Arguments</i>
   </p>
@@ -1908,6 +1986,14 @@
   </p>
 </li>
 <li><p>
+  <strong><a name="DumpGenotypeColorGrid">DumpGenotypeColorGrid</a></strong>
+  <i>[int num_colors=12] [string fname=""]</i>
+  </p>
+  <p>
+  
+  </p>
+</li>
+<li><p>
   <strong><a name="DumpGenotypeIDGrid">DumpGenotypeIDGrid</a></strong>
   <i>[string fname=""]</i>
   </p>
@@ -2028,6 +2114,14 @@
   </p>
 </li>
 <li><p>
+  <strong><a name="PrintAveNumTasks">PrintAveNumTasks</a></strong>
+  <i>[string fname=""]</i>
+  </p>
+  <p>
+  
+  </p>
+</li>
+<li><p>
   <strong><a name="print_average_data">print_average_data</a></strong>
   <i>[string fname="average.dat"]</i>
   </p>
@@ -2142,6 +2236,13 @@
   </p>
 </li>
 <li><p>
+  <strong><a name="PrintConsensusData">PrintConsensusData</a></strong>
+  </p>
+  <p>
+  
+  </p>
+</li>
+<li><p>
   <strong><a name="print_count_data">print_count_data</a></strong>
   <i>[string fname="count.dat"]</i>
   </p>
@@ -2948,6 +3049,14 @@
   </p>
 </li>
 <li><p>
+  <strong><a name="PrintNewTasksDataPlus">PrintNewTasksDataPlus</a></strong>
+  <i>[string fname="		newtasksplus.dat	"]</i>
+  </p>
+  <p>
+  
+  </p>
+</li>
+<li><p>
   <strong><a name="print_number_phenotypes">print_number_phenotypes</a></strong>
   <i>[string fname="phenotype_count.dat"]</i>
   </p>
@@ -3179,6 +3288,13 @@
   </p>
 </li>
 <li><p>
+  <strong><a name="PrintSimpleConsensusData">PrintSimpleConsensusData</a></strong>
+  </p>
+  <p>
+  
+  </p>
+</li>
+<li><p>
   <strong><a name="PrintSleepData">PrintSleepData</a></strong>
   <i>[string fname="sleep.dat"]</i>
   </p>

Modified: branches/parasites/documentation/environment.html
===================================================================
--- branches/parasites/documentation/environment.html	2009-12-15 22:39:52 UTC (rev 3557)
+++ branches/parasites/documentation/environment.html	2009-12-16 15:51:37 UTC (rev 3558)
@@ -562,9 +562,9 @@
     <br />&nbsp;&nbsp;&nbsp;<em>pow</em>: Multiply the current merit by 2<sup>bonus</sup>.
        this is effectively multiplicative, but positive bonuses are
        always beneficial, and negative bonuses are harmful.
-    <br />&nbsp;&nbsp;&nbsp;<em>enzyme</em>: Add bonus * resource / (resource + frac) to the current merit.
+    <br />&nbsp;&nbsp;&nbsp;<em>enzyme</em>: Add bonus * resource / (resource + ksubm) to the current merit.
     	This is gives a Michaelis-Menten enzyme type reward where bonus is the K<sub>cat</sub>
-    	and frac is the K<sub>m</sub>. Does not work with unlimited resources.
+    	and the K<sub>m</sub> is entered. Does not work with unlimited resources.
     <br />&nbsp;&nbsp;&nbsp;<em>energy</em>: Add the bonus energy to the organism's energy waiting to be applied buffer.  Bonus energy can be applied on completion of a reaction, execution of the sleep/eat instruction, or when the organisms divides.  See <a href="energy_model.html">Energy Model</a> documentation for more information.
   </td>
   <td>add</td>
@@ -640,6 +640,15 @@
     default
   </td>
 </tr>
+<tr>
+  <td class="resall">ksubm</td>
+  <td>
+    K<sub>m</sub> for an enzyme reaction.
+  </td>
+  <td>
+    0.0
+  </td>
+</tr>
 </table>
 <p>&nbsp;</p>
 </div>

Modified: branches/parasites/documentation/svn.html
===================================================================
--- branches/parasites/documentation/svn.html	2009-12-15 22:39:52 UTC (rev 3557)
+++ branches/parasites/documentation/svn.html	2009-12-16 15:51:37 UTC (rev 3558)
@@ -71,7 +71,7 @@
 <dd>This command will tell you the status of each file in the within your
     working copy.  Supplying the option --show-updates will show you updates
     that have occurred within the repository.</dd>
-<dt>cvs diff &lt;filename&gt;</dt>
+<dt>svn diff &lt;filename&gt;</dt>
 <dd>This command will show you any changes that you have made to the file
     since it was last updated.</dd>
 <dt>svn help</tt></b>

Modified: branches/parasites/source/actions/PopulationActions.cc
===================================================================
--- branches/parasites/source/actions/PopulationActions.cc	2009-12-15 22:39:52 UTC (rev 3557)
+++ branches/parasites/source/actions/PopulationActions.cc	2009-12-16 15:51:37 UTC (rev 3558)
@@ -1079,7 +1079,7 @@
 
 				double killprob;
 				if(m_exponent == -1.0)
-					killprob = min(1.0/(m_exprWeight+ exp(-count)), 100.0)/100.0;  //sigmoid
+					killprob = min(1.0/(m_exprWeight+ exp(double(-count))), 100.0)/100.0;  //sigmoid
 				else
 					killprob = min(pow(m_exprWeight*count,m_exponent), 100.0)/100.0;  // linear and exponential
 				
@@ -4013,6 +4013,7 @@
  - The radius of the kill zone (default: 0)
  - The name of the resource
  - The amount of resource below which to execute the kill (default: 0)
+ - The fraction of orgs in the region to kill (1=all, 0.5 leave half) (default: 1) -- useful for controlling density with biofilms
  */
 
 class cActionKillWithinRadiusBelowResourceThreshold : public cAction
@@ -4022,17 +4023,19 @@
     int m_radius;
     cString m_resname;
     double m_threshold;
+    double m_kill_density;
   public:
-    cActionKillWithinRadiusBelowResourceThreshold(cWorld* world, const cString& args) : cAction(world, args), m_numradii(0), m_radius(0), m_threshold(0.0)
+    cActionKillWithinRadiusBelowResourceThreshold(cWorld* world, const cString& args) : cAction(world, args), m_numradii(0), m_radius(0), m_threshold(0.0), m_kill_density(1.0)
     {
       cString largs(args);
       if (largs.GetSize()) m_numradii = largs.PopWord().AsInt();
       if (largs.GetSize()) m_radius = largs.PopWord().AsInt();
       if (largs.GetSize()) m_resname = largs.PopWord();
       if (largs.GetSize()) m_threshold = largs.PopWord().AsDouble();
+      if (largs.GetSize()) m_kill_density = largs.PopWord().AsDouble();
      }
     
-    static const cString GetDescription() { return "Arguments: [int numradii=0, int radius=0, string resource name, double threshold=0]"; }
+    static const cString GetDescription() { return "Arguments: [int numradii=0, int radius=0, string resource name, double threshold=0, double killdensity=1]"; }
     
     void Process(cAvidaContext& ctx)
     {
@@ -4045,6 +4048,8 @@
       assert(m_radius <= world_x);
       assert(m_radius <= world_y);
       assert(m_threshold >= 0.0);
+      assert(m_kill_density >= 0.0);
+      assert(m_kill_density <= 1.0);
       assert(geometry == nGeometry::GRID || geometry == nGeometry::TORUS);
       
       cPopulation& pop = m_world->GetPopulation();
@@ -4081,7 +4086,9 @@
               
               int current_cell = (world_x * row_adj) + col_adj;
 							cPopulationCell& cell = pop.GetCell(current_cell);
-							if (cell.IsOccupied()) {
+              m_world->GetStats().IncNumCellsScannedAtKill();
+
+							if( (cell.IsOccupied()) && (ctx.GetRandom().P(m_kill_density)) ) {
 								pop.KillOrganism(cell);
 								m_world->GetStats().IncNumOrgsKilled();
 							} else {
@@ -4098,7 +4105,103 @@
     } //End Process()
   };
 
+/*
+ Kill organisms within a given radius of a randomly-chosen cell if the level
+ of the given resource in the chosen cells are below the given threshold.  Currently
+ only works for toruses and bounded grids.
+ 
+ Parameters:
+ - The number of kill radii to use (default: 0)
+ - The radius of the kill zone (default: 0)
+ - The name of the resource
+ - The amount of resource below which to execute the kill (default: 0)
+ - The fraction of orgs in the region to kill (1=all, 0.5 leave half) (default: 1) -- useful for controlling density with biofilms
+ */
 
+class cActionKillWithinRadiusBelowResourceThresholdTestAll : public cAction {
+private:
+	int m_numradii;
+	int m_radius;
+	cString m_resname;
+	double m_threshold;
+	double m_kill_density;
+public:
+	cActionKillWithinRadiusBelowResourceThresholdTestAll(cWorld* world, const cString& args) : cAction(world, args), m_numradii(0), m_radius(0), m_threshold(0.0), m_kill_density(1.0)
+	{
+		cString largs(args);
+		if (largs.GetSize()) m_numradii = largs.PopWord().AsInt();
+		if (largs.GetSize()) m_radius = largs.PopWord().AsInt();
+		if (largs.GetSize()) m_resname = largs.PopWord();
+		if (largs.GetSize()) m_threshold = largs.PopWord().AsDouble();
+		if (largs.GetSize()) m_kill_density = largs.PopWord().AsDouble();
+	}
+	
+	static const cString GetDescription() { return "Arguments: [int numradii=0, int radius=0, string resource name, double threshold=0, double killdensity=1]"; }
+	
+	void Process(cAvidaContext& ctx)
+	{
+		const int world_x = m_world->GetPopulation().GetWorldX();
+		const int world_y = m_world->GetPopulation().GetWorldY();
+		const int geometry = m_world->GetConfig().WORLD_GEOMETRY.Get();
+		
+		assert(m_numradii >= 0);
+		assert(m_radius >= 0);
+		assert(m_radius <= world_x);
+		assert(m_radius <= world_y);
+		assert(m_threshold >= 0.0);
+		assert(m_kill_density >= 0.0);
+		assert(m_kill_density <= 1.0);
+		assert(geometry == nGeometry::GRID || geometry == nGeometry::TORUS);
+		
+		cPopulation& pop = m_world->GetPopulation();
+		int res_id = m_world->GetPopulation().GetResourceCount().GetResourceCountID(m_resname);
+		
+		assert(res_id != -1);
+		
+		for (int i = 0; i < m_numradii; i++) {
+			
+			int target_cell = m_world->GetRandom().GetInt(0, pop.GetSize()-1);
+			const int current_row = target_cell / world_x;
+			const int current_col = target_cell % world_x;
+			
+			for(int row = current_row - m_radius; row <= current_row + m_radius; row++) {
+				
+				if( ((row < 0) || (row >= world_y)) && (geometry == nGeometry::GRID) ) continue;
+				
+				for(int col = current_col - m_radius; col <= current_col + m_radius; col++) {
+					if( ((col < 0) || (col >= world_x)) && (geometry == nGeometry::GRID) ) continue;
+					
+					int row_adj = 0;
+					int col_adj = 0;
+					
+					if(geometry == nGeometry::TORUS) {
+						row_adj = (row + world_y) % world_y;
+						col_adj = (col + world_x) % world_x;
+					} else if(geometry == nGeometry::GRID) {
+						row_adj = row;
+						col_adj = col;
+					}
+					
+					int current_cell = (world_x * row_adj) + col_adj;
+					cPopulationCell& cell = pop.GetCell(current_cell);
+					m_world->GetStats().IncNumCellsScannedAtKill();
+					
+					double level = pop.GetResourceCount().GetSpatialResource(res_id).GetAmount(current_cell);
+					
+					if(level < m_threshold) {
+						if( (cell.IsOccupied()) && (ctx.GetRandom().P(m_kill_density)) ) {
+							pop.KillOrganism(cell);
+							m_world->GetStats().IncNumOrgsKilled();
+						} else {
+							m_world->GetStats().IncNumUnoccupiedCellAttemptedToKill();
+						}
+					}
+				}
+			}
+		}
+	}
+};
+
 /*
  Kill a percentage of organisms in all demes
  
@@ -4412,6 +4515,7 @@
   action_lib->Register<cActionKillNBelowResourceThreshold>("KillNBelowResourceThreshold");
   action_lib->Register<cActionKillNAboveResourceThreshold>("KillNAboveResourceThreshold");
   action_lib->Register<cActionKillWithinRadiusBelowResourceThreshold>("KillWithinRadiusBelowResourceThreshold");
+	action_lib->Register<cActionKillWithinRadiusBelowResourceThresholdTestAll>("KillWithinRadiusBelowResourceThresholdTestAll");
 	
 	action_lib->Register<cActionDiffuseHGTGenomeFragments>("DiffuseHGTGenomeFragments");
 	

Modified: branches/parasites/source/cpu/cHardwareExperimental.cc
===================================================================
--- branches/parasites/source/cpu/cHardwareExperimental.cc	2009-12-15 22:39:52 UTC (rev 3557)
+++ branches/parasites/source/cpu/cHardwareExperimental.cc	2009-12-16 15:51:37 UTC (rev 3558)
@@ -134,6 +134,7 @@
     tInstLibEntry<tMethod>("IO-expire", &cHardwareExperimental::Inst_TaskIOExpire, (nInstFlag::DEFAULT | nInstFlag::STALL), "Output ?BX?, and input new number back into ?BX?, if the number has not yet expired"),
     tInstLibEntry<tMethod>("input", &cHardwareExperimental::Inst_TaskInput, nInstFlag::STALL, "Input new number into ?BX?"),
     tInstLibEntry<tMethod>("output", &cHardwareExperimental::Inst_TaskOutput, nInstFlag::STALL, "Output ?BX?"),
+    tInstLibEntry<tMethod>("output-zero", &cHardwareExperimental::Inst_TaskOutputZero, nInstFlag::STALL, "Output ?BX?"),
     tInstLibEntry<tMethod>("output-expire", &cHardwareExperimental::Inst_TaskOutputExpire, nInstFlag::STALL, "Output ?BX?, as long as the output has not yet expired"),
     
     tInstLibEntry<tMethod>("mult", &cHardwareExperimental::Inst_Mult, 0, "Multiple BX by CX and place the result in ?BX?"),
@@ -144,10 +145,12 @@
     // Flow Control Instructions
     tInstLibEntry<tMethod>("label", &cHardwareExperimental::Inst_Label, (nInstFlag::DEFAULT | nInstFlag::LABEL)),
     
-    tInstLibEntry<tMethod>("h-search", &cHardwareExperimental::Inst_HeadSearch, nInstFlag::DEFAULT, "Find complement template and make with flow head"),
-    tInstLibEntry<tMethod>("h-search-nolabel", &cHardwareExperimental::Inst_HeadSearch_NoLabel, 0, "Find complement template and make with flow head"),
-    tInstLibEntry<tMethod>("h-search-noreg", &cHardwareExperimental::Inst_HeadSearch_NoReg, 0, "Find complement template and make with flow head"),
-    tInstLibEntry<tMethod>("h-search-direct", &cHardwareExperimental::Inst_HeadSearch_Direct, 0, "Find direct template and move the flow head"),
+    tInstLibEntry<tMethod>("search-s", &cHardwareExperimental::Inst_SearchS, nInstFlag::DEFAULT, "Find complement template from genome start and move the flow head"),
+    tInstLibEntry<tMethod>("search-f", &cHardwareExperimental::Inst_SearchF, 0, "Find complement template forward and move the flow head"),
+    tInstLibEntry<tMethod>("search-b", &cHardwareExperimental::Inst_SearchB, 0, "Find complement template backward and move the flow head"),
+    tInstLibEntry<tMethod>("search-s-direct", &cHardwareExperimental::Inst_SearchS_Direct, 0, "Find direct template from genome start and move the flow head"),
+    tInstLibEntry<tMethod>("search-f-direct", &cHardwareExperimental::Inst_SearchF_Direct, 0, "Find direct template forward and move the flow head"),
+    tInstLibEntry<tMethod>("search-b-direct", &cHardwareExperimental::Inst_SearchB_Direct, 0, "Find direct template backward and move the flow head"),
 
     tInstLibEntry<tMethod>("mov-head", &cHardwareExperimental::Inst_MoveHead, nInstFlag::DEFAULT, "Move head ?IP? to the flow head"),
     
@@ -170,6 +173,8 @@
     
     tInstLibEntry<tMethod>("repro", &cHardwareExperimental::Inst_Repro, nInstFlag::STALL, "Instantly reproduces the organism"),
 
+    tInstLibEntry<tMethod>("die", &cHardwareExperimental::Inst_Die, nInstFlag::STALL, "Instantly kills the organism"),
+
     
     // Goto Variants
     tInstLibEntry<tMethod>("goto", &cHardwareExperimental::Inst_Goto, 0, "Move IP to labeled position matching the label that follows"),
@@ -697,6 +702,57 @@
   return ip;
 }
 
+cHeadCPU cHardwareExperimental::FindLabelBackward(bool mark_executed)
+{
+  cHeadCPU& ip = getIP();
+  const cCodeLabel& search_label = GetLabel();
+  
+  // Make sure the label is of size > 0.
+  if (search_label.GetSize() == 0) return ip;
+  
+  cHeadCPU lpos(ip);
+  cHeadCPU pos(ip);
+  lpos--;
+  
+  while (pos.GetPosition() != ip.GetPosition()) {
+    if (m_inst_set->IsLabel(lpos.GetInst())) { // starting label found
+      pos.Set(lpos.GetPosition());
+      pos++;
+      
+      // Check for direct matched label pattern, can be substring of 'label'ed target
+      // - must match all NOPs in search_label
+      // - extra NOPs in 'label'ed target are ignored
+      int size_matched = 0;
+      while (size_matched < search_label.GetSize() && pos.GetPosition() != ip.GetPosition()) {
+        if (!m_inst_set->IsNop(pos.GetInst()) || search_label[size_matched] != m_inst_set->GetNopMod(pos.GetInst())) break;
+        size_matched++;
+        pos++;
+      }
+      
+      // Check that the label matches and has examined the full sequence of nops following the 'label' instruction
+      if (size_matched == search_label.GetSize()) {
+        pos--;
+        const int found_pos = pos.GetPosition();
+        
+        if (mark_executed) {
+          const int max = m_world->GetConfig().MAX_LABEL_EXE_SIZE.Get() + 1; // Max label + 1 for the label instruction itself
+          for (int i = 0; i < size_matched && i < max; i++, lpos++) lpos.SetFlagExecuted();
+        }
+        
+        // Return Head pointed at last NOP of label sequence
+        return cHeadCPU(this, found_pos, ip.GetMemSpace());
+      }
+    }
+    lpos--;
+  }
+  
+  // Return start point if not found
+  return ip;
+}
+
+
+
+
 cHeadCPU cHardwareExperimental::FindNopSequenceForward(bool mark_executed)
 {
   cHeadCPU& ip = getIP();
@@ -1415,6 +1471,20 @@
 }
 
 
+bool cHardwareExperimental::Inst_TaskOutputZero(cAvidaContext& ctx)
+{
+  const int reg_used = FindModifiedRegister(REG_BX);
+  sInternalValue& reg = m_threads[m_cur_thread].reg[reg_used];
+  
+  // Do the "put" component
+  m_organism->DoOutput(ctx, reg.value);  // Check for tasks completed.
+  m_last_output = m_cycle_count;
+  
+  setInternalValue(reg, 0);
+  
+  return true;
+}
+
 bool cHardwareExperimental::Inst_TaskOutputExpire(cAvidaContext& ctx)
 {
   const int reg_used = FindModifiedRegister(REG_BX);
@@ -1627,56 +1697,66 @@
   return true;
 }
 
-bool cHardwareExperimental::Inst_HeadSearch(cAvidaContext& ctx)
+bool cHardwareExperimental::Inst_SearchS(cAvidaContext& ctx)
 {
   ReadLabel();
   GetLabel().Rotate(1, NUM_NOPS);
   cHeadCPU found_pos = FindLabelStart(true);
-  const int search_size = found_pos.GetPosition() - getIP().GetPosition();
-  setInternalValue(m_threads[m_cur_thread].reg[REG_BX], search_size);
-  setInternalValue(m_threads[m_cur_thread].reg[REG_CX], GetLabel().GetSize());
   getHead(nHardware::HEAD_FLOW).Set(found_pos);
   getHead(nHardware::HEAD_FLOW).Advance();
   return true;
 }
 
-bool cHardwareExperimental::Inst_HeadSearch_NoLabel(cAvidaContext& ctx)
+bool cHardwareExperimental::Inst_SearchS_Direct(cAvidaContext& ctx)
 {
   ReadLabel();
-  GetLabel().Rotate(1, NUM_NOPS);
-  cHeadCPU found_pos = FindNopSequenceStart(true);
-  const int search_size = found_pos.GetPosition() - getIP().GetPosition();
-  setInternalValue(m_threads[m_cur_thread].reg[REG_BX], search_size);
-  setInternalValue(m_threads[m_cur_thread].reg[REG_CX], GetLabel().GetSize());
+  cHeadCPU found_pos = FindLabelStart(true);
   getHead(nHardware::HEAD_FLOW).Set(found_pos);
   getHead(nHardware::HEAD_FLOW).Advance();
   return true;
 }
 
-bool cHardwareExperimental::Inst_HeadSearch_NoReg(cAvidaContext& ctx)
+
+bool cHardwareExperimental::Inst_SearchF(cAvidaContext& ctx)
 {
   ReadLabel();
   GetLabel().Rotate(1, NUM_NOPS);
-  cHeadCPU found_pos = FindLabelStart(true);
+  cHeadCPU found_pos = FindLabelForward(true);
   getHead(nHardware::HEAD_FLOW).Set(found_pos);
   getHead(nHardware::HEAD_FLOW).Advance();
   return true;
 }
 
-bool cHardwareExperimental::Inst_HeadSearch_Direct(cAvidaContext& ctx)
+bool cHardwareExperimental::Inst_SearchF_Direct(cAvidaContext& ctx)
 {
   ReadLabel();
   cHeadCPU found_pos = FindLabelForward(true);
-  const int search_size = found_pos.GetPosition() - getIP().GetPosition();
-  setInternalValue(m_threads[m_cur_thread].reg[REG_BX], search_size);
-  setInternalValue(m_threads[m_cur_thread].reg[REG_CX], GetLabel().GetSize());
   getHead(nHardware::HEAD_FLOW).Set(found_pos);
   getHead(nHardware::HEAD_FLOW).Advance();
   return true;
 }
 
+bool cHardwareExperimental::Inst_SearchB(cAvidaContext& ctx)
+{
+  ReadLabel();
+  GetLabel().Rotate(1, NUM_NOPS);
+  cHeadCPU found_pos = FindLabelBackward(true);
+  getHead(nHardware::HEAD_FLOW).Set(found_pos);
+  getHead(nHardware::HEAD_FLOW).Advance();
+  return true;
+}
 
+bool cHardwareExperimental::Inst_SearchB_Direct(cAvidaContext& ctx)
+{
+  ReadLabel();
+  cHeadCPU found_pos = FindLabelBackward(true);
+  getHead(nHardware::HEAD_FLOW).Set(found_pos);
+  getHead(nHardware::HEAD_FLOW).Advance();
+  return true;
+}
 
+
+
 bool cHardwareExperimental::Inst_SetFlow(cAvidaContext& ctx)
 {
   const int reg_used = FindModifiedRegister(REG_CX);
@@ -1687,7 +1767,6 @@
 bool cHardwareExperimental::Inst_Goto(cAvidaContext& ctx)
 {
   ReadLabel();
-  GetLabel().Rotate(1, NUM_NOPS);
   cHeadCPU found_pos = FindLabelForward(true);
   getIP().Set(found_pos);
   return true;
@@ -2078,6 +2157,14 @@
 }
 
 
+bool cHardwareExperimental::Inst_Die(cAvidaContext& ctx)
+{
+  m_organism->Die();
+  
+  return true;
+}
+
+
 bool cHardwareExperimental::Inst_SGMove(cAvidaContext& ctx)
 {
   assert(m_ext_mem.GetSize() > 3);

Modified: branches/parasites/source/cpu/cHardwareExperimental.h
===================================================================
--- branches/parasites/source/cpu/cHardwareExperimental.h	2009-12-15 22:39:52 UTC (rev 3557)
+++ branches/parasites/source/cpu/cHardwareExperimental.h	2009-12-16 15:51:37 UTC (rev 3558)
@@ -329,6 +329,7 @@
   void ReadLabel(int max_size=nHardware::MAX_LABEL_SIZE);
   cHeadCPU FindLabelStart(bool mark_executed);
   cHeadCPU FindLabelForward(bool mark_executed);
+  cHeadCPU FindLabelBackward(bool mark_executed);
   cHeadCPU FindNopSequenceStart(bool mark_executed);
   cHeadCPU FindNopSequenceForward(bool mark_executed);
   bool& ReadingLabel() { return m_threads[m_cur_thread].reading; }
@@ -429,6 +430,7 @@
   bool Inst_TaskIOExpire(cAvidaContext& ctx);
   bool Inst_TaskInput(cAvidaContext& ctx);
   bool Inst_TaskOutput(cAvidaContext& ctx);
+  bool Inst_TaskOutputZero(cAvidaContext& ctx);
   bool Inst_TaskOutputExpire(cAvidaContext& ctx);
 
   // Head-based Instructions
@@ -444,10 +446,12 @@
   bool Inst_HeadWrite(cAvidaContext& ctx);
   bool Inst_HeadCopy(cAvidaContext& ctx);
   bool Inst_HeadCopy_NoLabel(cAvidaContext& ctx);
-  bool Inst_HeadSearch(cAvidaContext& ctx);
-  bool Inst_HeadSearch_NoLabel(cAvidaContext& ctx);
-  bool Inst_HeadSearch_NoReg(cAvidaContext& ctx);
-  bool Inst_HeadSearch_Direct(cAvidaContext& ctx);
+  bool Inst_SearchS(cAvidaContext& ctx);
+  bool Inst_SearchS_Direct(cAvidaContext& ctx);
+  bool Inst_SearchF(cAvidaContext& ctx);
+  bool Inst_SearchF_Direct(cAvidaContext& ctx);
+  bool Inst_SearchB(cAvidaContext& ctx);
+  bool Inst_SearchB_Direct(cAvidaContext& ctx);
   bool Inst_SetFlow(cAvidaContext& ctx);
   
   // Goto Variants
@@ -474,6 +478,7 @@
   
   // Replication
   bool Inst_Repro(cAvidaContext& ctx);
+  bool Inst_Die(cAvidaContext& ctx);
   
   // State Grid Navigation
   bool Inst_SGMove(cAvidaContext& ctx);

Modified: branches/parasites/source/main/cAvidaConfig.h
===================================================================
--- branches/parasites/source/main/cAvidaConfig.h	2009-12-15 22:39:52 UTC (rev 3557)
+++ branches/parasites/source/main/cAvidaConfig.h	2009-12-16 15:51:37 UTC (rev 3558)
@@ -669,6 +669,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\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: branches/parasites/source/main/cEnvironment.cc
===================================================================
--- branches/parasites/source/main/cEnvironment.cc	2009-12-15 22:39:52 UTC (rev 3557)
+++ branches/parasites/source/main/cEnvironment.cc	2009-12-16 15:51:37 UTC (rev 3558)
@@ -206,6 +206,11 @@
       if (in_frac > 1.0) in_frac = 1.0;
       new_process->SetMaxFraction(in_frac);
     }
+    else if (var_name == "ksubm") {
+      if (!AssertInputDouble(var_value, "ksubm", var_type)) return false;
+      double in_k_sub_m = var_value.AsDouble();
+      new_process->SetKsubM(in_k_sub_m);
+    }
     else if (var_name == "product") {
       cResource* test_resource = resource_lib.GetResource(var_value);
       if (!AssertInputValid(test_resource, "product", var_type, var_value)) {
@@ -1375,7 +1380,8 @@
           const int res_id = in_resource->GetID();
           assert(cur_process->GetMaxFraction() != 0);
           assert(resource_count[res_id] != 0);
-          double reward = cur_process->GetValue() * resource_count[res_id] / (resource_count[res_id] + cur_process->GetMaxFraction());
+          // double reward = cur_process->GetValue() * resource_count[res_id] / (resource_count[res_id] + cur_process->GetMaxFraction());
+          double reward = cur_process->GetValue() * resource_count[res_id] / (resource_count[res_id] + cur_process->GetKsubM());
           result.AddBonus( reward , reaction_id);
           break;
         }

Modified: branches/parasites/source/main/cGenome.cc
===================================================================
--- branches/parasites/source/main/cGenome.cc	2009-12-15 22:39:52 UTC (rev 3557)
+++ branches/parasites/source/main/cGenome.cc	2009-12-16 15:51:37 UTC (rev 3558)
@@ -189,7 +189,78 @@
   for (int i = 0; i < genome.GetSize(); i++) m_genome[i + pos] = genome[i];
 }
 
+/*! Replace [begin, end) instructions in this genome with g, respecting genome circularity.
+ 
+ This method replaces [begin,end) instructions in this genome with those in g.  Begin and end
+ follow STL-iterator semantics, which is to say that end "points" to **one past** the last
+ instruction that will be replaced.
+ 
+ Also, circularity of the genome is respected, which means that if end < begin 
+ (the instructions that are being replaced wrap-around the end of the genome), then
+ the replacement will too.
+ 
+ Caveat: if length([begin,end)) != length(g), all size changes are made at end.
+ */
+void cGenome::Replace(const cGenome& g, int begin, int end) {
+	if(begin == end) {
+		// we're actually doing an insertion...
+		Insert(begin, g);
+	} else if(begin < end) {
+		// no wrap-around
+		Replace(begin, end-begin, g);
+	} else {
+		// replacement wraps around the end.  two different replacements to do now:
+		// [begin, size) and [0, end).
+		
+		// first, replace the [begin, size) region of this genome with as much of g
+		// as we can get.
+		int tail_size = std::min(GetSize()-begin, g.GetSize());
+		cGenome tail(&g[0], &g[0]+tail_size);
+		Replace(begin, GetSize()-begin, tail);
 
+		// now, replace the [0, end) region or remove it if the whole fragment
+		// was already copied in:
+		if(tail_size != g.GetSize()) {
+			cGenome head(&g[0]+tail_size, &g[0]+g.GetSize());
+			Replace(0, end, head);
+		} else if(end > 0) {
+			Remove(0, end);
+		}
+	}
+}
+
+/*! Rotate this genome forward n instructions.
+ 
+ "Rotation" in this sense means to move instructions from begin->end, with instructions
+ at the end wrapping around to the beginning.  Specifically, given a genome
+ [0... n... m-n... m], Rotate(n) moves instructions to create [m-n... m, 0... n].
+ 
+ Negative rotation is supported, and moves instructions from the beginning to the end.
+ */
+void cGenome::Rotate(int n) {
+	assert(n < m_active_size);
+	if(n==0) { return; }
+
+	cInstruction* begin = &operator[](0);
+	cInstruction* end = &operator[](0) + GetSize();
+	
+	if(n > 0) {
+		// forward
+		cGenome head(end-n, end);
+		cGenome tail(begin, end-n);
+		head.Append(tail);
+		operator=(head);
+	} else {
+		assert(false);
+		// backward
+		cGenome head(begin, begin-n); // n is < 0, so this is addition.
+		cGenome tail(begin-n, end);
+		tail.Append(head);
+		operator=(tail);
+	}
+}
+
+
 void cGenome::operator=(const cGenome& other_genome)
 {
   m_active_size = other_genome.m_active_size;

Modified: branches/parasites/source/main/cGenome.h
===================================================================
--- branches/parasites/source/main/cGenome.h	2009-12-15 22:39:52 UTC (rev 3557)
+++ branches/parasites/source/main/cGenome.h	2009-12-16 15:51:37 UTC (rev 3558)
@@ -81,6 +81,10 @@
   virtual void Insert(int pos, const cGenome& genome);
   virtual void Remove(int pos, int num_sites = 1);
   virtual void Replace(int pos, int num_sites, const cGenome& genome);
+	//! Replace [begin, end) instructions in this genome with g, respecting genome circularity.
+	virtual void Replace(const cGenome& g, int begin, int end);
+	//! Rotate this genome forward n instructions.
+	virtual void Rotate(int n);
 
   inline void Append(const cInstruction& in_inst) { Insert(GetSize(), in_inst); }
   inline void Append(const cGenome& in_genome) { Insert(GetSize(), in_genome); }

Modified: branches/parasites/source/main/cGenomeUtil.cc
===================================================================
--- branches/parasites/source/main/cGenomeUtil.cc	2009-12-15 22:39:52 UTC (rev 3557)
+++ branches/parasites/source/main/cGenomeUtil.cc	2009-12-16 15:51:37 UTC (rev 3558)
@@ -29,14 +29,16 @@
 #include "cGenome.h"
 #include "cInitFile.h"
 #include "cInstSet.h"
+#include "cRandom.h"
 #include "functions.h"
 #include <algorithm>
-#include <strings.h>
+#include <string.h>
 
 
 using namespace std;
 
 
+
 int cGenomeUtil::FindInst(const cGenome & gen, const cInstruction & inst,
 			  int start_index)
 {
@@ -244,44 +246,141 @@
 }
 
 
-/*! Return all matches of substring within base.
+/*! Distance between begin and end.
+ */
+std::size_t cGenomeUtil::substring_match::distance() {
+	std::size_t d=0;
+	if(begin <= end) {
+		d = end - begin;
+	} else {
+		d = size - begin + end;
+	}
+	return d;
+}
+
+
+/*! Resize to n (preserve the absolute distance between begin and end, based around begin).
+ */
+void cGenomeUtil::substring_match::resize(std::size_t n) {
+	// fixup begin and end if they're negative or point beyond the current size
+	if(begin < 0) { begin = size - (-begin) % size; }
+	if(end < 0) { end = size - (-end) % size; }
+	begin %= size;
+	end %= size;
+	
+	// our work is done if there's no change in size...
+	if(size == n) { return; }
+	
+	// if this is triggered, it means that the current begin index would
+	// be truncated by the new, smaller string.
+	assert(begin < static_cast<int>(n));
+	
+	// distance between begin and end:
+	std::size_t d=distance();
+	
+	// if this is triggered, it means that the new size is smaller than the
+	// region described by this match.
+	assert(d < n);
+	
+	size = n;		
+	end = (begin + d) % size;
+}
+
+
+/*! Rotate around a size of n.
+ */
+void cGenomeUtil::substring_match::rotate(int r, std::size_t n) {
+	if(r < 0) {
+		r = -((-r) % n);
+	} else {
+		r %= n;
+	}
+	begin += r;
+	end += r;
+	resize(n); // fixup the indices
+}
+
+
+/*! Find (one of) the best substring matches of substring in 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
- and ending position (inclusive). 
+ The algorithm here is based on the well-known dynamic programming approach to
+ finding a substring match.  Here, it has been extended to track the beginning and
+ ending locations of that match.  Specifically, [begin,end) of the returned substring_match
+ denotes the matched region in the base string.
  */
-cGenomeUtil::substring_match_list_type cGenomeUtil::FindSubstringMatches(const cGenome& base, const cGenome& substring) {
-	substring_match_list_type ssml(base.GetSize());
+cGenomeUtil::substring_match cGenomeUtil::FindSubstringMatch(const cGenome& base, const cGenome& substring) {
 	const int rows=substring.GetSize()+1;
 	const int cols=base.GetSize()+1;
-	int costmat[2][cols];   
-	int* c=costmat[0]; // current row
-	int* p=costmat[1]; // previous row
-	bzero(costmat, sizeof(int)*2*cols);
+	substring_match m[2][cols];
+	substring_match* c=m[0];
+	substring_match* p=m[1];
 	
+	for(int j=1; j<cols; ++j) {
+		p[j].begin = j;
+	}
+	
 	for(int i=1; i<rows; ++i) {
-		c[0] = p[0]+1;
+		c[0].cost = i;
 		for(int j=1; j<cols; ++j) {
-			int l[3] = {p[j-1], p[j], c[j-1]};
-			c[j] = *std::min_element(l,l+3) + (substring[i-1] != base[j-1]);
-			ssml[j-1].cost = c[j];
-			ssml[j-1].position = j-1;
+			substring_match l[3] = {p[j-1], p[j], c[j-1]};
+			substring_match* s = &l[0]; // default match is to the upper left.
+			
+			if(substring[i-1] == base[j-1]) {
+				// if the characters match, take the default
+				c[j].cost = s->cost;
+			} else {
+				// otherwise, find the minimum cost, add 1.
+				s = std::min_element(l,l+3);
+				c[j].cost = s->cost + 1;				
+			}
+			
+			// update the beginning and end of the match.
+			c[j].begin = s->begin;
+			c[j].end = j;
 		}
 		std::swap(c,p);
 	}
 	
-	return ssml;
+	substring_match* min = std::min_element(p, p+cols);
+	min->size = base.GetSize();
+	return *min;
 }
 
 
-/*! Return the best match of substring within base.
+/*! Find (one of) the best unbiased matches of substring in base, respecting genome circularity.
  
- \todo Ties for the value of the best match should be broken randomly.
+ Substring matches are inherently biased towards matching near to the left-hand side of the string 
+ (lower indices).  This method removes that bias by rotating the string prior to performing the
+ match.
+ 
+ Genomes in Avida are logically (not physically) circular, but substring matches in general do not 
+ respect circularity.  To respect the logical circularity of genomes in Avida, we append the base
+ string with substring-size instructions from the beginning of the base string.  This guarantees 
+ that circular matches are detected.
+ 
+ The return value here is de-circularfied and de-rotated such that [begin,end) are correct
+ for the base string (note that, due to circularity, begin could be > end).
  */
-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());
+cGenomeUtil::substring_match cGenomeUtil::FindUnbiasedCircularMatch(cAvidaContext& ctx, const cGenome& base, const cGenome& substring) {
+	// create a copy of the genome:
+	cGenome circ(base);
+	
+	// rotate it so that we remove bias for matching at the front of the genome:
+	const int rotate = ctx.GetRandom().GetInt(circ.GetSize());
+	circ.Rotate(rotate);
+	
+	// need to take circularity of the genome into account.
+	// we can do this by appending the genome with a copy of its first substring-size instructions.
+	cGenome head(&circ[0],&circ[0]+substring.GetSize());
+	circ.Append(head);
+	
+	// find the location within the circular genome that best matches substring:
+	cGenomeUtil::substring_match location = FindSubstringMatch(circ, substring);	
+	
+	// unwind the resizing & rotation:
+	location.resize(base.GetSize());
+	location.rotate(-rotate, base.GetSize());
+	return location;
 }
 
 
@@ -457,3 +556,4 @@
   return genome;
 }
 
+

Modified: branches/parasites/source/main/cGenomeUtil.h
===================================================================
--- branches/parasites/source/main/cGenomeUtil.h	2009-12-15 22:39:52 UTC (rev 3557)
+++ branches/parasites/source/main/cGenomeUtil.h	2009-12-16 15:51:37 UTC (rev 3558)
@@ -60,30 +60,44 @@
 
 	/*! Substring match record.
 	 
-	 The intent behind a substring match record is that it specifies where (position) a match
-	 between two genomes was found, the length (extent) of that match in the base string,
-	 and the edit distance (cost) of that match.
+	 The intent behind a substring match record is that it specifies where a match
+	 between two genomes was found as well as the edit distance (cost) of that match.
 	 
-	 The position and extent are inclusive, and describe the matching region in the
-	 base string like so: [position-extent, position]
+	 The begin, end members follow iterator semantics.  I.e., the matched region in
+	 the base string is [begin, end).  (End points to the element immediately following
+	 the match).
 	 */
+	//! Substring match record.
 	struct substring_match {
 		//! Default constructor.
-		substring_match() : position(0), //extent(0),
-		cost(0) { }
+		substring_match() : begin(0), end(0), cost(0), size(0) { }
+		//! Initializing constructor.
+		substring_match(int b, int e, int c=0, std::size_t s=0) : begin(b), end(e), cost(c), size(s) { }
+		//! Convenience method to set all values of a substring match.
+		void set(int b, int e, int c, std::size_t s) { begin = b; end = e; cost = c; size = s; }
 		//! 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.
+		bool operator<(const substring_match& that) const { return cost < that.cost; }
+		//! Operator== overload (to support testing)
+		bool operator==(const substring_match& that) const { 
+			return (begin == that.begin) && (end == that.end) && (cost == that.cost) && (size == that.size);
+		}
+		//! Distance between begin and end.
+		std::size_t distance();
+		//! Resize to n (preserve the absolute distance between begin and end, based around begin).
+		void resize(std::size_t n);
+		//! Rotate around a size of n.
+		void rotate(int r, std::size_t n);
+		
+		int begin; //!< Beginning of the substring match.
+		int end; //!< Ending of the substring match.
 		int cost; //!< Cost (edit distance) of this match.
+		std::size_t size; //!< Size of the base string.
 	};
 	
-	//! 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);
+	//! Find (one of) the best matches of substring in base.
+	static substring_match FindSubstringMatch(const cGenome& base, const cGenome& substring);	
+	//! Find (one of) the best unbiased matches of substring in base, respecting genome circularity.
+	static substring_match FindUnbiasedCircularMatch(cAvidaContext& ctx, const cGenome& base, const cGenome& substring);
 
   // ===== Construction methods =====
   static cGenome Crop(const cGenome& genome, int start, int end);

Modified: branches/parasites/source/main/cPopulationCell.cc
===================================================================
--- branches/parasites/source/main/cPopulationCell.cc	2009-12-15 22:39:52 UTC (rev 3557)
+++ branches/parasites/source/main/cPopulationCell.cc	2009-12-16 15:51:37 UTC (rev 3558)
@@ -315,13 +315,21 @@
 
 	m_world->GetPopulation().AdjustHGTResource(genome.GetSize());
 
+	// copy & rotate this genome to remove bais for the beginning and end of the genome:
+	cGenome g(genome);
+	g.Rotate(m_world->GetRandom().GetInt(g.GetSize()));
+	
 	// chop this genome up into pieces, add each to the back of this cell's buffer.
-	int remaining_size=genome.GetSize();
-	const cInstruction* i=&genome[0];
+	int remaining_size=g.GetSize();
+	const cInstruction* i=&g[0];
 	do {
-		int fsize = std::min(remaining_size,
-												 (int)floor(m_world->GetRandom().GetRandNormal(m_world->GetConfig().HGT_FRAGMENT_SIZE_MEAN.Get(),
-																																			 m_world->GetConfig().HGT_FRAGMENT_SIZE_VARIANCE.Get())));
+		int fsize=0;
+		while(!fsize) {
+			fsize = std::min(remaining_size,
+											 static_cast<int>(floor(fabs(m_world->GetRandom().GetRandNormal(m_world->GetConfig().HGT_FRAGMENT_SIZE_MEAN.Get(),
+																																											m_world->GetConfig().HGT_FRAGMENT_SIZE_VARIANCE.Get())))));
+		}
+		
 		m_hgt->fragments.push_back(cGenome(i, i+fsize));
 		i+=fsize;
 		remaining_size-=fsize;

Modified: branches/parasites/source/main/cPopulationInterface.cc
===================================================================
--- branches/parasites/source/main/cPopulationInterface.cc	2009-12-15 22:39:52 UTC (rev 3557)
+++ branches/parasites/source/main/cPopulationInterface.cc	2009-12-16 15:51:37 UTC (rev 3558)
@@ -28,13 +28,11 @@
 #include "cDeme.h"
 #include "cEnvironment.h"
 #include "cGenotype.h"
-#include "cGenomeUtil.h"
 #include "cHardwareManager.h"
 #include "cOrganism.h"
 #include "cOrgSinkMessage.h"
 #include "cOrgMessage.h"
 #include "cPopulation.h"
-#include "cPopulationCell.h"
 #include "cStats.h"
 #include "cTestCPU.h"
 
@@ -627,14 +625,12 @@
 
 /*! Perform an HGT mutation on this offspring. 
  
- HGT mutations are location-dependent, hence they are implemented here as opposed to
- the CPU or organism.
+ HGT mutations are location-dependent, hence they are piped through the populatin
+ interface as opposed to being implemented in 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.
  */
 void cPopulationInterface::DoHGTMutation(cAvidaContext& ctx, cGenome& offspring) {
 	// get this organism's cell:
@@ -642,50 +638,105 @@
 	
 	// 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()));
-	
-	// need to take circularity of the genome into account.
-	// we can do this by appending the genome with a copy of its first fragment-size
-	// instructions.  handling insertions and replacements gets complicated after this...
-	cGenome circ(offspring);
-	for(int i=0; i<f->GetSize(); ++i) {
-		circ.Append(offspring[i]);
+
+	// select the fragment and figure out where we're putting it:
+	fragment_list_type::iterator selected;
+	cGenomeUtil::substring_match location;
+	switch(m_world->GetConfig().HGT_FRAGMENT_SELECTION.Get()) {
+		case 0: { // random selection
+			HGTRandomFragmentSelection(ctx, offspring, cell.GetFragments(), selected, location);
+			break;
+		}
+		case 1: { // random selection with redundant instruction trimming
+			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;
+		}
 	}
 	
-	// find the location within the offspring's genome that best matches the selected fragment:
-	cGenomeUtil::substring_match ssm = cGenomeUtil::FindBestSubstringMatch(circ, *f);
-	
-	if(ssm.position > offspring.GetSize()) {
-		// we matched on the circular portion of the genome, so we have to modify the
-		// matched position to reflect this;
-		ssm.position -= offspring.GetSize();
-	} 
-	
-	// there are (currently) two supported types of HGT mutations: insertions & replacements.
-	// which one are we doing?
+	// do the mutation; we currently support insertions and replacements, but this can
+	// be extended in the same way as fragment selection if need be.
 	if(ctx.GetRandom().P(m_world->GetConfig().HGT_INSERTION_MUT_P.Get())) {
-		// insertion: insert the fragment just after the final location of the match:
-		offspring.Insert(ssm.position+1, *f);
+		// insert the fragment just after the final location:
+		offspring.Insert(location.end, *selected);
 	} else {
-		// replacement: replace up to fragment size instructions in the genome.
-		// note that replacement can wrap around from front->back.  replacement counts
-		// forward, so we have to find the start position first.
-		int start = ssm.position - f->GetSize() + 1;
-		//int start = ssm.position - ssm.extent + 1; // this isn't turned on yet.
-		if(start < 0) { start += offspring.GetSize(); }
-		for(int i=0; i<f->GetSize(); ++i) {
-			offspring[start] = (*f)[i];
-			if(++start >= offspring.GetSize()) { start = 0; }
-		}
+		// replacement: replace [begin,end) instructions in the genome with the fragment,
+		// respecting circularity.
+		offspring.Replace(*selected, location.begin, location.end);
 	}
 	
 	// resource utilization, cleanup, and stats tracking:
-	m_world->GetPopulation().AdjustHGTResource(-f->GetSize());
-	m_world->GetStats().GenomeFragmentInserted(cell.GetOrganism(), *f);
-	fragments.erase(f);
+	m_world->GetPopulation().AdjustHGTResource(-selected->GetSize());
+	m_world->GetStats().GenomeFragmentInserted(cell.GetOrganism(), *selected, location);
+	cell.GetFragments().erase(selected);
 }
+
+
+/*! Randomly select the fragment used for HGT mutation.
+ */
+void cPopulationInterface::HGTRandomFragmentSelection(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()));
+
+	// find the location within the offspring's genome that best matches the selected fragment:
+	location = cGenomeUtil::FindUnbiasedCircularMatch(ctx, offspring, *selected);
+}
+
+
+/*! Randomly select the fragment used for HGT mutation, trimming redundant instructions.
+ 
+ In this fragment selection method, the fragment itself is selected randomly, but the
+ match location within the genome is calculated on a "trimmed" fragment.  Specifically,
+ the trimmed fragment has all duplicate instructions at its end removed prior to the match.
+ 
+ Mutations to the offspring are still performed using the entire fragment, so this effectively
+ increases the insertion rate.  E.g., hgt(abcde, abcccc) -> abccccde.
+ */
+void cPopulationInterface::HGTTrimmedFragmentSelection(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()));
+	
+	// copy the selected fragment, trimming redundant instructions at the end:
+	cGenome trimmed(*selected);
+	while((trimmed.GetSize() >= 2) && (trimmed[trimmed.GetSize()-1] == trimmed[trimmed.GetSize()-2])) {
+		trimmed.Remove(trimmed.GetSize()-1);
+	}
+	
+	// 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: branches/parasites/source/main/cPopulationInterface.h
===================================================================
--- branches/parasites/source/main/cPopulationInterface.h	2009-12-15 22:39:52 UTC (rev 3557)
+++ branches/parasites/source/main/cPopulationInterface.h	2009-12-16 15:51:37 UTC (rev 3558)
@@ -35,12 +35,13 @@
 #ifndef cWorldDriver_h
 #include "cWorldDriver.h"
 #endif
+#include "cGenomeUtil.h"
+#include "cPopulationCell.h"
 
 class cAvidaContext;
 class cDeme;
 class cGenome;
 class cPopulation;
-class cPopulationCell;
 class cOrgMessage;
 
 class cPopulationInterface : public cOrgInterface
@@ -141,8 +142,25 @@
 	
 	// -------- HGT support --------
 public:
+	//! Container type for fragments used during HGT.
+	typedef cPopulationCell::fragment_list_type fragment_list_type;
+	//! Match record, used to indicate the region within a genome that should be mutated.
+	typedef cGenomeUtil::substring_match substring_match;
 	//! Perform an HGT mutation on this offspring.
 	void DoHGTMutation(cAvidaContext& ctx, cGenome& offspring);
+protected:
+	//! 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);
+	//! Random selection of the fragment used for HGT mutation, with redundant instructions trimmed.
+	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);	
 };
 
 

Modified: branches/parasites/source/main/cReactionProcess.h
===================================================================
--- branches/parasites/source/main/cReactionProcess.h	2009-12-15 22:39:52 UTC (rev 3557)
+++ branches/parasites/source/main/cReactionProcess.h	2009-12-16 15:51:37 UTC (rev 3558)
@@ -52,6 +52,7 @@
   double max_number;     // Max quantity of resource usable.
   double min_number;     // Minimum quantity of resource needed (otherwise 0)
   double max_fraction;   // Max fraction of avaiable resources useable.
+  double k_sub_m;        // k sub m variable needed for enzyme reaction
   cResource* product;    // Output resource.
   double conversion;     // Conversion factor.
   bool lethal;		 // Lethality of reaction
@@ -82,6 +83,7 @@
     , max_number(1.0)
     , min_number(0.0)
     , max_fraction(1.0)
+    , k_sub_m(0.0)
     , product(NULL)
     , conversion(1.0)
     , lethal(0)
@@ -104,6 +106,7 @@
   double GetMaxNumber() const { return max_number; }
   double GetMinNumber() const { return min_number; }
   double GetMaxFraction() const { return max_fraction; }
+  double GetKsubM() const { return k_sub_m; }
   cResource* GetProduct() const { return product; }
   double GetConversion() const { return conversion; }
   int GetInstID() const { return inst_id; }
@@ -124,6 +127,7 @@
   void SetMaxNumber(double _in) { max_number = _in; }
   void SetMinNumber(double _in) { min_number = _in; }
   void SetMaxFraction(double _in) { max_fraction = _in; }
+  void SetKsubM(double _in) { k_sub_m = _in; }
   void SetProduct(cResource* _in) { product = _in; }
   void SetConversion(double _in) { conversion = _in; }
   void SetInstID(int _in) { inst_id = _in; }

Modified: branches/parasites/source/main/cStats.cc
===================================================================
--- branches/parasites/source/main/cStats.cc	2009-12-15 22:39:52 UTC (rev 3557)
+++ branches/parasites/source/main/cStats.cc	2009-12-16 15:51:37 UTC (rev 3558)
@@ -136,6 +136,7 @@
   , m_spec_waste(0)
   , num_orgs_killed(0)
 	, num_unoccupied_cell_kill_attempts(0)
+  , num_cells_scanned_at_kill(0)
   , num_migrations(0)
   , m_deme_num_repls(0)
 	, m_deme_num_repls_treatable(0)
@@ -581,6 +582,7 @@
   
   num_orgs_killed = 0;
 	num_unoccupied_cell_kill_attempts = 0;
+  num_cells_scanned_at_kill = 0;
   num_migrations = 0;
 }
 
@@ -2483,6 +2485,7 @@
   df.Write(m_update,   "Update");
   df.Write(num_orgs_killed, "Num Orgs Killed");
   df.Write(num_unoccupied_cell_kill_attempts, "Num Unoccupied Cell Kill Attempts");
+  df.Write(num_cells_scanned_at_kill, "Num Cells Scanned By Kill Event");
   df.Endl();
 } //End PrintNumOrgsKilledData()
 
@@ -2952,7 +2955,9 @@
 	m_hgt_metabolized.Add(fragment.GetSize());
 }
 
-void cStats::GenomeFragmentInserted(cOrganism* organism, const cGenome& fragment) {
+/*! Called when a fragment is inserted into an offspring's genome via HGT.
+ */
+void cStats::GenomeFragmentInserted(cOrganism* organism, const cGenome& fragment, const cGenomeUtil::substring_match& location) {
 	m_hgt_inserted.Add(fragment.GetSize());
 }
 

Modified: branches/parasites/source/main/cStats.h
===================================================================
--- branches/parasites/source/main/cStats.h	2009-12-15 22:39:52 UTC (rev 3557)
+++ branches/parasites/source/main/cStats.h	2009-12-16 15:51:37 UTC (rev 3558)
@@ -67,6 +67,7 @@
 #include "nGeometry.h"
 #endif
 #include "cGenome.h"
+#include "cGenomeUtil.h"
 
 #if USE_tMemTrack
 # ifndef tMemTrack_h
@@ -342,6 +343,7 @@
   // Number of organisms killed by kill actions
   int num_orgs_killed;
 	int num_unoccupied_cell_kill_attempts;
+  int num_cells_scanned_at_kill;
   
   // Number of migrations that have been made
   int num_migrations;
@@ -576,6 +578,7 @@
   
   void IncNumOrgsKilled() { num_orgs_killed++; }
 	void IncNumUnoccupiedCellAttemptedToKill() { num_unoccupied_cell_kill_attempts++; }
+  void IncNumCellsScannedAtKill() { num_cells_scanned_at_kill++; }
   void IncNumMigrations() { num_migrations++; }
 
   void AddCurTask(int task_num) { task_cur_count[task_num]++; }
@@ -752,6 +755,7 @@
   int GetSpeculativeWaste() const { return m_spec_waste; }
   
   int GetNumOrgsKilled() const { return num_orgs_killed; }
+  int GetNumCellsScannedAtKill() const { return num_cells_scanned_at_kill; }
   int GetNumMigrations() const { return num_migrations; }
 
   // this value gets recorded when a creature with the particular
@@ -1031,7 +1035,7 @@
 	//! Called when an organism metabolizes a genome fragment.
 	void GenomeFragmentMetabolized(cOrganism* organism, const cGenome& fragment);
 	//! Called when an organism inserts a genome fragment.
-	void GenomeFragmentInserted(cOrganism* organism, const cGenome& fragment);
+	void GenomeFragmentInserted(cOrganism* organism, const cGenome& fragment, const cGenomeUtil::substring_match& location);
 	//! Print HGT statistics.
 	void PrintHGTData(const cString& filename);
 };

Modified: branches/parasites/source/tools/cBitArray.h
===================================================================
--- branches/parasites/source/tools/cBitArray.h	2009-12-15 22:39:52 UTC (rev 3557)
+++ branches/parasites/source/tools/cBitArray.h	2009-12-16 15:51:37 UTC (rev 3558)
@@ -120,7 +120,7 @@
   void Ones(const int num_bits) {
     const int num_fields = GetNumFields(num_bits);
     for (int i = 0; i < num_fields; i++) {
-      bit_fields[i] = -1;
+      bit_fields[i] = ~0;
     }    
     const int last_bit = GetFieldPos(num_bits);
     if (last_bit > 0) {

Modified: branches/parasites/tests/default_transsmt_100u/test_list
===================================================================
--- branches/parasites/tests/default_transsmt_100u/test_list	2009-12-15 22:39:52 UTC (rev 3557)
+++ branches/parasites/tests/default_transsmt_100u/test_list	2009-12-16 15:51:37 UTC (rev 3558)
@@ -12,7 +12,7 @@
 email = brysonda at egr.msu.edu ; Email address for the test's creator
 
 [consistency]
-enabled = yes            ; Is this test a consistency test?
+enabled = no            ; Is this test a consistency test?
 long = no                ; Is this test a long test?
 
 [performance]




More information about the Avida-cvs mailing list