5 #ifndef DIGNEA_EIGBUILDER_H
6 #define DIGNEA_EIGBUILDER_H
8 #include <dignea/factories/CXFactory.h>
9 #include <dignea/factories/MutFactory.h>
17 #include <dignea/searches/NSFeatures.h>
18 #include <dignea/searches/NSPerformance.h>
24 enum class GeneratorType { LinearScaled, MultiObjective,
MapElites };
34 template <
typename IP,
typename IS,
typename OP,
typename S>
36 using EA = unique_ptr<AbstractEA<S>>;
43 operator unique_ptr<EIG<IP, IS, OP, S>>();
62 const float &finalThresh,
const int k,
90 void newCompSet() { compSet++; }
93 unique_ptr<EIG<IP, IS, OP, S>> generator;
97 static int MUST_COMPS;
100 template <
typename IP,
typename IS,
typename OP,
typename S>
112 template <
typename IP,
typename IS,
typename OP,
typename S>
126 template <
typename IP,
typename IS,
typename OP,
typename S>
128 : compSet(0), problemSet(false), type(t) {
131 case GeneratorType::LinearScaled:
132 this->generator = make_unique<EIG<IP, IS, OP, S>>();
137 case GeneratorType::MapElites:
139 this->generator = make_unique<MapElites<IP, IS, OP, S>>();
142 std::cerr <<
"Unknown type in EIGBuilder. LinearScaled algorithm "
145 this->generator = make_unique<EIG<IP, IS, OP, S>>();
161 template <
typename IP,
typename IS,
typename OP,
typename S>
163 if (!this->problemSet) {
164 std::cerr <<
"EIG created but not problem set. "
165 "Remember to set a problem before calling run"
168 if (compSet >= MUST_COMPS) {
169 return move(this->generator);
172 "No all the components are set. EIG requires: "
173 "configurations, evaluation method,"
174 "Novelty Search configuration, "
175 "mutation operator, crSsover operator, "
176 "selection operator, mutation rate, "
177 "crSsover rate, population size, "
178 "max generations and repetitions");
192 template <
typename IP,
typename IS,
typename OP,
typename S>
194 unique_ptr<IP> problem) {
195 this->generator->setInstanceProblem(move(problem));
197 this->problemSet =
true;
213 template <
typename IP,
typename IS,
typename OP,
typename S>
216 this->generator->setWeightedFunction(fW, nW);
233 template <
typename IP,
typename IS,
typename OP,
typename S>
235 vector<EA> &configs) {
236 this->generator->setPortfolio(configs);
257 template <
typename IP,
typename IS,
typename OP,
typename S>
260 const float &finalThresh,
const int k,
bool warmUp) {
262 auto ns = factory.
create(nsType, move(dist), thres, finalThresh, k, warmUp);
263 this->generator->setNoveltySearch(move(ns));
279 template <
typename IP,
typename IS,
typename OP,
typename S>
281 unique_ptr<InstanceFitness> evalMethod) {
282 this->generator->setInstanceFitness(move(evalMethod));
298 template <
typename IP,
typename IS,
typename OP,
typename S>
301 this->generator->setRepetitions(reps);
317 template <
typename IP,
typename IS,
typename OP,
typename S>
320 auto cx = factory.
create(cxType);
321 this->generator->setCrossover(move(cx));
336 template <
typename IP,
typename IS,
typename OP,
typename S>
338 const float &crSsRate) {
339 this->generator->setCrossoverRate(crSsRate);
355 template <
typename IP,
typename IS,
typename OP,
typename S>
359 auto mut = factory.
create(mutation);
360 this->generator->setMutation(move(mut));
375 template <
typename IP,
typename IS,
typename OP,
typename S>
377 const float &mutRate) {
378 this->generator->setMutationRate(mutRate);
394 template <
typename IP,
typename IS,
typename OP,
typename S>
398 auto sel = factory.
create(selType);
399 this->generator->setSelection(move(sel));
404 template <
typename IP,
typename IS,
typename OP,
typename S>
406 ReplacementTypes repType) {
408 auto rep = factory.
create(repType);
409 this->generator->setReplacement(move(rep));
425 template <
typename IP,
typename IS,
typename OP,
typename S>
427 const int &popsize) {
428 this->generator->setPopulationSize(popsize);
445 template <
typename IP,
typename IS,
typename OP,
typename S>
447 const int &generations) {
448 this->generator->setMaxEvaluations(generations);
463 template <
typename IP,
typename IS,
typename OP,
typename S>
466 if (this->type == GeneratorType::MapElites) {
468 ->setFeaturesInfo(f);
CXType
Types of Crossover Operators implemented in dignea.
Definition: CrossoverTypes.h:23
std::map< int, FeatureInfo > Features
Features defines the information a feature.
Definition: MapElites.h:46
MutType
Type of Mutation Operators implemented in dignea.
Definition: MutationTypes.h:22
NSType
Type of Novelty Search algorithms available in dignea at the moment.
Definition: NSTypes.h:23
SelType
Types of Selection Operators implemented in dignea.
Definition: SelectionTypes.h:19
Crossover factory which allows the user to create Crossover operators easily.
Definition: CXFactory.h:19
unique_ptr< Crossover< S > > create(CXType type)
Creates a unique pointer to a Crossover Operator of the given type. Variants are available at CXType.
Definition: CXFactory.h:39
Class which represents a Builder for the EIG. Creates a EIG step by step from all the different compo...
Definition: EIGBuilder.h:35
EIGBuilder< IP, IS, OP, S > & weights(const float &fW, const float &mW)
Sets the weights that will be used in the Weighted Fitness Function. Notice that fW + nW = 1....
Definition: EIGBuilder.h:214
EIGBuilder< IP, IS, OP, S > & selection(SelType selType)
Defines the selection operator to use. Variants are available at SelType.
Definition: EIGBuilder.h:395
EIGBuilder< IP, IS, OP, S > & withSearch(NSType nsType, unique_ptr< Distance< float >> dist, const float &thres, const float &finalThresh, const int k, bool warmUp=false)
Novelty search configuration for the EIG. Here we define the Novelty Approach (Features,...
Definition: EIGBuilder.h:258
EIGBuilder< IP, IS, OP, S > & withCrossRate(const float &crSsRate)
Defines the crossover rate to apply the crossover operator.
Definition: EIGBuilder.h:337
EIGBuilder< IP, IS, OP, S > & mutation(MutType mutation)
Defines the mutation operator type to use with this Genetic Algorithm. Variants are available at MutT...
Definition: EIGBuilder.h:356
EIGBuilder< IP, IS, OP, S > & repeating(const int &reps)
Defines how many repetitions the algorithms in the portfolio must perform over each instance in each ...
Definition: EIGBuilder.h:299
static EIGBuilder< IP, IS, OP, S > create(GeneratorType type)
Creates a EIGBuilder object.
Definition: EIGBuilder.h:113
EIGBuilder< IP, IS, OP, S > & evalWith(unique_ptr< InstanceFitness > evalMethod)
Evaluation approach for generating instances. The instances must be considered easy to solve for the ...
Definition: EIGBuilder.h:280
EIGBuilder< IP, IS, OP, S > & runDuring(const int &generations)
Defines the number of generations to perform by EIG. Notice that the EIG works by generations instead...
Definition: EIGBuilder.h:446
EIGBuilder< IP, IS, OP, S > & toSolve(unique_ptr< IP > problem)
Defines the AbstractDomain to solve.
Definition: EIGBuilder.h:193
EIGBuilder< IP, IS, OP, S > & portfolio(vector< EA > &configs)
Defines the portfolio of solvers to evaluate the instances during the evolutionary process....
Definition: EIGBuilder.h:234
EIGBuilder< IP, IS, OP, S > & populationOf(const int &popsize)
Defines the population of instances to use. This is the number of instances that the EIG will be evol...
Definition: EIGBuilder.h:426
EIGBuilder< IP, IS, OP, S > & setFeatures(const Features &f)
Defines the Feature information for MapElites.
Definition: EIGBuilder.h:464
EIGBuilder< IP, IS, OP, S > & withMutRate(const float &mutRate)
Defines the mutation rate to apply in the mutation operator.
Definition: EIGBuilder.h:376
EIGBuilder< IP, IS, OP, S > & with()
This method only returns *this and it is used to make the building process more natural....
Definition: EIGBuilder.h:55
EIGBuilder< IP, IS, OP, S > & crossover(CXType cxType)
Defines the crossover operator type to use with this Genetic Algorithm. Variants are available at CXT...
Definition: EIGBuilder.h:318
Instance Generation Algorithm. Known as Meta-Evolutionary Algorithm (MapElites). This algorithm uses ...
Definition: MapElites.h:66
Mutation factory which allows the user to create Mutation Operators easily.
Definition: MutFactory.h:23
unique_ptr< Mutation< S > > create(MutType type)
Creates a unique pointer to a Mutation Operator of type.
Definition: MutFactory.h:45
Novelty Search factory which allows the user to create Novelty Search algorithms on the go.
Definition: NSFactory.h:29
unique_ptr< NoveltySearch< S > > create(NSType type, unique_ptr< Distance< float >> dist, const float &thres, const float &finalThresh, const int k, bool warmUp)
Creates a unique pointer to a Novelty Search algorithm of given type. Variants are available at NSTyp...
Definition: NSFactory.h:64
Replacement Factory which allows the user to easily create Replacement Operators.
Definition: RepFactory.h:29
unique_ptr< Replacement< S > > create(ReplacementTypes type)
Creates a unique pointer to a Selection Operator of type.
Definition: RepFactory.h:51
Selection factory which allows the user to create Selection Operators easily.
Definition: SelFactory.h:25
unique_ptr< Selection< S > > create(SelType type)
Creates a unique pointer to a Selection Operator of type.
Definition: SelFactory.h:41