[avida-cvs] avida CVS commits: /current/source/main analyze.cc analyze.hh avida_driver_analyze.cc avida_driver_analyze.hh config.cc config.hh primitive.cc

mercere99 avida-cvs at alife.org
Fri Dec 5 21:39:23 PST 2003


mercere99		Fri Dec  5 13:39:23 2003 EDT

  Modified files:              
    /avida/current/source/main	analyze.cc analyze.hh 
                              	avida_driver_analyze.cc 
                              	avida_driver_analyze.hh config.cc 
                              	config.hh primitive.cc 
  Log:
  Added two new analyze commands:
   LOAD_MULTI_DETAIL <start UD> <step UD> <stop UD> <dir='./'> <start batch=0>
  
     Allows the user to load in multiple detail files at once, one per
     batch.  This is helpful when you're trying to do parallel analysis
     on many detail files, or else to create a phylogenetic depth map.
  
     Example: LOAD_MULTI_DETAIL 100 100 100000 ../my_run/run100/
  
     This would load in the files detail_pop.100 through detail_pop.100000 
     in steps of 100, from the directory of my choosing.  Since 1000 files will
     be loaded and we didn't specify starting batch, they will be put in
     batches 0 through 999.
  
  
   MAP_DEPTH <filename='depth_map.dat'> <min_batch=0> <max_batch=cur_batch-1>
  
     This will create a depth map (like those we use for phylogeny visualization)
     in the filename specified.  You can direct which batches to take this from,
     but by default it will work perfectly after a LOAD_MULTI_DETAIL.
  
  
-------------- next part --------------
Index: avida/current/source/main/analyze.cc
diff -u avida/current/source/main/analyze.cc:1.87 avida/current/source/main/analyze.cc:1.88
--- avida/current/source/main/analyze.cc:1.87	Thu Dec  4 13:36:18 2003
+++ avida/current/source/main/analyze.cc	Fri Dec  5 13:39:22 2003
@@ -276,6 +276,103 @@
   batch[cur_batch].SetAligned(false);
 }
 
