[Avida-cvs] [avida-svn] r791 - in development/source: actions analyze event

brysonda@myxo.css.msu.edu brysonda at myxo.css.msu.edu
Mon Jul 3 11:53:01 PDT 2006


Author: brysonda
Date: 2006-07-03 14:53:01 -0400 (Mon, 03 Jul 2006)
New Revision: 791

Modified:
   development/source/actions/LandscapeActions.cc
   development/source/analyze/cAnalyzeUtil.cc
   development/source/analyze/cAnalyzeUtil.h
   development/source/event/cEventManager.cc
Log:
Add Deletion/Insertion Landscape actions.  Add the option to specify output files for entropy and sitecount data to FullLandscape.  Remove old calc_landscape event.

Modified: development/source/actions/LandscapeActions.cc
===================================================================
--- development/source/actions/LandscapeActions.cc	2006-07-03 16:34:58 UTC (rev 790)
+++ development/source/actions/LandscapeActions.cc	2006-07-03 18:53:01 UTC (rev 791)
@@ -143,14 +143,14 @@
  this is that it supports multithreaded execution, whereas lazy evaluation during
  detailing will be serialized.
 */
-class cActionCalcLandscape : public cAction  // @parallelized
+class cActionPrecalcLandscape : public cAction  // @parallelized
 {
 public:
-  cActionCalcLandscape(cWorld* world, const cString& args) : cAction(world, args) { ; }
+  cActionPrecalcLandscape(cWorld* world, const cString& args) : cAction(world, args) { ; }
   
   const cString GetDescription()
   {
-    return "CalcLandscape";
+    return "PrecalcLandscape";
   }
   
   void Process(cAvidaContext& ctx)
@@ -178,22 +178,26 @@
 class cActionFullLandscape : public cAction  // @parallelized
 {
 private:
-  cString m_filename;
+  cString m_sfilename;
+  cString m_efilename;
+  cString m_cfilename;
   int m_dist;
   tList<cLandscape> m_batch;
   
 public:
   cActionFullLandscape(cWorld* world, const cString& args)
-    : cAction(world, args), m_filename("land-full.dat"), m_dist(1)
+    : cAction(world, args), m_sfilename("land-full.dat"), m_efilename(""), m_cfilename(""), m_dist(1)
   {
       cString largs(args);
-      if (largs.GetSize()) m_filename = largs.PopWord();
+      if (largs.GetSize()) m_sfilename = largs.PopWord();
       if (largs.GetSize()) m_dist = largs.PopWord().AsInt();
+      if (largs.GetSize()) m_efilename = largs.PopWord();
+      if (largs.GetSize()) m_cfilename = largs.PopWord();
   }
   
   const cString GetDescription()
   {
-    return "FullLandscape [filename='land-full.dat'] [int distance=1]";
+    return "FullLandscape [string filename='land-full.dat'] [int distance=1] [string entropy_file=''] [string sitecount_file='']";
   }
   
   void Process(cAvidaContext& ctx)
@@ -234,15 +238,159 @@
       update = m_world->GetStats().GetUpdate();      
     }
     
-    std::ofstream& outfile = m_world->GetDataFileOFStream(m_filename);
+    std::ofstream& sfile = m_world->GetDataFileOFStream(m_sfilename);
     while (land = m_batch.Pop()) {
-      land->PrintStats(outfile, update);
+      land->PrintStats(sfile, update);
+      if (m_efilename.GetSize()) land->PrintEntropy(m_world->GetDataFileOFStream(m_efilename));
+      if (m_cfilename.GetSize()) land->PrintSiteCount(m_world->GetDataFileOFStream(m_cfilename));
       delete land;
     }
   }
 };
 
 
