Darwin Neuroevolution Framework
unicycle.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 namespace unicycle {
21 
23 struct Config : public core::PropertySet {
24  PROPERTY(gravity, float, 9.8f, "Gravitational acceleration");
25  PROPERTY(max_distance, float, 3.0f, "Maximum distance from the center");
26  PROPERTY(max_angle, float, 60.0f, "Maximum angle from vertical");
27  PROPERTY(max_initial_angle, float, 10.0f, "Maximum starting angle from vertical");
28  PROPERTY(pole_length, float, 1.5f, "Pole length");
29  PROPERTY(pole_density, float, 1.0f, "Pole density");
30  PROPERTY(wheel_radius, float, 0.2f, "Wheel size (radius)");
31  PROPERTY(wheel_density, float, 1.0f, "Wheel density");
32  PROPERTY(wheel_friction, float, 10.0f, "Wheel friction");
33  PROPERTY(max_torque, float, 1.0f, "Maximum torque which can be applied to the wheel");
34 
35  PROPERTY(input_pole_angle, bool, true, "Use the pole angle as input");
36  PROPERTY(input_angular_velocity, bool, true, "Use the angular velocity as input");
37  PROPERTY(input_wheel_distance, bool, true, "Use the wheel distance as input");
38  PROPERTY(input_wheel_velocity, bool, true, "Use the wheel linear velocity as input");
39  PROPERTY(input_distance_from_target, bool, true, "Distance from target position");
40 
41  PROPERTY(test_worlds, int, 5, "Number of test worlds per generation");
42  PROPERTY(max_steps, int, 1000, "Maximum number of steps per episode");
43 
44  PROPERTY(discrete_controls,
45  bool,
46  false,
47  "Force the actuator force to fixed +/-discrete_force_magnitude");
48 
50  float,
51  0.5f,
52  "The fixed force magnitude used if discrete_controls is true");
53 };
54 
102 class Unicycle : public darwin::Domain {
103  public:
104  explicit Unicycle(const core::PropertySet& config);
105 
106  size_t inputs() const override;
107  size_t outputs() const override;
108 
109  bool evaluatePopulation(darwin::Population* population) const override;
110 
111  const Config& config() const { return config_; }
112 
113  float randomInitialAngle() const;
114  float randomTargetPosition() const;
115 
116  private:
117  void validateConfiguration();
118 
119  private:
120  Config config_;
121 };
122 
123 class Factory : public darwin::DomainFactory {
124  unique_ptr<darwin::Domain> create(const core::PropertySet& config) override;
125  unique_ptr<core::PropertySet> defaultConfig(darwin::ComplexityHint hint) const override;
126 };
127 
128 inline void init() {
129  darwin::registry()->domains.add<Factory>("unicycle");
130 }
131 
132 } // namespace unicycle
size_t inputs() const override
Number of inputs to a Brain.
Definition: unicycle.cpp:34
Definition: agent.cpp:18
bool discrete_controls
"Force the actuator force to fixed +/-discrete_force_magnitude"
Definition: unicycle.h:47
bool input_wheel_velocity
"Use the wheel linear velocity as input"
Definition: unicycle.h:38
ComplexityHint
A generic hint for the initial population & domain setup.
Definition: darwin.h:47
float max_angle
"Maximum angle from vertical"
Definition: unicycle.h:26
A population implementation encapsulates the fixed-size set of genotypes, together with the rules for...
Definition: darwin.h:161
float pole_density
"Pole density"
Definition: unicycle.h:29
float wheel_friction
"Wheel friction"
Definition: unicycle.h:32
bool input_distance_from_target
"Distance from target position"
Definition: unicycle.h:39
Registry * registry()
Accessor to the Registry singleton.
Definition: darwin.h:295
int test_worlds
"Number of test worlds per generation"
Definition: unicycle.h:41
bool input_angular_velocity
"Use the angular velocity as input"
Definition: unicycle.h:36
bool input_pole_angle
"Use the pole angle as input"
Definition: unicycle.h:35
Interface to the domain factory.
Definition: darwin.h:263
float max_torque
"Maximum torque which can be applied to the wheel"
Definition: unicycle.h:33
Unicycle domain configuration.
Definition: unicycle.h:23
float discrete_torque_magnitude
"The fixed force magnitude used if discrete_controls is true"
Definition: unicycle.h:52
float wheel_density
"Wheel density"
Definition: unicycle.h:31
float max_initial_angle
"Maximum starting angle from vertical"
Definition: unicycle.h:27
float gravity
"Gravitational acceleration"
Definition: unicycle.h:24
The foundation for data structures supporting runtime reflection.
Definition: properties.h:388
bool evaluatePopulation(darwin::Population *population) const override
Assigns fitness values to every genotype.
Definition: unicycle.cpp:42
core::ImplementationsSet< DomainFactory > domains
Registered domains.
Definition: darwin.h:288
Interface to a domain implementation.
Definition: darwin.h:229
bool input_wheel_distance
"Use the wheel distance as input"
Definition: unicycle.h:37
float pole_length
"Pole length"
Definition: unicycle.h:28
int max_steps
"Maximum number of steps per episode"
Definition: unicycle.h:42
Domain: Unicycle.
Definition: unicycle.h:102
float wheel_radius
"Wheel size (radius)"
Definition: unicycle.h:30
float max_distance
"Maximum distance from the center"
Definition: unicycle.h:25
size_t outputs() const override
Number of outputs from a Brain.
Definition: unicycle.cpp:38