+void cAnalyze::LoadMultiDetail(cString cur_string)
+{
+  // LOAD_MULTI_DETAIL
+
+  int start_UD = cur_string.PopWord().AsInt();
+  int step_UD = cur_string.PopWord().AsInt();
+  int stop_UD = cur_string.PopWord().AsInt();
+  cString data_directory = PopDirectory(cur_string, "./");
+  cur_batch = cur_string.PopWord().AsInt();
+
+  if (step_UD == 0) {
+    cerr << "Error: LOAD_MULTI_DETAIL must have a non-zero value for step."
+	 << endl;
+    return;
+  }
+
+  int num_steps = (stop_UD - start_UD) / step_UD + 1;
+  if (num_steps > 1000) {
+    cerr << "Warning: Loading over 1000 files in LOAD_MULTI_DETAIL!"
+	 << endl;
+  }
+
+  if (verbose == true) {
+    cout << "Loading in " << num_steps
+	 << " detail files from update " << start_UD
+	 << " to update " << stop_UD
+	 << endl;
+  } else {
+    cout << "Running LOAD_MULTI_DETAIL" << endl;
+  }
+
+  for (int cur_UD = start_UD; cur_UD <= stop_UD; cur_UD += step_UD) {
+    cString filename = cStringUtil::Stringf("detail_pop.%d", cur_UD);
+
+    cout << "Loading '" << filename
+	 << "' into batch " << cur_batch
+	 << endl;
+
+    cInitFile input_file(filename);
+    if (!input_file.IsOpen()) {
+      cerr << "Error: Cannot load file: \"" << filename << "\"." << endl;
+      exit(1);
+    }
+    input_file.Load();
+    input_file.Compress();
+    input_file.Close();
+    
+    // Setup the genome...
+
+    for (int line_id = 0; line_id < input_file.GetNumLines(); line_id++) {
+      cString cur_line = input_file.GetLine(line_id);
+      
+      // Setup the genotype for this line...
+      
+      int id_num      = cur_line.PopWord().AsInt();
+      int parent_id   = cur_line.PopWord().AsInt();
+      int parent_dist = cur_line.PopWord().AsInt();
+      int num_cpus    = cur_line.PopWord().AsInt();
+      int total_cpus  = cur_line.PopWord().AsInt();
+      int length      = cur_line.PopWord().AsInt();
+      double merit    = cur_line.PopWord().AsDouble();
+      int gest_time   = cur_line.PopWord().AsInt();
+      double fitness  = cur_line.PopWord().AsDouble();
+      int update_born = cur_line.PopWord().AsInt();
+      int update_dead = cur_line.PopWord().AsInt();
+      int depth       = cur_line.PopWord().AsInt();
+      cString name = cStringUtil::Stringf("org-%d", id_num);
+      
+      cAnalyzeGenotype * genotype =
+	new cAnalyzeGenotype(cur_line.PopWord(), inst_set);
+      
+      genotype->SetID(id_num);
+      genotype->SetParentID(parent_id);
+      genotype->SetParentDist(parent_dist);
+      genotype->SetNumCPUs(num_cpus);
+      genotype->SetTotalCPUs(total_cpus);
+      genotype->SetLength(length);
+      genotype->SetMerit(merit);
+      genotype->SetGestTime(gest_time);
+      genotype->SetFitness(fitness);
+      genotype->SetUpdateBorn(update_born);
+      genotype->SetUpdateDead(update_dead);
+      genotype->SetDepth(depth);
+      genotype->SetName(name);
+      
+      // Add this genotype to the proper batch.
+      batch[cur_batch].List().PushRear(genotype);
+    }
+    
+    // Adjust the flags on this batch
+    batch[cur_batch].SetLineage(false);
+    batch[cur_batch].SetAligned(false);
+    
+    cur_batch++;
+  }
+}
+
 void cAnalyze::LoadSequence(cString cur_string)
 {
   // LOAD_SEQUENCE
@@ -2364,6 +2461,51 @@
 }
 
 
+void cAnalyze::CommandMapDepth(cString cur_string)
+{
+  cout << "Constructing depth map..." << endl;
+
+  cString filename("depth_map.dat");
+  if (cur_string.GetSize() != 0) filename = cur_string.PopWord();  
+
+  int min_batch = 0;
+  int max_batch = cur_batch - 1;
+
+  if (cur_string.GetSize() != 0) min_batch = cur_string.PopWord().AsInt();
+  if (cur_string.GetSize() != 0) max_batch = cur_string.PopWord().AsInt();
+
+  // First, scan all of the batches to find the maximum depth.
+  int max_depth = -1;
+  cAnalyzeGenotype * genotype;
+  for (int i = min_batch; i <= max_batch; i++) {
+    tListIterator<cAnalyzeGenotype> list_it(batch[i].List());
+    while ((genotype = list_it.Next()) != NULL) {
+      if (genotype->GetDepth() > max_depth) max_depth = genotype->GetDepth();
+    }
+  }
+
+  cout << "max_depth = " << max_depth << endl;
+
+  ofstream & fp = data_file_manager.GetOFStream(filename);
+
+  cout << "Output to " << filename << endl;
+  tArray<int> depth_array(max_depth+1);
+  for (cur_batch = min_batch; cur_batch <= max_batch; cur_batch++) {
+    depth_array.SetAll(0);
+    tListIterator<cAnalyzeGenotype> list_it(batch[cur_batch].List());
+    while ((genotype = list_it.Next()) != NULL) {
+      const int cur_depth = genotype->GetDepth();
+      const int cur_count = genotype->GetNumCPUs();
+      depth_array[cur_depth] += cur_count;
+    }
+
+    for (int i = 0; i <= max_depth; i++) {
+      fp << depth_array[i] << " ";
+    }
+    fp << endl;
+  }
+}
+
 void cAnalyze::CommandHamming(cString cur_string)
 {
   cString filename("hamming.dat");
@@ -3591,51 +3733,7 @@
   // No Args needed...
   (void) cur_string;
 
-  cout << "Entering interactive mode..." << endl;
-
-  char text_input[2048];
-  while (true) {
-    cout << ">> ";
-    cout.flush();
-    cin.getline(text_input, 2048);
-    cString cur_input(text_input);
-    cString command = cur_input.PopWord();
-    command.ToUpper();
-
-    cAnalyzeCommand * cur_command;
-    cAnalyzeCommandDefBase * command_def = FindAnalyzeCommandDef(command);
-    if (command == "") {
-      // Don't worry about blank lines...
-      continue;
-    }
-    else if (command == "END" || command == "QUIT" || command == "EXIT") {
-      // We are done with interactive mode...
-      break;
-    }
-    else if (command_def != NULL && command_def->IsFlowCommand() == true) {
-      // This code has a body to it... fill it out!
-      cur_command = new cAnalyzeFlowCommand(command, cur_input);
-      InteractiveLoadCommandList(*(cur_command->GetCommandList()));
-    }
-    else {
-      // This is a normal command...
-      cur_command = new cAnalyzeCommand(command, cur_input);
-    }
-
-    cString args = cur_command->GetArgs();
-    PreProcessArgs(args);
-
-    cAnalyzeCommandDefBase * command_fun = FindAnalyzeCommandDef(command);
-
-    // First check for built-in functions...
-    if (command_fun != NULL) command_fun->Run(this, args, *cur_command);
-
-    // Then for user defined functions
-    else if (FunctionRun(command, args) == true) { }
-
-    // Otherwise, give an error.
-    else cerr << "Error: Unknown command '" << command << "'." << endl;
-  }
+  RunInteractive();
 }
 
 
