[Avida-cvs] [avida-svn] r933 - in development: documentation source/actions source/main

brysonda at myxo.css.msu.edu brysonda at myxo.css.msu.edu
Thu Sep 7 17:31:57 PDT 2006


Author: brysonda
Date: 2006-09-07 20:31:57 -0400 (Thu, 07 Sep 2006)
New Revision: 933

Modified:
   development/documentation/actions.html
   development/source/actions/LandscapeActions.cc
   development/source/main/cLandscape.cc
   development/source/main/cLandscape.h
Log:
Update HillClimb to use cDataFile.   Remove empty HillClimb_(Neut/Rand) methods and meaningless actions.  Update documentation to reflect removed actions.  Add AnalyzePopulation documentation.

Modified: development/documentation/actions.html
===================================================================
--- development/documentation/actions.html	2006-09-07 23:58:12 UTC (rev 932)
+++ development/documentation/actions.html	2006-09-08 00:31:57 UTC (rev 933)
@@ -50,7 +50,8 @@
 <table>
   <tr>
     <td>
-      <br /><a href="#AnalyzeLandscape">AnalyzeLandscape</a>
+      <a href="#AnalyzeLandscape">AnalyzeLandscape</a>
+      <br /><a href="#AnalyzePopulation">AnalyzePopulation</a>
       <br /><a href="#CompeteDemes">CompeteDemes</a>
       <br /><a href="#ConnectCells">ConnectCells</a>
       <br /><a href="#CopyDeme">CopyDeme</a>
@@ -69,8 +70,6 @@
       <br /><a href="#ExitAveLineageLabelLess">ExitAveLineageLabelLess</a>
       <br /><a href="#FullLandscape">FullLandscape</a>
       <br /><a href="#HillClimb">HillClimb</a>
-      <br /><a href="#HillClimbNeut">HillClimbNeut</a>
-      <br /><a href="#HillClimbRand">HillClimbRand</a>
       <br /><a href="#Inject">Inject</a>
       <br /><a href="#InjectAll">InjectAll</a>
       <br /><a href="#InjectParasite">InjectParasite</a>
@@ -83,10 +82,10 @@
       <br /><a href="#JoinGridCol">JoinGridCol</a>
       <br /><a href="#JoinGridRow">JoinGridRow</a>
       <br /><a href="#KillProb">KillProb</a>
+      <br /><a href="#KillRate">KillRate</a>
     </td>
     <td>
-      <br /><a href="#KillRate">KillRate</a>
-      <br /><a href="#KillRectangle">KillRectangle</a>
+      <a href="#KillRectangle">KillRectangle</a>
       <br /><a href="#LoadClone">LoadClone</a>
       <br /><a href="#LoadPopulation">LoadPopulation</a>
       <br /><a href="#ModMutProb">ModMutProb</a>
@@ -118,10 +117,10 @@
       <br /><a href="#PrintLineageTotals">PrintLineageTotals</a>
       <br /><a href="#PrintMutationRateData">PrintMutationRateData</a>
       <br /><a href="#PrintPhenotypeData">PrintPhenotypeData</a>
+      <br /><a href="#PrintPhenotypeStatus">PrintPhenotypeStatus</a>
     </td>
     <td>
-      <br /><a href="#PrintPhenotypeStatus">PrintPhenotypeStatus</a>
-      <br /><a href="#PrintPopulationDistanceData">PrintPopulationDistanceData</a>
+      <a href="#PrintPopulationDistanceData">PrintPopulationDistanceData</a>
       <br /><a href="#PrintResourceData">PrintResourceData</a>
       <br /><a href="#PrintSpeciesAbundanceData">PrintSpeciesAbundanceData</a>
       <br /><a href="#PrintStatsData">PrintStatsData</a>
@@ -1121,27 +1120,21 @@
   </p>
 </li>
 <li>
-  <strong><a name="HillClimbNeut">HillClimbNeut</a></strong>
-  [<span class="cmdarg">string filename='hillclimb.dat'</span>]
+  <strong><a name="PairTestLandscape">PairTestLandscape</a></strong>
+  [<span class="cmdarg">string filename=''</span>] [<span class="cmdarg">int sample_size=0</span>]
   
   <p>
+  If sample_size = 0, pairtest the full landscape.
   </p>
 </li>
 <li>
-  <strong><a name="HillClimbRand">HillClimbRand</a></strong>
-  [<span class="cmdarg">string filename='hillclimb.dat'</span>]
-  
+  <strong><a name="AnalyzePopulation">AnalyzePopulation</a></strong>
+  [<span class="cmdarg">double sample_prob=1</span>] [<span class="cmdarg">int landscape=0</span>]
+  [<span class="cmdarg">int save_genotype=0</span>] [<span class="cmdarg">string filename=''</span>]
+
   <p>
   </p>
 </li>
