Darwin Neuroevolution Framework
test_domain.h
1 // Copyright 2019 The Darwin Neuroevolution Framework Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #pragma once
16 
17 #include <core/darwin.h>
18 #include <core/properties.h>
19 
20 #include <limits>
21 using namespace std;
22 
23 namespace test_domain {
24 
26 struct Config : public core::PropertySet {
27  PROPERTY(inputs, int, 8, "Number of inputs");
28  PROPERTY(outputs, int, 3, "Number of outputs");
29 
30  PROPERTY(input_range, float, 10.0f, "The range of (random) input values");
31  PROPERTY(output_range,
32  float,
33  numeric_limits<float>::infinity(),
34  "The expected outputs range (checked at runtime)");
35 
36  PROPERTY(fitness_mean, float, 0.0f, "The mean of the fitness values distribution");
37  PROPERTY(fitness_stddev, float, 1.0f, "The stddev of the fitness values distribution");
38  PROPERTY(fitness_resolution, float, 0.01f, "The resolution of the fitness values");
39 
40  PROPERTY(eval_steps, int, 500, "Number of eval steps for each genotype");
41 };
42 
52 class TestDomain : public darwin::Domain {
53  public:
54  explicit TestDomain(const core::PropertySet& config);
55 
56  size_t inputs() const override;
57  size_t outputs() const override;
58 
59  bool evaluatePopulation(darwin::Population* population) const override;
60 
61  const Config& config() const { return config_; }
62 
63  private:
64  Config config_;
65 };
66 
67 class Factory : public darwin::DomainFactory {
68  unique_ptr<darwin::Domain> create(const core::PropertySet& config) override;
69  unique_ptr<core::PropertySet> defaultConfig(darwin::ComplexityHint hint) const override;
70 };
71 
72 inline void init() {
73  darwin::registry()->domains.add<Factory>("test_domain");
74 }
75 
76 } // namespace test_domain
ComplexityHint
A generic hint for the initial population & domain setup.
Definition: darwin.h:47
A population implementation encapsulates the fixed-size set of genotypes, together with the rules for...
Definition: darwin.h:161
Registry * registry()
Accessor to the Registry singleton.
Definition: darwin.h:295
STL namespace.
Definition: agent.cpp:21
Interface to the domain factory.
Definition: darwin.h:263
Domain: TestDomain.
Definition: test_domain.h:52
The foundation for data structures supporting runtime reflection.
Definition: properties.h:388
core::ImplementationsSet< DomainFactory > domains
Registered domains.
Definition: darwin.h:288
Interface to a domain implementation.
Definition: darwin.h:229
TestDomain configuration.
Definition: test_domain.h:26