GEGELATI

Loading...
Searching...
No Matches
mapElitesArchive.h
1
2
3#ifndef MAP_ELITES_ARCHIVE_H
4#define MAP_ELITES_ARCHIVE_H
5
6#include <cmath>
7#include <fstream>
8#include <iostream>
9#include <string>
10#include <vector>
11
12#include "learn/evaluationResult.h"
13#include "tpg/tpgGraph.h"
14
15 namespace Selector {
16 namespace MapElites {
17
24 class MapElitesArchive
25 {
26 protected:
28 uint64_t nbBinPerDescriptor;
29
31 uint64_t nbDescriptors;
32
34 double minValue;
35
37 double maxValue;
38
40 std::vector<double> archiveLimits;
41
44 std::vector<std::pair<std::shared_ptr<Learn::EvaluationResult>,
45 const TPG::TPGVertex*>>
46 archive;
47
48 public:
57 MapElitesArchive(size_t nbBinPerDescriptor, size_t nbDescriptors,
58 double minValue, double maxValue)
59 : nbBinPerDescriptor{nbBinPerDescriptor},
60 nbDescriptors{nbDescriptors}, minValue{minValue},
61 maxValue{maxValue}
62 {
63
64 if (nbBinPerDescriptor > 0 && nbDescriptors > 0) {
65 archive.resize(std::pow(nbBinPerDescriptor, nbDescriptors));
66 }
67
68 for (size_t idx = 1; idx <= nbBinPerDescriptor; ++idx) {
69 archiveLimits.push_back((double)idx *
70 (maxValue - minValue) /
71 (double)nbBinPerDescriptor +
72 minValue);
73 }
74 }
75
79 uint64_t size() const;
80
84 std::pair<uint64_t, uint64_t> getDimensions() const;
85
89 std::vector<double> getArchiveLimits() const;
90
94 virtual const std::vector<
95 std::pair<std::shared_ptr<Learn::EvaluationResult>,
96 const TPG::TPGVertex*>>&
97 getAllArchive() const;
98
104 virtual const std::pair<std::shared_ptr<Learn::EvaluationResult>,
105 const TPG::TPGVertex*>&
106 getArchiveAt(const std::vector<uint64_t>& indices) const;
107
114 virtual const std::pair<std::shared_ptr<Learn::EvaluationResult>,
115 const TPG::TPGVertex*>&
116 getArchiveFromDescriptors(
117 const std::vector<double>& descriptors) const;
118
126 virtual void setArchiveAt(
127 const TPG::TPGVertex* vertex,
128 std::shared_ptr<Learn::EvaluationResult> eval,
129 const std::vector<uint64_t>& indices);
130
139 virtual void setArchiveFromDescriptors(
140 const TPG::TPGVertex* vertex,
141 std::shared_ptr<Learn::EvaluationResult> eval,
142 const std::vector<double>& descriptors);
143
149 virtual uint64_t getIndexArchive(double value) const;
150
157 virtual uint64_t computeLinearIndex(
158 const std::vector<uint64_t>& indices) const;
159
165 virtual std::vector<uint64_t> computeIndices(uint64_t index) const;
166
172 virtual bool containsRoot(const TPG::TPGVertex* root) const;
173
182 virtual void removeRootFromArchiveIfNotComplete(
183 const TPG::TPGVertex* root, size_t maxNbEvaluation);
184
192 virtual void removeRootFromArchive(const TPG::TPGVertex* root,
193 size_t maxNbEvaluation);
194
198 virtual std::set<const TPG::TPGVertex*> getVerticesInArchive()
199 const;
200 };
201
202 }; // namespace MapElites
203}; // namespace Selector
204
205#endif // MAP_ELITES_SELECTOR_H
Selector::MapElites::MapElitesArchive
Class representing a Map Elites archive.
Definition mapElitesArchive.h:25
Selector::MapElites::MapElitesArchive::minValue
double minValue
Minimum value for the descriptors.
Definition mapElitesArchive.h:34
Selector::MapElites::MapElitesArchive::getIndexArchive
virtual uint64_t getIndexArchive(double value) const
Get the index in one dimension of the archive from a value.
Definition mapElitesArchive.cpp:28
Selector::MapElites::MapElitesArchive::getDimensions
std::pair< uint64_t, uint64_t > getDimensions() const
Get the dimensions of the archive.
Definition mapElitesArchive.cpp:10
Selector::MapElites::MapElitesArchive::removeRootFromArchive
virtual void removeRootFromArchive(const TPG::TPGVertex *root, size_t maxNbEvaluation)
Remove a root TPGVertex from the archive.
Definition mapElitesArchive.cpp:130
Selector::MapElites::MapElitesArchive::computeIndices
virtual std::vector< uint64_t > computeIndices(uint64_t index) const
Compute the multi-dimensional indices from linear index.
Definition mapElitesArchive.cpp:52
Selector::MapElites::MapElitesArchive::maxValue
double maxValue
Maximum value for the descriptors.
Definition mapElitesArchive.h:37
Selector::MapElites::MapElitesArchive::archive
std::vector< std::pair< std::shared_ptr< Learn::EvaluationResult >, const TPG::TPGVertex * > > archive
Definition mapElitesArchive.h:46
Selector::MapElites::MapElitesArchive::computeLinearIndex
virtual uint64_t computeLinearIndex(const std::vector< uint64_t > &indices) const
Compute the linear index from multi-dimensional indices.
Definition mapElitesArchive.cpp:38
Selector::MapElites::MapElitesArchive::nbBinPerDescriptor
uint64_t nbBinPerDescriptor
Number of bins per descriptor.
Definition mapElitesArchive.h:28
Selector::MapElites::MapElitesArchive::removeRootFromArchiveIfNotComplete
virtual void removeRootFromArchiveIfNotComplete(const TPG::TPGVertex *root, size_t maxNbEvaluation)
Remove a root TPGVertex from the archive if its number of evaluation is below maxNbEvaluation.
Definition mapElitesArchive.cpp:115
Selector::MapElites::MapElitesArchive::getVerticesInArchive
virtual std::set< const TPG::TPGVertex * > getVerticesInArchive() const
Return a set with the current vectors in the archive.
Definition mapElitesArchive.cpp:143
Selector::MapElites::MapElitesArchive::setArchiveAt
virtual void setArchiveAt(const TPG::TPGVertex *vertex, std::shared_ptr< Learn::EvaluationResult > eval, const std::vector< uint64_t > &indices)
Set the archive content at given indices.
Definition mapElitesArchive.cpp:96
Selector::MapElites::MapElitesArchive::nbDescriptors
uint64_t nbDescriptors
Number of descriptors for this archive.
Definition mapElitesArchive.h:31
Selector::MapElites::MapElitesArchive::MapElitesArchive
MapElitesArchive(size_t nbBinPerDescriptor, size_t nbDescriptors, double minValue, double maxValue)
Constructor of the MapElitesArchive.
Definition mapElitesArchive.h:57
Selector::MapElites::MapElitesArchive::getArchiveLimits
std::vector< double > getArchiveLimits() const
get the archive limits
Definition mapElitesArchive.cpp:15
Selector::MapElites::MapElitesArchive::getAllArchive
virtual const std::vector< std::pair< std::shared_ptr< Learn::EvaluationResult >, const TPG::TPGVertex * > > & getAllArchive() const
Get all the archive content.
Definition mapElitesArchive.cpp:23
Selector::MapElites::MapElitesArchive::getArchiveFromDescriptors
virtual const std::pair< std::shared_ptr< Learn::EvaluationResult >, const TPG::TPGVertex * > & getArchiveFromDescriptors(const std::vector< double > &descriptors) const
Get the archive content at given descriptors.
Definition mapElitesArchive.cpp:65
Selector::MapElites::MapElitesArchive::size
uint64_t size() const
Get the size of the archive.
Definition mapElitesArchive.cpp:4
Selector::MapElites::MapElitesArchive::containsRoot
virtual bool containsRoot(const TPG::TPGVertex *root) const
Check if the archive contains a root TPGVertex.
Definition mapElitesArchive.cpp:103
Selector::MapElites::MapElitesArchive::archiveLimits
std::vector< double > archiveLimits
Limits of the bins for the descriptors.
Definition mapElitesArchive.h:40
Selector::MapElites::MapElitesArchive::getArchiveAt
virtual const std::pair< std::shared_ptr< Learn::EvaluationResult >, const TPG::TPGVertex * > & getArchiveAt(const std::vector< uint64_t > &indices) const
Get the archive content at given indices.
Definition mapElitesArchive.cpp:90
Selector::MapElites::MapElitesArchive::setArchiveFromDescriptors
virtual void setArchiveFromDescriptors(const TPG::TPGVertex *vertex, std::shared_ptr< Learn::EvaluationResult > eval, const std::vector< double > &descriptors)
Set the archive content at given descriptors.
Definition mapElitesArchive.cpp:76
TPG::TPGVertex
Abstract class representing the vertices of a TPGGraph.
Definition tpgVertex.h:55
Selector
Definition mapElitesArchiveLogger.h:45