+class cActionDeletionLandscape : public cAction  // @parallelized
+{
+private:
+  cString m_sfilename;
+  cString m_cfilename;
+  int m_dist;
+  tList<cLandscape> m_batch;
+  
+public:
+  cActionDeletionLandscape(cWorld* world, const cString& args)
+    : cAction(world, args), m_sfilename("land-del.dat"), m_cfilename(""), m_dist(1)
+  {
+      cString largs(args);
+      if (largs.GetSize()) m_sfilename = largs.PopWord();
+      if (largs.GetSize()) m_dist = largs.PopWord().AsInt();
+      if (largs.GetSize()) m_cfilename = largs.PopWord();
+  }
+  
+  const cString GetDescription()
+  {
+    return "DeletionLandscape [string filename='land-del.dat'] [int distance=1] [string sitecount_file='']";
+  }
+  
+  void Process(cAvidaContext& ctx)
+  {
+    int update = -1;
+    cLandscape* land = NULL;
+    
+    if (ctx.GetAnalyzeMode()) {
+      if (m_world->GetConfig().VERBOSITY.Get() >= VERBOSE_ON) {
+        cString msg("Deletion Landscaping batch ");
+        msg += cStringUtil::Convert(m_world->GetAnalyze().GetCurrentBatchID());
+        m_world->GetDriver().NotifyComment(msg);
+      } else if (m_world->GetConfig().VERBOSITY.Get() > VERBOSE_SILENT) {
+        m_world->GetDriver().NotifyComment("Deletion Landscapping...");
+      }
+
+      cAnalyzeJobQueue& jobqueue = m_world->GetAnalyze().GetJobQueue();
+      cInstSet& inst_set = m_world->GetHardwareManager().GetInstSet();
+      
+      tListIterator<cAnalyzeGenotype> batch_it(m_world->GetAnalyze().GetCurrentBatch().List());
+      cAnalyzeGenotype* genotype = NULL;
+      while (genotype = batch_it.Next()) {
+        land = new cLandscape(m_world, genotype->GetGenome(), inst_set);
+        land->SetDistance(m_dist);
+        m_batch.PushRear(land);
+        jobqueue.AddJob(new tAnalyzeJob<cLandscape>(land, &cLandscape::ProcessDelete));
+      }
+      jobqueue.Execute();
+    } else {
+      if (m_world->GetConfig().VERBOSITY.Get() >= VERBOSE_DETAILS)
+        m_world->GetDriver().NotifyComment("Deletion Landscaping...");
+      
+      land = new cLandscape(m_world, m_world->GetClassificationManager().GetBestGenotype()->GetGenome(),
+                            m_world->GetHardwareManager().GetInstSet());
+      m_batch.PushRear(land);
+      land->SetDistance(m_dist);
+      land->ProcessDelete(ctx);
+      update = m_world->GetStats().GetUpdate();      
+    }
+    
+    std::ofstream& sfile = m_world->GetDataFileOFStream(m_sfilename);
+    while (land = m_batch.Pop()) {
+      land->PrintStats(sfile, update);
+      if (m_cfilename.GetSize()) land->PrintSiteCount(m_world->GetDataFileOFStream(m_cfilename));
+      delete land;
+    }
+  }
+};
+
+
+class cActionInsertionLandscape : public cAction  // @parallelized
+{
+private:
+  cString m_sfilename;
+  cString m_cfilename;
+  int m_dist;
+  tList<cLandscape> m_batch;
+  
+public:
+  cActionInsertionLandscape(cWorld* world, const cString& args)
+    : cAction(world, args), m_sfilename("land-ins.dat"), m_cfilename(""), m_dist(1)
+  {
+      cString largs(args);
+      if (largs.GetSize()) m_sfilename = largs.PopWord();
+      if (largs.GetSize()) m_dist = largs.PopWord().AsInt();
+      if (largs.GetSize()) m_cfilename = largs.PopWord();
+  }
+  
+  const cString GetDescription()
+  {
+    return "InsertionLandscape [string filename='land-ins.dat'] [int distance=1] [string sitecount_file='']";
+  }
+  
+  void Process(cAvidaContext& ctx)
+  {
+    int update = -1;
+    cLandscape* land = NULL;
+    
+    if (ctx.GetAnalyzeMode()) {
+      if (m_world->GetConfig().VERBOSITY.Get() >= VERBOSE_ON) {
+        cString msg("Insertion Landscaping batch ");
+        msg += cStringUtil::Convert(m_world->GetAnalyze().GetCurrentBatchID());
+        m_world->GetDriver().NotifyComment(msg);
+      } else if (m_world->GetConfig().VERBOSITY.Get() > VERBOSE_SILENT) {
+        m_world->GetDriver().NotifyComment("Insertion Landscapping...");
+      }
+
+      cAnalyzeJobQueue& jobqueue = m_world->GetAnalyze().GetJobQueue();
+      cInstSet& inst_set = m_world->GetHardwareManager().GetInstSet();
+      
+      tListIterator<cAnalyzeGenotype> batch_it(m_world->GetAnalyze().GetCurrentBatch().List());
+      cAnalyzeGenotype* genotype = NULL;
+      while (genotype = batch_it.Next()) {
+        land = new cLandscape(m_world, genotype->GetGenome(), inst_set);
+        land->SetDistance(m_dist);
+        m_batch.PushRear(land);
+        jobqueue.AddJob(new tAnalyzeJob<cLandscape>(land, &cLandscape::ProcessInsert));
+      }
+      jobqueue.Execute();
+    } else {
+      if (m_world->GetConfig().VERBOSITY.Get() >= VERBOSE_DETAILS)
+        m_world->GetDriver().NotifyComment("Insertion Landscaping...");
+      
+      land = new cLandscape(m_world, m_world->GetClassificationManager().GetBestGenotype()->GetGenome(),
+                            m_world->GetHardwareManager().GetInstSet());
+      m_batch.PushRear(land);
+      land->SetDistance(m_dist);
+      land->ProcessInsert(ctx);
+      update = m_world->GetStats().GetUpdate();      
+    }
+    
+    std::ofstream& sfile = m_world->GetDataFileOFStream(m_sfilename);
+    while (land = m_batch.Pop()) {
+      land->PrintStats(sfile, update);
+      if (m_cfilename.GetSize()) land->PrintSiteCount(m_world->GetDataFileOFStream(m_cfilename));
+      delete land;
+    }
+  }
+};
+
+
 class cActionPredictWLandscape : public cAction  // @not_parallelized
 {
 private:
@@ -563,8 +711,10 @@
 void RegisterLandscapeActions(cActionLibrary* action_lib)
 {
   action_lib->Register<cActionAnalyzeLandscape>("AnalyzeLandscape");
-  action_lib->Register<cActionCalcLandscape>("CalcLandscape");
+  action_lib->Register<cActionPrecalcLandscape>("PrecalcLandscape");
   action_lib->Register<cActionFullLandscape>("FullLandscape");
+  action_lib->Register<cActionDeletionLandscape>("DeletionLandscape");
+  action_lib->Register<cActionInsertionLandscape>("InsertionLandscape");
   action_lib->Register<cActionPredictWLandscape>("PredictWLandscape");
   action_lib->Register<cActionPredictNuLandscape>("PredictNuLandscape");
   action_lib->Register<cActionRandomLandscape>("RandomLandscape");

Modified: development/source/analyze/cAnalyzeUtil.cc
===================================================================
--- development/source/analyze/cAnalyzeUtil.cc	2006-07-03 16:34:58 UTC (rev 790)
+++ development/source/analyze/cAnalyzeUtil.cc	2006-07-03 18:53:01 UTC (rev 791)
@@ -111,48 +111,6 @@
 }
 
 
-
-// Returns the genome of maximal fitness.
-cGenome cAnalyzeUtil::CalcLandscape(cWorld* world, int dist, const cGenome & genome,
-                                    cInstSet & inst_set)
-{
-  cAvidaContext& ctx = world->GetDefaultContext();
-
-  cLandscape landscape(world, genome, inst_set);
-  landscape.SetDistance(dist);
-  landscape.Process(ctx);
-  double peak_fitness = landscape.GetPeakFitness();
-  cGenome peak_genome = landscape.GetPeakGenome();
-  
-  // Print the results.
-  landscape.PrintStats(world->GetDataFileOFStream("landscape.dat"));
-  landscape.PrintEntropy(world->GetDataFileOFStream("land-entropy.dat"));
-  landscape.PrintSiteCount(world->GetDataFileOFStream("land-sitecount.dat"));
-  
-  // Repeat for Insertions...
-  landscape.Reset(genome);
-  landscape.ProcessInsert(ctx);
-  landscape.PrintStats(world->GetDataFileOFStream("landscape-ins.dat"));
-  landscape.PrintSiteCount(world->GetDataFileOFStream("land-ins-sitecount.dat"));
-  if (landscape.GetPeakFitness() > peak_fitness) {
-    peak_fitness = landscape.GetPeakFitness();
-    peak_genome = landscape.GetPeakGenome();
-  }
-  
-  // And Deletions...
-  landscape.Reset(genome);
-  landscape.ProcessDelete(ctx);
-  landscape.PrintStats(world->GetDataFileOFStream("landscape-del.dat"));
-  landscape.PrintSiteCount(world->GetDataFileOFStream("land-del-sitecount.dat"));
-  if (landscape.GetPeakFitness() > peak_fitness) {
-    peak_fitness = landscape.GetPeakFitness();
-    peak_genome = landscape.GetPeakGenome();
-  }
-  
-  return peak_genome;
-}
-
-
 void cAnalyzeUtil::PairTestLandscape(cWorld* world, const cGenome &genome, cInstSet &inst_set,
                                      int sample_size, int update)
 {

Modified: development/source/analyze/cAnalyzeUtil.h
===================================================================
--- development/source/analyze/cAnalyzeUtil.h	2006-07-03 16:34:58 UTC (rev 790)
+++ development/source/analyze/cAnalyzeUtil.h	2006-07-03 18:53:01 UTC (rev 791)
@@ -35,8 +35,6 @@
 
 
   // Landscape-based analysis
-  static cGenome CalcLandscape(cWorld* world, int dist, const cGenome & genome,
-			       cInstSet & inst_set);
   static void PairTestLandscape(cWorld* world, const cGenome & genome, cInstSet & inst_set,
 				int sample_size=0, int update=-1);
 

Modified: development/source/event/cEventManager.cc
===================================================================
--- development/source/event/cEventManager.cc	2006-07-03 16:34:58 UTC (rev 790)
+++ development/source/event/cEventManager.cc	2006-07-03 18:53:01 UTC (rev 791)
@@ -401,34 +401,6 @@
   }
 };
 
