[Avida-cvs] [Avida2-svn] r299 - trunk/source/cpu
brysonda@myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Mon Aug 29 12:15:32 PDT 2005
Author: brysonda
Date: 2005-08-29 15:15:32 -0400 (Mon, 29 Aug 2005)
New Revision: 299
Added:
trunk/source/cpu/cCPUMemory.cc
trunk/source/cpu/cCPUMemory.h
trunk/source/cpu/cCPUStack.cc
trunk/source/cpu/cCPUStack.h
trunk/source/cpu/cCPUTestInfo.cc
trunk/source/cpu/cCPUTestInfo.h
trunk/source/cpu/cCodeLabel.cc
trunk/source/cpu/cCodeLabel.h
trunk/source/cpu/sCPUStats.h
Removed:
trunk/source/cpu/code_label.cc
trunk/source/cpu/code_label.hh
trunk/source/cpu/cpu_memory.cc
trunk/source/cpu/cpu_memory.hh
trunk/source/cpu/cpu_stack.cc
trunk/source/cpu/cpu_stack.hh
trunk/source/cpu/cpu_stats.hh
trunk/source/cpu/cpu_test_info.cc
trunk/source/cpu/cpu_test_info.hh
Modified:
trunk/source/cpu/CMakeLists.txt
trunk/source/cpu/cpu.pri
trunk/source/cpu/hardware_4stack.cc
trunk/source/cpu/hardware_4stack.hh
trunk/source/cpu/hardware_4stack_thread.hh
trunk/source/cpu/hardware_cpu.cc
trunk/source/cpu/hardware_cpu.hh
trunk/source/cpu/hardware_cpu_thread.hh
trunk/source/cpu/hardware_smt.cc
trunk/source/cpu/hardware_smt.h
trunk/source/cpu/hardware_smt_thread.h
trunk/source/cpu/head_cpu.cc
trunk/source/cpu/head_multi_mem.cc
trunk/source/cpu/test_cpu.cc
trunk/source/cpu/test_util.cc
Log:
Rename cpu/cC* classes to reflect new naming conventions.
Modified: trunk/source/cpu/CMakeLists.txt
===================================================================
--- trunk/source/cpu/CMakeLists.txt 2005-08-29 18:54:25 UTC (rev 298)
+++ trunk/source/cpu/CMakeLists.txt 2005-08-29 19:15:32 UTC (rev 299)
@@ -1,8 +1,8 @@
SET(libcpu_a_SOURCES
- code_label.cc
- cpu_memory.cc
- cpu_stack.cc
- cpu_test_info.cc
+ cCodeLabel.cc
+ cCPUMemory.cc
+ cCPUStack.cc
+ cCPUTestInfo.cc
hardware_4stack.cc
hardware_4stack_thread.cc
hardware_base.cc
Copied: trunk/source/cpu/cCPUMemory.cc (from rev 298, trunk/source/cpu/cpu_memory.cc)
===================================================================
--- trunk/source/cpu/cpu_memory.cc 2005-08-29 18:54:25 UTC (rev 298)
+++ trunk/source/cpu/cCPUMemory.cc 2005-08-29 19:15:32 UTC (rev 299)
@@ -0,0 +1,227 @@
+//////////////////////////////////////////////////////////////////////////////
+// Copyright (C) 1993 - 2003 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 CPU_MEMORY_HH
+#include "cCPUMemory.h"
+#endif
+
+using namespace std;
+
+const double MEMORY_INCREASE_FACTOR = 1.5;
+const double MEMORY_SHRINK_TEST_FACTOR = 4.0;
+
+////////////////
+// cCPUMemory
+////////////////
+
+cCPUMemory::cCPUMemory(int _size) : cGenome(_size), flag_array(_size)
+{
+}
+
+cCPUMemory::cCPUMemory(const cCPUMemory & in_memory)
+ : cGenome(in_memory), flag_array(in_memory.GetSize())
+{
+ for (int i = 0; i < flag_array.GetSize(); i++) {
+ flag_array[i] = in_memory.flag_array[i];
+ }
+}
+
+cCPUMemory::cCPUMemory(const cGenome & in_genome)
+ : cGenome(in_genome), flag_array(in_genome.GetSize())
+{
+}
+
+cCPUMemory::cCPUMemory(const cString & in_string)
+ : cGenome(in_string), flag_array(in_string.GetSize())
+{
+}
+
+cCPUMemory::~cCPUMemory()
+{
+}
+
+
+// --- Private Methods ---
+
+void cCPUMemory::SloppyResize(int new_size)
+{
+ assert(new_size > 0);
+
+ // Make sure we're really changing the size...
+ if (new_size == active_size) return;
+
+ const int array_size = genome.GetSize();
+
+ // Determine if we need to adjust the allocated array sizes...
+ if (new_size > array_size ||
+ new_size * MEMORY_SHRINK_TEST_FACTOR < array_size) {
+ const int new_array_size = (int) (new_size * MEMORY_INCREASE_FACTOR);
+ genome.Resize(new_array_size);
+ flag_array.Resize(new_array_size);
+ }
+
+ // And just change the active_size once we're sure it will be in range.
+ active_size = new_size;
+}
+
+
+void cCPUMemory::SloppyInsert(int pos, int num_lines)
+{
+ assert(pos >= 0 && pos <= active_size); // Must insert at a legal position!
+ assert(num_lines > 0); // Must insert positive number of lines!
+
+ // Re-adjust the size...
+ const int old_size = active_size;
+ const int new_size = active_size + num_lines;
+ SloppyResize(new_size);
+
+ // Shift any lines needed...
+ for (int i = old_size - 1; i >= pos; i--) {
+ genome[i+num_lines] = genome[i];
+ flag_array[i+num_lines] = flag_array[i];
+ }
+}
+
+
+// --- Public Methods ---
+
+
+void cCPUMemory::operator=(const cCPUMemory & other_memory)
+{
+ SloppyResize(other_memory.active_size);
+
+ // Fill in the new information...
+ for (int i = 0; i < active_size; i++) {
+ genome[i] = other_memory.genome[i];
+ flag_array[i] = other_memory.flag_array[i];
+ }
+}
+
+
+void cCPUMemory::operator=(const cGenome & other_genome)
+{
+ SloppyResize(other_genome.GetSize());
+
+ // Fill in the new information...
+ for (int i = 0; i < active_size; i++) {
+ genome[i] = other_genome[i];
+ flag_array[i].Clear();
+ }
+}
+
+void cCPUMemory::Copy(int to, int from)
+{
+ assert(to >= 0);
+ assert(to < genome.GetSize());
+ assert(from >= 0);
+ assert(from < genome.GetSize());
+
+ genome[to] = genome[from];
+ flag_array[to] = flag_array[from];
+}
+
+void cCPUMemory::Clear()
+{
+ for (int i = 0; i < active_size; i++) {
+ genome[i].SetOp(0);
+ flag_array[i].Clear();
+ }
+}
+
+void cCPUMemory::ClearFlags()
+{
+ for (int i = 0; i < active_size; i++) flag_array[i].Clear();
+}
+
+void cCPUMemory::Reset(int new_size)
+{
+ assert(new_size >= 0);
+
+ SloppyResize(new_size);
+ Clear();
+}
+
+
+void cCPUMemory::Resize(int new_size)
+{
+ assert(new_size >= 0);
+
+ // Do a sloppy resize first, saving old values...
+ const int old_size = active_size;
+ const int old_array_size = genome.GetSize();
+ SloppyResize(new_size);
+
+ // Clean up all of the old memory that might need it...
+ for (int i = old_size; i < new_size && i < old_array_size; i++) {
+ genome[i].SetOp(0);
+ flag_array[i].Clear();
+ }
+}
+
+
+void cCPUMemory::ResizeOld(int new_size)
+{
+ assert(new_size >= 0);
+
+ // Do a sloppy resize, which will still have old values.
+ SloppyResize(new_size);
+}
+
+
+void cCPUMemory::Insert(int pos, const cInstruction & in_inst)
+{
+ assert(pos >= 0);
+ assert(pos <= genome.GetSize());
+
+ SloppyInsert(pos, 1);
+ genome[pos] = in_inst;
+ flag_array[pos].Clear();
+}
+
+void cCPUMemory::Insert(int pos, const cGenome & in_genome)
+{
+ assert(pos >= 0);
+ assert(pos <= genome.GetSize());
+
+ SloppyInsert(pos, in_genome.GetSize());
+ for (int i = 0; i < in_genome.GetSize(); i++) {
+ genome[i+pos] = in_genome[i];
+ flag_array[i+pos].Clear();
+ }
+}
+
+void cCPUMemory::Remove(int pos, int num_insts)
+{
+ assert(num_insts > 0); // Must remove something...
+ assert(pos >= 0); // Removal must be in genome.
+ assert(pos + num_insts <= active_size); // Cannot extend past end of genome.
+
+ const int new_size = active_size - num_insts;
+ for (int i = pos; i < new_size; i++) {
+ genome[i] = genome[i + num_insts];
+ flag_array[i] = flag_array[i + num_insts];
+ }
+ SloppyResize(new_size);
+}
+
+void cCPUMemory::Replace(int pos, int num_insts, const cGenome & in_genome)
+{
+ assert(pos >= 0); // Replace must be in genome.
+ assert(num_insts >= 0); // Cannot replace negative.
+ assert(pos + num_insts <= active_size); // Cannot extend past end!
+
+ const int size_change = in_genome.GetSize() - num_insts;
+
+ // First, get the size right.
+ if (size_change > 0) SloppyInsert(pos, size_change);
+ else if (size_change < 0) Remove(pos, -size_change);
+
+ // Now just copy everything over!
+ for (int i = 0; i < in_genome.GetSize(); i++) {
+ genome[i + pos] = in_genome[i];
+ }
+}
Copied: trunk/source/cpu/cCPUMemory.h (from rev 298, trunk/source/cpu/cpu_memory.hh)
Copied: trunk/source/cpu/cCPUStack.cc (from rev 298, trunk/source/cpu/cpu_stack.cc)
===================================================================
--- trunk/source/cpu/cpu_stack.cc 2005-08-29 18:54:25 UTC (rev 298)
+++ trunk/source/cpu/cCPUStack.cc 2005-08-29 19:15:32 UTC (rev 299)
@@ -0,0 +1,77 @@
+//////////////////////////////////////////////////////////////////////////////
+// Copyright (C) 1993 - 2001 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 "cCPUStack.h"
+
+#include <assert.h>
+#include "string.hh"
+
+using namespace std;
+
+
+cCPUStack::cCPUStack()
+{
+ Clear();
+}
+
+cCPUStack::cCPUStack(const cCPUStack & in_stack)
+{
+ for (int i = 0; i < STACK_SIZE; i++) {
+ stack[i] = in_stack.stack[i];
+ }
+ stack_pointer = in_stack.stack_pointer;
+}
+
+cCPUStack::~cCPUStack()
+{
+}
+
+void cCPUStack::operator=(const cCPUStack & in_stack)
+{
+ for (int i = 0; i < STACK_SIZE; i++) {
+ stack[i] = in_stack.stack[i];
+ }
+ stack_pointer = in_stack.stack_pointer;
+}
+
+void cCPUStack::Flip()
+{
+ int new_stack[STACK_SIZE];
+ int i;
+ for (i = 0; i < STACK_SIZE; i++) new_stack[i] = Pop();
+ for (i = 0; i < STACK_SIZE; i++) Push(new_stack[i]);
+}
+
+bool cCPUStack::OK()
+{
+ assert(stack_pointer < STACK_SIZE); // stack_pointer out of range
+ return true;
+}
+
+void cCPUStack::SaveState(ostream & fp)
+{
+ assert(fp.good());
+ fp<<"cCPUStack"<<" ";
+ // stack (in inverse order so load can just push)
+ for(int i = STACK_SIZE - 1; i >= 0; i-- ){
+ fp<<Get(i)<<" ";
+ }
+ fp<<endl;
+}
+
+void cCPUStack::LoadState(istream & fp)
+{
+ assert(fp.good());
+ cString foo;
+ fp>>foo;
+ assert( foo == "cCPUStack");
+ int value;
+ for( int i=0; i<STACK_SIZE; ++i ){
+ fp>>value;
+ Push(value);
+ }
+}
Copied: trunk/source/cpu/cCPUStack.h (from rev 298, trunk/source/cpu/cpu_stack.hh)
Copied: trunk/source/cpu/cCPUTestInfo.cc (from rev 298, trunk/source/cpu/cpu_test_info.cc)
===================================================================
--- trunk/source/cpu/cpu_test_info.cc 2005-08-29 18:54:25 UTC (rev 298)
+++ trunk/source/cpu/cCPUTestInfo.cc 2005-08-29 19:15:32 UTC (rev 299)
@@ -0,0 +1,77 @@
+//////////////////////////////////////////////////////////////////////////////
+// Copyright (C) 1993 - 2003 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 "cCPUTestInfo.h"
+
+#include "hardware_status_printer.hh"
+#include "organism.hh"
+#include "phenotype.hh"
+
+#include <assert.h>
+
+/////////////////
+// cCPUTestInfo
+/////////////////
+
+cCPUTestInfo::cCPUTestInfo(int max_tests)
+ : generation_tests(max_tests) // These vars not reset on Clear()
+ , test_threads(false)
+ , print_threads(false)
+ , trace_execution(false)
+ , trace_task_order(false)
+ , use_random_inputs(false)
+ , org_array(max_tests)
+ , m_tracer(NULL)
+{
+ org_array.SetAll(NULL);
+ Clear();
+}
+
+
+cCPUTestInfo::~cCPUTestInfo()
+{
+ for (int i = 0; i < generation_tests; i++) {
+ if (org_array[i] != NULL) delete org_array[i];
+ }
+}
+
+
+void cCPUTestInfo::Clear()
+{
+ is_viable = false;
+ max_depth = -1;
+ depth_found = -1;
+ max_cycle = 0;
+ cycle_to = -1;
+
+ for (int i = 0; i < generation_tests; i++) {
+ if (org_array[i] == NULL) break;
+ delete org_array[i];
+ org_array[i] = NULL;
+ }
+}
+
+
+void cCPUTestInfo::SetTraceExecution(cHardwareTracer *tracer)
+{
+ trace_execution = (tracer)?(true):(false);
+ m_tracer = tracer;
+}
+
+
+double cCPUTestInfo::GetGenotypeFitness()
+{
+ if (org_array[0] != NULL) return org_array[0]->GetPhenotype().GetFitness();
+ return 0.0;
+}
+
+
+double cCPUTestInfo::GetColonyFitness()
+{
+ if (IsViable()) return GetColonyOrganism()->GetPhenotype().GetFitness();
+ return 0.0;
+}
Copied: trunk/source/cpu/cCPUTestInfo.h (from rev 298, trunk/source/cpu/cpu_test_info.hh)
Copied: trunk/source/cpu/cCodeLabel.cc (from rev 298, trunk/source/cpu/code_label.cc)
===================================================================
--- trunk/source/cpu/code_label.cc 2005-08-29 18:54:25 UTC (rev 298)
+++ trunk/source/cpu/cCodeLabel.cc 2005-08-29 19:15:32 UTC (rev 299)
@@ -0,0 +1,222 @@
+//////////////////////////////////////////////////////////////////////////////
+// Copyright (C) 1993 - 2002 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 "cCodeLabel.h"
+
+#include "tools.hh" // for g_memory & g_debug
+
+
+
+#include <cmath>
+#include <vector>
+#include <iostream>
+#include <iomanip>
+
+using namespace std;
+
+
+
+////////////////////////////////
+// cCodeLabel stuff...
+////////////////////////////////
+
+bool cCodeLabel::OK()
+{
+ bool result = true;
+
+ assert (size <= MAX_LABEL_SIZE);
+ assert (size <= nop_sequence.GetSize());
+ for (int i = 0; i < size; i++) {
+ assert (nop_sequence[i] < MAX_NOPS);
+ }
+
+ return result;
+}
+
+bool cCodeLabel::operator==(const cCodeLabel & other_label) const
+{
+ if (size != other_label.GetSize()) {
+ return false;
+ }
+
+ for (int i = 0; i < size; i++) {
+ if (nop_sequence[i] != other_label[i]) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+
+// This function returns true if the sub_label can be found within
+// the label affected.
+int cCodeLabel::FindSublabel(cCodeLabel & sub_label)
+{
+ bool error = false;
+
+ for (int offset = 0; offset <= size - sub_label.GetSize(); offset++) {
+ for (int i = 0; i < sub_label.GetSize(); i++) {
+ if (nop_sequence[i + offset] != sub_label[i]) {
+ error = true;
+ break;
+ }
+ }
+ if (!error) return offset;
+ error = false;
+ }
+
+ return -1;
+}
+
+void cCodeLabel::SaveState(ostream & fp)
+{
+// assert(fp.good());
+// fp<<"cCodeLabel"<<" ";
+
+// fp<<"|"; // marker
+
+// fp << size << " " << base << " ";
+// for( int i=0; i < size; ++i ){
+// fp<<nop_sequence[i];
+// }
+// fp<<endl;
+}
+
+
+void cCodeLabel::LoadState(istream & fp)
+{
+// assert(fp.good());
+// cString foo;
+// fp>>foo;
+// assert( foo == "cCodeLabel");
+
+// char marker;
+// fp>>marker;
+// assert( marker == '|' );
+
+// fp.get(size);
+// fp.get(base);
+// for( int i=0; i<MAX_LABEL_SIZE; ++i ){
+// fp.get(nop_sequence[i]);
+// }
+}
+
+int cCodeLabel::AsInt(const int base) const
+{
+ int value = 0;
+
+ for (int i = 0; i < size; i++) {
+ value *= base;
+ value += nop_sequence[i];
+ }
+
+ return value;
+}
+
+int cCodeLabel::AsIntGreyCode(const int base) const
+{
+ int value = 0;
+ int oddCount = 0;
+
+ for (int i = 0; i < size; i++) {
+ value *= base;
+
+ if(oddCount % 2 == 0) {
+ value += nop_sequence[i];
+ } else {
+ value += (NUM_NOPS - 1) - nop_sequence[i];
+ }
+
+ if(nop_sequence[i] % 2 == 1) {
+ oddCount++;
+ }
+ }
+
+ return value;
+}
+
+int cCodeLabel::AsIntDirect(const int base) const
+{
+ int value = 0;
+
+ for (int i = 0; i < size; i++) {
+ value *= base;
+ value += nop_sequence[i];
+ }
+
+ return value;
+}
+
+int cCodeLabel::AsIntAdditivePolynomial(const int base) const
+{
+ double value = 0.0;
+
+ for (int i = 0; i < size; i++) {
+#if 1
+ int n = (int)nop_sequence[i] + 1;
+ double a = pow((double)n, 0.4 * (double)(size-1));
+ double b = 0.3 * (double)i * (double)(size-1);
+ double c = 0.45 * (double)i;
+ value += a + b + c;
+#else
+ value += (pow(((double)nop_sequence[i] + 1.0), (0.4 * (double)(size-1))) +
+ (0.3 * (double)i * (double)(size-1)) +
+ (0.45 * (double)i));
+#endif
+ }
+
+ return (int)(value + 0.5);
+}
+
+int cCodeLabel::AsIntFib(const int base) const
+{
+ int value = 0;
+ if(base < 3) { return 0; }
+
+ vector<int> fib;
+ fib.resize(base, 0);
+ fib[0] = 0;
+ fib[1] = 1;
+ fib[2] = 2;
+ for(int i=3; i<base; i++) {
+ fib[i] = fib[i-2] + fib[i-1];
+ }
+
+ for (int i = 0; i < size; i++) {
+ value += fib[(int)nop_sequence[i]];
+
+ fib[2] = fib[base-2] + fib[base-1];
+ fib[1] = fib[base-1];
+ for(int j=3; j<base; j++) {
+ fib[j] = fib[j-2] + fib[j-1];
+ }
+ }
+
+ return value;
+}
+
+int cCodeLabel::AsIntPolynomialCoefficent(const int base) const
+{
+ int value = 0;
+
+ int extra = size % 2;
+ int c = 1;
+
+ for (int i = 0; i < size - extra; i+=2, c++) {
+ int b = nop_sequence[i];
+ int a = nop_sequence[i+1];
+
+ value += (int)pow((double)((a * base) + b), c);
+ }
+
+ if(extra) {
+ value += (int)pow((double)nop_sequence[size-1], c);
+ }
+
+ return value;
+}
Copied: trunk/source/cpu/cCodeLabel.h (from rev 298, trunk/source/cpu/code_label.hh)
Deleted: trunk/source/cpu/code_label.cc
===================================================================
--- trunk/source/cpu/code_label.cc 2005-08-29 18:54:25 UTC (rev 298)
+++ trunk/source/cpu/code_label.cc 2005-08-29 19:15:32 UTC (rev 299)
@@ -1,222 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 1993 - 2002 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 "code_label.hh"
-
-#include "tools.hh" // for g_memory & g_debug
-
-
-
-#include <cmath>
-#include <vector>
-#include <iostream>
-#include <iomanip>
-
-using namespace std;
-
-
-
-////////////////////////////////
-// cCodeLabel stuff...
-////////////////////////////////
-
-bool cCodeLabel::OK()
-{
- bool result = true;
-
- assert (size <= MAX_LABEL_SIZE);
- assert (size <= nop_sequence.GetSize());
- for (int i = 0; i < size; i++) {
- assert (nop_sequence[i] < MAX_NOPS);
- }
-
- return result;
-}
-
-bool cCodeLabel::operator==(const cCodeLabel & other_label) const
-{
- if (size != other_label.GetSize()) {
- return false;
- }
-
- for (int i = 0; i < size; i++) {
- if (nop_sequence[i] != other_label[i]) {
- return false;
- }
- }
-
- return true;
-}
-
-
-// This function returns true if the sub_label can be found within
-// the label affected.
-int cCodeLabel::FindSublabel(cCodeLabel & sub_label)
-{
- bool error = false;
-
- for (int offset = 0; offset <= size - sub_label.GetSize(); offset++) {
- for (int i = 0; i < sub_label.GetSize(); i++) {
- if (nop_sequence[i + offset] != sub_label[i]) {
- error = true;
- break;
- }
- }
- if (!error) return offset;
- error = false;
- }
-
- return -1;
-}
-
-void cCodeLabel::SaveState(ostream & fp)
-{
-// assert(fp.good());
-// fp<<"cCodeLabel"<<" ";
-
-// fp<<"|"; // marker
-
-// fp << size << " " << base << " ";
-// for( int i=0; i < size; ++i ){
-// fp<<nop_sequence[i];
-// }
-// fp<<endl;
-}
-
-
-void cCodeLabel::LoadState(istream & fp)
-{
-// assert(fp.good());
-// cString foo;
-// fp>>foo;
-// assert( foo == "cCodeLabel");
-
-// char marker;
-// fp>>marker;
-// assert( marker == '|' );
-
-// fp.get(size);
-// fp.get(base);
-// for( int i=0; i<MAX_LABEL_SIZE; ++i ){
-// fp.get(nop_sequence[i]);
-// }
-}
-
-int cCodeLabel::AsInt(const int base) const
-{
- int value = 0;
-
- for (int i = 0; i < size; i++) {
- value *= base;
- value += nop_sequence[i];
- }
-
- return value;
-}
-
-int cCodeLabel::AsIntGreyCode(const int base) const
-{
- int value = 0;
- int oddCount = 0;
-
- for (int i = 0; i < size; i++) {
- value *= base;
-
- if(oddCount % 2 == 0) {
- value += nop_sequence[i];
- } else {
- value += (NUM_NOPS - 1) - nop_sequence[i];
- }
-
- if(nop_sequence[i] % 2 == 1) {
- oddCount++;
- }
- }
-
- return value;
-}
-
-int cCodeLabel::AsIntDirect(const int base) const
-{
- int value = 0;
-
- for (int i = 0; i < size; i++) {
- value *= base;
- value += nop_sequence[i];
- }
-
- return value;
-}
-
-int cCodeLabel::AsIntAdditivePolynomial(const int base) const
-{
- double value = 0.0;
-
- for (int i = 0; i < size; i++) {
-#if 1
- int n = (int)nop_sequence[i] + 1;
- double a = pow((double)n, 0.4 * (double)(size-1));
- double b = 0.3 * (double)i * (double)(size-1);
- double c = 0.45 * (double)i;
- value += a + b + c;
-#else
- value += (pow(((double)nop_sequence[i] + 1.0), (0.4 * (double)(size-1))) +
- (0.3 * (double)i * (double)(size-1)) +
- (0.45 * (double)i));
-#endif
- }
-
- return (int)(value + 0.5);
-}
-
-int cCodeLabel::AsIntFib(const int base) const
-{
- int value = 0;
- if(base < 3) { return 0; }
-
- vector<int> fib;
- fib.resize(base, 0);
- fib[0] = 0;
- fib[1] = 1;
- fib[2] = 2;
- for(int i=3; i<base; i++) {
- fib[i] = fib[i-2] + fib[i-1];
- }
-
- for (int i = 0; i < size; i++) {
- value += fib[(int)nop_sequence[i]];
-
- fib[2] = fib[base-2] + fib[base-1];
- fib[1] = fib[base-1];
- for(int j=3; j<base; j++) {
- fib[j] = fib[j-2] + fib[j-1];
- }
- }
-
- return value;
-}
-
-int cCodeLabel::AsIntPolynomialCoefficent(const int base) const
-{
- int value = 0;
-
- int extra = size % 2;
- int c = 1;
-
- for (int i = 0; i < size - extra; i+=2, c++) {
- int b = nop_sequence[i];
- int a = nop_sequence[i+1];
-
- value += (int)pow((double)((a * base) + b), c);
- }
-
- if(extra) {
- value += (int)pow((double)nop_sequence[size-1], c);
- }
-
- return value;
-}
Deleted: trunk/source/cpu/code_label.hh
===================================================================
--- trunk/source/cpu/code_label.hh 2005-08-29 18:54:25 UTC (rev 298)
+++ trunk/source/cpu/code_label.hh 2005-08-29 19:15:32 UTC (rev 299)
@@ -1,97 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 1993 - 2003 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 CODE_LABEL_HH
-#define CODE_LABEL_HH
-
-#ifndef CPU_DEFS_HH
-#include "cpu_defs.hh" // #defines only
-#endif
-#ifndef DEFS_HH
-#include "defs.hh"
-#endif
-#ifndef STRING_HH
-#include "string.hh"
-#endif
-#ifndef TARRAY_HH
-#include "tArray.hh"
-#endif
-#ifndef TOOLS_HH
-#include "tools.hh"
-#endif
-
-/**
- * The cCodeLabel class is used to identify a label within the genotype of
- * a creature, and aid in its manipulation.
- **/
-
-class cCodeLabel {
-private:
- tArray<char> nop_sequence;
- int size;
- //const int base;
-public:
- cCodeLabel() : size(0) { ; }
- cCodeLabel(const cCodeLabel& in_label) : nop_sequence(in_label.nop_sequence), size(in_label.size) { ; }
- ~cCodeLabel() { ; }
-
- bool OK();
- bool operator==(const cCodeLabel & other_label) const;
- bool operator!=(const cCodeLabel & other_label) const
- { return !(operator==(other_label)); }
- char operator[](int position) const { return (int) nop_sequence[position]; }
- int FindSublabel(cCodeLabel & sub_label);
-
- void Clear() { size = 0; }
- inline void AddNop(int nop_num);
- inline void Rotate(const int rot, const int base);
-
- int GetSize() const { return size; }
- //int GetBase() const { return base; }
- inline cString AsString() const;
- int AsInt(const int base) const;
- int AsIntGreyCode(const int base) const;
- int AsIntDirect(const int base) const;
- int AsIntAdditivePolynomial(const int base) const;
- int AsIntFib(const int base) const;
- int AsIntPolynomialCoefficent(const int base) const;
-
- void SaveState(std::ostream & fp);
- void LoadState(std::istream & fp);
-};
-
-void cCodeLabel::AddNop(int nop_num) {
- assert (nop_num < MAX_NOPS);
-
- if (size < MAX_LABEL_SIZE) {
- if (size == nop_sequence.GetSize()) {
- nop_sequence.Resize(size+1);
- }
- nop_sequence[size++] = (char) nop_num;
- }
-}
-
-void cCodeLabel::Rotate(const int rot, const int base)
-{
- for (int i = 0; i < size; i++) {
- nop_sequence[i] += rot;
- if (nop_sequence[i] >= base) nop_sequence[i] -= base;
- }
-}
-
-
-cString cCodeLabel::AsString() const
-{
- cString out_string;
- for (int i = 0; i < size; i++) {
- out_string += (char) nop_sequence[i] + 'A';
- }
-
- return out_string;
-}
-
-#endif
Modified: trunk/source/cpu/cpu.pri
===================================================================
--- trunk/source/cpu/cpu.pri 2005-08-29 18:54:25 UTC (rev 298)
+++ trunk/source/cpu/cpu.pri 2005-08-29 19:15:32 UTC (rev 299)
@@ -1,11 +1,11 @@
cpu {
HEADERS += \
- $$CPU_HH/code_label.hh \
+ $$CPU_HH/cCodeLabel.h \
$$CPU_HH/cpu_defs.hh \
- $$CPU_HH/cpu_memory.hh \
- $$CPU_HH/cpu_stack.hh \
- $$CPU_HH/cpu_stats.hh \
+ $$CPU_HH/cCPUMemory.h \
+ $$CPU_HH/cCPUStack.h \
+ $$CPU_HH/sCPUStats.h \
$$CPU_HH/hardware_4stack.hh \
$$CPU_HH/hardware_base.hh \
$$CPU_HH/hardware_cpu.hh \
@@ -16,11 +16,11 @@
SOURCES += \
$$CPU_CC/4stack_head.cc \
- $$CPU_CC/code_label.cc \
+ $$CPU_CC/cCodeLabel.cc \
$$CPU_CC/cpu_head.cc \
- $$CPU_CC/cpu_memory.cc \
- $$CPU_CC/cpu_stack.cc \
- $$CPU_CC/cpu_test_info.cc \
+ $$CPU_CC/cCPUMemory.cc \
+ $$CPU_CC/cCPUStack.cc \
+ $$CPU_CC/cCPUTestInfo.cc \
$$CPU_CC/hardware_4stack.cc \
$$CPU_CC/hardware_4stack_thread.cc \
$$CPU_CC/hardware_base.cc \
Deleted: trunk/source/cpu/cpu_memory.cc
===================================================================
--- trunk/source/cpu/cpu_memory.cc 2005-08-29 18:54:25 UTC (rev 298)
+++ trunk/source/cpu/cpu_memory.cc 2005-08-29 19:15:32 UTC (rev 299)
@@ -1,227 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 1993 - 2003 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 CPU_MEMORY_HH
-#include "cpu_memory.hh"
-#endif
-
-using namespace std;
-
-const double MEMORY_INCREASE_FACTOR = 1.5;
-const double MEMORY_SHRINK_TEST_FACTOR = 4.0;
-
-////////////////
-// cCPUMemory
-////////////////
-
-cCPUMemory::cCPUMemory(int _size) : cGenome(_size), flag_array(_size)
-{
-}
-
-cCPUMemory::cCPUMemory(const cCPUMemory & in_memory)
- : cGenome(in_memory), flag_array(in_memory.GetSize())
-{
- for (int i = 0; i < flag_array.GetSize(); i++) {
- flag_array[i] = in_memory.flag_array[i];
- }
-}
-
-cCPUMemory::cCPUMemory(const cGenome & in_genome)
- : cGenome(in_genome), flag_array(in_genome.GetSize())
-{
-}
-
-cCPUMemory::cCPUMemory(const cString & in_string)
- : cGenome(in_string), flag_array(in_string.GetSize())
-{
-}
-
-cCPUMemory::~cCPUMemory()
-{
-}
-
-
-// --- Private Methods ---
-
-void cCPUMemory::SloppyResize(int new_size)
-{
- assert(new_size > 0);
-
- // Make sure we're really changing the size...
- if (new_size == active_size) return;
-
- const int array_size = genome.GetSize();
-
- // Determine if we need to adjust the allocated array sizes...
- if (new_size > array_size ||
- new_size * MEMORY_SHRINK_TEST_FACTOR < array_size) {
- const int new_array_size = (int) (new_size * MEMORY_INCREASE_FACTOR);
- genome.Resize(new_array_size);
- flag_array.Resize(new_array_size);
- }
-
- // And just change the active_size once we're sure it will be in range.
- active_size = new_size;
-}
-
-
-void cCPUMemory::SloppyInsert(int pos, int num_lines)
-{
- assert(pos >= 0 && pos <= active_size); // Must insert at a legal position!
- assert(num_lines > 0); // Must insert positive number of lines!
-
- // Re-adjust the size...
- const int old_size = active_size;
- const int new_size = active_size + num_lines;
- SloppyResize(new_size);
-
- // Shift any lines needed...
- for (int i = old_size - 1; i >= pos; i--) {
- genome[i+num_lines] = genome[i];
- flag_array[i+num_lines] = flag_array[i];
- }
-}
-
-
-// --- Public Methods ---
-
-
-void cCPUMemory::operator=(const cCPUMemory & other_memory)
-{
- SloppyResize(other_memory.active_size);
-
- // Fill in the new information...
- for (int i = 0; i < active_size; i++) {
- genome[i] = other_memory.genome[i];
- flag_array[i] = other_memory.flag_array[i];
- }
-}
-
-
-void cCPUMemory::operator=(const cGenome & other_genome)
-{
- SloppyResize(other_genome.GetSize());
-
- // Fill in the new information...
- for (int i = 0; i < active_size; i++) {
- genome[i] = other_genome[i];
- flag_array[i].Clear();
- }
-}
-
-void cCPUMemory::Copy(int to, int from)
-{
- assert(to >= 0);
- assert(to < genome.GetSize());
- assert(from >= 0);
- assert(from < genome.GetSize());
-
- genome[to] = genome[from];
- flag_array[to] = flag_array[from];
-}
-
-void cCPUMemory::Clear()
-{
- for (int i = 0; i < active_size; i++) {
- genome[i].SetOp(0);
- flag_array[i].Clear();
- }
-}
-
-void cCPUMemory::ClearFlags()
-{
- for (int i = 0; i < active_size; i++) flag_array[i].Clear();
-}
-
-void cCPUMemory::Reset(int new_size)
-{
- assert(new_size >= 0);
-
- SloppyResize(new_size);
- Clear();
-}
-
-
-void cCPUMemory::Resize(int new_size)
-{
- assert(new_size >= 0);
-
- // Do a sloppy resize first, saving old values...
- const int old_size = active_size;
- const int old_array_size = genome.GetSize();
- SloppyResize(new_size);
-
- // Clean up all of the old memory that might need it...
- for (int i = old_size; i < new_size && i < old_array_size; i++) {
- genome[i].SetOp(0);
- flag_array[i].Clear();
- }
-}
-
-
-void cCPUMemory::ResizeOld(int new_size)
-{
- assert(new_size >= 0);
-
- // Do a sloppy resize, which will still have old values.
- SloppyResize(new_size);
-}
-
-
-void cCPUMemory::Insert(int pos, const cInstruction & in_inst)
-{
- assert(pos >= 0);
- assert(pos <= genome.GetSize());
-
- SloppyInsert(pos, 1);
- genome[pos] = in_inst;
- flag_array[pos].Clear();
-}
-
-void cCPUMemory::Insert(int pos, const cGenome & in_genome)
-{
- assert(pos >= 0);
- assert(pos <= genome.GetSize());
-
- SloppyInsert(pos, in_genome.GetSize());
- for (int i = 0; i < in_genome.GetSize(); i++) {
- genome[i+pos] = in_genome[i];
- flag_array[i+pos].Clear();
- }
-}
-
-void cCPUMemory::Remove(int pos, int num_insts)
-{
- assert(num_insts > 0); // Must remove something...
- assert(pos >= 0); // Removal must be in genome.
- assert(pos + num_insts <= active_size); // Cannot extend past end of genome.
-
- const int new_size = active_size - num_insts;
- for (int i = pos; i < new_size; i++) {
- genome[i] = genome[i + num_insts];
- flag_array[i] = flag_array[i + num_insts];
- }
- SloppyResize(new_size);
-}
-
-void cCPUMemory::Replace(int pos, int num_insts, const cGenome & in_genome)
-{
- assert(pos >= 0); // Replace must be in genome.
- assert(num_insts >= 0); // Cannot replace negative.
- assert(pos + num_insts <= active_size); // Cannot extend past end!
-
- const int size_change = in_genome.GetSize() - num_insts;
-
- // First, get the size right.
- if (size_change > 0) SloppyInsert(pos, size_change);
- else if (size_change < 0) Remove(pos, -size_change);
-
- // Now just copy everything over!
- for (int i = 0; i < in_genome.GetSize(); i++) {
- genome[i + pos] = in_genome[i];
- }
-}
Deleted: trunk/source/cpu/cpu_memory.hh
===================================================================
--- trunk/source/cpu/cpu_memory.hh 2005-08-29 18:54:25 UTC (rev 298)
+++ trunk/source/cpu/cpu_memory.hh 2005-08-29 19:15:32 UTC (rev 299)
@@ -1,74 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 1993 - 2003 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 CPU_MEMORY_HH
-#define CPU_MEMORY_HH
-
-#ifndef GENOME_HH
-#include "genome.hh"
-#endif
-#ifndef TARRAY_HH
-#include "tArray.hh"
-#endif
-#ifndef MEMORY_FLAGS_HH
-#include "memory_flags.hh"
-#endif
-
-class cGenome;
-class cInstruction;
-class cMemoryFlags; // access
-class cString;
-template <class T> class tArray; // aggregate
-
-class cCPUMemory : public cGenome {
-private:
- tArray<cMemoryFlags> flag_array;
-
- // A collection of sloppy instructions to perform oft-used functions that
- // will need to be cleaned up after this is run.
- void SloppyResize(int new_size); // Set size, ignore new contents.
- void SloppyInsert(int pos, int num_lines); // Add lines, ignore new contents.
-public:
- explicit cCPUMemory(int _size=1);
- cCPUMemory(const cCPUMemory & in_memory);
- cCPUMemory(const cGenome & in_genome);
- cCPUMemory(const cString & in_string);
- ~cCPUMemory();
-
- void operator=(const cCPUMemory & other_memory);
- void operator=(const cGenome & other_genome);
- void Copy(int to, int from);
-
- void Clear();
- void ClearFlags();
- void Reset(int new_size); // Reset size, clearing contents...
- void Resize(int new_size); // Reset size, save contents, init to default
- void ResizeOld(int new_size); // Reset size, save contents, init to previous
-
- bool FlagCopied(int pos) const { return flag_array[pos].copied; }
- bool FlagMutated(int pos) const { return flag_array[pos].mutated; }
- bool FlagExecuted(int pos) const { return flag_array[pos].executed; }
- bool FlagBreakpoint(int pos) const { return flag_array[pos].breakpoint; }
- bool FlagPointMut(int pos) const { return flag_array[pos].point_mut; }
- bool FlagCopyMut(int pos) const { return flag_array[pos].copy_mut; }
- bool FlagInjected(int pos) const { return flag_array[pos].injected; }
-
- bool & FlagCopied(int pos) { return flag_array[pos].copied; }
- bool & FlagMutated(int pos) { return flag_array[pos].mutated; }
- bool & FlagExecuted(int pos) { return flag_array[pos].executed; }
- bool & FlagBreakpoint(int pos) { return flag_array[pos].breakpoint; }
- bool & FlagPointMut(int pos) { return flag_array[pos].point_mut; }
- bool & FlagCopyMut(int pos) { return flag_array[pos].copy_mut; }
- bool & FlagInjected(int pos) { return flag_array[pos].injected; }
-
- void Insert(int pos, const cInstruction & in_inst);
- void Insert(int pos, const cGenome & in_genome);
- void Remove(int pos, int num_insts=1);
- void Replace(int pos, int num_insts, const cGenome & in_genome);
-};
-
-#endif
Deleted: trunk/source/cpu/cpu_stack.cc
===================================================================
--- trunk/source/cpu/cpu_stack.cc 2005-08-29 18:54:25 UTC (rev 298)
+++ trunk/source/cpu/cpu_stack.cc 2005-08-29 19:15:32 UTC (rev 299)
@@ -1,77 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 1993 - 2001 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_stack.hh"
-
-#include <assert.h>
-#include "string.hh"
-
-using namespace std;
-
-
-cCPUStack::cCPUStack()
-{
- Clear();
-}
-
-cCPUStack::cCPUStack(const cCPUStack & in_stack)
-{
- for (int i = 0; i < STACK_SIZE; i++) {
- stack[i] = in_stack.stack[i];
- }
- stack_pointer = in_stack.stack_pointer;
-}
-
-cCPUStack::~cCPUStack()
-{
-}
-
-void cCPUStack::operator=(const cCPUStack & in_stack)
-{
- for (int i = 0; i < STACK_SIZE; i++) {
- stack[i] = in_stack.stack[i];
- }
- stack_pointer = in_stack.stack_pointer;
-}
-
-void cCPUStack::Flip()
-{
- int new_stack[STACK_SIZE];
- int i;
- for (i = 0; i < STACK_SIZE; i++) new_stack[i] = Pop();
- for (i = 0; i < STACK_SIZE; i++) Push(new_stack[i]);
-}
-
-bool cCPUStack::OK()
-{
- assert(stack_pointer < STACK_SIZE); // stack_pointer out of range
- return true;
-}
-
-void cCPUStack::SaveState(ostream & fp)
-{
- assert(fp.good());
- fp<<"cCPUStack"<<" ";
- // stack (in inverse order so load can just push)
- for(int i = STACK_SIZE - 1; i >= 0; i-- ){
- fp<<Get(i)<<" ";
- }
- fp<<endl;
-}
-
-void cCPUStack::LoadState(istream & fp)
-{
- assert(fp.good());
- cString foo;
- fp>>foo;
- assert( foo == "cCPUStack");
- int value;
- for( int i=0; i<STACK_SIZE; ++i ){
- fp>>value;
- Push(value);
- }
-}
Deleted: trunk/source/cpu/cpu_stack.hh
===================================================================
--- trunk/source/cpu/cpu_stack.hh 2005-08-29 18:54:25 UTC (rev 298)
+++ trunk/source/cpu/cpu_stack.hh 2005-08-29 19:15:32 UTC (rev 299)
@@ -1,82 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 1993 - 2003 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 CPU_STACK_HH
-#define CPU_STACK_HH
-
-#include <iostream>
-
-#ifndef CPU_DEFS_HH
-#include "cpu_defs.hh"
-#endif
-
-/**
- * A CPU stack, used by various hardware components.
- *
- * @see cCPUThread, cHeadCPU, cHardware
- **/
-
-class cCPUStack {
-private:
- int stack[STACK_SIZE];
- unsigned char stack_pointer;
-public:
- cCPUStack();
- cCPUStack(const cCPUStack & in_stack);
- ~cCPUStack();
-
- void operator=(const cCPUStack & in_stack);
-
- inline void Push(int value);
- inline int Pop();
- inline int Get(int depth=0) const;
- inline void Clear();
- inline int Top();
- void Flip();
-
- bool OK();
-
- void SaveState(std::ostream & fp);
- void LoadState(std::istream & fp);
-};
-
-
-inline void cCPUStack::Push(int value)
-{
- if (stack_pointer == 0) stack_pointer = STACK_SIZE - 1;
- else stack_pointer--;
- stack[stack_pointer] = value;
-}
-
-inline int cCPUStack::Pop()
-{
- int value = stack[stack_pointer];
- stack[stack_pointer] = 0;
- stack_pointer++;
- if (stack_pointer == STACK_SIZE) stack_pointer = 0;
- return value;
-}
-
-inline int cCPUStack::Get(int depth) const
-{
- int array_pos = depth + stack_pointer;
- if (array_pos >= STACK_SIZE) array_pos -= STACK_SIZE;
- return stack[array_pos];
-}
-
-inline void cCPUStack::Clear()
-{
- for (int i =0; i < STACK_SIZE; i++) { stack[i] = 0; }
- stack_pointer = 0;
-}
-
-inline int cCPUStack::Top()
-{
- return stack[stack_pointer];
-}
-
-#endif
Deleted: trunk/source/cpu/cpu_stats.hh
===================================================================
--- trunk/source/cpu/cpu_stats.hh 2005-08-29 18:54:25 UTC (rev 298)
+++ trunk/source/cpu/cpu_stats.hh 2005-08-29 19:15:32 UTC (rev 299)
@@ -1,67 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 1993 - 2003 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 CPU_STATS_HH
-#define CPU_STATS_HH
-
-/**
- * Class to facilitate passing information from CPU to Stats.
- **/
-
-class sCPUStats {
-public:
- class sMutationStats {
- public:
- // Counts of mutations INHERITED FROM PARENT
- int point_mut_count;
- int copy_mut_count;
- int insert_mut_count;
- int delete_mut_count;
- int div_mut_count;
- // Counts of Mutated _Lines_
- int point_mut_line_count; // In PARENT
- int parent_mut_line_count; // In PARENT
- int copy_mut_line_count; // In CHILD
- // Theses happen by divide, so they should be 0 or 1
- int divide_mut_count;
- int divide_insert_mut_count;
- int divide_delete_mut_count;
- // Other info needed for mutation calculations
- int copies_exec;
-
- void Clear() {
- point_mut_count = 0;
- copy_mut_count = 0;
- insert_mut_count = 0;
- point_mut_line_count = 0;
- parent_mut_line_count = 0;
- copy_mut_line_count = 0;
- delete_mut_count = 0;
- div_mut_count=0;
- divide_mut_count = 0;
- divide_insert_mut_count = 0;
- divide_delete_mut_count = 0;
- copies_exec = 0;
- }
- };
-
-
- // Contiually Set
- sMutationStats mut_stats;
-
-
- void Setup(int num_instructions) {
- (void) num_instructions;
- mut_stats.Clear();
- }
-
- void Clear() { // Called on any New Creature
- mut_stats.Clear();
- }
-};
-
-#endif
Deleted: trunk/source/cpu/cpu_test_info.cc
===================================================================
--- trunk/source/cpu/cpu_test_info.cc 2005-08-29 18:54:25 UTC (rev 298)
+++ trunk/source/cpu/cpu_test_info.cc 2005-08-29 19:15:32 UTC (rev 299)
@@ -1,77 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 1993 - 2003 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_test_info.hh"
-
-#include "hardware_status_printer.hh"
-#include "organism.hh"
-#include "phenotype.hh"
-
-#include <assert.h>
-
-/////////////////
-// cCPUTestInfo
-/////////////////
-
-cCPUTestInfo::cCPUTestInfo(int max_tests)
- : generation_tests(max_tests) // These vars not reset on Clear()
- , test_threads(false)
- , print_threads(false)
- , trace_execution(false)
- , trace_task_order(false)
- , use_random_inputs(false)
- , org_array(max_tests)
- , m_tracer(NULL)
-{
- org_array.SetAll(NULL);
- Clear();
-}
-
-
-cCPUTestInfo::~cCPUTestInfo()
-{
- for (int i = 0; i < generation_tests; i++) {
- if (org_array[i] != NULL) delete org_array[i];
- }
-}
-
-
-void cCPUTestInfo::Clear()
-{
- is_viable = false;
- max_depth = -1;
- depth_found = -1;
- max_cycle = 0;
- cycle_to = -1;
-
- for (int i = 0; i < generation_tests; i++) {
- if (org_array[i] == NULL) break;
- delete org_array[i];
- org_array[i] = NULL;
- }
-}
-
-
-void cCPUTestInfo::SetTraceExecution(cHardwareTracer *tracer)
-{
- trace_execution = (tracer)?(true):(false);
- m_tracer = tracer;
-}
-
-
-double cCPUTestInfo::GetGenotypeFitness()
-{
- if (org_array[0] != NULL) return org_array[0]->GetPhenotype().GetFitness();
- return 0.0;
-}
-
-
-double cCPUTestInfo::GetColonyFitness()
-{
- if (IsViable()) return GetColonyOrganism()->GetPhenotype().GetFitness();
- return 0.0;
-}
Deleted: trunk/source/cpu/cpu_test_info.hh
===================================================================
--- trunk/source/cpu/cpu_test_info.hh 2005-08-29 18:54:25 UTC (rev 298)
+++ trunk/source/cpu/cpu_test_info.hh 2005-08-29 19:15:32 UTC (rev 299)
@@ -1,96 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 1993 - 2003 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 CPU_TEST_INFO_HH
-#define CPU_TEST_INFO_HH
-
-#ifndef CPU_DEFS_HH
-#include "cpu_defs.hh"
-#endif
-#ifndef STRING_HH
-#include "string.hh"
-#endif
-#ifndef TARRAY_HH
-#include "tArray.hh"
-#endif
-
-class cHardwareTracer;
-class cOrganism;
-class cString;
-
-class cCPUTestInfo {
- friend class cTestCPU;
-private:
- // Inputs...
- const int generation_tests; // Maximum depth in generations to test
- bool test_threads; // Should a report of threading be saved?
- bool print_threads; // Should the report be printed?
- 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?
- cHardwareTracer *m_tracer;
-
- // Outputs...
- bool is_viable; // Is this organism colony forming?
- int max_depth; // Deepest tests went...
- int depth_found; // Depth actually found (often same as max_depth)
- int max_cycle; // Longest cycle found.
- int cycle_to; // Cycle path of the last genotype.
-
- tArray<cOrganism *> org_array;
-
-private:
- // disabled copy constructor.
- cCPUTestInfo(const cCPUTestInfo &);
-public:
- cCPUTestInfo(int max_tests=TEST_CPU_GENERATIONS);
- ~cCPUTestInfo();
-
- void Clear();
-
- // Input Setup
- void TestThreads(bool _test=true) { test_threads = _test; }
- 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(cHardwareTracer *tracer = NULL);
-
- // Input Accessors
- int GetGenerationTests() const { return generation_tests; }
- bool GetTestThreads() const { return test_threads; }
- bool GetPrintThreads() const { return print_threads; }
- bool GetTraceTaskOrder() const { return trace_task_order; }
- bool GetUseRandomInputs() const { return use_random_inputs; }
- bool GetTraceExecution() const { return trace_execution; }
- cHardwareTracer *GetTracer() { return m_tracer; }
-
-
- // Output Accessors
- bool IsViable() const { return is_viable; }
- int GetMaxDepth() const { return max_depth; }
- int GetDepthFound() const { return depth_found; }
- int GetMaxCycle() const { return max_cycle; }
- int GetCycleTo() const { return cycle_to; }
-
- // Genotype Stats...
- cOrganism * GetTestOrganism(int level=0) {
- assert(org_array[level] != NULL);
- return org_array[level];
- }
-
- cOrganism * GetColonyOrganism() {
- const int depth_used = (depth_found == -1) ? 0 : depth_found;
- assert(org_array[depth_used] != NULL);
- return org_array[depth_used];
- }
-
- // And just because these are so commonly used...
- double GetGenotypeFitness();
- double GetColonyFitness();
-};
-
-#endif
Modified: trunk/source/cpu/hardware_4stack.cc
===================================================================
--- trunk/source/cpu/hardware_4stack.cc 2005-08-29 18:54:25 UTC (rev 298)
+++ trunk/source/cpu/hardware_4stack.cc 2005-08-29 19:15:32 UTC (rev 299)
@@ -10,7 +10,7 @@
#include "hardware_4stack.hh"
#include "config.hh"
-#include "cpu_test_info.hh"
+#include "cCPUTestInfo.h"
#include "functions.hh"
#include "genome_util.hh"
#include "inst_lib_base.hh"
Modified: trunk/source/cpu/hardware_4stack.hh
===================================================================
--- trunk/source/cpu/hardware_4stack.hh 2005-08-29 18:54:25 UTC (rev 298)
+++ trunk/source/cpu/hardware_4stack.hh 2005-08-29 19:15:32 UTC (rev 299)
@@ -11,10 +11,10 @@
#include <iomanip>
#ifndef CPU_MEMORY_HH
-#include "cpu_memory.hh"
+#include "cCPUMemory.h"
#endif
#ifndef CPU_STACK_HH
-#include "cpu_stack.hh"
+#include "cCPUStack.h"
#endif
#ifndef DEFS_HH
#include "defs.hh"
Modified: trunk/source/cpu/hardware_4stack_thread.hh
===================================================================
--- trunk/source/cpu/hardware_4stack_thread.hh 2005-08-29 18:54:25 UTC (rev 298)
+++ trunk/source/cpu/hardware_4stack_thread.hh 2005-08-29 19:15:32 UTC (rev 299)
@@ -11,10 +11,10 @@
#include <iostream>
#ifndef CODE_LABEL_HH
-#include "code_label.hh"
+#include "cCodeLabel.h"
#endif
#ifndef CPU_STACK_HH
-#include "cpu_stack.hh"
+#include "cCPUStack.h"
#endif
#ifndef HEAD_MULTI_MEM_HH
#include "head_multi_mem.hh"
Modified: trunk/source/cpu/hardware_cpu.cc
===================================================================
--- trunk/source/cpu/hardware_cpu.cc 2005-08-29 18:54:25 UTC (rev 298)
+++ trunk/source/cpu/hardware_cpu.cc 2005-08-29 19:15:32 UTC (rev 299)
@@ -8,7 +8,7 @@
#include "hardware_cpu.hh"
#include "config.hh"
-#include "cpu_test_info.hh"
+#include "cCPUTestInfo.h"
#include "functions.hh"
#include "genome_util.hh"
#include "genotype.hh"
Modified: trunk/source/cpu/hardware_cpu.hh
===================================================================
--- trunk/source/cpu/hardware_cpu.hh 2005-08-29 18:54:25 UTC (rev 298)
+++ trunk/source/cpu/hardware_cpu.hh 2005-08-29 19:15:32 UTC (rev 299)
@@ -15,7 +15,7 @@
#include "defs.hh"
#endif
#ifndef CODE_LABEL_HH
-#include "code_label.hh"
+#include "cCodeLabel.h"
#endif
#ifndef CPU_DEFS_HH
#include "cpu_defs.hh"
@@ -24,10 +24,10 @@
#include "head_cpu.hh"
#endif
#ifndef CPU_MEMORY_HH
-#include "cpu_memory.hh"
+#include "cCPUMemory.h"
#endif
#ifndef CPU_STACK_HH
-#include "cpu_stack.hh"
+#include "cCPUStack.h"
#endif
#ifndef HARDWARE_BASE_HH
#include "hardware_base.hh"
Modified: trunk/source/cpu/hardware_cpu_thread.hh
===================================================================
--- trunk/source/cpu/hardware_cpu_thread.hh 2005-08-29 18:54:25 UTC (rev 298)
+++ trunk/source/cpu/hardware_cpu_thread.hh 2005-08-29 19:15:32 UTC (rev 299)
@@ -11,7 +11,7 @@
#include <iostream>
#ifndef CODE_LABEL_HH
-#include "code_label.hh"
+#include "cCodeLabel.h"
#endif
#ifndef CPU_DEFS_HH
#include "cpu_defs.hh"
@@ -20,7 +20,7 @@
#include "head_cpu.hh"
#endif
#ifndef CPU_STACK_HH
-#include "cpu_stack.hh"
+#include "cCPUStack.h"
#endif
#ifndef TBUFFER_HH
#include "tBuffer.hh"
Modified: trunk/source/cpu/hardware_smt.cc
===================================================================
--- trunk/source/cpu/hardware_smt.cc 2005-08-29 18:54:25 UTC (rev 298)
+++ trunk/source/cpu/hardware_smt.cc 2005-08-29 19:15:32 UTC (rev 299)
@@ -10,7 +10,7 @@
#include "hardware_smt.h"
#include "config.hh"
-#include "cpu_test_info.hh"
+#include "cCPUTestInfo.h"
#include "functions.hh"
#include "genome_util.hh"
#include "inst_lib_base.hh"
Modified: trunk/source/cpu/hardware_smt.h
===================================================================
--- trunk/source/cpu/hardware_smt.h 2005-08-29 18:54:25 UTC (rev 298)
+++ trunk/source/cpu/hardware_smt.h 2005-08-29 19:15:32 UTC (rev 299)
@@ -13,10 +13,10 @@
#include <iomanip>
#ifndef CPU_MEMORY_HH
-#include "cpu_memory.hh"
+#include "cCPUMemory.h"
#endif
#ifndef CPU_STACK_HH
-#include "cpu_stack.hh"
+#include "cCPUStack.h"
#endif
#ifndef DEFS_HH
#include "defs.hh"
Modified: trunk/source/cpu/hardware_smt_thread.h
===================================================================
--- trunk/source/cpu/hardware_smt_thread.h 2005-08-29 18:54:25 UTC (rev 298)
+++ trunk/source/cpu/hardware_smt_thread.h 2005-08-29 19:15:32 UTC (rev 299)
@@ -13,10 +13,10 @@
#include <iostream>
#ifndef CODE_LABEL_HH
-#include "code_label.hh"
+#include "cCodeLabel.h"
#endif
#ifndef CPU_STACK_HH
-#include "cpu_stack.hh"
+#include "cCPUStack.h"
#endif
#ifndef HEAD_MULTI_MEM_HH
#include "head_multi_mem.hh"
Modified: trunk/source/cpu/head_cpu.cc
===================================================================
--- trunk/source/cpu/head_cpu.cc 2005-08-29 18:54:25 UTC (rev 298)
+++ trunk/source/cpu/head_cpu.cc 2005-08-29 19:15:32 UTC (rev 299)
@@ -10,10 +10,10 @@
#endif
#ifndef CPU_MEMORY_HH
-#include "cpu_memory.hh"
+#include "cCPUMemory.h"
#endif
#ifndef CODE_LABEL_HH
-#include "code_label.hh"
+#include "cCodeLabel.h"
#endif
#ifndef GENOME_HH
#include "genome.hh"
Modified: trunk/source/cpu/head_multi_mem.cc
===================================================================
--- trunk/source/cpu/head_multi_mem.cc 2005-08-29 18:54:25 UTC (rev 298)
+++ trunk/source/cpu/head_multi_mem.cc 2005-08-29 19:15:32 UTC (rev 299)
@@ -10,7 +10,7 @@
#endif
#ifndef CPU_MEMORY_HH
-#include "cpu_memory.hh"
+#include "cCPUMemory.h"
#endif
#ifndef HARDWARE_BASE_HH
#include "hardware_base.hh"
Copied: trunk/source/cpu/sCPUStats.h (from rev 298, trunk/source/cpu/cpu_stats.hh)
Modified: trunk/source/cpu/test_cpu.cc
===================================================================
--- trunk/source/cpu/test_cpu.cc 2005-08-29 18:54:25 UTC (rev 298)
+++ trunk/source/cpu/test_cpu.cc 2005-08-29 19:15:32 UTC (rev 299)
@@ -7,7 +7,7 @@
#include "test_cpu.hh"
-#include "cpu_test_info.hh"
+#include "cCPUTestInfo.h"
#include "config.hh"
#include "environment.hh"
#include "functions.hh"
Modified: trunk/source/cpu/test_util.cc
===================================================================
--- trunk/source/cpu/test_util.cc 2005-08-29 18:54:25 UTC (rev 298)
+++ trunk/source/cpu/test_util.cc 2005-08-29 19:15:32 UTC (rev 299)
@@ -7,7 +7,7 @@
#include "test_util.hh"
-#include "cpu_test_info.hh"
+#include "cCPUTestInfo.h"
#include "environment.hh"
#include "genome.hh"
#include "genotype.hh"
More information about the Avida-cvs
mailing list