[Avida-cvs] [avida-svn] r777 - in development/source: actions cpu event

brysonda@myxo.css.msu.edu brysonda at myxo.css.msu.edu
Mon Jun 26 08:44:06 PDT 2006


Author: brysonda
Date: 2006-06-26 11:44:06 -0400 (Mon, 26 Jun 2006)
New Revision: 777

Modified:
   development/source/actions/PopulationActions.cc
   development/source/actions/PrintActions.cc
   development/source/actions/SaveLoadActions.cc
   development/source/cpu/cCodeLabel.cc
   development/source/cpu/cCodeLabel.h
   development/source/cpu/cHardwareSMT.cc
   development/source/event/cEventList.cc
   development/source/event/cEventManager.cc
Log:
Add InjectParasite and InjectParasitePair.   Added new method to cCodeLabel that reads in a cString, parsing it as a NOP sequence.  Fixed a bug in InjectHost.

Modified: development/source/actions/PopulationActions.cc
===================================================================
--- development/source/actions/PopulationActions.cc	2006-06-26 12:53:49 UTC (rev 776)
+++ development/source/actions/PopulationActions.cc	2006-06-26 15:44:06 UTC (rev 777)
@@ -11,6 +11,7 @@
 
 #include "cAction.h"
 #include "cActionLibrary.h"
+#include "cCodeLabel.h"
 #include "cGenome.h"
 #include "cHardwareManager.h"
 #include "cInstUtil.h"
@@ -56,7 +57,7 @@
     if (m_filename == "START_CREATURE") m_filename = m_world->GetConfig().START_CREATURE.Get();
 }
   