@@ -4261,6 +4359,7 @@
   AddLibraryDef("LOAD_ORGANISM", &cAnalyze::LoadOrganism);
   AddLibraryDef("LOAD_BASE_DUMP", &cAnalyze::LoadBasicDump);
   AddLibraryDef("LOAD_DETAIL_DUMP", &cAnalyze::LoadDetailDump);
+  AddLibraryDef("LOAD_MULTI_DETAIL", &cAnalyze::LoadMultiDetail);
   AddLibraryDef("LOAD_SEQUENCE", &cAnalyze::LoadSequence);
   AddLibraryDef("LOAD_DOMINANT", &cAnalyze::LoadDominant);
   AddLibraryDef("LOAD", &cAnalyze::LoadFile);
@@ -4295,7 +4394,8 @@
   AddLibraryDef("MAP_MUTATIONS", &cAnalyze::CommandMapMutations);
   AddLibraryDef("ANALYZE_COMPLEXITY", &cAnalyze::AnalyzeComplexity);
   AddLibraryDef("ANALYZE_POP_COMPLEXITY", &cAnalyze::AnalyzePopComplexity);
-
+  AddLibraryDef("MAP_DEPTH", &cAnalyze::CommandMapDepth);
+  
   // Population comparison commands...
   AddLibraryDef("HAMMING", &cAnalyze::CommandHamming);
   AddLibraryDef("LEVENSTEIN", &cAnalyze::CommandLevenstein);
@@ -4355,4 +4455,53 @@
   }
 
   return lib_it.Get();