-<li>
-  <strong><a name="PairTestLandscape">PairTestLandscape</a></strong>
-  [<span class="cmdarg">string filename=''</span>] [<span class="cmdarg">int sample_size=0</span>]
-  
-  <p>
-  If sample_size = 0, pairtest the full landscape.
-  </p>
-</li>
 </ul>
 
 

Modified: development/source/actions/LandscapeActions.cc
===================================================================
--- development/source/actions/LandscapeActions.cc	2006-09-07 23:58:12 UTC (rev 932)
+++ development/source/actions/LandscapeActions.cc	2006-09-08 00:31:57 UTC (rev 933)
@@ -676,7 +676,6 @@
   void Process(cAvidaContext& ctx)
   {
     cInstSet& inst_set = m_world->GetHardwareManager().GetInstSet();
-    std::ofstream& outfile = m_world->GetDataFileOFStream(m_filename);
     
     if (ctx.GetAnalyzeMode()) {
       if (m_world->GetVerbosity() >= VERBOSE_ON) {
@@ -687,125 +686,27 @@
         m_world->GetDriver().NotifyComment("Calculating Hill Climb...");
       }
       
+      cDataFile& df = m_world->GetDataFile(m_filename);
       tListIterator<cAnalyzeGenotype> batch_it(m_world->GetAnalyze().GetCurrentBatch().List());
       cAnalyzeGenotype* genotype = NULL;
       while (genotype = batch_it.Next()) {
         cLandscape land(m_world, genotype->GetGenome(), inst_set);
-        land.HillClimb(ctx, outfile);
+        land.HillClimb(ctx, df);
       }
+      m_world->GetDataFileManager().Remove(m_filename);
     } else {
       if (m_world->GetVerbosity() >= VERBOSE_DETAILS)
         m_world->GetDriver().NotifyComment("Calculating Hill Climb...");
       
       const cGenome& best_genome = m_world->GetClassificationManager().GetBestGenotype()->GetGenome();
       cLandscape land(m_world, best_genome, inst_set);
-      land.HillClimb(ctx, outfile);
+      land.HillClimb(ctx, m_world->GetDataFile(m_filename));
     }
   }
 };
 
 
-class cActionHillClimbNeut : public cAction  // @not_parallized
-{
-private:
-  cString m_filename;
-  
-public:
-  cActionHillClimbNeut(cWorld* world, const cString& args)
-  : cAction(world, args), m_filename("hillclimb.dat")
-  {
-    cString largs(args);
-    if (largs.GetSize()) m_filename = largs.PopWord();
-  }
-  
-  static const cString GetDescription()
-  {
-    return "Arguments: [string filename='hillclimb.dat']";
-  }
-  
-  void Process(cAvidaContext& ctx)
-  {
-    cInstSet& inst_set = m_world->GetHardwareManager().GetInstSet();
-    std::ofstream& outfile = m_world->GetDataFileOFStream(m_filename);
-    
-    if (ctx.GetAnalyzeMode()) {
-      if (m_world->GetVerbosity() >= VERBOSE_ON) {
-        cString msg("Calculating Hill Climb on batch ");
-        msg += cStringUtil::Convert(m_world->GetAnalyze().GetCurrentBatchID());
-        m_world->GetDriver().NotifyComment(msg);
-      } else if (m_world->GetVerbosity() > VERBOSE_SILENT) {
-        m_world->GetDriver().NotifyComment("Calculating Hill Climb...");
-      }
-      
-      tListIterator<cAnalyzeGenotype> batch_it(m_world->GetAnalyze().GetCurrentBatch().List());
-      cAnalyzeGenotype* genotype = NULL;
-      while (genotype = batch_it.Next()) {
-        cLandscape land(m_world, genotype->GetGenome(), inst_set);
-        land.HillClimb_Neut(ctx, outfile);
-      }
-    } else {
-      if (m_world->GetVerbosity() >= VERBOSE_DETAILS)
-        m_world->GetDriver().NotifyComment("Calculating Hill Climb...");
-      
-      const cGenome& best_genome = m_world->GetClassificationManager().GetBestGenotype()->GetGenome();
-      cLandscape land(m_world, best_genome, inst_set);
-      land.HillClimb_Neut(ctx, outfile);
-    }
-  }
-};
 
