[Avida-cvs] [Avida2-svn] r132 - in branches/developers/kaben-organism-scope/source: bindings/Boost.Python cpu main

kaben at myxo.css.msu.edu kaben at myxo.css.msu.edu
Fri Apr 8 18:47:33 PDT 2005


Author: kaben
Date: 2005-04-08 21:47:33 -0400 (Fri, 08 Apr 2005)
New Revision: 132

Added:
   branches/developers/kaben-organism-scope/source/cpu/hardware_status_printer.cc
   branches/developers/kaben-organism-scope/source/cpu/hardware_status_printer.hh
Modified:
   branches/developers/kaben-organism-scope/source/bindings/Boost.Python/CMakeLists.txt
   branches/developers/kaben-organism-scope/source/bindings/Boost.Python/cpu_test_info.pyste
   branches/developers/kaben-organism-scope/source/bindings/Boost.Python/hardware_base.pyste
   branches/developers/kaben-organism-scope/source/bindings/Boost.Python/landscape.pyste
   branches/developers/kaben-organism-scope/source/bindings/Boost.Python/py_avida_driver-fixups.cc
   branches/developers/kaben-organism-scope/source/cpu/CMakeLists.txt
   branches/developers/kaben-organism-scope/source/cpu/cpu_test_info.cc
   branches/developers/kaben-organism-scope/source/cpu/cpu_test_info.hh
   branches/developers/kaben-organism-scope/source/cpu/hardware_4stack.cc
   branches/developers/kaben-organism-scope/source/cpu/hardware_base.cc
   branches/developers/kaben-organism-scope/source/cpu/hardware_base.hh
   branches/developers/kaben-organism-scope/source/cpu/hardware_cpu.cc
   branches/developers/kaben-organism-scope/source/cpu/test_cpu.cc
   branches/developers/kaben-organism-scope/source/main/analyze.cc
   branches/developers/kaben-organism-scope/source/main/landscape.cc
   branches/developers/kaben-organism-scope/source/main/landscape.hh
Log:

* Altered analyze mode to use added class cHardwareStatusPrinter for
  tracing genotypes.
  - class cHardwareStatusPrinter implements cHardwareTracer_4Stack,
    cHardwareTracer_CPU, and cHardwareTracer_TestCPU.
  - (Note: along the way, removed redundant include guards from some .cc
    files; as Charles has pointed-out, they're only needed in header
    files.)




Modified: branches/developers/kaben-organism-scope/source/bindings/Boost.Python/CMakeLists.txt
===================================================================
--- branches/developers/kaben-organism-scope/source/bindings/Boost.Python/CMakeLists.txt	2005-04-09 01:46:27 UTC (rev 131)
+++ branches/developers/kaben-organism-scope/source/bindings/Boost.Python/CMakeLists.txt	2005-04-09 01:47:33 UTC (rev 132)
@@ -192,6 +192,7 @@
   population:: # XXX XXX XXX
   population_interface:: # XXX XXX XXX
   py_avida_driver::${CMAKE_CURRENT_SOURCE_DIR}/avida_driver_population.pyste # XXX XXX XXX
+  py_hardware_tracer::
   reaction_lib:: # XXX XXX XXX
   resource_count:: # XXX XXX XXX
   resource_lib:: # XXX XXX XXX

Modified: branches/developers/kaben-organism-scope/source/bindings/Boost.Python/cpu_test_info.pyste
===================================================================
--- branches/developers/kaben-organism-scope/source/bindings/Boost.Python/cpu_test_info.pyste	2005-04-09 01:46:27 UTC (rev 131)
+++ branches/developers/kaben-organism-scope/source/bindings/Boost.Python/cpu_test_info.pyste	2005-04-09 01:47:33 UTC (rev 132)
@@ -1,8 +1,12 @@
 
+Include("hardware_tracer.hh")
 Include("organism.hh")
 
 cCPUTestInfo = Class("cCPUTestInfo", "cpu_test_info.hh")
 # returns std::ofstream &, i.e., not the Python Way.
-exclude(cCPUTestInfo.GetTraceFP)
+#exclude(cCPUTestInfo.GetTraceFP)
 set_policy(cCPUTestInfo.GetTestOrganism, return_internal_reference())
 set_policy(cCPUTestInfo.GetColonyOrganism, return_internal_reference())
+set_policy(cCPUTestInfo.GetColonyOrganism, return_internal_reference())
+# Another reason to use ref-counting... Dangerous return value policy in use:
+set_policy(cCPUTestInfo.GetTracer, return_value_policy(reference_existing_object))

