[Avida-SVN] r3356 - in development/source: actions analyze cpu main

jbarrick at myxo.css.msu.edu jbarrick at myxo.css.msu.edu
Mon Aug 3 20:26:22 PDT 2009


Author: jbarrick
Date: 2009-08-03 23:26:21 -0400 (Mon, 03 Aug 2009)
New Revision: 3356

Modified:
   development/source/actions/LandscapeActions.cc
   development/source/analyze/cAnalyze.cc
   development/source/analyze/cAnalyze.h
   development/source/analyze/cAnalyzeGenotype.cc
   development/source/analyze/cAnalyzeGenotype.h
   development/source/analyze/cModularityAnalysis.cc
   development/source/analyze/cModularityAnalysis.h
   development/source/cpu/cCPUTestInfo.cc
   development/source/cpu/cCPUTestInfo.h
   development/source/main/cLandscape.cc
   development/source/main/cLandscape.h
   development/source/main/cMutationRates.h
Log:
Manual inputs can be used in more analysis commands.


Modified: development/source/actions/LandscapeActions.cc
===================================================================
--- development/source/actions/LandscapeActions.cc	2009-07-22 18:03:26 UTC (rev 3355)
+++ development/source/actions/LandscapeActions.cc	2009-08-04 03:26:21 UTC (rev 3356)
@@ -165,12 +165,21 @@
  * Precalculates landscape data for use in detail files.  The primary
  * advantage of this is that it supports multithreaded execution, whereas
  * lazy evaluation during detailing will be serialized.