-
-class cActionHillClimbRand : public cAction  // @not_parallized
-{
-private:
-  cString m_filename;
-  
-public:
-  cActionHillClimbRand(cWorld* world, const cString& args)
-  : cAction(world, args), m_filename("hillclimb.dat")
-  {
-    cString largs(args);
-    if (largs.GetSize()) m_filename = largs.PopWord();
-  }
-  
-  static const cString GetDescription()
-  {
-    return "Arguments: [string filename='hillclimb.dat']";
-  }
-  
-  void Process(cAvidaContext& ctx)
-  {
-    cInstSet& inst_set = m_world->GetHardwareManager().GetInstSet();
-    std::ofstream& outfile = m_world->GetDataFileOFStream(m_filename);
-    
-    if (ctx.GetAnalyzeMode()) {
-      if (m_world->GetVerbosity() >= VERBOSE_ON) {
-        cString msg("Calculating Hill Climb on batch ");
-        msg += cStringUtil::Convert(m_world->GetAnalyze().GetCurrentBatchID());
-        m_world->GetDriver().NotifyComment(msg);
-      } else if (m_world->GetVerbosity() > VERBOSE_SILENT) {
-        m_world->GetDriver().NotifyComment("Calculating Hill Climb...");
-      }
-      
-      tListIterator<cAnalyzeGenotype> batch_it(m_world->GetAnalyze().GetCurrentBatch().List());
-      cAnalyzeGenotype* genotype = NULL;
-      while (genotype = batch_it.Next()) {
-        cLandscape land(m_world, genotype->GetGenome(), inst_set);
-        land.HillClimb_Rand(ctx, outfile);
-      }
-    } else {
-      if (m_world->GetVerbosity() >= VERBOSE_DETAILS)
-        m_world->GetDriver().NotifyComment("Calculating Hill Climb...");
-      
-      const cGenome& best_genome = m_world->GetClassificationManager().GetBestGenotype()->GetGenome();
-      cLandscape land(m_world, best_genome, inst_set);
-      land.HillClimb_Rand(ctx, outfile);
-    }
-  }
-};
-
-
-
 class cActionMutationalNeighborhood : public cAction  // @parallelized
 {
 private:
@@ -1073,8 +974,6 @@
   action_lib->Register<cActionRandomLandscape>("RandomLandscape");
   action_lib->Register<cActionSampleLandscape>("SampleLandscape");
   action_lib->Register<cActionHillClimb>("HillClimb");
-  action_lib->Register<cActionHillClimb>("HillClimbNeut");
-  action_lib->Register<cActionHillClimb>("HillClimbRand");
   action_lib->Register<cActionPairTestLandscape>("PairTestLandscape");
   action_lib->Register<cActionAnalyzePopulation>("AnalyzePopulation");
 

Modified: development/source/main/cLandscape.cc
===================================================================
--- development/source/main/cLandscape.cc	2006-09-07 23:58:12 UTC (rev 932)
+++ development/source/main/cLandscape.cc	2006-09-08 00:31:57 UTC (rev 933)
@@ -677,26 +677,19 @@
 }
 
 
-void cLandscape::HillClimb(cAvidaContext& ctx, ofstream& fp)
+void cLandscape::HillClimb(cAvidaContext& ctx, cDataFile& df)
 {
   cTestCPU* testcpu = m_world->GetHardwareManager().CreateTestCPU();
   cGenome cur_genome(base_genome);
-  int gen = 0;
-  HillClimb_Body(ctx, testcpu, fp, cur_genome, gen);
-  delete testcpu;
-}
-
-void cLandscape::HillClimb_Body(cAvidaContext& ctx, cTestCPU* testcpu, ofstream& fp, cGenome & cur_genome,
-                                int & gen)
-{
   cCPUMemory mod_genome(base_genome);
+
+  int gen = 0;
   
   const int inst_size = inst_set.GetSize();
-  
   double pos_frac = 1.0;
   
   distance = 1;
-
+  
   bool finished = false;
   while (finished == false) {
     if (pos_frac == 0.0) finished = true;
@@ -732,40 +725,29 @@
     pos_frac = GetProbPos();
     
     // Print the information on the current best.
-    HillClimb_Print(ctx, testcpu, fp, cur_genome, gen);
-    
+    cCPUTestInfo test_info;
+    testcpu->TestGenome(ctx, test_info, cur_genome);
+    cPhenotype& colony_phenotype = test_info.GetColonyOrganism()->GetPhenotype();
+    df.Write(gen, "Generation");
+    df.Write(colony_phenotype.GetMerit().GetDouble(), "Merit");
+    df.Write(colony_phenotype.GetGestationTime(), "Gestation Time");
+    df.Write(colony_phenotype.GetFitness(), "Fitness");
+    df.Write(cur_genome.GetSize(), "Genome Length");
+    df.Write(GetProbDead(), "Probability Lethal");
+    df.Write(GetProbNeg(), "Probability Deleterious");
+    df.Write(GetProbNeut(), "Probability Neutral");
+    df.Write(GetProbPos(), "Probability Beneficial");
+    df.Endl();
+              
     // Move on to the peak genome found.
     cur_genome = GetPeakGenome();
     gen++;
   }
-}
 