+}
+
+void cAnalyze::RunInteractive()
+{
+  cout << "Entering interactive mode..." << endl;
+
+  char text_input[2048];
+  while (true) {
+    cout << ">> ";
+    cout.flush();
+    cin.getline(text_input, 2048);
+    cString cur_input(text_input);
+    cString command = cur_input.PopWord();
+    command.ToUpper();
+
+    cAnalyzeCommand * cur_command;
+    cAnalyzeCommandDefBase * command_def = FindAnalyzeCommandDef(command);
+    if (command == "") {
+      // Don't worry about blank lines...
+      continue;
+    }
+    else if (command == "END" || command == "QUIT" || command == "EXIT") {
+      // We are done with interactive mode...
+      break;
+    }
+    else if (command_def != NULL && command_def->IsFlowCommand() == true) {
+      // This code has a body to it... fill it out!
+      cur_command = new cAnalyzeFlowCommand(command, cur_input);
+      InteractiveLoadCommandList(*(cur_command->GetCommandList()));
+    }
+    else {
+      // This is a normal command...
+      cur_command = new cAnalyzeCommand(command, cur_input);
+    }
+
+    cString args = cur_command->GetArgs();
+    PreProcessArgs(args);
+
+    cAnalyzeCommandDefBase * command_fun = FindAnalyzeCommandDef(command);
+
+    // First check for built-in functions...
+    if (command_fun != NULL) command_fun->Run(this, args, *cur_command);
+
+    // Then for user defined functions
+    else if (FunctionRun(command, args) == true) { }
+
+    // Otherwise, give an error.
+    else cerr << "Error: Unknown command '" << command << "'." << endl;
+  }
 }
Index: avida/current/source/main/analyze.hh
diff -u avida/current/source/main/analyze.hh:1.50 avida/current/source/main/analyze.hh:1.51
--- avida/current/source/main/analyze.hh:1.50	Tue Nov 25 09:37:56 2003
+++ avida/current/source/main/analyze.hh	Fri Dec  5 13:39:23 2003
@@ -27,7 +27,7 @@
 #include "tList.hh"
 #endif
 
-#define MAX_BATCHES 200
+#define MAX_BATCHES 2000
 
 // cAnalyze            : The master analyze object.
 
@@ -107,6 +107,7 @@
   void LoadOrganism(cString cur_string);
   void LoadBasicDump(cString cur_string);
   void LoadDetailDump(cString cur_string);
+  void LoadMultiDetail(cString cur_string);
   void LoadSequence(cString cur_string);
   void LoadDominant(cString cur_string);
   void LoadFile(cString cur_string);
@@ -138,6 +139,7 @@
   void CommandMapTasks(cString cur_string);
   void CommandAverageModularity(cString cur_string);
   void CommandMapMutations(cString cur_string);
+  void CommandMapDepth(cString cur_string);
 
   // Population Comparison Commands...
   void CommandHamming(cString cur_string);
@@ -192,6 +194,8 @@
 public:
   cAnalyze(cString filename);
   ~cAnalyze();
+
+  void RunInteractive();
 };
 
 #endif
Index: avida/current/source/main/avida_driver_analyze.cc
diff -u avida/current/source/main/avida_driver_analyze.cc:1.1 avida/current/source/main/avida_driver_analyze.cc:1.2
--- avida/current/source/main/avida_driver_analyze.cc:1.1	Tue Nov 25 09:37:56 2003
+++ avida/current/source/main/avida_driver_analyze.cc	Fri Dec  5 13:39:23 2003
@@ -24,7 +24,8 @@
 //  cAvidaDriver_Analyze
 //////////////////////////
 
-cAvidaDriver_Analyze::cAvidaDriver_Analyze()
+cAvidaDriver_Analyze::cAvidaDriver_Analyze(bool _interactive)
+  : interactive(_interactive)
 {
 }
 
@@ -36,4 +37,7 @@
 {
   cout << "In analyze mode!!" << endl;
   cAnalyze analyze(cConfig::GetAnalyzeFilename());
+  if (interactive == true) {
+    analyze.RunInteractive();
+  }
 }
Index: avida/current/source/main/avida_driver_analyze.hh
diff -u avida/current/source/main/avida_driver_analyze.hh:1.1 avida/current/source/main/avida_driver_analyze.hh:1.2
--- avida/current/source/main/avida_driver_analyze.hh:1.1	Tue Nov 25 09:37:56 2003
+++ avida/current/source/main/avida_driver_analyze.hh	Fri Dec  5 13:39:23 2003
@@ -14,8 +14,9 @@
 
 class cAvidaDriver_Analyze : public cAvidaDriver_Base {
 protected:
+  bool interactive;
 public:
-  cAvidaDriver_Analyze();
+  cAvidaDriver_Analyze(bool _interactive=false);
   virtual ~cAvidaDriver_Analyze();
   virtual void Run();
 };