-  const cString GetDescription() { return "Inject [cString fname=\"START_CREATURE\"] [int cell_id=0] [double merit=-1] [int lineage_label=0] [double neutral_metric=0]"; }
+  const cString GetDescription() { return "Inject [string fname=\"START_CREATURE\"] [int cell_id=0] [double merit=-1] [int lineage_label=0] [double neutral_metric=0]"; }
 
   void Process(cAvidaContext& ctx)
   {
@@ -67,6 +68,50 @@
 
 
 /*
+ Injects a randomly generated genome into the population.
+ 
+ Parameters:
+   length (integer) [required]
+     Number of instructions in the randomly generated genome.
+   cell ID (integer) default: 0
+     The grid-point into which the organism should be placed.
+   merit (double) default: -1
+     The initial merit of the organism. If set to -1, this is ignored.
+   lineage label (integer) default: 0
+     An integer that marks all descendants of this organism.
+   neutral metric (double) default: 0
+     A double value that randomly drifts over time.
+*/
+class cActionInjectRandom : public cAction
+{
+private:
+  int m_length;
+  int m_cell_id;
+  double m_merit;
+  int m_lineage_label;
+  double m_neutral_metric;
+public:
+  cActionInjectRandom(cWorld* world, const cString& args) : cAction(world, args), m_cell_id(0), m_merit(-1), m_lineage_label(0), m_neutral_metric(0)
+  {
+    cString largs(args);
+    m_length = largs.PopWord().AsInt();
+    if (largs.GetSize()) m_cell_id = largs.PopWord().AsInt();
+    if (largs.GetSize()) m_merit = largs.PopWord().AsDouble();
+    if (largs.GetSize()) m_lineage_label = largs.PopWord().AsInt();
+    if (largs.GetSize()) m_neutral_metric = largs.PopWord().AsDouble();
+  }
+  
+  const cString GetDescription() { return "InjectRandom <int length> [int cell_id=0] [double merit=-1] [int lineage_label=0] [double neutral_metric=0]"; }
+
+  void Process(cAvidaContext& ctx)
+  {
+    cGenome genome = cInstUtil::RandomGenome(ctx, m_length, m_world->GetHardwareManager().GetInstSet());
+    m_world->GetPopulation().Inject(genome, m_cell_id, m_merit, m_lineage_label, m_neutral_metric);
+  }
+};
+
+
+/*
  Injects identical organisms into all cells of the population.
  
  Parameters:
@@ -102,7 +147,7 @@
     if (m_filename == "START_CREATURE") m_filename = m_world->GetConfig().START_CREATURE.Get();
   }
   
-  const cString GetDescription() { return "InjectAll [cString fname=\"START_CREATURE\"] [double merit=-1] [int lineage_label=0] [double neutral_metric=0]"; }
+  const cString GetDescription() { return "InjectAll [string fname=\"START_CREATURE\"] [double merit=-1] [int lineage_label=0] [double neutral_metric=0]"; }
   
   void Process(cAvidaContext& ctx)
   {
@@ -141,7 +186,8 @@
   int m_lineage_label;
   double m_neutral_metric;
 public:
-  cActionInjectRange(cWorld* world, const cString& args) : cAction(world, args), m_cell_start(0), m_cell_end(-1), m_merit(-1), m_lineage_label(0), m_neutral_metric(0)
+  cActionInjectRange(cWorld* world, const cString& args)
+  : cAction(world, args), m_cell_start(0), m_cell_end(-1), m_merit(-1), m_lineage_label(0), m_neutral_metric(0)
   {
     cString largs(args);
     if (!largs.GetSize()) m_filename = "START_CREATURE"; else m_filename = largs.PopWord();
@@ -155,14 +201,14 @@
     if (m_cell_end == -1) m_cell_end = m_cell_start + 1;
   }
   
-  const cString GetDescription() { return "InjectRange [cString fname=\"START_CREATURE\"] [int cell_start=0] [int cell_end=-1] [double merit=-1] [int lineage_label=0] [double neutral_metric=0]"; }
+  const cString GetDescription() { return "InjectRange [string fname=\"START_CREATURE\"] [int cell_start=0] [int cell_end=-1] [double merit=-1] [int lineage_label=0] [double neutral_metric=0]"; }
   
   void Process(cAvidaContext& ctx)
   {
-    cGenome genome = cInstUtil::LoadGenome(m_filename, m_world->GetHardwareManager().GetInstSet());
     if (m_cell_start < 0 || m_cell_end > m_world->GetPopulation().GetSize() || m_cell_start >= m_cell_end) {
       m_world->GetDriver().NotifyWarning("InjectRange has invalid range!");
     } else {
+      cGenome genome = cInstUtil::LoadGenome(m_filename, m_world->GetHardwareManager().GetInstSet());
       for (int i = m_cell_start; i < m_cell_end; i++) {
         m_world->GetPopulation().Inject(genome, i, m_merit, m_lineage_label, m_neutral_metric);
       }
@@ -173,15 +219,126 @@
 
 
 /*
+ Injects identical organisms into a range of cells of the population.
+ 
+ Parameters:
+   sequence (string) [required]
+     The genome sequence for this organism.
+   cell_start (int)
+     First cell to inject into.
+   cell_end (int)
+     First cell *not* to inject into.
+   merit (double) default: -1
+     The initial merit of the organism. If set to -1, this is ignored.
+   lineage label (integer) default: 0
+     An integer that marks all descendants of this organism.
+   neutral metric (double) default: 0
+     A double value that randomly drifts over time.
+*/
+class cActionInjectSequence : public cAction
+{
+private:
+  cString m_sequence;
+  int m_cell_start;
+  int m_cell_end;
+  double m_merit;
+  int m_lineage_label;
+  double m_neutral_metric;
+public:
+  cActionInjectSequence(cWorld* world, const cString& args)
+  : cAction(world, args), m_cell_start(0), m_cell_end(-1), m_merit(-1), m_lineage_label(0), m_neutral_metric(0)
+  {
+    cString largs(args);
+    m_sequence = largs.PopWord();
+    if (largs.GetSize()) m_cell_start = largs.PopWord().AsInt();
+    if (largs.GetSize()) m_cell_end = largs.PopWord().AsInt();
+    if (largs.GetSize()) m_merit = largs.PopWord().AsDouble();
+    if (largs.GetSize()) m_lineage_label = largs.PopWord().AsInt();
+    if (largs.GetSize()) m_neutral_metric = largs.PopWord().AsDouble();
+    
+    if (m_cell_end == -1) m_cell_end = m_cell_start + 1;
+  }
+  
+  const cString GetDescription() { return "InjectSequence [string fname=\"START_CREATURE\"] [int cell_start=0] [int cell_end=-1] [double merit=-1] [int lineage_label=0] [double neutral_metric=0]"; }
+  
+  void Process(cAvidaContext& ctx)
+  {
+    if (m_cell_start < 0 || m_cell_end > m_world->GetPopulation().GetSize() || m_cell_start >= m_cell_end) {
+      m_world->GetDriver().NotifyWarning("InjectRange has invalid range!");
+    } else {
+      cGenome genome(m_sequence);
+      for (int i = m_cell_start; i < m_cell_end; i++) {
+        m_world->GetPopulation().Inject(genome, i, m_merit, m_lineage_label, m_neutral_metric);
+      }
+      m_world->GetPopulation().SetSyncEvents(true);
+    }
+  }
+};
+
+
+/*
  Injects identical parasites into a range of cells of the population.
  
  Parameters:
-   filename (string)
+   filename (string) [required]
      The filename of the genotype to load.
+   label (string) [required]
+     The parasite's inject target label.
    cell_start (int)
      First cell to inject into.
    cell_end (int)
      First cell *not* to inject into.
+*/
+class cActionInjectParasite : public cAction
+{
+private:
+  cString m_filename;
+  cCodeLabel m_label;
+  int m_cell_start;
+  int m_cell_end;
+public:
+  cActionInjectParasite(cWorld* world, const cString& args) : cAction(world, args), m_cell_start(0), m_cell_end(-1)
+  {
+    cString largs(args);
+    m_filename = largs.PopWord();
+    m_label.ReadString(largs.PopWord());
+    if (largs.GetSize()) m_cell_start = largs.PopWord().AsInt();
+    if (largs.GetSize()) m_cell_end = largs.PopWord().AsInt();
+    
+    if (m_cell_end == -1) m_cell_end = m_cell_start + 1;
+  }
+  
+  const cString GetDescription() { return "InjectParasite <string filename> <string label> [int cell_start=0] [int cell_end=-1]"; }
+  
+  void Process(cAvidaContext& ctx)
+  {
+    if (m_cell_start < 0 || m_cell_end > m_world->GetPopulation().GetSize() || m_cell_start >= m_cell_end) {
+      m_world->GetDriver().NotifyWarning("InjectParasite has invalid range!");
+    } else {
+      cGenome genome = cInstUtil::LoadGenome(m_filename, m_world->GetHardwareManager().GetInstSet());
+      for (int i = m_cell_start; i < m_cell_end; i++) {
+        m_world->GetPopulation().InjectParasite(m_label, genome, i);
+      }
+      m_world->GetPopulation().SetSyncEvents(true);
+    }
+  }
+};
+
+
+/*
+ Injects identical parasites into a range of cells of the population.
+ 
+ Parameters:
+   filename_genome (string) [required]
+     The filename of the genotype to load.
+   filename_parasite (string) [required]
+     The filename of the parasite to load.
+   label (string) [required]
+     The parasite's inject target label.
+   cell_start (int)
+     First cell to inject into.
+   cell_end (int)
+     First cell *not* to inject into.
    merit (double) default: -1
      The initial merit of the organism. If set to -1, this is ignored.
    lineage label (integer) default: 0
@@ -189,39 +346,46 @@
    neutral metric (double) default: 0
      A double value that randomly drifts over time.
 */
-class cActionInjectParasiteRange : public cAction
+class cActionInjectParasitePair : public cAction
 {
 private:
-  cString m_filename;
+  cString m_filename_genome;
+  cString m_filename_parasite;
+  cCodeLabel m_label;
   int m_cell_start;
   int m_cell_end;
   double m_merit;
   int m_lineage_label;
   double m_neutral_metric;
 public:
-  cActionInjectParasiteRange(cWorld* world, const cString& args) : cAction(world, args), m_cell_start(0), m_cell_end(-1), m_merit(-1), m_lineage_label(0), m_neutral_metric(0)
+  cActionInjectParasitePair(cWorld* world, const cString& args)
+  : cAction(world, args), m_cell_start(0), m_cell_end(-1), m_merit(-1), m_lineage_label(0), m_neutral_metric(0)
   {
-      cString largs(args);
-      if (!largs.GetSize()) m_filename = "default.para"; else m_filename = largs.PopWord();
-      if (largs.GetSize()) m_cell_start = largs.PopWord().AsInt();
-      if (largs.GetSize()) m_cell_end = largs.PopWord().AsInt();
-      if (largs.GetSize()) m_merit = largs.PopWord().AsDouble();
-      if (largs.GetSize()) m_lineage_label = largs.PopWord().AsInt();
-      if (largs.GetSize()) m_neutral_metric = largs.PopWord().AsDouble();
-      
-      if (m_cell_end == -1) m_cell_end = m_cell_start + 1;
+    cString largs(args);
+    m_filename_genome = largs.PopWord();
+    m_filename_parasite = largs.PopWord();
+    m_label.ReadString(largs.PopWord());
+    if (largs.GetSize()) m_cell_start = largs.PopWord().AsInt();
+    if (largs.GetSize()) m_cell_end = largs.PopWord().AsInt();
+    if (largs.GetSize()) m_merit = largs.PopWord().AsDouble();
+    if (largs.GetSize()) m_lineage_label = largs.PopWord().AsInt();
+    if (largs.GetSize()) m_neutral_metric = largs.PopWord().AsDouble();
+    
+    if (m_cell_end == -1) m_cell_end = m_cell_start + 1;
   }
   
-  const cString GetDescription() { return "InjectRange <cString filename=\"START_CREATURE\"> [int cell_start=0] [int cell_end=-1] [double merit=-1] [int lineage_label=0] [double neutral_metric=0]"; }
+  const cString GetDescription() { return "InjectParasitePair <string filename_genome> <string filename_parasite> <string label> [int cell_start=0] [int cell_end=-1] [double merit=-1] [int lineage_label=0] [double neutral_metric=0]"; }
   
   void Process(cAvidaContext& ctx)
   {
-    cGenome genome = cInstUtil::LoadGenome(m_filename, m_world->GetHardwareManager().GetInstSet());
     if (m_cell_start < 0 || m_cell_end > m_world->GetPopulation().GetSize() || m_cell_start >= m_cell_end) {
-      m_world->GetDriver().NotifyWarning("InjectParasiteRange has invalid range!");
+      m_world->GetDriver().NotifyWarning("InjectParasitePair has invalid range!");
     } else {
+      cGenome genome = cInstUtil::LoadGenome(m_filename_genome, m_world->GetHardwareManager().GetInstSet());
+      cGenome parasite = cInstUtil::LoadGenome(m_filename_parasite, m_world->GetHardwareManager().GetInstSet());
       for (int i = m_cell_start; i < m_cell_end; i++) {
-        // @DMB 
+        m_world->GetPopulation().Inject(genome, i, m_merit, m_lineage_label, m_neutral_metric);
+        m_world->GetPopulation().InjectParasite(m_label, parasite, i);
       }
       m_world->GetPopulation().SetSyncEvents(true);
     }
@@ -233,12 +397,20 @@
 void RegisterPopulationActions(cActionLibrary* action_lib)
 {
   action_lib->Register<cActionInject>("Inject");
+  action_lib->Register<cActionInjectRandom>("InjectRandom");
   action_lib->Register<cActionInjectAll>("InjectAll");
   action_lib->Register<cActionInjectRange>("InjectRange");
+  action_lib->Register<cActionInjectSequence>("InjectSequence");
 
+  action_lib->Register<cActionInjectParasite>("InjectParasite");
+  action_lib->Register<cActionInjectParasitePair>("InjectParasitePair");
 
+
+
   // @DMB - The following actions are DEPRECATED aliases - These will be removed in 2.7.
   action_lib->Register<cActionInject>("inject");
+  action_lib->Register<cActionInjectRandom>("inject_random");
   action_lib->Register<cActionInjectAll>("inject_all");
   action_lib->Register<cActionInjectRange>("inject_range");
+  action_lib->Register<cActionInject>("inject_sequence");
 }

Modified: development/source/actions/PrintActions.cc
===================================================================
--- development/source/actions/PrintActions.cc	2006-06-26 12:53:49 UTC (rev 776)
+++ development/source/actions/PrintActions.cc	2006-06-26 15:44:06 UTC (rev 777)
@@ -42,7 +42,7 @@
     cString largs(args);                                                                  /*  8 */ \
     if (largs == "") m_filename = #DEFAULT; else m_filename = largs.PopWord();            /*  9 */ \
   }                                                                                       /* 10 */ \
-  const cString GetDescription() { return #METHOD " [cString fname=\"" #DEFAULT "\"]"; }  /* 11 */ \
+  const cString GetDescription() { return #METHOD " [string fname=\"" #DEFAULT "\"]"; }  /* 11 */ \
   void Process(cAvidaContext& ctx) { m_world->GetStats().METHOD(m_filename); }            /* 12 */ \
 }                                                                                         /* 13 */ \
 
@@ -75,7 +75,7 @@
     cString largs(args);                                                                  /*  8 */ \
     if (largs == "") m_filename = #DEFAULT; else m_filename = largs.PopWord();            /*  9 */ \
   }                                                                                       /* 10 */ \
-  const cString GetDescription() { return #METHOD " [cString fname=\"" #DEFAULT "\"]"; }  /* 11 */ \
+  const cString GetDescription() { return #METHOD " [string fname=\"" #DEFAULT "\"]"; }  /* 11 */ \
   void Process(cAvidaContext& ctx) { m_world->GetPopulation().METHOD(m_filename); }       /* 12 */ \
 }                                                                                         /* 13 */ \
 
@@ -117,7 +117,7 @@
     if (largs == "") m_filename = "instruction_histogram.dat"; else m_filename = largs.PopWord();
   }
 
-  const cString GetDescription() { return "PrintInstructionAbundanceHistogram [cString fname=\"instruction_histogram.dat\"]"; }
+  const cString GetDescription() { return "PrintInstructionAbundanceHistogram [string fname=\"instruction_histogram.dat\"]"; }
   
   void Process(cAvidaContext& ctx)
   {
@@ -161,7 +161,7 @@
     if (largs == "") m_filename = "depth_histogram.dat"; else m_filename = largs.PopWord();
   }
   
-  const cString GetDescription() { return "PrintDepthHistogram [cString fname=\"depth_histogram.dat\"]"; }
+  const cString GetDescription() { return "PrintDepthHistogram [string fname=\"depth_histogram.dat\"]"; }
   
   void Process(cAvidaContext& ctx)
   {
@@ -234,7 +234,7 @@
     if (largs == "") m_filename = "genotype_abundance_histogram.dat"; else m_filename = largs.PopWord();
   }
   
-  const cString GetDescription() { return "PrintGenotypeAbundanceHistogram [cString fname=\"genotype_abundance_histogram.dat\"]"; }
+  const cString GetDescription() { return "PrintGenotypeAbundanceHistogram [string fname=\"genotype_abundance_histogram.dat\"]"; }
   
   void Process(cAvidaContext& ctx)
   {
@@ -270,7 +270,7 @@
     if (largs == "") m_filename = "species_abundance_histogram.dat"; else m_filename = largs.PopWord();
   }
   
-  const cString GetDescription() { return "PrintSpeciesAbundanceHistogram [cString fname=\"species_abundance_histogram.dat\"]"; }
+  const cString GetDescription() { return "PrintSpeciesAbundanceHistogram [string fname=\"species_abundance_histogram.dat\"]"; }
   
   void Process(cAvidaContext& ctx)
   {
@@ -320,7 +320,7 @@
     if (largs.GetSize()) m_verbose = largs.PopWord().AsInt();
   }
   
-  const cString GetDescription() { return "PrintLineageTotals [cString fname='lineage_totals.dat'] [int verbose=1]"; }
+  const cString GetDescription() { return "PrintLineageTotals [string fname='lineage_totals.dat'] [int verbose=1]"; }
   
   void Process(cAvidaContext& ctx)
   {
@@ -345,7 +345,7 @@
     if (largs.GetSize()) m_verbose = largs.PopWord().AsInt();
   }
   
-  const cString GetDescription() { return "PrintLineageCounts [cString fname='lineage_counts.dat'] [int verbose=1]"; }
+  const cString GetDescription() { return "PrintLineageCounts [string fname='lineage_counts.dat'] [int verbose=1]"; }
   
   void Process(cAvidaContext& ctx)
   {
@@ -384,7 +384,7 @@
     if (largs.GetSize()) m_filename = largs.PopWord();
   }
   
-  const cString GetDescription() { return "PrintDominantGenotype [cString fname='']"; }
+  const cString GetDescription() { return "PrintDominantGenotype [string fname='']"; }
   
   void Process(cAvidaContext& ctx)
   {
@@ -417,7 +417,7 @@
     if (largs.GetSize()) m_filename = largs.PopWord();
   }
   
-  const cString GetDescription() { return "PrintDominantParasiteGenotype [cString fname='']"; }
+  const cString GetDescription() { return "PrintDominantParasiteGenotype [string fname='']"; }
   
   void Process(cAvidaContext& ctx)
   {
@@ -477,7 +477,7 @@
     if (largs.GetSize()) m_filename = largs.PopWord();
   }
   
-  const cString GetDescription() { return "PrintGenotypes [cString data_fields=\"all\"] [int historic=0] [cString fname='']"; }
+  const cString GetDescription() { return "PrintGenotypes [string data_fields=\"all\"] [int historic=0] [string fname='']"; }
   
   void Process(cAvidaContext& ctx)
   {
@@ -538,7 +538,7 @@
     if (!largs.GetSize()) m_filenames[2] = "fitness_histos_testCPU.dat"; else m_filenames[2] = largs.PopWord();
   }
   
-  const cString GetDescription() { return "PrintDetailedFitnessData [int save_max_f_genotype=0] [int print_fitness_histo=0] [double hist_fmax=1] [double hist_fstep=0.1] [cString datafn=\"fitness.dat\"] [cString histofn=\"fitness_histos.dat\"] [cString histotestfn=\"fitness_histos_testCPU.dat\"]"; }
+  const cString GetDescription() { return "PrintDetailedFitnessData [int save_max_f_genotype=0] [int print_fitness_histo=0] [double hist_fmax=1] [double hist_fstep=0.1] [string datafn=\"fitness.dat\"] [string histofn=\"fitness_histos.dat\"] [string histotestfn=\"fitness_histos_testCPU.dat\"]"; }
   
   void Process(cAvidaContext& ctx)
   {
@@ -691,7 +691,7 @@
     if (largs.GetSize()) m_filename = largs.PopWord();
   }
   
-  const cString GetDescription() { return "PrintGeneticDistanceData [cString ref_creature_file='START_CREATURE'] [cString fname='genetic_distance.dat']"; }
+  const cString GetDescription() { return "PrintGeneticDistanceData [string ref_creature_file='START_CREATURE'] [string fname='genetic_distance.dat']"; }
   
   void Process(cAvidaContext& ctx)
   {
@@ -745,7 +745,7 @@
     if (largs.GetSize()) m_filename = largs.PopWord();
   }
   
-  const cString GetDescription() { return "PrintDumpMemory [cString fname='']"; }
+  const cString GetDescription() { return "PrintDumpMemory [string fname='']"; }
   
   void Process(cAvidaContext& ctx)
   {

Modified: development/source/actions/SaveLoadActions.cc
===================================================================
--- development/source/actions/SaveLoadActions.cc	2006-06-26 12:53:49 UTC (rev 776)
+++ development/source/actions/SaveLoadActions.cc	2006-06-26 15:44:06 UTC (rev 777)
@@ -39,7 +39,7 @@
     if (largs.GetSize()) m_filename = largs.PopWord();
   }
 
-  const cString GetDescription() { return "SaveClone [cString fname='']"; }
+  const cString GetDescription() { return "SaveClone [string fname='']"; }
 
   void Process(cAvidaContext& ctx)
   {
@@ -135,7 +135,7 @@
     if (largs.GetSize()) m_filename = largs.PopWord();
   }
   
-  const cString GetDescription() { return "DumpPopulation [cString fname='']"; }
+  const cString GetDescription() { return "DumpPopulation [string fname='']"; }
   
   void Process(cAvidaContext& ctx)
   {
@@ -165,7 +165,7 @@
     if (largs.GetSize()) m_filename = largs.PopWord();
   }
   
-  const cString GetDescription() { return "SavePopulation [cString fname='']"; }
+  const cString GetDescription() { return "SavePopulation [string fname='']"; }
   
   void Process(cAvidaContext& ctx)
   {
@@ -197,7 +197,7 @@
     if (largs.GetSize()) m_filename = largs.PopWord();
   }
   
-  const cString GetDescription() { return "SaveSexPopulation [cString fname='']"; }
+  const cString GetDescription() { return "SaveSexPopulation [string fname='']"; }
   
   void Process(cAvidaContext& ctx)
   {
@@ -221,7 +221,7 @@
     if (largs.GetSize()) m_filename = largs.PopWord();
   }
   
-  const cString GetDescription() { return "SaveParasitePopulation [cString fname='']"; }
+  const cString GetDescription() { return "SaveParasitePopulation [string fname='']"; }
   
   void Process(cAvidaContext& ctx)
   {
@@ -260,7 +260,7 @@
     if (largs.GetSize()) m_filename = largs.PopWord();
   }
   
-  const cString GetDescription() { return "SaveHistoricPopulation [int back_dist=-1] [cString fname='']"; }
+  const cString GetDescription() { return "SaveHistoricPopulation [int back_dist=-1] [string fname='']"; }
   
   void Process(cAvidaContext& ctx)
   {
@@ -292,7 +292,7 @@
     if (largs.GetSize()) m_filename = largs.PopWord();
   }
   
-  const cString GetDescription() { return "SaveHistoricSexPopulation [cString fname='']"; }
+  const cString GetDescription() { return "SaveHistoricSexPopulation [string fname='']"; }
   
   void Process(cAvidaContext& ctx)
   {

Modified: development/source/cpu/cCodeLabel.cc
===================================================================
--- development/source/cpu/cCodeLabel.cc	2006-06-26 12:53:49 UTC (rev 776)
+++ development/source/cpu/cCodeLabel.cc	2006-06-26 15:44:06 UTC (rev 777)
@@ -20,14 +20,34 @@
 
 using namespace std;
 
+
+void cCodeLabel::ReadString(const cString& label_str)
+{
+  cString lbl(label_str);
+  lbl.Trim();
+  m_size = lbl.GetSize();
+  m_nops.Resize(lbl.GetSize());
+  
+  for (int i = 0; i < lbl.GetSize(); i++) {
+    int nop = lbl[i] - 'A';
+    if (nop < 0 || nop >= nHardware::MAX_NOPS) {
+      // on invalid nop, terminate sequence
+      m_size = i;
+      m_nops.Resize(i);
+      break;
+    }
+    m_nops[i] =  nop;
+  }
+}
+
 bool cCodeLabel::OK()
 {
   bool result = true;
 
-  assert (size <= nHardware::MAX_LABEL_SIZE);
-  assert (size <= nop_sequence.GetSize());
-  for (int i = 0; i < size; i++) {
-    assert (nop_sequence[i] < nHardware::MAX_NOPS);
+  assert (m_size <= nHardware::MAX_LABEL_SIZE);
+  assert (m_size <= m_nops.GetSize());
+  for (int i = 0; i < m_size; i++) {
+    assert (m_nops[i] < nHardware::MAX_NOPS);
   }
 
   return result;
@@ -35,12 +55,12 @@
 
 bool cCodeLabel::operator==(const cCodeLabel & other_label) const
 {
-  if (size != other_label.GetSize()) {
+  if (m_size != other_label.GetSize()) {
     return false;
   }
 
-  for (int i = 0; i < size; i++) {
-    if (nop_sequence[i] != other_label[i]) {
+  for (int i = 0; i < m_size; i++) {
+    if (m_nops[i] != other_label[i]) {
       return false;
     }
   }
@@ -55,9 +75,9 @@
 {
   bool error = false;
 
-  for (int offset = 0; offset <= size - sub_label.GetSize(); offset++) {
+  for (int offset = 0; offset <= m_size - sub_label.GetSize(); offset++) {
     for (int i = 0; i < sub_label.GetSize(); i++) {
-      if (nop_sequence[i + offset] != sub_label[i]) {
+      if (m_nops[i + offset] != sub_label[i]) {
 	error = true;
 	break;
       }
@@ -73,9 +93,9 @@
 {
   int value = 0;
 
-  for (int i = 0; i < size; i++) {
+  for (int i = 0; i < m_size; i++) {
     value *= base;
-    value += nop_sequence[i];
+    value += m_nops[i];
   }
 
   return value;
@@ -86,17 +106,17 @@
   int value = 0;
   int oddCount = 0;
 
-  for (int i = 0; i < size; i++) {
+  for (int i = 0; i < m_size; i++) {
     value *= base;
 
     if(oddCount % 2 == 0) {
-      value += nop_sequence[i];
+      value += m_nops[i];
     } else {
       // @DMB - this should not be relying on hardware specific NUM_NOPS
-      value += (nHardwareCPU::NUM_NOPS - 1) - nop_sequence[i];
+      value += (nHardwareCPU::NUM_NOPS - 1) - m_nops[i];
     }
 
-    if(nop_sequence[i] % 2 == 1) {
+    if(m_nops[i] % 2 == 1) {
       oddCount++;
     }
   }
@@ -108,9 +128,9 @@
 {
   int value = 0;
 
-  for (int i = 0; i < size; i++) {
+  for (int i = 0; i < m_size; i++) {
     value *= base;
-    value += nop_sequence[i];
+    value += m_nops[i];
   }
 
   return value;
@@ -120,16 +140,16 @@
 {
   double value = 0.0;
 
-  for (int i = 0; i < size; i++) {
+  for (int i = 0; i < m_size; i++) {
 #if 1
-    int n = (int)nop_sequence[i] + 1;
-    double a = pow((double)n, 0.4 * (double)(size-1));
-    double b = 0.3 * (double)i * (double)(size-1);
+    int n = (int)m_nops[i] + 1;
+    double a = pow((double)n, 0.4 * (double)(m_size-1));
+    double b = 0.3 * (double)i * (double)(m_size-1);
     double c = 0.45 * (double)i;
     value += a + b + c;
 #else
-    value += (pow(((double)nop_sequence[i] + 1.0), (0.4 * (double)(size-1))) +
-	      (0.3 * (double)i * (double)(size-1)) +
+    value += (pow(((double)m_nops[i] + 1.0), (0.4 * (double)(m_size-1))) +
+	      (0.3 * (double)i * (double)(m_size-1)) +
 	      (0.45 * (double)i));
 #endif
   }
@@ -151,8 +171,8 @@
     fib[i] = fib[i-2] + fib[i-1];
   }
 
-  for (int i = 0; i < size; i++) {
-    value += fib[(int)nop_sequence[i]];
+  for (int i = 0; i < m_size; i++) {
+    value += fib[(int)m_nops[i]];
 
     fib[2] = fib[base-2] + fib[base-1];
     fib[1] = fib[base-1];
@@ -168,18 +188,18 @@
 {
   int value = 0;
 
-  int extra = size % 2;
+  int extra = m_size % 2;
   int c = 1;
 
-  for (int i = 0; i < size - extra; i+=2, c++) {
-    int b = nop_sequence[i];
-    int a = nop_sequence[i+1];
+  for (int i = 0; i < m_size - extra; i+=2, c++) {
+    int b = m_nops[i];
+    int a = m_nops[i+1];
 
     value += (int)pow((double)((a * base) + b), c);
   }
 
   if(extra) {
-    value += (int)pow((double)nop_sequence[size-1], c);
+    value += (int)pow((double)m_nops[m_size-1], c);
   }
 
   return value;

Modified: development/source/cpu/cCodeLabel.h
===================================================================
--- development/source/cpu/cCodeLabel.h	2006-06-26 12:53:49 UTC (rev 776)
+++ development/source/cpu/cCodeLabel.h	2006-06-26 15:44:06 UTC (rev 777)
@@ -35,33 +35,34 @@
 class cCodeLabel
 {
 private:
-  tArray<char> nop_sequence;
-  int size;
+  tArray<char> m_nops;
+  int m_size;
 
 public:
-  cCodeLabel() : size(0) { ; }
-  cCodeLabel(const cCodeLabel& in_label) : nop_sequence(in_label.nop_sequence), size(in_label.size) { ; }  
+  cCodeLabel() : m_size(0) { ; }
+  cCodeLabel(const cCodeLabel& in_label) : m_nops(in_label.m_nops), m_size(in_label.m_size) { ; }  
   ~cCodeLabel() { ; }
 
   bool OK();
   bool operator==(const cCodeLabel& other_label) const;
   bool operator!=(const cCodeLabel& other_label) const { return !(operator==(other_label)); }
-  char operator[](int position) const { return (int) nop_sequence[position]; }
+  char operator[](int position) const { return (int) m_nops[position]; }
   cCodeLabel& operator=(const cCodeLabel& in_lbl)
   {
-    nop_sequence = in_lbl.nop_sequence;
-    size = in_lbl.size;
+    m_nops = in_lbl.m_nops;
+    m_size = in_lbl.m_size;
     return *this;
   }
+
+  void ReadString(const cString& label_str);
   
-  int FindSublabel(cCodeLabel & sub_label);
+  int FindSublabel(cCodeLabel& sub_label);
 
-  void Clear() { size = 0; }
+  void Clear() { m_size = 0; }
   inline void AddNop(int nop_num);
   inline void Rotate(const int rot, const int base);
 
-  int GetSize() const { return size; }
-  //int GetBase() const { return base; }
+  int GetSize() const { return m_size; }
   inline cString AsString() const;
   int AsInt(const int base) const;
   int AsIntGreyCode(const int base) const;
@@ -86,19 +87,19 @@
 void cCodeLabel::AddNop(int nop_num) {
   assert (nop_num < nHardware::MAX_NOPS);
 
-  if (size < nHardware::MAX_LABEL_SIZE) {
-    if (size == nop_sequence.GetSize()) {
-      nop_sequence.Resize(size+1);
+  if (m_size < nHardware::MAX_LABEL_SIZE) {
+    if (m_size == m_nops.GetSize()) {
+      m_nops.Resize(m_size + 1);
     }
-    nop_sequence[size++] = (char) nop_num;
+    m_nops[m_size++] = (char) nop_num;
   }
 }
 
 void cCodeLabel::Rotate(const int rot, const int base)
 {
-  for (int i = 0; i < size; i++) {
-    nop_sequence[i] += rot;
-    if (nop_sequence[i] >= base) nop_sequence[i] -= base;
+  for (int i = 0; i < m_size; i++) {
+    m_nops[i] += rot;
+    if (m_nops[i] >= base) m_nops[i] -= base;
   }
 }
 
@@ -106,8 +107,8 @@
 cString cCodeLabel::AsString() const
 {
   cString out_string;
-  for (int i = 0; i < size; i++) {
-    out_string += (char) nop_sequence[i] + 'A';
+  for (int i = 0; i < m_size; i++) {
+    out_string += (char) m_nops[i] + 'A';
   }
 
   return out_string;

Modified: development/source/cpu/cHardwareSMT.cc
===================================================================
--- development/source/cpu/cHardwareSMT.cc	2006-06-26 12:53:49 UTC (rev 776)
+++ development/source/cpu/cHardwareSMT.cc	2006-06-26 15:44:06 UTC (rev 777)
@@ -746,11 +746,11 @@
 bool cHardwareSMT::InjectHost(const cCodeLabel& in_label, const cGenome& inject_code)
 {
   // Inject fails if the memory space is already in use or thread exists
-  if (MemorySpaceExists(in_label) || FindThreadLabel(in_label) == -1) return false;
+  if (MemorySpaceExists(in_label) || FindThreadLabel(in_label) != -1) return false;
 
   // Otherwise create the memory space and copy in the genome
   int mem_space_used = FindMemorySpaceLabel(in_label, -1);
-  assert(mem_space_used == -1);
+  assert(mem_space_used != -1);
   m_mem_array[mem_space_used] = inject_code;
   
   // Create a thread for this parasite

Modified: development/source/event/cEventList.cc
===================================================================
--- development/source/event/cEventList.cc	2006-06-26 12:53:49 UTC (rev 776)
+++ development/source/event/cEventList.cc	2006-06-26 15:44:06 UTC (rev 777)
@@ -169,8 +169,7 @@
           
         }
         
-      } // End Non-IMMEDITAE events
-      
+      } // End Non-IMMEDIATE events
     }  // end condition to do event
     
     entry = next_entry;

Modified: development/source/event/cEventManager.cc
===================================================================
--- development/source/event/cEventManager.cc	2006-06-26 12:53:49 UTC (rev 776)
+++ development/source/event/cEventManager.cc	2006-06-26 15:44:06 UTC (rev 777)
@@ -190,207 +190,6 @@
 
 
 
-///// inject_sequence /////
-
-/**
-* Injects identical organisms into a range of cells of the population.
- *
- * Parameters:
- * sequence (string)
- *   The genome sequence for this organism.  This is a mandatory argument.
- * start_cell (int)
- *   First cell to inject into.
- * stop_cell (int)
- *   First cell *not* to inject into.
- * merit (double) default: -1
-   *   The initial merit of the organism. If set to -1, this is ignored.
-   * lineage label (integer) default: 0
-     *   An integer that marks all descendants of this organism.
-     * neutral metric (double) default: 0
-       *   A double value that randomly drifts over time.
-       *
-       * Example:
-       *   inject_range ckdfhgklsahnfsaggdsgajfg 0 10 100
-       *
-       * Will inject 10 organisms into cells 0 through 9 with a merit of 100.
-       **/
-
-
-class cEvent_inject_sequence : public cEvent {
-private:
-  cString seq;
-  int start_cell;
-  int end_cell;
-  double merit;
-  int lineage_label;
-  double neutral_metric;
-public:
-    const cString GetName() const { return "inject_sequence"; }
-  const cString GetDescription() const { return "inject_sequence  <cString seq> [int start_cell=0] [int end_cell=-1] [double merit=-1] [int lineage_label=0] [double neutral_metric=0]"; }
-  
-  void Configure(cWorld* world, const cString& in_args)
-  {
-    m_world = world;
-    m_args = in_args;
-    cString args(in_args);
-    seq = args.PopWord();
-    if (args == "") start_cell=0; else start_cell=args.PopWord().AsInt();
-    if (args == "") end_cell=-1; else end_cell=args.PopWord().AsInt();
-    if (args == "") merit=-1; else merit=args.PopWord().AsDouble();
-    if (args == "") lineage_label=0; else lineage_label=args.PopWord().AsInt();
-    if (args == "") neutral_metric=0; else neutral_metric=args.PopWord().AsDouble();
-  }
-  ///// inject_sequence /////
-  void Process(){
-    if (end_cell == -1) end_cell = start_cell + 1;
-    if (start_cell < 0 ||
-        end_cell > m_world->GetPopulation().GetSize() ||
-        start_cell >= end_cell) {
-      m_world->GetDriver().NotifyWarning("inject_sequence has invalid range!");
-    }
-    else {
-      cGenome genome(seq);
-      for (int i = start_cell; i < end_cell; i++) {
-        m_world->GetPopulation().Inject(genome, i, merit, lineage_label, neutral_metric);
-      }
-      m_world->GetPopulation().SetSyncEvents(true);
-    }
-  }
-};
-
-///// inject_random /////
-
-/**
-* Injects a randomly generated genome into the population.
- *
- * Parameters:
- * length (integer) [required]
- *   Number of instructions in the randomly generated genome.
- * cell ID (integer) default: -1
-   *   The grid-point into which the genome should be placed.  Default is random.
-   * merit (double) default: -1
-     *   The initial merit of the organism. If set to -1, this is ignored.
-     * lineage label (integer) default: 0
-       *   An integer that marks all descendants of this organism.
-       * neutral metric (double) default: 0
-         *   A double value that randomly drifts over time.
-         **/
-
-
-class cEvent_inject_random : public cEvent {
-private:
-  int length;
-  int cell_id;
-  double merit;
-  int lineage_label;
-  double neutral_metric;
-public:
-    const cString GetName() const { return "inject_random"; }
-  const cString GetDescription() const { return "inject_random  <int length> [int cell_id=-1] [double merit=-1] [int lineage_label=0] [double neutral_metric=0]"; }
-  
-  void Configure(cWorld* world, const cString& in_args)
-  {
-    m_world = world;
-    m_args = in_args;
-    cString args(in_args);
-    length = args.PopWord().AsInt();
-    if (args == "") cell_id=-1; else cell_id=args.PopWord().AsInt();
-    if (args == "") merit=-1; else merit=args.PopWord().AsDouble();
-    if (args == "") lineage_label=0; else lineage_label=args.PopWord().AsInt();
-    if (args == "") neutral_metric=0; else neutral_metric=args.PopWord().AsDouble();
-  }
-  ///// inject_random /////
-  void Process(){
-    if (cell_id == -1) cell_id = m_world->GetRandom().GetUInt(m_world->GetPopulation().GetSize());
-    
-    cAvidaContext& ctx = m_world->GetDefaultContext();
-    
-    cGenome genome =
-      cInstUtil::RandomGenome(ctx, length, m_world->GetHardwareManager().GetInstSet());
-    m_world->GetPopulation().Inject(genome, cell_id, merit, lineage_label, neutral_metric);
-  }
-};
-
-
-///// inject_range_pair /////
-
-/**
-* Injects identical organisms into a range of cells of the population.
- *
- * Parameters:
- * filename (string)
- *   The filename of the genotype to load. If this is left empty, or the keyword
- *   "START_CREATURE" is given, than the genotype specified in the genesis
- *   file under "START_CREATURE" is used.
- * start_cell (int)
- *   First cell to inject into.
- * stop_cell (int)
- *   First cell *not* to inject into.
- * merit (double) default: -1
-   *   The initial merit of the organism. If set to -1, this is ignored.
-   * lineage label (integer) default: 0
-     *   An integer that marks all descendants of this organism.
-     * neutral metric (double) default: 0
-       *   A double value that randomly drifts over time.
-       *
-       * Example:
-       *   inject_range creature.gen 0 10
-       *
-       * Will inject 10 organisms into cells 0 through 9.
-       **/
-
-
-class cEvent_inject_range_pair : public cEvent {
-private:
-  cString fname;
-  cString fname_parasite;
-  int start_cell;
-  int end_cell;
-  double merit;
-  int lineage_label;
-  double neutral_metric;
-  int mem_space;
-public:
-    const cString GetName() const { return "inject_range_pair"; }
-  const cString GetDescription() const { return "inject_range_pair  [cString fname=\"START_CREATURE\"] [cString fname_parasite=\"organism.parasite\"] [int start_cell=0] [int end_cell=-1] [double merit=-1] [int lineage_label=0] [double neutral_metric=0] [int mem_space=2]"; }
-  
-  void Configure(cWorld* world, const cString& in_args)
-  {
-    m_world = world;
-    m_args = in_args;
-    cString args(in_args);
-    if (args == "") fname="START_CREATURE"; else fname=args.PopWord();
-    if (args == "") fname_parasite="organism.parasite"; else fname_parasite=args.PopWord();
-    if (args == "") start_cell=0; else start_cell=args.PopWord().AsInt();
-    if (args == "") end_cell=-1; else end_cell=args.PopWord().AsInt();
-    if (args == "") merit=-1; else merit=args.PopWord().AsDouble();
-    if (args == "") lineage_label=0; else lineage_label=args.PopWord().AsInt();
-    if (args == "") neutral_metric=0; else neutral_metric=args.PopWord().AsDouble();
-    if (args == "") mem_space=2; else mem_space=args.PopWord().AsInt();
-  }
-  ///// inject_range_pair /////
-  void Process(){
-    if (fname == "START_CREATURE") fname = m_world->GetConfig().START_CREATURE.Get();
-    if (end_cell == -1) end_cell = start_cell + 1;
-    if (start_cell < 0 ||
-        end_cell > m_world->GetPopulation().GetSize() ||
-        start_cell >= end_cell) {
-      m_world->GetDriver().NotifyWarning("inject_range has invalid range!");
-    }
-    else {
-      cGenome genome =
-      cInstUtil::LoadGenome(fname, m_world->GetHardwareManager().GetInstSet());
-      cGenome genome_parasite =
-        cInstUtil::LoadGenome(fname_parasite, m_world->GetHardwareManager().GetInstSet());
-      for (int i = start_cell; i < end_cell; i++) {
-        m_world->GetPopulation().Inject(genome, i, merit, lineage_label, neutral_metric);
-// @DMB        m_world->GetPopulation().Inject(genome_parasite, i, merit, lineage_label, neutral_metric, mem_space);
-      }
-      m_world->GetPopulation().SetSyncEvents(true);
-    }
-  }
-};
-
 ///// zero_muts /////
 
 /**
@@ -641,7 +440,7 @@
   cString datafile;
 public:
   const cString GetName() const { return "predict_w_landscape"; }
-  const cString GetDescription() const { return "predict_w_landscape  [cString datafile=\"land-predict.dat\"]"; }
+  const cString GetDescription() const { return "predict_w_landscape  [string datafile=\"land-predict.dat\"]"; }
   
   void Configure(cWorld* world, const cString& in_args)
   {
@@ -671,7 +470,7 @@
   cString datafile;
 public:
   const cString GetName() const { return "predict_nu_landscape"; }
-  const cString GetDescription() const { return "predict_nu_landscape  [cString datafile=\"land-predict.dat\"]"; }
+  const cString GetDescription() const { return "predict_nu_landscape  [string datafile=\"land-predict.dat\"]"; }
   
   void Configure(cWorld* world, const cString& in_args)
   {
@@ -757,7 +556,7 @@
   cString filename;
 public:
     const cString GetName() const { return "analyze_population"; }
-  const cString GetDescription() const { return "analyze_population  [double sample_prob=1] [int landscape=0] [int save_genotype=0] [cString filename=\"\"]"; }
+  const cString GetDescription() const { return "analyze_population  [double sample_prob=1] [int landscape=0] [int save_genotype=0] [string filename=\"\"]"; }
   
   void Configure(cWorld* world, const cString& in_args)
   {
@@ -792,7 +591,7 @@
   int save_genotype;
 public:
     const cString GetName() const { return "genetic_distance_pop_dump"; }
-  const cString GetDescription() const { return "genetic_distance_pop_dump  [cString creature_name=\"\"] [cString filename=\"\"] [int save_genotype=0]"; }
+  const cString GetDescription() const { return "genetic_distance_pop_dump  [string creature_name=\"\"] [string filename=\"\"] [int save_genotype=0]"; }
   
   void Configure(cWorld* world, const cString& in_args)
   {
@@ -826,7 +625,7 @@
   cString filename;
 public:
   const cString GetName() const { return "task_snapshot"; }
-  const cString GetDescription() const { return "task_snapshot  [cString filename=\"\"]"; }
+  const cString GetDescription() const { return "task_snapshot  [string filename=\"\"]"; }
   
   void Configure(cWorld* world, const cString& in_args)
   {
@@ -855,7 +654,7 @@
   cString filename;
 public:
   const cString GetName() const { return "print_viable_tasks_data"; }
-  const cString GetDescription() const { return "print_viable_tasks_data  [cString filename=\"viable_tasks.dat\"]"; }
+  const cString GetDescription() const { return "print_viable_tasks_data  [string filename=\"viable_tasks.dat\"]"; }
   
   void Configure(cWorld* world, const cString& in_args)
   {
@@ -1305,7 +1104,7 @@
   cString filename;
 public:
     const cString GetName() const { return "test_size_change_robustness"; }
-  const cString GetDescription() const { return "test_size_change_robustness  [int num_trials=100] [cString filename=\"size_change.dat\"]"; }
+  const cString GetDescription() const { return "test_size_change_robustness  [int num_trials=100] [string filename=\"size_change.dat\"]"; }
   
   void Configure(cWorld* world, const cString& in_args)
   {
@@ -1580,7 +1379,7 @@
   cString filename;
 public:
   const cString GetName() const { return "print_tree_depths"; }
-  const cString GetDescription() const { return "print_tree_depths  [cString filename=\"\"]"; }
+  const cString GetDescription() const { return "print_tree_depths  [string filename=\"\"]"; }
   
   void Configure(cWorld* world, const cString& in_args)
   {
@@ -2225,9 +2024,6 @@
   REGISTER(exit_if_ave_lineage_label_smaller);
   REGISTER(exit_if_ave_lineage_label_larger);
   
-  REGISTER(inject_sequence);
-  REGISTER(inject_random);
-  REGISTER(inject_range_pair);
   REGISTER(zero_muts);
   REGISTER(mod_copy_mut);
   REGISTER(mod_div_mut);




More information about the Avida-cvs mailing list