GEGELATI

Loading...
Searching...
No Matches
archive.h
1
37#ifndef ARCHIVE_H
38#define ARCHIVE_H
39
40#include <deque>
41#include <map>
42#include <memory>
43#include <random>
44
45#include "data/dataHandler.h"
46#include "mutator/rng.h"
47#include "program/program.h"
48
57 typedef struct ArchiveRecording
58{
60 const Program::Program* const prog;
61
63 const size_t dataHash;
64
67 const double result;
68} ArchiveRecording;
69
79 class Archive
80{
81 protected:
83 const size_t maxSize;
84
96 Mutator::RNG rng;
97
106 std::map<size_t,
107 std::vector<std::reference_wrapper<const Data::DataHandler>>>
108 dataHandlers;
109
120 std::map<const Program::Program*, std::deque<ArchiveRecording>>
121 recordingsPerProgram;
122
124 std::deque<ArchiveRecording> recordings;
125
129 const double archivingProbability;
130
131 public:
140 Archive(size_t size = 50, double archivingProbability = 1.0,
141 size_t initialSeed = 0)
142 : archivingProbability{archivingProbability}, maxSize{size},
143 recordings(), rng(initialSeed){};
144
151 Archive(const Archive& other) = delete;
152
159 ~Archive();
160
169 static size_t getCombinedHash(
170 const std::vector<std::reference_wrapper<const Data::DataHandler>>&
171 dHandler);
172
180 const ArchiveRecording& at(uint64_t n) const;
181
187 void setRandomSeed(size_t newSeed);
188
210 virtual void addRecording(
211 const Program::Program* const program,
212 const std::vector<std::reference_wrapper<const Data::DataHandler>>&
213 dHandler,
214 double result, bool forced = false);
215
223 bool hasDataHandlers(const size_t& hash) const;
224
234 virtual bool areProgramResultsUnique(
235 const std::map<size_t, double>& hashesAndResults,
236 double tau = 1e-4) const;
237
243 size_t getNbRecordings() const;
244
251 size_t getNbDataHandlers() const;
252
262 const std::map<
263 size_t, std::vector<std::reference_wrapper<const Data::DataHandler>>>&
264 getDataHandlers() const;
265
269 void clear();
270};
271
272#endif
Archive
Definition archive.h:80
Archive::hasDataHandlers
bool hasDataHandlers(const size_t &hash) const
Check whether the given hash is already in the archive.
Definition archive.cpp:150
Archive::~Archive
~Archive()
Destructor of the class.
Definition archive.cpp:40
Archive::getNbRecordings
size_t getNbRecordings() const
Get the number of recordings currently held in the Archive.
Definition archive.cpp:199
Archive::recordingsPerProgram
std::map< const Program::Program *, std::deque< ArchiveRecording > > recordingsPerProgram
Map storing the Program pointers referenced in recordings the associated recording.
Definition archive.h:121
Archive::getCombinedHash
static size_t getCombinedHash(const std::vector< std::reference_wrapper< const Data::DataHandler > > &dHandler)
Combien the hash of a set of dataHandlers into a single one.
Definition archive.cpp:50
Archive::dataHandlers
std::map< size_t, std::vector< std::reference_wrapper< const Data::DataHandler > > > dataHandlers
Storage for DataHandler copies used in recordings.
Definition archive.h:108
Archive::setRandomSeed
void setRandomSeed(size_t newSeed)
Set a new seed for the randomEngine.
Definition archive.cpp:67
Archive::archivingProbability
const double archivingProbability
Probability of adding any program execution to the archive.
Definition archive.h:129
Archive::addRecording
virtual void addRecording(const Program::Program *const program, const std::vector< std::reference_wrapper< const Data::DataHandler > > &dHandler, double result, bool forced=false)
Add a new recording to the Archive.
Definition archive.cpp:72
Archive::areProgramResultsUnique
virtual bool areProgramResultsUnique(const std::map< size_t, double > &hashesAndResults, double tau=1e-4) const
Definition archive.cpp:155
Archive::Archive
Archive(const Archive &other)=delete
Archive::rng
Mutator::RNG rng
Randomness engine for archiving.
Definition archive.h:96
Archive::Archive
Archive(size_t size=50, double archivingProbability=1.0, size_t initialSeed=0)
Main constructor for Archive.
Definition archive.h:140
Archive::maxSize
const size_t maxSize
Maximum number of recordings held in the Archive.
Definition archive.h:83
Archive::at
const ArchiveRecording & at(uint64_t n) const
Access the nth ArchiveRecording within the Archive.
Definition archive.cpp:62
Archive::getDataHandlers
const std::map< size_t, std::vector< std::reference_wrapper< const Data::DataHandler > > > & getDataHandlers() const
Const accessor to the dataHandlers attribute.
Definition archive.cpp:211
Archive::getNbDataHandlers
size_t getNbDataHandlers() const
Get the number of different vector of DataHandler associated to recordings.
Definition archive.cpp:204
Archive::clear
void clear()
Clear all content from the Archive.
Definition archive.cpp:216
Archive::recordings
std::deque< ArchiveRecording > recordings
Recordings of the Archive.
Definition archive.h:124
Mutator::RNG
Definition rng.h:52
Program::Program
The Program class contains a list of program lines that can be executed within a well defined Environ...
Definition program.h:57
ArchiveRecording
Class used to store one recording of an Archive.
Definition archive.h:58
ArchiveRecording::dataHash
const size_t dataHash
Hash of the set of DataHandler for this recording.
Definition archive.h:63
ArchiveRecording::result
const double result
Definition archive.h:67
ArchiveRecording::prog
const Program::Program *const prog
Pointer to the Program. This pointer may point to a freed program.
Definition archive.h:60