Index: avida/current/source/main/config.cc
diff -u avida/current/source/main/config.cc:1.65 avida/current/source/main/config.cc:1.66
--- avida/current/source/main/config.cc:1.65	Tue Nov 25 09:37:56 2003
+++ avida/current/source/main/config.cc	Fri Dec  5 13:39:23 2003
@@ -31,6 +31,7 @@
 tList<cConfig::cConfigGroup> cConfig::group_list;
 bool cConfig::analyze_mode;
 bool cConfig::primitive_mode;
+bool cConfig::interactive_analyze;
 cString cConfig::default_dir;
 cString cConfig::genesis_filename;
 cString cConfig::inst_filename;
@@ -489,6 +490,7 @@
   int arg_num = 1;              // Argument number being looked at.
   analyze_mode = false;         // Initialize analyze_mode tp be off.
   primitive_mode = false;       // Initialize primitive_mode tp be off.
+  interactive_analyze = false;  // Don't start analyze interactively either.
 
   // Load all of the args into string objects for ease of access.
   cString * args = new cString[argc];
@@ -560,6 +562,7 @@
 	   << "  -l[oad] <filename>    Load a clone file"<<endl
 	   << "  -loadpop <filename>   Load a saved population file (precedence over load)"<<endl
 	   << "  -a[nalyze]            Process analyze.cfg instead of normal run."<<endl
+	   << "  -i[nteractive]        Run analyze mode interactively."
 	// <<"  -p[rimitive]          Overide viewer to be primitive."<<endl
 	   << endl;
 	
@@ -577,6 +580,9 @@
       genesis.AddInput("RANDOM_SEED", in_seed);
     } else if (cur_arg == "-analyze" || cur_arg == "-a") {
       analyze_mode = true;
+    } else if (cur_arg == "-interactive" || cur_arg == "-i") {
+      analyze_mode = true;
+      interactive_analyze = true;
     } else if (cur_arg == "-primitive" || cur_arg == "-p") {
       primitive_mode = true;
     } else if (cur_arg == "-load" || cur_arg == "-l") {
Index: avida/current/source/main/config.hh
diff -u avida/current/source/main/config.hh:1.58 avida/current/source/main/config.hh:1.59
--- avida/current/source/main/config.hh:1.58	Tue Nov 25 09:37:56 2003
+++ avida/current/source/main/config.hh	Fri Dec  5 13:39:23 2003
@@ -160,6 +160,7 @@
   // Major Configurations
   static bool analyze_mode;     // Should avida do only analysis work?
   static bool primitive_mode;   // Should avida run in primitive mode?
+  static bool interactive_analyze; // Should analyze mode be interactive?
 
   // Config Filenames
   static cString default_dir;
@@ -282,6 +283,7 @@
   // ``Get''
   static bool GetAnalyzeMode() { return analyze_mode; }
   static bool GetPrimitiveMode() { return primitive_mode; }
+  static bool GetInteractiveAnalyze() { return interactive_analyze; }
 
   /*
   addition to permit access to cConfig::default_dir for use in locating
Index: avida/current/source/main/primitive.cc
diff -u avida/current/source/main/primitive.cc:1.5 avida/current/source/main/primitive.cc:1.6
--- avida/current/source/main/primitive.cc:1.5	Tue Nov 25 09:37:57 2003
+++ avida/current/source/main/primitive.cc	Fri Dec  5 13:39:23 2003
@@ -18,7 +18,8 @@
   SetupAvida( argc, argv, environment, test_interface );
 
   if (cConfig::GetAnalyzeMode() == true) {
-    cAvidaDriver_Base::main_driver = new cAvidaDriver_Analyze();
+    cAvidaDriver_Base::main_driver =
+      new cAvidaDriver_Analyze(cConfig::GetInteractiveAnalyze());
   }
   else {
     cAvidaDriver_Base::main_driver = new cAvidaDriver_Population(environment);


More information about the Avida-cvs mailing list