-///// calc_landscape /////
-
-/**
-**/
-
-
-class cEvent_calc_landscape : public cEvent {
-private:
-  int landscape_dist;
-public:
-  const cString GetName() const { return "calc_landscape"; }
-  const cString GetDescription() const { return "calc_landscape  [int landscape_dist=1]"; }
-  
-  void Configure(cWorld* world, const cString& in_args)
-  {
-    m_world = world;
-    m_args = in_args;
-    cString args(in_args);
-    if (args == "") landscape_dist=1; else landscape_dist=args.PopWord().AsInt();
-  }
-  ///// calc_landscape /////
-  void Process(){
-    cGenome & genome = m_world->GetClassificationManager().GetBestGenotype()->GetGenome();
-    cAnalyzeUtil::CalcLandscape(m_world, landscape_dist, genome,
-                                m_world->GetHardwareManager().GetInstSet());
-  }
-};
-
 ///// pairtest_landscape /////
 
 /**
@@ -1970,7 +1942,6 @@
   REGISTER(set_copy_mut);
   REGISTER(mod_point_mut);
   REGISTER(set_point_mut);
-  REGISTER(calc_landscape);
   REGISTER(pairtest_landscape);
   REGISTER(test_dom);
   REGISTER(analyze_population);




More information about the Avida-cvs mailing list