-void cLandscape::HillClimb_Neut(cAvidaContext& ctx, ofstream& fp)
-{
+  delete testcpu;
 }
 
-void cLandscape::HillClimb_Rand(cAvidaContext& ctx, ofstream& fp)
-{
-}
 
-void cLandscape::HillClimb_Print(cAvidaContext& ctx, cTestCPU* testcpu, ofstream& fp,
-                                 const cGenome& _genome, const int gen) const
-{
-  cCPUTestInfo test_info;
-  testcpu->TestGenome(ctx, test_info, _genome);
-  cPhenotype &colony_phenotype = test_info.GetColonyOrganism()->GetPhenotype();
-  fp << gen << " "
-    << colony_phenotype.GetMerit().GetDouble() << " "
-    << colony_phenotype.GetGestationTime() << " "
-    << colony_phenotype.GetFitness() << " "
-    << _genome.GetSize() << " "
-    << GetProbDead() << " "
-    << GetProbNeg() << " "
-    << GetProbNeut() << " "
-    << GetProbPos() << " "
-    << endl;
-}
-
 double cLandscape::TestMutPair(cAvidaContext& ctx, cTestCPU* testcpu, cGenome& mod_genome, int line1, int line2,
                                const cInstruction& mut1, const cInstruction& mut2, ostream& fp)
 {
@@ -780,18 +762,7 @@
   double mut1_fitness = fitness_chart(line1, mut1.GetOp()) / base_fitness;
   double mut2_fitness = fitness_chart(line2, mut2.GetOp()) / base_fitness;
   double mult_combo = mut1_fitness * mut2_fitness;
-  
-  /*
-   fp << line1        << " "
-   << line2        << " "
-   << ( (int) mut1.GetOp() ) << " "
-   << ( (int) mut2.GetOp() ) << " ";
-   
-   fp << ( fitness_chart(line1, mut1.GetOp()) / base_fitness ) << " "
-   << ( fitness_chart(line2, mut2.GetOp()) / base_fitness ) << " "
-   << combo_fitness << endl;
-   */
-  
+    
   total_epi_count++;
   if ((mut1_fitness==0 || mut2_fitness==0)&&(combo_fitness==0)) {
     dead_epi_count++;

Modified: development/source/main/cLandscape.h
===================================================================
--- development/source/main/cLandscape.h	2006-09-07 23:58:12 UTC (rev 932)
+++ development/source/main/cLandscape.h	2006-09-08 00:31:57 UTC (rev 933)
@@ -91,10 +91,6 @@
   void ProcessBase(cAvidaContext& ctx, cTestCPU* testcpu);
   void Process_Body(cAvidaContext& ctx, cTestCPU* testcpu, cGenome& cur_genome, int cur_distance, int start_line);
 
-  void HillClimb_Body(cAvidaContext& ctx, cTestCPU* testcpu, std::ofstream& fp, cGenome& cur_genome, int& gen);
-  void HillClimb_Print(cAvidaContext& ctx, cTestCPU* testcpu, std::ofstream& fp,
-                       const cGenome& _genome, const int gen) const;
-
   double TestMutPair(cAvidaContext& ctx, cTestCPU* testcpu, cGenome& mod_genome, int line1, int line2,
                      const cInstruction& mut1, const cInstruction& mut2, std::ostream& fp);
 
@@ -127,9 +123,7 @@
   void TestPairs(cAvidaContext& ctx, int in_trials, std::ostream& fp);
   void TestAllPairs(cAvidaContext& ctx, std::ostream& fp);
 
-  void HillClimb(cAvidaContext& ctx, std::ofstream& fp);
-  void HillClimb_Neut(cAvidaContext& ctx, std::ofstream& fp);
-  void HillClimb_Rand(cAvidaContext& ctx, std::ofstream& fp);
+  void HillClimb(cAvidaContext& ctx, cDataFile& df);
 
   void PrintStats(cDataFile& df, int update = -1);
   void PrintEntropy(cDataFile& fp);




More information about the Avida-cvs mailing list