Modified: branches/developers/kaben-organism-scope/source/bindings/Boost.Python/hardware_base.pyste
===================================================================
--- branches/developers/kaben-organism-scope/source/bindings/Boost.Python/hardware_base.pyste	2005-04-09 01:46:27 UTC (rev 131)
+++ branches/developers/kaben-organism-scope/source/bindings/Boost.Python/hardware_base.pyste	2005-04-09 01:47:33 UTC (rev 132)
@@ -2,6 +2,7 @@
 Include("code_label.hh")
 Include("cpu_memory.hh")
 Include("genome.hh")
+Include("hardware_tracer.hh")
 Include("inst_set.hh")
 Include("organism.hh")
 

Modified: branches/developers/kaben-organism-scope/source/bindings/Boost.Python/landscape.pyste
===================================================================
--- branches/developers/kaben-organism-scope/source/bindings/Boost.Python/landscape.pyste	2005-04-09 01:46:27 UTC (rev 131)
+++ branches/developers/kaben-organism-scope/source/bindings/Boost.Python/landscape.pyste	2005-04-09 01:47:33 UTC (rev 132)
@@ -1,3 +1,5 @@
 Include("inst_set.hh")
 
+Include("fstream")
+
 cLandscape = Class("cLandscape", "landscape.hh")

Modified: branches/developers/kaben-organism-scope/source/bindings/Boost.Python/py_avida_driver-fixups.cc
===================================================================
--- branches/developers/kaben-organism-scope/source/bindings/Boost.Python/py_avida_driver-fixups.cc	2005-04-09 01:46:27 UTC (rev 131)
+++ branches/developers/kaben-organism-scope/source/bindings/Boost.Python/py_avida_driver-fixups.cc	2005-04-09 01:47:33 UTC (rev 132)
@@ -1,39 +1,20 @@
 
-#ifndef PY_AVIDA_DRIVER_HH
 #include "py_avida_driver.hh"
-#endif
 
-#ifndef GENEBANK_HH
 #include "main/genebank.hh"
-#endif
-#ifndef GENOTYPE_HH
 #include "main/genotype.hh"
-#endif
-#ifndef POPULATION_CELL_HH
 #include "main/population_cell.hh"
-#endif
-#ifndef HARDWARE_FACTORY_HH
 #include "cpu/hardware_factory.hh"
-#endif
-#ifndef ORGANISM_HH
 #include "main/organism.hh"
-#endif  
-#ifndef HARDWARE_BASE_HH
 #include "cpu/hardware_base.hh"
-#endif
-#ifndef STRING_HH
 #include "tools/string.hh"
-#endif
-#ifndef CONFIG_HH
 #include "main/config.hh"
-#endif
-#ifndef POPULATION_HH
 #include "main/population.hh"
-#endif
 
 
 #include <iostream>
 