+ * @JEB: This also now supports setting some test CPU info, just manual inputs for now,
+ * (BEWARE: resource settings that are passed are NOT HONORED yet).
 */
 
 class cActionPrecalcLandscape : public cAction  // @parallelized
 {
+private:
+  cCPUTestInfo m_cpu_test_info;
+
 public:
-  cActionPrecalcLandscape(cWorld* world, const cString& args) : cAction(world, args) { ; }
+  cActionPrecalcLandscape(cWorld* world, const cString& in_args) : cAction(world, in_args), m_cpu_test_info() 
+  { 
+    cString args(in_args); 
+    cAnalyze::PopCommonCPUTestParameters(world, args, m_cpu_test_info);
+  }
   
   static const cString GetDescription()
   {
@@ -191,6 +200,7 @@
       tAnalyzeJobBatch<cAnalyzeGenotype> jobbatch(m_world->GetAnalyze().GetJobQueue());
       tListIterator<cAnalyzeGenotype> batch_it(m_world->GetAnalyze().GetCurrentBatch().List());
       for (cAnalyzeGenotype* cur_genotype = batch_it.Next(); cur_genotype; cur_genotype = batch_it.Next()) {
+        cur_genotype->SetCPUTestInfo(m_cpu_test_info);
         jobbatch.AddJob(cur_genotype, &cAnalyzeGenotype::CalcLandscape);
       }
       jobbatch.RunBatch();

Modified: development/source/analyze/cAnalyze.cc
===================================================================
--- development/source/analyze/cAnalyze.cc	2009-07-22 18:03:26 UTC (rev 3355)
+++ development/source/analyze/cAnalyze.cc	2009-08-04 03:26:21 UTC (rev 3356)
@@ -4929,11 +4929,14 @@
 {
   cout << "Calculating Functional Modularity..." << endl;
 
+  cCPUTestInfo test_info;
+  PopCommonCPUTestParameters(m_world, cur_string, test_info, m_resources, m_resource_time_spent_offset);
+
   tList<cModularityAnalysis> mod_list;
   tAnalyzeJobBatch<cModularityAnalysis> jobbatch(m_jobqueue);
   tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
   for (cAnalyzeGenotype* cur_genotype = batch_it.Next(); cur_genotype; cur_genotype = batch_it.Next()) {
-    cModularityAnalysis* mod = new cModularityAnalysis(cur_genotype);
+    cModularityAnalysis* mod = new cModularityAnalysis(cur_genotype, test_info);
     mod_list.Push(mod);
     jobbatch.AddJob(mod, &cModularityAnalysis::CalcFunctionalModularity);
   }
@@ -5430,7 +5433,7 @@
     double PM = 1.0 - (ave_dist / (double) (base_length * trait_count));
     double ave_sites = ((double) site_count) / (double) trait_count;
     
-    // Write the restults to file...
+    // Write the results to file...
     df.Write(PM,          "Physical Modularity");
     df.Write(trait_count, "Number of traits used in calculation");
     df.Write(ave_sites,   "Average num sites associated with traits");
@@ -9102,6 +9105,38 @@
 }
 
 
+void cAnalyze::PopCommonCPUTestParameters(cWorld* in_world, cString& cur_string, cCPUTestInfo& test_info, cResourceHistory* in_resource_history, int in_resource_time_spent_offset)
+{
+  tArray<int> manual_inputs;  // Used only if manual inputs are specified  
+  cString msg;                // Holds any information we may want to send the driver to display
+  int use_resources      = (cur_string.GetSize()) ? cur_string.PopWord().AsInt() : 0;
+  int update             = (cur_string.GetSize()) ? cur_string.PopWord().AsInt() : -1;
+  bool use_random_inputs = (cur_string.GetSize()) ? cur_string.PopWord().AsInt() == 1: false;
+  bool use_manual_inputs = false;
+  
+  //Manual inputs will override random input request and must be the last arguments.
+  if (cur_string.CountNumWords() > 0){
+    if (cur_string.CountNumWords() == in_world->GetEnvironment().GetInputSize()){
+      manual_inputs.Resize(in_world->GetEnvironment().GetInputSize());
+      use_random_inputs = false;
+      use_manual_inputs = true;
+      for (int k = 0; cur_string.GetSize(); k++)
+        manual_inputs[k] = cur_string.PopWord().AsInt();
+    } else if (in_world->GetVerbosity() >= VERBOSE_ON){
+      msg.Set("Invalid number of environment inputs requested for recalculation: %d specified, %d required.", 
+              cur_string.CountNumWords(), in_world->GetEnvironment().GetInputSize());
+      in_world->GetDriver().NotifyWarning(msg);
+    }
+  }
+  
+  if (use_manual_inputs)
+    test_info.UseManualInputs(manual_inputs);
+  else
+    test_info.UseRandomInputs(use_random_inputs); 
+  test_info.SetResourceOptions(use_resources, in_resource_history, update, in_resource_time_spent_offset);
+}
+
+
 // The following function will print a cell in a table with a background color based on a comparison
 // with its parent (the result of which is passed in as the 'compare' argument).  The cell_flags argument
 // includes any other information you want in the <td> tag; 'null_text' is the text you want to replace a

Modified: development/source/analyze/cAnalyze.h
===================================================================
--- development/source/analyze/cAnalyze.h	2009-07-22 18:03:26 UTC (rev 3355)
+++ development/source/analyze/cAnalyze.h	2009-08-04 03:26:21 UTC (rev 3356)
@@ -70,6 +70,7 @@
 class cAnalyzeFunction;
 class cAnalyzeGenotype;
 class cAnalyzeScreen;
+class cCPUTestInfo;
 class cEnvironment;
 class cInitFile;
 class cInstSet;
@@ -166,8 +167,10 @@
   cAnalyzeJobQueue& GetJobQueue() { return m_jobqueue; }
   
   void AlignCurrentBatch() { CommandAlign(""); }
-
   
+  static void PopCommonCPUTestParameters(cWorld* in_world, cString& cur_string, cCPUTestInfo& test_info,
+    cResourceHistory* in_resource_history = NULL, int in_resource_time_spent_offset = 0);
+  
 private:
   // Pop specific types of arguments from an arg list.
   cString PopDirectory(cString  in_string, const cString default_dir);

Modified: development/source/analyze/cAnalyzeGenotype.cc
===================================================================
--- development/source/analyze/cAnalyzeGenotype.cc	2009-07-22 18:03:26 UTC (rev 3355)
+++ development/source/analyze/cAnalyzeGenotype.cc	2009-08-04 03:26:21 UTC (rev 3356)
@@ -56,6 +56,7 @@
   , genome(symbol_string)
   , m_inst_set(in_inst_set)
   , name("")
+  , m_cpu_test_info()
   , m_data(new sGenotypeDatastore)
   , aligned_sequence("")
   , tag("")
@@ -111,6 +112,7 @@
   , genome(_genome)
   , m_inst_set(in_inst_set)
   , name("")
+  , m_cpu_test_info() 
   , m_data(new sGenotypeDatastore)
   , aligned_sequence("")
   , tag("")
@@ -155,6 +157,7 @@
   , genome(_gen.genome)
   , m_inst_set(_gen.m_inst_set)
   , name(_gen.name)
+  , m_cpu_test_info(_gen.m_cpu_test_info)  
   , m_data(_gen.m_data)
   , aligned_sequence(_gen.aligned_sequence)
   , tag(_gen.tag)
@@ -552,6 +555,7 @@
 {
   if (m_land == NULL) {
     m_land = new cLandscape(m_world, genome, m_inst_set);
+    m_land->SetCPUTestInfo(m_cpu_test_info);
     m_land->SetDistance(1);
     m_land->Process(m_world->GetDefaultContext());
   }
@@ -574,6 +578,7 @@
 void cAnalyzeGenotype::CalcLandscape(cAvidaContext& ctx)
 {
   if (m_land == NULL) m_land = new cLandscape(m_world, genome, m_inst_set);
+  m_land->SetCPUTestInfo(m_cpu_test_info);
   m_land->SetDistance(1);
   m_land->Process(ctx);
 }

Modified: development/source/analyze/cAnalyzeGenotype.h
===================================================================
--- development/source/analyze/cAnalyzeGenotype.h	2009-07-22 18:03:26 UTC (rev 3355)
+++ development/source/analyze/cAnalyzeGenotype.h	2009-08-04 03:26:21 UTC (rev 3356)
@@ -111,6 +111,7 @@
   cGenome genome;            // Full Genome
   cInstSet& m_inst_set;      // Instruction set used in this genome
   cString name;              // Name, if one was provided in loading
+  cCPUTestInfo m_cpu_test_info; // Use this test info
   
   struct sGenotypeDatastore : public cRCObject
   {
@@ -253,7 +254,8 @@
   void SetGenotypeData(int data_id, cGenotypeData* data);
   cGenotypeData* GetGenotypeData(ReadToken* tk, int data_id) const { tk->Validate(this); return m_data->dmap.GetWithDefault(data_id, NULL); }
   
-
+  void SetCPUTestInfo(cCPUTestInfo& in_cpu_test_info) { m_cpu_test_info = in_cpu_test_info; }
+  
   void Recalculate(cAvidaContext& ctx, cCPUTestInfo* test_info = NULL, cAnalyzeGenotype* parent_genotype = NULL, int num_trials = 1);
   void PrintTasks(std::ofstream& fp, int min_task = 0, int max_task = -1);
   void PrintTasksQuality(std::ofstream& fp, int min_task = 0, int max_task = -1);

Modified: development/source/analyze/cModularityAnalysis.cc
===================================================================
--- development/source/analyze/cModularityAnalysis.cc	2009-07-22 18:03:26 UTC (rev 3355)
+++ development/source/analyze/cModularityAnalysis.cc	2009-08-04 03:26:21 UTC (rev 3356)
@@ -57,14 +57,14 @@
 void cModularityAnalysis::CalcFunctionalModularity(cAvidaContext& ctx)
 {
   cTestCPU* testcpu = m_genotype->GetWorld()->GetHardwareManager().CreateTestCPU();
-  cCPUTestInfo test_info;
-
+  cCPUTestInfo test_info = m_test_info;
+  
   const cGenome& base_genome = m_genotype->GetGenome();
 
   // Calculate the stats for the genotype we're working with...
   testcpu->TestGenome(ctx, test_info, base_genome);  
   double base_fitness = test_info.GetColonyFitness();
-  
+    
   // Check if the organism does any tasks
   bool does_tasks = false;
   const tArray<int> base_tasks = test_info.GetColonyOrganism()->GetPhenotype().GetLastTaskCount();

Modified: development/source/analyze/cModularityAnalysis.h
===================================================================
--- development/source/analyze/cModularityAnalysis.h	2009-07-22 18:03:26 UTC (rev 3355)
+++ development/source/analyze/cModularityAnalysis.h	2009-08-04 03:26:21 UTC (rev 3356)
@@ -28,6 +28,9 @@
 #ifndef cGenotypeData_h
 #include "cGenotypeData.h"
 #endif
+#ifndef cCPUTestInfo_h
+#include "cCPUTestInfo.h"
+#endif
 #ifndef tArray_h
 #include "tArray.h"
 #endif
@@ -42,9 +45,9 @@
 {
 private:
   cAnalyzeGenotype* m_genotype;
-  
+  cCPUTestInfo m_test_info;
 public:
-  cModularityAnalysis(cAnalyzeGenotype* genotype) : m_genotype(genotype) { ; }
+  cModularityAnalysis(cAnalyzeGenotype* genotype, const cCPUTestInfo& test_info) : m_genotype(genotype), m_test_info(test_info) { ; }
   
   static void Initialize();
   

Modified: development/source/cpu/cCPUTestInfo.cc
===================================================================
--- development/source/cpu/cCPUTestInfo.cc	2009-07-22 18:03:26 UTC (rev 3355)
+++ development/source/cpu/cCPUTestInfo.cc	2009-08-04 03:26:21 UTC (rev 3356)
@@ -25,9 +25,11 @@
 
 #include "cCPUTestInfo.h"
 
+#include "cInstSet.h"
 #include "cHardwareStatusPrinter.h"
 #include "cOrganism.h"
 #include "cPhenotype.h"
+#include "cResourceHistory.h"
 
 #include <cassert>
 
@@ -49,7 +51,45 @@
   Clear();
 }
 
+cCPUTestInfo::cCPUTestInfo(const cCPUTestInfo& test_info)
+{
+  *this = test_info;
+}
 
+
+cCPUTestInfo& cCPUTestInfo::operator=(const cCPUTestInfo& test_info)
+{
+  generation_tests = test_info.generation_tests;
+  trace_task_order = test_info.trace_task_order;
+  use_random_inputs = test_info.use_random_inputs;
+	use_manual_inputs = test_info.use_manual_inputs;
+  manual_inputs = test_info.manual_inputs; 
+  m_tracer = NULL;
+  if (test_info.m_tracer) {
+    *m_tracer = *test_info.m_tracer;
+  }
+  m_inst_set = NULL;
+  if (test_info.m_inst_set)
+  {
+    *m_inst_set = *test_info.m_inst_set;
+  }
+  m_mut_rates = test_info.m_mut_rates;
+  m_cur_sg = test_info.m_cur_sg;
+  is_viable = test_info.is_viable;
+  max_depth = test_info.max_depth;
+  depth_found = test_info.depth_found;
+  max_cycle = test_info.max_cycle;
+  cycle_to = test_info.cycle_to;
+  used_inputs = test_info.used_inputs; 
+  org_array = test_info.org_array;
+  m_res_method = test_info.m_res_method;
+  m_res = NULL;  //Beware -- Resource history is NOT COPIED.
+  m_res_update = test_info.m_res_update;
+  m_res_cpu_cycle_offset = test_info.m_res_cpu_cycle_offset;
+  return *this;
+}
+
+
 cCPUTestInfo::~cCPUTestInfo()
 {
   for (int i = 0; i < generation_tests; i++) {

Modified: development/source/cpu/cCPUTestInfo.h
===================================================================
--- development/source/cpu/cCPUTestInfo.h	2009-07-22 18:03:26 UTC (rev 3355)
+++ development/source/cpu/cCPUTestInfo.h	2009-08-04 03:26:21 UTC (rev 3356)
@@ -61,7 +61,7 @@
   friend class cTestCPU;
 private:
   // Inputs...
-  const int generation_tests; // Maximum depth in generations to test
+  int generation_tests; // Maximum depth in generations to test
   bool trace_task_order;      // Should we keep track of ordering of tasks?
   bool use_random_inputs;     // Should we give the organism random inputs?
 	bool use_manual_inputs;     // Do we have inputs that we must use?
@@ -88,11 +88,11 @@
   int m_res_update;
   int m_res_cpu_cycle_offset;
 
-  cCPUTestInfo(const cCPUTestInfo&); // @not_implemented
-  cCPUTestInfo& operator=(const cCPUTestInfo&); // @not_implemented
 
 public:
   cCPUTestInfo(int max_tests=nHardware::TEST_CPU_GENERATIONS);
+  cCPUTestInfo(const cCPUTestInfo&);
+  cCPUTestInfo& operator=(const cCPUTestInfo&);
   ~cCPUTestInfo();
 
   void Clear();

Modified: development/source/main/cLandscape.cc
===================================================================
--- development/source/main/cLandscape.cc	2009-07-22 18:03:26 UTC (rev 3355)
+++ development/source/main/cLandscape.cc	2009-08-04 03:26:21 UTC (rev 3356)
@@ -43,7 +43,7 @@
   m_max_trials(0), site_count(NULL)
 {
   Reset(in_genome);
-  test_info.SetInstSet(const_cast<cInstSet*>(&inst_set));
+  m_cpu_test_info.SetInstSet(const_cast<cInstSet*>(&inst_set));
 }
 
 cLandscape::~cLandscape()
@@ -97,9 +97,9 @@
 
 double cLandscape::ProcessGenome(cAvidaContext& ctx, cTestCPU* testcpu, cGenome& in_genome)
 {
-  testcpu->TestGenome(ctx, test_info, in_genome);
+  testcpu->TestGenome(ctx, m_cpu_test_info, in_genome);
   
-  double test_fitness = test_info.GetColonyFitness();
+  double test_fitness = m_cpu_test_info.GetColonyFitness();
   
   total_fitness += test_fitness;
   total_sqr_fitness += test_fitness * test_fitness;
@@ -127,10 +127,10 @@
 {
   // Collect info on base creature.
   
-  testcpu->TestGenome(ctx, test_info, base_genome);
+  testcpu->TestGenome(ctx, m_cpu_test_info, base_genome);
   
-  cPhenotype & phenotype = test_info.GetColonyOrganism()->GetPhenotype();
-  base_fitness = test_info.GetColonyFitness();
+  cPhenotype & phenotype = m_cpu_test_info.GetColonyOrganism()->GetPhenotype();
+  base_fitness = m_cpu_test_info.GetColonyFitness();
   base_merit = phenotype.GetMerit().GetDouble();
   base_gestation = phenotype.GetGestationTime();
   
@@ -190,7 +190,7 @@
       mod_genome[line_num].SetOp(inst_num);
       if (cur_distance <= 1) {
         ProcessGenome(ctx, testcpu, mod_genome);
-        if (test_info.GetColonyFitness() >= neut_min) site_count[line_num]++;
+        if (m_cpu_test_info.GetColonyFitness() >= neut_min) site_count[line_num]++;
       } else {
         Process_Body(ctx, testcpu, mod_genome, cur_distance - 1, line_num + 1);
       }
@@ -258,7 +258,7 @@
     int cur_inst = base_genome[line_num].GetOp();
     mod_genome.Remove(line_num);
     ProcessGenome(ctx, testcpu, mod_genome);
-    if (test_info.GetColonyFitness() >= neut_min) site_count[line_num]++;
+    if (m_cpu_test_info.GetColonyFitness() >= neut_min) site_count[line_num]++;
     mod_genome.Insert(line_num, cInstruction(cur_inst));
   }
   
@@ -283,7 +283,7 @@
     for (int inst_num = 0; inst_num < inst_size; inst_num++) {
       mod_genome.Insert(line_num, cInstruction(inst_num));
       ProcessGenome(ctx, testcpu, mod_genome);
-      if (test_info.GetColonyFitness() >= neut_min) site_count[line_num]++;
+      if (m_cpu_test_info.GetColonyFitness() >= neut_min) site_count[line_num]++;
       mod_genome.Remove(line_num);
     }
   }
@@ -649,7 +649,7 @@
       
       mod_genome[line_num].SetOp(inst_num);
       ProcessGenome(ctx, testcpu, mod_genome);
-      fitness_chart(line_num, inst_num) = test_info.GetColonyFitness();
+      fitness_chart(line_num, inst_num) = m_cpu_test_info.GetColonyFitness();
     }
     
     mod_genome[line_num].SetOp(cur_inst);
@@ -778,8 +778,8 @@
     pos_frac = GetProbPos();
     
     // Print the information on the current best.
-    testcpu->TestGenome(ctx, test_info, cur_genome);
-    cPhenotype& colony_phenotype = test_info.GetColonyOrganism()->GetPhenotype();
+    testcpu->TestGenome(ctx, m_cpu_test_info, cur_genome);
+    cPhenotype& colony_phenotype = m_cpu_test_info.GetColonyOrganism()->GetPhenotype();
     df.Write(gen, "Generation");
     df.Write(colony_phenotype.GetMerit().GetDouble(), "Merit");
     df.Write(colony_phenotype.GetGestationTime(), "Gestation Time");
@@ -805,8 +805,8 @@
 {
   mod_genome[line1] = mut1;
   mod_genome[line2] = mut2;
-  testcpu->TestGenome(ctx, test_info, mod_genome);
-  double combo_fitness = test_info.GetColonyFitness() / base_fitness;
+  testcpu->TestGenome(ctx, m_cpu_test_info, mod_genome);
+  double combo_fitness = m_cpu_test_info.GetColonyFitness() / base_fitness;
   
   mod_genome[line1] = base_genome[line1];
   mod_genome[line2] = base_genome[line2];

Modified: development/source/main/cLandscape.h
===================================================================
--- development/source/main/cLandscape.h	2009-07-22 18:03:26 UTC (rev 3355)
+++ development/source/main/cLandscape.h	2009-08-04 03:26:21 UTC (rev 3356)
@@ -51,6 +51,7 @@
 private:
   cWorld* m_world;
   const cInstSet& inst_set;
+  cCPUTestInfo m_cpu_test_info;
   cGenome base_genome;
   cGenome peak_genome;
   double base_fitness;
@@ -91,7 +92,6 @@
   double total_entropy;
   double complexity;
 
-  cCPUTestInfo test_info;  // Info used for all cpu calculations.
   double neut_min;         // These two variables are a range around the base
   double neut_max;         //   fitness to be counted as neutral mutations.
   tMatrix<double> fitness_chart; // Chart of all one-step mutations.
@@ -128,6 +128,11 @@
   inline void SetTrials(int in_trials) { trials = in_trials; }
   inline void SetMinFound(int min_found) { m_min_found = min_found; }
   inline void SetMaxTrials(int max_trials) { m_max_trials = max_trials; }
+  inline void SetCPUTestInfo(const cCPUTestInfo& in_cpu_test_info) 
+  { 
+      m_cpu_test_info = in_cpu_test_info; 
+      m_cpu_test_info.SetInstSet(const_cast<cInstSet*>(&inst_set));
+  }
 
   void SampleProcess(cAvidaContext& ctx);
   void RandomProcess(cAvidaContext& ctx);

Modified: development/source/main/cMutationRates.h
===================================================================
--- development/source/main/cMutationRates.h	2009-07-22 18:03:26 UTC (rev 3355)
+++ development/source/main/cMutationRates.h	2009-08-04 03:26:21 UTC (rev 3356)
@@ -86,11 +86,10 @@
   };
   sMetaMuts meta;
 
-  cMutationRates& operator=(const cMutationRates&); // @not_implemented
-
 public:
   cMutationRates() { Clear(); }
   cMutationRates(const cMutationRates& in_muts) { Copy(in_muts); }
+  cMutationRates& operator=(const cMutationRates& in_muts) { Copy(in_muts); return *this; }
   ~cMutationRates() { ; }
 
   void Setup(cWorld* world);




More information about the Avida-cvs mailing list