GEGELATI
Loading...
Searching...
No Matches
environment.h
1
38#ifndef ENVIRONMENT_H
39#define ENVIRONMENT_H
40
41#include <cmath>
42#include <iostream>
43
44#include "data/constantHandler.h"
45#include "data/dataHandler.h"
46#include "data/primitiveTypeArray.h"
47#include "instructions/instruction.h"
48#include "instructions/set.h"
49#include "learn/learningParameters.h"
50
52typedef struct LineSize
53{
66
68 operator size_t() const
69 {
70 return totalNbBits;
71 }
72} LineSize;
73
86{
87 protected:
90
93
95 const std::vector<std::reference_wrapper<const Data::DataHandler>>
97
99 const size_t nbRegisters;
100
102 const size_t nbConstants;
103
105 std::vector<std::reference_wrapper<const Data::DataHandler>>
107
110
113
116
118 const size_t nbInstructions;
119
121 const size_t maxNbOperands;
122
124 const size_t nbDataSources;
125
128
131
142 static size_t computeLargestAddressSpace(
143 const size_t nbRegisters, const size_t nbConstants,
144 const std::vector<std::reference_wrapper<const Data::DataHandler>>&
145 dHandlers);
146
165 static const LineSize computeLineSize(const Environment& env);
166
179 const Instructions::Set& iSet, const size_t nbRegisters,
180 const size_t nbConstants,
181 const std::vector<std::reference_wrapper<const Data::DataHandler>>&
183
184 private:
186 Environment() = delete;
187
188 public:
205 const Instructions::Set& iSet, const Learn::LearningParameters& p,
206 const std::vector<std::reference_wrapper<const Data::DataHandler>>&
207 dHandlers,
208 size_t nbContinuousAct = 0)
210 p.nbProgramConstant, dHandlers)},
211 params{p}, dataSources{dHandlers}, nbRegisters{p.nbRegisters},
212 nbConstants{p.nbProgramConstant}, fakeRegisters(p.nbRegisters),
213 fakeConstants(p.nbProgramConstant),
216 nbContinuousActions{nbContinuousAct},
218 dHandlers.size() +
219 (p.nbProgramConstant > 0
220 ? 2
221 : 1)}, // if Constants are used, we need an extra
222 // datasource to store them in the environment
224 p.nbRegisters, p.nbProgramConstant, dHandlers)},
226 {
227 this->fakeDataSources.push_back(
228 (std::reference_wrapper<const Data::DataHandler>)this
229 ->fakeRegisters);
230
231 if (p.nbProgramConstant > 0) {
232 this->fakeDataSources.push_back(this->fakeConstants);
233 }
234
235 for (auto& elem : this->dataSources)
236 this->fakeDataSources.push_back(elem);
237 };
238
243
249 size_t getNbContinuousActions() const;
250
257 size_t getNbInstructions() const;
258
265 size_t getMaxNbOperands() const;
266
272 size_t getNbDataSources() const;
273
279 size_t getLargestAddressSpace() const;
280
286 const LineSize& getLineSize() const;
287
294 const std::vector<std::reference_wrapper<const Data::DataHandler>>&
295 getDataSources() const;
296
305 const std::vector<std::reference_wrapper<const Data::DataHandler>>&
306 getFakeDataSources() const;
307
315};
316
317#endif
Data::DataHandler used by Program::Program to handle their set of Constant values.
Definition constantHandler.h:56
DataHandler for 2D arrays of primitive types.
Definition primitiveTypeArray2D.h:69
The Environment class contains all information needed to execute a Program.
Definition environment.h:86
const std::vector< std::reference_wrapper< const Data::DataHandler > > & getDataSources() const
Get the DataHandler of the Environment.
Definition environment.cpp:204
const Data::PrimitiveTypeArray< double > fakeRegisters
DataHandler whost type corresponds to registers.
Definition environment.h:109
size_t getLargestAddressSpace() const
Get the size of the largestAddressSpace of DataHandlers.
Definition environment.cpp:193
const Learn::LearningParameters & getParams() const
Get the instance of parameters used.
Definition environment.cpp:168
const LineSize & getLineSize() const
Get the size of the line for this environment (in bits).
Definition environment.cpp:198
const Learn::LearningParameters params
Parameters for the learning process.
Definition environment.h:92
const Data::ConstantHandler fakeConstants
DataHandler whost type corresponds to the programs constants.
Definition environment.h:112
const size_t nbContinuousActions
Number of continuous actions.
Definition environment.h:115
const LineSize lineSize
Size of lines within this Environment.
Definition environment.h:130
const std::vector< std::reference_wrapper< const Data::DataHandler > > dataSources
List of DataHandler that can be accessed within this Environment.
Definition environment.h:96
size_t getNbInstructions() const
Get the size of the number of Instruction within the Instructions::Set.
Definition environment.cpp:178
size_t getNbContinuousActions() const
Get the number of continuous actions.
Definition environment.cpp:173
const size_t nbRegisters
Number of registers.
Definition environment.h:99
std::vector< std::reference_wrapper< const Data::DataHandler > > fakeDataSources
Vector of DataHandlers containing the environment's dataSources.
Definition environment.h:106
const size_t maxNbOperands
Maxmimum number of operands of the Instructions::Set.
Definition environment.h:121
static Instructions::Set filterInstructionSet(const Instructions::Set &iSet, const size_t nbRegisters, const size_t nbConstants, const std::vector< std::reference_wrapper< const Data::DataHandler > > &dataSources)
Filter an InstructionSet to keep only Instruction with operand types provided by the given DataHandle...
Definition environment.cpp:56
const size_t nbConstants
Number of constants.
Definition environment.h:102
const std::vector< std::reference_wrapper< const Data::DataHandler > > & getFakeDataSources() const
Definition environment.cpp:210
size_t getMaxNbOperands() const
Get the size of the maximum number of operands of Instructions::Set.
Definition environment.cpp:183
const Instructions::Set instructionSet
Set of Instruction used by Program running within this Environment.
Definition environment.h:89
size_t getNbDataSources() const
Get the size of the number of DataHandlers.
Definition environment.cpp:188
Environment(const Instructions::Set &iSet, const Learn::LearningParameters &p, const std::vector< std::reference_wrapper< const Data::DataHandler > > &dHandlers, size_t nbContinuousAct=0)
Constructor with initialization of all attributes.
Definition environment.h:204
const size_t nbDataSources
Number of DataHandler from which data can be accessed.
Definition environment.h:124
const size_t largestAddressSpace
Size of the largestAddressSpace of DataHandlers.
Definition environment.h:127
const size_t nbInstructions
Number of Instruction in the Instructions::Set.
Definition environment.h:118
const Instructions::Set & getInstructionSet() const
Get the Instruction Set of the Environment.
Definition environment.cpp:215
static const LineSize computeLineSize(const Environment &env)
Static method used to compute the size of Program lines based on information from the Enviroment.
Definition environment.cpp:125
static size_t computeLargestAddressSpace(const size_t nbRegisters, const size_t nbConstants, const std::vector< std::reference_wrapper< const Data::DataHandler > > &dHandlers)
Static method used when constructing a new Environment to compute the largest AddressSpace of a set o...
Definition environment.cpp:43
Class for storing a set of Instruction.
Definition set.h:55
Structure for simplifying the transmission of LearningParameters to functions.
Definition learningParameters.h:55
size_t nbProgramConstant
Number of Constants available in a program.
Definition learningParameters.h:143
LineSize structure to be used within the Environment.
Definition environment.h:53
size_t nbInstructionBits
Number of bits used to encode the instructionIndex.
Definition environment.h:55
size_t nbOperandLocationBits
Number of bits used for each operand pair, to encode location.
Definition environment.h:63
size_t nbDestinationBits
Number of bits used to encode the destinationIndex.
Definition environment.h:57
size_t nbOperandsBits
Total number of bits used to encode the operands info.
Definition environment.h:59
size_t nbOperandDataSourceIndexBits
Number of bits used for each operand pair, to encode dataSourceIndex.
Definition environment.h:61
size_t totalNbBits
Total number of bits to encode a program line.
Definition environment.h:65