+
 bool pyAvidaDriver::preUpdate(const unsigned int){
   GetEvents();
   if(true == done_flag){ return false; }

Modified: branches/developers/kaben-organism-scope/source/cpu/CMakeLists.txt
===================================================================
--- branches/developers/kaben-organism-scope/source/cpu/CMakeLists.txt	2005-04-09 01:46:27 UTC (rev 131)
+++ branches/developers/kaben-organism-scope/source/cpu/CMakeLists.txt	2005-04-09 01:47:33 UTC (rev 132)
@@ -12,6 +12,7 @@
   hardware_cpu_thread.cc
   hardware_factory.cc
   hardware_util.cc
+  hardware_status_printer.cc
   memory_flags.cc
   test_cpu.cc
   test_util.cc

Modified: branches/developers/kaben-organism-scope/source/cpu/cpu_test_info.cc
===================================================================
--- branches/developers/kaben-organism-scope/source/cpu/cpu_test_info.cc	2005-04-09 01:46:27 UTC (rev 131)
+++ branches/developers/kaben-organism-scope/source/cpu/cpu_test_info.cc	2005-04-09 01:47:33 UTC (rev 132)
@@ -5,16 +5,11 @@
 // before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
 //////////////////////////////////////////////////////////////////////////////
 
-#ifndef CPU_TEST_INFO_HH
 #include "cpu_test_info.hh"
-#endif
 
-#ifndef ORGANISM_HH
+#include "hardware_status_printer.hh"
 #include "organism.hh"
-#endif
-#ifndef PHENOTYPE_HH
 #include "phenotype.hh"
-#endif
 
 #include <assert.h>
 
@@ -30,6 +25,7 @@
   , trace_task_order(false)
   , use_random_inputs(false)
   , org_array(max_tests)
+  , m_tracer(NULL)
 {
   org_array.SetAll(NULL);
   Clear();
@@ -60,11 +56,10 @@
 }
  
 
-void cCPUTestInfo::SetTraceExecution(const cString & filename)
+void cCPUTestInfo::SetTraceExecution(cHardwareTracer *tracer)
 {
-  trace_execution = true;
-  trace_fp.open(filename);
-  assert (trace_fp.good() == true); // Unable to open trace file.
+  trace_execution = (tracer)?(true):(false);
+  m_tracer = tracer;
 }
 
 

Modified: branches/developers/kaben-organism-scope/source/cpu/cpu_test_info.hh
===================================================================
--- branches/developers/kaben-organism-scope/source/cpu/cpu_test_info.hh	2005-04-09 01:46:27 UTC (rev 131)
+++ branches/developers/kaben-organism-scope/source/cpu/cpu_test_info.hh	2005-04-09 01:47:33 UTC (rev 132)
@@ -8,8 +8,6 @@
 #ifndef CPU_TEST_INFO_HH
 #define CPU_TEST_INFO_HH
 
-#include <fstream>
-
 #ifndef CPU_DEFS_HH
 #include "cpu_defs.hh"
 #endif
@@ -20,6 +18,7 @@
 #include "tArray.hh"
 #endif
 
+class cHardwareTracer;
 class cOrganism;
 class cString;
 
@@ -33,7 +32,7 @@
   bool trace_execution;       // Should we trace this CPU?
   bool trace_task_order;      // Should we keep track of ordering of tasks?
   bool use_random_inputs;     // Should we give the organism random inputs?
-  std::ofstream trace_fp;
+  cHardwareTracer *m_tracer;
 
   // Outputs...
   bool is_viable;         // Is this organism colony forming?
@@ -55,7 +54,7 @@
   void PrintThreads(bool _print=true) { print_threads = _print; }
   void TraceTaskOrder(bool _trace=true) { trace_task_order = _trace; }
   void UseRandomInputs(bool _rand=true) { use_random_inputs = _rand; }
-  void SetTraceExecution(const cString & filename="trace.dat");
+  void SetTraceExecution(cHardwareTracer *tracer = NULL);
 
   // Input Accessors
   int GetGenerationTests() const { return generation_tests; }
@@ -64,7 +63,7 @@
   bool GetTraceTaskOrder() const { return trace_task_order; }
   bool GetUseRandomInputs() const { return use_random_inputs; }
   bool GetTraceExecution() const { return trace_execution; }
-  std::ofstream & GetTraceFP() { return trace_fp; }
+  cHardwareTracer *GetTracer() { return m_tracer; }
 
 
   // Output Accessors

Modified: branches/developers/kaben-organism-scope/source/cpu/hardware_4stack.cc
===================================================================
--- branches/developers/kaben-organism-scope/source/cpu/hardware_4stack.cc	2005-04-09 01:46:27 UTC (rev 131)
+++ branches/developers/kaben-organism-scope/source/cpu/hardware_4stack.cc	2005-04-09 01:47:33 UTC (rev 132)
@@ -7,52 +7,24 @@
 
 
 
-#ifndef HARDWARE_4STACK_HH
 #include "hardware_4stack.hh"
-#endif
 
-#ifndef CONFIG_HH
 #include "config.hh"
-#endif
-#ifndef CPU_TEST_INFO_HH
 #include "cpu_test_info.hh"
-#endif
-#ifndef FUNCTIONS_HH
 #include "functions.hh"
-#endif
-#ifndef GENOME_UTIL_HH
 #include "genome_util.hh"
-#endif
-#ifndef INST_LIB_BASE_HH
 #include "inst_lib_base.hh"
-#endif
-#ifndef INST_SET_HH
 #include "inst_set.hh"
-#endif
-#ifndef MUTATION_HH
+#include "hardware_tracer.hh"
+#include "hardware_tracer_4stack.hh"
 #include "mutation.hh"
-#endif
-#ifndef MUTATION_LIB_HH
 #include "mutation_lib.hh"
-#endif
-#ifndef MUTATION_MACROS_HH
 #include "mutation_macros.hh"
-#endif
-#ifndef ORGANISM_HH
 #include "organism.hh"
-#endif
-#ifndef PHENOTYPE_HH
 #include "phenotype.hh"
-#endif
-#ifndef RANDOM_HH
 #include "random.hh"
-#endif
-#ifndef STRING_UTIL_HH
 #include "string_util.hh"
-#endif
-#ifndef TEST_CPU_HH
 #include "test_cpu.hh"
-#endif
 
 #include <limits.h>
 
@@ -386,9 +358,12 @@
 #endif
     
     // Print the status of this CPU at each step...
-    if (trace_fp != NULL) {
-      const cString & next_name = inst_set->GetName(IP().GetInst())();
-      organism->PrintStatus(*trace_fp, next_name);
+    if (m_tracer != NULL) {
+      if (cHardwareTracer_4Stack * tracer
+          = dynamic_cast<cHardwareTracer_4Stack *>(m_tracer)
+      ){
+        tracer->TraceHardware_4Stack(*this);
+      }
     }
     
     // Find the instruction to be executed
@@ -496,10 +471,12 @@
 
   // @CAO FIX PRINTING TO INDICATE THIS IS A BONUS
   // Print the status of this CPU at each step...
-  if (trace_fp != NULL) {
-    cString next_name = cStringUtil::Stringf("%s (bonus instruction)",
-					     inst_set->GetName(inst)());
-    organism->PrintStatus(*trace_fp, next_name);
+  if (m_tracer != NULL) {
+    if (cHardwareTracer_4Stack * tracer
+        = dynamic_cast<cHardwareTracer_4Stack *>(m_tracer)
+    ){
+      tracer->TraceHardware_4StackBonus(*this);
+    }
   }
     
   SingleProcess_ExecuteInst(inst);

Modified: branches/developers/kaben-organism-scope/source/cpu/hardware_base.cc
===================================================================
--- branches/developers/kaben-organism-scope/source/cpu/hardware_base.cc	2005-04-09 01:46:27 UTC (rev 131)
+++ branches/developers/kaben-organism-scope/source/cpu/hardware_base.cc	2005-04-09 01:47:33 UTC (rev 132)
@@ -5,13 +5,9 @@
 // before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
 //////////////////////////////////////////////////////////////////////////////
 
-#ifndef HARDWARE_BASE_HH
 #include "hardware_base.hh"
-#endif
 
-#ifndef INST_SET_HH
 #include "inst_set.hh"
-#endif
 
 using namespace std;
 
@@ -21,7 +17,7 @@
   : organism(in_organism)
   , inst_set(in_inst_set)
   , viewer_lock(-1)
-  , trace_fp(NULL)
+  , m_tracer(NULL)
 {
   assert(inst_set->OK());
   assert(organism != NULL);

Modified: branches/developers/kaben-organism-scope/source/cpu/hardware_base.hh
===================================================================
--- branches/developers/kaben-organism-scope/source/cpu/hardware_base.hh	2005-04-09 01:46:27 UTC (rev 131)
+++ branches/developers/kaben-organism-scope/source/cpu/hardware_base.hh	2005-04-09 01:47:33 UTC (rev 132)
@@ -19,6 +19,7 @@
 class cCodeLabel;
 class cCPUMemory;
 class cGenome;
+class cHardwareTracer;
 class cInstruction; // aggregate
 class cInstSet;
 class cOrganism;
@@ -30,7 +31,7 @@
   int viewer_lock;            // Used if the viewer should only lock onto
                               //  one aspect of the hardware.
 
-  ostream * trace_fp;         // Set this if you want execution traced.
+  cHardwareTracer * m_tracer;         // Set this if you want execution traced.
 
   static int instance_count;
 public:
@@ -72,7 +73,7 @@
   virtual void SaveState(std::ostream & fp) = 0;
   virtual void LoadState(std::istream & fp) = 0;
 
-  void SetTrace(ostream * in_fp) { trace_fp = in_fp; }
+  void SetTrace(cHardwareTracer * tracer) { m_tracer = tracer; }
 
 
   // --------  Mutations (Must be Virtual)  --------

Modified: branches/developers/kaben-organism-scope/source/cpu/hardware_cpu.cc
===================================================================
--- branches/developers/kaben-organism-scope/source/cpu/hardware_cpu.cc	2005-04-09 01:46:27 UTC (rev 131)
+++ branches/developers/kaben-organism-scope/source/cpu/hardware_cpu.cc	2005-04-09 01:47:33 UTC (rev 132)
@@ -5,52 +5,24 @@
 // before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
 //////////////////////////////////////////////////////////////////////////////
 
-#ifndef HARDWARE_CPU_HH
 #include "hardware_cpu.hh"
-#endif
 
-#ifndef CONFIG_HH
 #include "config.hh"
-#endif
-#ifndef CPU_TEST_INFO_HH
 #include "cpu_test_info.hh"
-#endif
-#ifndef FUNCTIONS_HH
 #include "functions.hh"
-#endif
-#ifndef GENOME_UTIL_HH
 #include "genome_util.hh"
-#endif
-#ifndef GENOTYPE_HH
 #include "genotype.hh"
-#endif
-#ifndef INST_LIB_CPU_HH
+#include "hardware_tracer.hh"
+#include "hardware_tracer_cpu.hh"
 #include "inst_lib_cpu.hh"
-#endif
-#ifndef INST_SET_HH
 #include "inst_set.hh"
-#endif
-#ifndef MUTATION_HH
 #include "mutation.hh"
-#endif
-#ifndef MUTATION_LIB_HH
 #include "mutation_lib.hh"
-#endif
-#ifndef MUTATION_MACROS_HH
 #include "mutation_macros.hh"
-#endif
-#ifndef ORGANISM_HH
 #include "organism.hh"
-#endif
-#ifndef PHENOTYPE_HH
 #include "phenotype.hh"
-#endif
-#ifndef STRING_UTIL_HH
 #include "string_util.hh"
-#endif
-#ifndef TEST_CPU_HH
 #include "test_cpu.hh"
-#endif
 
 #include <limits.h>
 #include <fstream>
@@ -484,9 +456,12 @@
 #endif
     
     // Print the status of this CPU at each step...
-    if (trace_fp != NULL) {
-      const cString & next_name = inst_set->GetName(IP().GetInst())();
-      organism->PrintStatus(*trace_fp, next_name);
+    if (m_tracer != NULL) {
+      if (cHardwareTracer_CPU * tracer
+          = dynamic_cast<cHardwareTracer_CPU *>(m_tracer)
+      ){
+        tracer->TraceHardware_CPU(*this);
+      }
     }
     
     // Find the instruction to be executed
@@ -595,10 +570,12 @@
 
   // @CAO FIX PRINTING TO INDICATE THIS IS A BONUS
   // Print the status of this CPU at each step...
-  if (trace_fp != NULL) {
-    cString next_name = cStringUtil::Stringf("%s (bonus instruction)",
-					     inst_set->GetName(inst)());
-    organism->PrintStatus(*trace_fp, next_name);
+  if (m_tracer != NULL) {
+    if (cHardwareTracer_CPU * tracer
+        = dynamic_cast<cHardwareTracer_CPU *>(m_tracer)
+    ){
+      tracer->TraceHardware_CPUBonus(*this);
+    }
   }
     
   SingleProcess_ExecuteInst(inst);

Added: branches/developers/kaben-organism-scope/source/cpu/hardware_status_printer.cc
===================================================================
--- branches/developers/kaben-organism-scope/source/cpu/hardware_status_printer.cc	2005-04-09 01:46:27 UTC (rev 131)
+++ branches/developers/kaben-organism-scope/source/cpu/hardware_status_printer.cc	2005-04-09 01:47:33 UTC (rev 132)
@@ -0,0 +1,76 @@
+//////////////////////////////////////////////////////////////////////////////
+// Copyright (C) 1993 - 2004 California Institute of Technology             //
+//                                                                          //
+// Read the COPYING and README files, or contact 'avida at alife.org',         //
+// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
+//////////////////////////////////////////////////////////////////////////////
+
+#include "cpu_head.hh"
+#include "hardware_4stack.hh"
+#include "hardware_base.hh"
+#include "hardware_cpu.hh"
+#include "hardware_status_printer.hh"
+#include "inst_set.hh"
+#include "organism.hh"
+#include "string.hh"
+#include "string_util.hh"
+
+
+cHardwareStatusPrinter::cHardwareStatusPrinter(ostream &trace_fp)
+: m_trace_fp(trace_fp)
+{}
+
+const cString & cHardwareStatusPrinter::GetNextInstName(
+  cHardwareCPU &hardware
+){
+  return hardware.GetInstSet().GetName(hardware.IP().GetInst());
+}
+
+const cString & cHardwareStatusPrinter::GetNextInstName(
+  cHardware4Stack &hardware
+){
+  return hardware.GetInstSet().GetName(hardware.IP().GetInst());
+}
+
+cString cHardwareStatusPrinter::Bonus(const cString &next_name){
+  return cStringUtil::Stringf("%s (bonus instruction)", next_name());
+}
+
+void cHardwareStatusPrinter::PrintStatus(
+  cHardwareBase &hardware,
+  const cString &next_name
+){
+  cOrganism *organism = hardware.GetOrganism();
+  if(organism) organism->PrintStatus(m_trace_fp, next_name);
+}
+
+void cHardwareStatusPrinter::TraceHardware_CPU(cHardwareCPU &hardware){
+  PrintStatus(hardware, GetNextInstName(hardware));
+}
+void cHardwareStatusPrinter::TraceHardware_4Stack(cHardware4Stack &hardware){
+  PrintStatus(hardware, GetNextInstName(hardware));
+}
+void cHardwareStatusPrinter::TraceHardware_CPUBonus(cHardwareCPU &hardware){
+  PrintStatus(hardware, Bonus(GetNextInstName(hardware)));
+}
+void cHardwareStatusPrinter::TraceHardware_4StackBonus(cHardware4Stack &hardware){
+  PrintStatus(hardware, Bonus(GetNextInstName(hardware)));
+}
+void cHardwareStatusPrinter::TraceHardware_TestCPU(
+  int time_used,
+  int time_allocated,
+  cOrganism &organism
+){
+  if (time_used == time_allocated) {
+    m_trace_fp << endl << "TIMEOUT: No offspring produced." << endl;
+  }
+  else if (organism.GetHardware().GetMemory().GetSize() == 0) {
+    m_trace_fp << endl << "ORGANISM DEATH: No offspring produced." << endl;
+  }
+  else {
+    m_trace_fp << endl << "Final Memory: "
+    << organism.GetHardware().GetMemory().AsString() << endl
+    << "Child Memory: " << organism.ChildGenome().AsString()
+    << endl;
+  }
+}

Added: branches/developers/kaben-organism-scope/source/cpu/hardware_status_printer.hh
===================================================================
--- branches/developers/kaben-organism-scope/source/cpu/hardware_status_printer.hh	2005-04-09 01:46:27 UTC (rev 131)
+++ branches/developers/kaben-organism-scope/source/cpu/hardware_status_printer.hh	2005-04-09 01:47:33 UTC (rev 132)
@@ -0,0 +1,64 @@
+//////////////////////////////////////////////////////////////////////////////
+// Copyright (C) 1993 - 2004 California Institute of Technology             //
+//                                                                          //
+// Read the COPYING and README files, or contact 'avida at alife.org',         //
+// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef HARDWARE_STATUS_PRINTER_HH
+#define HARDWARE_STATUS_PRINTER_HH
+
+#include <iostream>
+
+#ifndef HARDWARE_TRACER_HH
+#include "hardware_tracer.hh"
+#endif
+#ifndef HARDWARE_TRACER_4STACK_HH
+#include "hardware_tracer_4stack.hh"
+#endif
+#ifndef HARDWARE_TRACER_CPU_HH
+#include "hardware_tracer_cpu.hh"
+#endif
+#ifndef HARDWARE_TRACER_TEST_CPU_HH
+#include "hardware_tracer_test_cpu.hh"
+#endif
+#ifndef STRING_HH
+#include "string.hh"
+#endif
+
+
+using namespace std;
+
+
+class cHardwareBase;
+class cHardwareCPU;
+class cHardware4Stack;
+class cOrganism;
+
+class cHardwareStatusPrinter :
+  public cHardwareTracer,
+  public cHardwareTracer_CPU,
+  public cHardwareTracer_4Stack,
+  public cHardwareTracer_TestCPU
+{
+protected:
+  ostream &m_trace_fp;
+protected:
+  const cString & GetNextInstName(cHardwareCPU &hardware);
+  const cString & GetNextInstName(cHardware4Stack &hardware);
+  cString Bonus(const cString &next_name);
+  void PrintStatus(cHardwareBase &hardware, const cString &next_name);
+public:
+  cHardwareStatusPrinter(ostream &trace_fp);
+  virtual void TraceHardware_CPU(cHardwareCPU &hardware);
+  virtual void TraceHardware_4Stack(cHardware4Stack &hardware);
+  virtual void TraceHardware_CPUBonus(cHardwareCPU &hardware);
+  virtual void TraceHardware_4StackBonus(cHardware4Stack &hardware);
+  virtual void TraceHardware_TestCPU(
+    int time_used,
+    int time_allocated,
+    cOrganism &organism
+  );
+};
+
+#endif

Modified: branches/developers/kaben-organism-scope/source/cpu/test_cpu.cc
===================================================================
--- branches/developers/kaben-organism-scope/source/cpu/test_cpu.cc	2005-04-09 01:46:27 UTC (rev 131)
+++ branches/developers/kaben-organism-scope/source/cpu/test_cpu.cc	2005-04-09 01:47:33 UTC (rev 132)
@@ -5,61 +5,27 @@
 // before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
 //////////////////////////////////////////////////////////////////////////////
 
-#ifndef TEST_CPU_HH
 #include "test_cpu.hh"
-#endif
 
-#ifndef CPU_TEST_INFO_HH
 #include "cpu_test_info.hh"
-#endif
-#ifndef CONFIG_HH
 #include "config.hh"
-#endif
-#ifndef ENVIRONMENT_HH
 #include "environment.hh"
-#endif
-#ifndef FUNCTIONS_HH
 #include "functions.hh"
-#endif
-#ifndef HARDWARE_BASE_HH
 #include "hardware_base.hh"
-#endif
-#ifndef INST_SET_HH
+#include "hardware_status_printer.hh"
 #include "inst_set.hh"
-#endif
-#ifndef INST_UTIL_HH
 #include "inst_util.hh"
-#endif
-#ifndef ORGANISM_HH
 #include "organism.hh"
-#endif
-#ifndef PHENOTYPE_HH
 #include "phenotype.hh"
-#endif
-#ifndef POPULATION_INTERFACE_HH
 #include "population_interface.hh"
-#endif
-#ifndef RESOURCE_COUNT_HH
 #include "resource_count.hh"
-#endif
-#ifndef RESOURCE_LIB_HH
 #include "resource_lib.hh"
-#endif
-#ifndef RESOURCE_HH
 #include "resource.hh"
-#endif
-#ifndef STRING_UTIL_HH
 #include "string_util.hh"
-#endif
-#ifndef TMATRIX_HH
 #include "tMatrix.hh"
-#endif
 
 #include <iomanip>
 
-
-#include "population_interface.hh"
-
 using namespace std;
 
 
@@ -158,15 +124,15 @@
   cur_receive = 0;
 
   // Determine if we're tracing and what we need to print.
-  ostream * trace_fp =
-    test_info.GetTraceExecution() ? &(test_info.GetTraceFP()) : NULL;
+  cHardwareTracer * tracer =
+    test_info.GetTraceExecution() ? (test_info.GetTracer()) : NULL;
 
   int time_used = 0;
   while (time_used < time_allocated &&
 	 organism.GetHardware().GetMemory().GetSize() &&
 	 organism.GetPhenotype().GetNumDivides() == 0) {
     time_used++;
-    organism.GetHardware().SetTrace(trace_fp);
+    organism.GetHardware().SetTrace(tracer);
     organism.GetHardware().SingleProcess();
     organism.GetHardware().SetTrace(NULL);
     //resource_count.Update(1/cConfig::GetAveTimeslice());
@@ -174,19 +140,12 @@
   }
 
   // Print out some final info in trace...
-  if (trace_fp != NULL) {
-    if (time_used == time_allocated) {
-      *trace_fp << endl << "TIMEOUT: No offspring produced." << endl;
+  if (tracer != NULL) {
+    if (cHardwareTracer_TestCPU * tracer_test_cpu
+        = dynamic_cast<cHardwareTracer_TestCPU *>(tracer)
+    ){
+     tracer_test_cpu->TraceHardware_TestCPU(time_used, time_allocated, organism);
     }
-    else if (organism.GetHardware().GetMemory().GetSize() == 0) {
-      *trace_fp << endl << "ORGANISM DEATH: No offspring produced." << endl;
-    }
-    else {
-      *trace_fp << endl << "Final Memory: "
-		<< organism.GetHardware().GetMemory().AsString() << endl
-		<< "Child Memory: " << organism.ChildGenome().AsString()
-		<< endl;
-    }
   }
 
   // For now, always return true.

Modified: branches/developers/kaben-organism-scope/source/main/analyze.cc
===================================================================
--- branches/developers/kaben-organism-scope/source/main/analyze.cc	2005-04-09 01:46:27 UTC (rev 131)
+++ branches/developers/kaben-organism-scope/source/main/analyze.cc	2005-04-09 01:47:33 UTC (rev 132)
@@ -9,101 +9,40 @@
 #include <sstream>
 #include <string>
 
-#ifndef ANALYZE_HH
 #include "analyze.hh"
-#endif
 
-#ifndef ANALYZE_COMMAND_HH
 #include "analyze_command.hh"
-#endif
-#ifndef ANALYZE_COMMAND_DEF_HH
 #include "analyze_command_def.hh"
-#endif
-#ifndef ANALYZE_COMMAND_DEF_BASE_HH
 #include "analyze_command_def_base.hh"
-#endif
-#ifndef ANALYZE_FLOW_COMMAND_HH
 #include "analyze_flow_command.hh"
-#endif
-#ifndef ANALYZE_FLOW_COMMAND_DEF_HH
 #include "analyze_flow_command_def.hh"
-#endif
-#ifndef ANALYZE_FUNCTION_HH
 #include "analyze_function.hh"
-#endif
-#ifndef ANALYZE_GENOTYPE_HH
 #include "analyze_genotype.hh"
-#endif
-#ifndef CONFIG_HH
 #include "config.hh"
-#endif
-#ifndef DATA_FILE_HH
 #include "data_file.hh"
-#endif
-#ifndef ENVIRONMENT_HH
 #include "environment.hh"
-#endif
-#ifndef FITNESS_MATRIX_HH
 #include "fitness_matrix.hh"
-#endif
-#ifndef GENOME_UTIL_HH
 #include "genome_util.hh"
-#endif
-#ifndef HARDWARE_BASE_HH
 #include "hardware_base.hh"
-#endif
-#ifndef HARDWARE_UTIL_HH
+#include "hardware_status_printer.hh"
 #include "hardware_util.hh"
-#endif
-#ifndef HELP_MANAGER_HH
 #include "help_manager.hh"
-#endif
-#ifndef INIT_FILE_HH
 #include "init_file.hh"
-#endif
-#ifndef INST_SET_HH
 #include "inst_set.hh"
-#endif
-#ifndef INST_UTIL_HH
 #include "inst_util.hh"
-#endif
-#ifndef LANDSCAPE_HH
 #include "landscape.hh"
-#endif
-#ifndef PHENOTYPE_HH
 #include "phenotype.hh"
-#endif
-#ifndef SPECIES_HH
 #include "species.hh"
-#endif
-#ifndef TARGDATAENTRY_HH
 #include "tArgDataEntry.hh"
-#endif
-#ifndef TASK_ENTRY_HH
 #include "task_entry.hh"
-#endif
-#ifndef TDATAENTRY_HH
 #include "tDataEntry.hh"
-#endif
-#ifndef TDATAENTRYCOMMAND_HH
 #include "tDataEntryCommand.hh"
-#endif
-#ifndef TEST_CPU_HH
 #include "test_cpu.hh"
-#endif
-#ifndef CPU_TEST_INFO_HH
 #include "cpu_test_info.hh"
-#endif
-#ifndef TEST_UTIL_HH
 #include "test_util.hh"
-#endif
-#ifndef RESOURCE_HH
 #include "resource.hh"
-#endif
 #ifdef WIN32
-# ifndef WIN32_MKDIR_HACK_HH
 #  include "win32_mkdir_hack.hh"
-# endif
 #endif
 
 extern "C" {
@@ -1215,10 +1154,16 @@
       break;
     }
 
+    // Build the hardware status printer for tracing.
+    ofstream trace_fp;
+    trace_fp.open(filename);
+    assert (trace_fp.good() == true); // Unable to open trace file.
+    cHardwareStatusPrinter trace_printer(trace_fp);
+
     // Build the test info for printing.
     cCPUTestInfo test_info;
     test_info.TestThreads();
-    test_info.SetTraceExecution(filename);
+    test_info.SetTraceExecution(&trace_printer);
 
     cTestCPU::TestGenome(test_info, genotype->GetGenome());
 

Modified: branches/developers/kaben-organism-scope/source/main/landscape.cc
===================================================================
--- branches/developers/kaben-organism-scope/source/main/landscape.cc	2005-04-09 01:46:27 UTC (rev 131)
+++ branches/developers/kaben-organism-scope/source/main/landscape.cc	2005-04-09 01:47:33 UTC (rev 132)
@@ -5,37 +5,17 @@
 // before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
 //////////////////////////////////////////////////////////////////////////////
 
-#ifndef LANDSCAPE_HH
 #include "landscape.hh"
-#endif
 
-#ifndef CPU_MEMORY_HH
 #include "cpu_memory.hh"
-#endif
-#ifndef ENVIRONMENT_HH
 #include "environment.hh"
-#endif
-#ifndef INST_SET_HH
 #include "inst_set.hh"
-#endif
-#ifndef ORGANISM_HH
 #include "organism.hh"
-#endif
-#ifndef PHENOTYPE_HH
 #include "phenotype.hh"
-#endif
-#ifndef STATS_HH
 #include "stats.hh"             // For GetUpdate in outputs...
-#endif
-#ifndef TEST_CPU_HH
 #include "test_cpu.hh"
-#endif
-#ifndef TEST_UTIL_HH
 #include "test_util.hh"
-#endif
-#ifndef TOOLS_HH
 #include "tools.hh"
-#endif
 
 using namespace std;
 

Modified: branches/developers/kaben-organism-scope/source/main/landscape.hh
===================================================================
--- branches/developers/kaben-organism-scope/source/main/landscape.hh	2005-04-09 01:46:27 UTC (rev 131)
+++ branches/developers/kaben-organism-scope/source/main/landscape.hh	2005-04-09 01:47:33 UTC (rev 132)
@@ -8,8 +8,6 @@
 #ifndef LANDSCAPE_HH
 #define LANDSCAPE_HH
 
-#include <iostream>
-
 #ifndef CPU_TEST_INFO_HH
 #include "cpu_test_info.hh"
 #endif




More information about the Avida-cvs mailing list