17 #include "ann_utils.h" 20 #include "properties.h" 21 #include "stringify.h" 24 #include <third_party/json/json.h> 28 #include <condition_variable> 31 #include <initializer_list> 53 inline auto customStringify(core::TypeTag<ComplexityHint>) {
55 { ComplexityHint::Minimal,
"minimal" },
56 { ComplexityHint::Balanced,
"balanced" },
57 { ComplexityHint::Extra,
"extra" },
71 virtual ~
Brain() =
default;
74 virtual void setInput(
int index,
float value) = 0;
78 virtual float output(
int index)
const = 0;
81 virtual void think() = 0;
85 virtual void resetState() = 0;
102 Genealogy(
const string& genetic_operator, initializer_list<int> parents)
103 : genetic_operator(genetic_operator), parents(parents) {}
106 genetic_operator.clear();
138 virtual unique_ptr<Brain> grow()
const = 0;
141 virtual unique_ptr<Genotype> clone()
const = 0;
144 virtual json save()
const = 0;
147 virtual void load(
const json& json_obj) = 0;
149 virtual void reset() {
167 virtual size_t size()
const = 0;
170 virtual Genotype* genotype(
size_t index) = 0;
173 virtual const Genotype* genotype(
size_t index)
const = 0;
181 virtual vector<size_t> rankingIndex()
const = 0;
184 virtual int generation()
const = 0;
187 virtual void createPrimordialGeneration(
int population_size) = 0;
196 virtual void createNextGeneration() = 0;
200 const Genotype* operator[](
size_t index)
const {
return genotype(index); }
210 const Domain& domain) = 0;
213 virtual unique_ptr<core::PropertySet> defaultConfig(
ComplexityHint hint)
const = 0;
232 virtual ~
Domain() =
default;
235 virtual size_t inputs()
const = 0;
238 virtual size_t outputs()
const = 0;
252 virtual bool evaluatePopulation(
Population* population)
const = 0;
257 [maybe_unused]]
const Genotype* genotype)
const {
269 virtual unique_ptr<core::PropertySet> defaultConfig(
ComplexityHint hint)
const = 0;
279 virtual QWidget* newSandboxWindow() = 0;
305 PROPERTY(population_size,
int, 5000,
"Population size");
307 PROPERTY(population_name,
string,
"",
"Population name");
308 PROPERTY(domain_name,
string,
"",
"Domain name");
310 PROPERTY(population_hint,
312 ComplexityHint::Balanced,
313 "Population complexity hint");
315 PROPERTY(domain_hint,
317 ComplexityHint::Balanced,
318 "Domain complexity hint");
334 const optional<db::RowId>& base_variation_id,
341 const optional<string>&
name()
const {
return name_; }
357 const core::PropertySet* populationConfig()
const {
return population_config_.get(); }
386 void prepareForEvolution();
392 void basicSetup(
const optional<string>& name,
const ExperimentSetup& setup);
393 void loadLatestVariation();
396 optional<string> name_;
400 unique_ptr<core::PropertySet> population_config_;
401 unique_ptr<core::PropertySet> domain_config_;
402 unique_ptr<core::PropertySet> core_config_;
410 unique_ptr<DbExperiment> db_experiment_;
411 unique_ptr<DbExperimentVariation> db_variation_;
414 bool modified_ =
false;
Support for registering populations and domains.
Definition: registry.cpp:37
The interface to the Phenotype
Definition: darwin.h:69
Interface to a domain UI factory.
Definition: darwin.h:276
ComplexityHint
A generic hint for the initial population & domain setup.
Definition: darwin.h:47
A set of instances implementing common interface (primarily intended to support registering named fac...
Definition: modules.h:63
A population implementation encapsulates the fixed-size set of genotypes, together with the rules for...
Definition: darwin.h:161
best guess for the ideal performance/results trade-offs
An experiment configuration.
Definition: darwin.h:304
core::ImplementationsSet< DomainUiFactory > domains_ui
Registered domains UIs.
Definition: darwin.h:291
The persistent storage for all the experiments and variations.
Definition: universe.h:111
core::PropertySet * domainConfig()
Domain specific configuration.
Definition: darwin.h:360
int64_t RowId
Represents the ID of a row in the database.
Definition: database.h:44
The available domains and populations.
Definition: darwin.h:283
const ExperimentSetup * setup() const
The experiment's setup values.
Definition: darwin.h:344
bare minimum, fast but poor results (mostly useful for testing)
DomainFactory * domainFactory() const
Accessor to the DomainFactory for the experiment's domain.
Definition: darwin.h:350
void setModified(bool modified)
Update the configuration modification flag.
Definition: darwin.h:382
core::PropertySet * populationConfig()
Population specific configuration.
Definition: darwin.h:356
Root of the polymorphic factories.
Definition: modules.h:92
Universe * universe() const
The associated Darwin Universe.
Definition: darwin.h:368
Models the genealogy information of a genotype.
Definition: darwin.h:93
Interface to the domain factory.
Definition: darwin.h:263
vector< int > parents
The rank indexes of the parents from the previous generation.
Definition: darwin.h:98
const optional< string > & name() const
The experiment's name.
Definition: darwin.h:341
might produce more sophisticated solutions, but very slow
Encapsulates the runtime experiment state.
Definition: darwin.h:328
The foundation for data structures supporting runtime reflection.
Definition: properties.h:388
DomainUiFactory * domainUiFactory() const
Accessor to the DomainUiFactory for the experiment's domain UI.
Definition: darwin.h:353
Key Darwin Neuroevolution Framework interfaces.
Classes derived from this are not copyable or movable.
Definition: utils.h:69
Genotype * operator[](size_t index)
Array subscript operator (required for pp::for_each)
Definition: darwin.h:199
core::ImplementationsSet< PopulationFactory > populations
Registered populations.
Definition: darwin.h:285
core::ImplementationsSet< DomainFactory > domains
Registered domains.
Definition: darwin.h:288
Interface to a domain implementation.
Definition: darwin.h:229
Genealogy genealogy
Genealogy information.
Definition: darwin.h:132
virtual unique_ptr< core::PropertySet > calibrateGenotype([[maybe_unused]] const Genotype *genotype) const
Optional: additional fitness metrics (normally not used in the population evaluation, ie a test set)
Definition: darwin.h:256
PopulationFactory * populationFactory() const
Accessor to the PopulationFactory for the experiment's population.
Definition: darwin.h:347
Handles types with a fixed, known set of values (enumerations for example)
Definition: stringify.h:85
core::PropertySet * coreConfig()
Core configuration values.
Definition: darwin.h:364
Universe representation of an experiment.
Definition: universe.h:44
string genetic_operator
Name of the genetic operator used to create the genotype from its parents.
Definition: darwin.h:95
const Stringify< T > * stringify()
Returns the stringifier for type T.
Definition: stringify.h:166
The interface to the population-specific "genetic material", the Genotype
Definition: darwin.h:126
Interface to a population factory.
Definition: darwin.h:206