Darwin Neuroevolution Framework
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 #include <core/sim/drone.h>
20 
21 #include <third_party/box2d/box2d.h>
22 
23 namespace drone_track {
24 
26 struct Config : public core::PropertySet {
27  PROPERTY(drone_radius, float, 0.3f, "Drone size");
28  PROPERTY(max_move_force, float, 10.0f, "Maximum force used to move the drone");
29  PROPERTY(max_lateral_force, float, 10.0f, "Maximum lateral force");
30  PROPERTY(max_rotate_torque, float, 0.5f, "Maximum torque used to rotate the drone");
31  PROPERTY(drone_friction, float, 0.1f, "Drone friction");
32 
33  PROPERTY(camera_fov, float, 60, "Camera field of view (FOV)");
34  PROPERTY(camera_resolution, int, 64, "Camera resolution");
35  PROPERTY(camera_depth, bool, false, "Use camera depth channel");
36 
37  PROPERTY(touch_sensor, bool, false, "Use the drone's touch sensor");
38  PROPERTY(touch_resolution, int, 8, "Touch sensor resolution");
39  PROPERTY(accelerometer, bool, false, "Use the drone's accelerometer");
40  PROPERTY(compass, bool, false, "Use the drone's compass");
41 
42  PROPERTY(track_width, float, 1.8f, "Track width");
43  PROPERTY(track_complexity, int, 20, "The approximate number of turns");
44  PROPERTY(track_resolution, int, 500, "Number of track segments");
45  PROPERTY(curb_width, float, 0.1f, "Curb width");
46  PROPERTY(curb_friction, float, 0.5f, "Track's curb friction");
47  PROPERTY(track_gates, bool, true, "Generate track gates");
48  PROPERTY(solid_gate_posts, bool, true, "Solid gate posts");
49 
50  PROPERTY(test_worlds, int, 3, "Number of test worlds per generation");
51  PROPERTY(max_steps, int, 1000, "Maximum number of steps per episode");
52 };
53 
74 class DroneTrack : public darwin::Domain {
75  public:
76  explicit DroneTrack(const core::PropertySet& config);
77 
78  size_t inputs() const override;
79  size_t outputs() const override;
80 
81  bool evaluatePopulation(darwin::Population* population) const override;
82 
83  const Config& config() const { return config_; }
84  const sim::DroneConfig& droneConfig() const { return drone_config_; }
85 
86  private:
87  void validateConfiguration();
88 
89  private:
90  Config config_;
91  sim::DroneConfig drone_config_;
92 };
93 
94 class Factory : public darwin::DomainFactory {
95  unique_ptr<darwin::Domain> create(const core::PropertySet& config) override;
96  unique_ptr<core::PropertySet> defaultConfig(darwin::ComplexityHint hint) const override;
97 };
98 
99 inline void init() {
100  darwin::registry()->domains.add<Factory>("drone_track");
101 }
102 
103 } // namespace drone_track
int touch_resolution
"Touch sensor resolution"
Definition: domain.h:38
bool camera_depth
"Use camera depth channel"
Definition: domain.h:35
float curb_width
"Curb width"
Definition: domain.h:45
bool track_gates
"Generate track gates"
Definition: domain.h:47
float max_lateral_force
"Maximum lateral force"
Definition: domain.h:29
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
bool touch_sensor
"Use the drone&#39;s touch sensor"
Definition: domain.h:37
float max_rotate_torque
"Maximum torque used to rotate the drone"
Definition: domain.h:30
bool accelerometer
"Use the drone&#39;s accelerometer"
Definition: domain.h:39
Registry * registry()
Accessor to the Registry singleton.
Definition: darwin.h:295
bool compass
"Use the drone&#39;s compass"
Definition: domain.h:40
float camera_fov
"Camera field of view (FOV)"
Definition: domain.h:33
float drone_radius
"Drone size"
Definition: domain.h:27
int track_complexity
"The approximate number of turns"
Definition: domain.h:43
size_t outputs() const override
Number of outputs from a Brain.
Definition: domain.cpp:56
bool solid_gate_posts
"Solid gate posts"
Definition: domain.h:48
Interface to the domain factory.
Definition: darwin.h:263
Definition: domain.cpp:28
float track_width
"Track width"
Definition: domain.h:42
int camera_resolution
"Camera resolution"
Definition: domain.h:34
int track_resolution
"Number of track segments"
Definition: domain.h:44
int max_steps
"Maximum number of steps per episode"
Definition: domain.h:51
The foundation for data structures supporting runtime reflection.
Definition: properties.h:388
size_t inputs() const override
Number of inputs to a Brain.
Definition: domain.cpp:52
float drone_friction
"Drone friction"
Definition: domain.h:31
core::ImplementationsSet< DomainFactory > domains
Registered domains.
Definition: darwin.h:288
Interface to a domain implementation.
Definition: darwin.h:229
float curb_friction
"Track&#39;s curb friction"
Definition: domain.h:46
float max_move_force
"Maximum force used to move the drone"
Definition: domain.h:28
bool evaluatePopulation(darwin::Population *population) const override
Assigns fitness values to every genotype.
Definition: domain.cpp:60
int test_worlds
"Number of test worlds per generation"
Definition: domain.h:50
Drone Track domain configuration.
Definition: domain.h:26
Domain: Drone Track.
Definition: domain.h:74