1 /*
2 * cCPUTestInfo.h
3 * Avida
4 *
5 * Called "cpu_test_info.hh" prior to 11/29/05.
6 * Copyright 1999-2011 Michigan State University. All rights reserved.
7 * Copyright 1999-2003 California Institute of Technology.
8 *
9 *
10 * This file is part of Avida.
11 *
12 * Avida is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
14 *
15 * Avida is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License along with Avida.
19 * If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23 #ifndef cCPUTestInfo_h
24 #define cCPUTestInfo_h
25
26 #ifndef nHardware_h
27 #include "nHardware.h"
28 #endif
29 #ifndef cMutationRates_h
30 #include "cMutationRates.h"
31 #endif
32 #ifndef cString_h
33 #include "cString.h"
34 #endif
35 #ifndef tArray_h
36 #include "tArray.h"
37 #endif
38
39 class cHardwareTracer;
40 class cOrganism;
41 class cPhenotype;
42 class cResourceHistory;
43 class cString;
44
45
46 enum eTestCPUResourceMethod { RES_INITIAL = 0, RES_CONSTANT, RES_UPDATED_DEPLETABLE, RES_DYNAMIC, RES_LAST };
47 // Modes for how the test CPU handles resources:
48 // OFF - all resources are at zero. (OLD: use_resources = 0)
49 // CONSTANT - resources stay constant at input values for the specified update. (OLD: use_resources = 1)
50 // UPDATED_DEPLETABLE - resources change every update according to resource data file (assuming an update
51 // is an average time slice). The organism also depletes these resources when using them.
52 // DYNAMIC - UPDATED_DEPLETABLE + resources inflow/outflow (NOT IMPLEMENTED YET!)
53
54
55 class cCPUTestInfo
56 {
57 friend class cTestCPU;
58 private:
59 // Inputs...
60 int generation_tests; // Maximum depth in generations to test
61 bool trace_task_order; // Should we keep track of ordering of tasks?
62 bool use_random_inputs; // Should we give the organism random inputs?
63 bool use_manual_inputs; // Do we have inputs that we must use?
64 tArray<int> manual_inputs; // if so, use these.
65 cHardwareTracer* m_tracer;
66 cMutationRates m_mut_rates;
67
68 int m_cur_sg;
69
70 // Outputs...
71 bool is_viable; // Is this organism colony forming?
72 int max_depth; // Deepest tests went...
73 int depth_found; // Depth actually found (often same as max_depth)
74 int max_cycle; // Longest cycle found.
75 int cycle_to; // Cycle path of the last genotype.
76 tArray<int> used_inputs; //Depth 0 inputs
77
78 tArray<cOrganism*> org_array;
79
80 // Information about how to handle resources
81 eTestCPUResourceMethod m_res_method;
82 cResourceHistory* m_res;
83 int m_res_update;
84 int m_res_cpu_cycle_offset;
85
86
87 public:
88 cCPUTestInfo(int max_tests=nHardware::TEST_CPU_GENERATIONS);
89 cCPUTestInfo(const cCPUTestInfo&);
90 cCPUTestInfo& operator=(const cCPUTestInfo&);
91 ~cCPUTestInfo();
92
93 void Clear();
94
95 // Input Setup
96 void TraceTaskOrder(bool _trace=true) { trace_task_order = _trace; }
97 void UseRandomInputs(bool _rand=true) { use_random_inputs = _rand; use_manual_inputs = false; }
UseManualInputs(tArray<int> inputs)98 void UseManualInputs(tArray<int> inputs) {use_manual_inputs = true; use_random_inputs = false; manual_inputs = inputs;}
ResetInputMode()99 void ResetInputMode() {use_manual_inputs = false; use_random_inputs = false;}
100 void SetTraceExecution(cHardwareTracer* tracer = NULL) { m_tracer = tracer; }
101 void SetResourceOptions(int res_method = RES_INITIAL, cResourceHistory* res = NULL, int update = 0, int cpu_cycle_offset = 0)
102 { m_res_method = (eTestCPUResourceMethod)res_method; m_res = res; m_res_update = update; m_res_cpu_cycle_offset = cpu_cycle_offset; }
103
SetCurrentStateGridID(int sg)104 void SetCurrentStateGridID(int sg) { m_cur_sg = sg; }
MutationRates()105 cMutationRates& MutationRates() { return m_mut_rates; }
106
107 // Input Accessors
GetGenerationTests()108 int GetGenerationTests() const { return generation_tests; }
GetTraceTaskOrder()109 bool GetTraceTaskOrder() const { return trace_task_order; }
GetUseRandomInputs()110 bool GetUseRandomInputs() const { return use_random_inputs; }
GetTraceExecution()111 bool GetTraceExecution() const { return (m_tracer); }
GetUseManualInputs()112 bool GetUseManualInputs() const { return use_manual_inputs; }
GetTestCPUInputs()113 tArray<int> GetTestCPUInputs() const { return used_inputs; }
GetTracer()114 cHardwareTracer *GetTracer() { return m_tracer; }
115
116
117 // Output Accessors
IsViable()118 bool IsViable() const { return is_viable; }
GetMaxDepth()119 int GetMaxDepth() const { return max_depth; }
GetDepthFound()120 int GetDepthFound() const { return depth_found; }
GetMaxCycle()121 int GetMaxCycle() const { return max_cycle; }
GetCycleTo()122 int GetCycleTo() const { return cycle_to; }
123
124 // Genotype Stats...
125 inline cOrganism* GetTestOrganism(int level = 0);
126 cPhenotype& GetTestPhenotype(int level = 0);
127 inline cOrganism* GetColonyOrganism();
128
129 // And just because these are so commonly used...
130 double GetGenotypeFitness();
131 double GetColonyFitness();
132
GetStateGridID()133 int GetStateGridID() const { return m_cur_sg; }
134 };
135
136
GetTestOrganism(int level)137 inline cOrganism* cCPUTestInfo::GetTestOrganism(int level)
138 {
139 assert(org_array[level] != NULL);
140 return org_array[level];
141 }
142
GetColonyOrganism()143 inline cOrganism* cCPUTestInfo::GetColonyOrganism()
144 {
145 const int depth_used = (depth_found == -1) ? 0 : depth_found;
146 assert(org_array[depth_used] != NULL);
147 return org_array[depth_used];
148 }
149
150 #endif
151