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_follow {
24 
26 struct Config : public core::PropertySet {
27  PROPERTY(drone_radius, float, 0.5f, "Drone size");
28  PROPERTY(drone_lights, bool, true, "Drone has navigation lights");
29  PROPERTY(max_move_force, float, 5.0f, "Maximum force used to move the drone");
30  PROPERTY(max_lateral_force, float, 10.0f, "Maximum lateral force");
31  PROPERTY(max_rotate_torque, float, 1.0f, "Maximum torque used to rotate the drone");
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(target_distance, float, 5.0f, "The ideal following distance");
43 
44  PROPERTY(scene_columns, bool, false, "Scene includes a few fixed columns");
45  PROPERTY(scene_debris, bool, false, "Scene includes random debris");
46 
47  PROPERTY(test_worlds, int, 3, "Number of test worlds per generation");
48  PROPERTY(max_steps, int, 1000, "Maximum number of steps per episode");
49 };
50 
75 class DroneFollow : public darwin::Domain {
76  public:
77  explicit DroneFollow(const core::PropertySet& config);
78 
79  size_t inputs() const override;
80  size_t outputs() const override;
81 
82  bool evaluatePopulation(darwin::Population* population) const override;
83 
84  const Config& config() const { return config_; }
85  const sim::DroneConfig& droneConfig() const { return drone_config_; }
86 
87  private:
88  void validateConfiguration();
89 
90  private:
91  Config config_;
92  sim::DroneConfig drone_config_;
93 };
94 
95 class Factory : public darwin::DomainFactory {
96  unique_ptr<darwin::Domain> create(const core::PropertySet& config) override;
97  unique_ptr<core::PropertySet> defaultConfig(darwin::ComplexityHint hint) const override;
98 };
99 
100 inline void init() {
101  darwin::registry()->domains.add<Factory>("drone_follow");
102 }
103 
104 } // namespace drone_follow
bool evaluatePopulation(darwin::Population *population) const override
Assigns fitness values to every genotype.
Definition: domain.cpp:58
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
Domain: Drone Follow.
Definition: domain.h:75
size_t outputs() const override
Number of outputs from a Brain.
Definition: domain.cpp:54
size_t inputs() const override
Number of inputs to a Brain.
Definition: domain.cpp:50
Definition: domain.cpp:27
bool compass
"Use the drone&#39;s compass"
Definition: domain.h:40
float max_rotate_torque
"Maximum torque used to rotate the drone"
Definition: domain.h:31
int touch_resolution
"Touch sensor resolution"
Definition: domain.h:38
Interface to the domain factory.
Definition: darwin.h:263
int camera_resolution
"Camera resolution"
Definition: domain.h:34
bool drone_lights
"Drone has navigation lights"
Definition: domain.h:28
bool accelerometer
"Use the drone&#39;s accelerometer"
Definition: domain.h:39
The foundation for data structures supporting runtime reflection.
Definition: properties.h:388
float drone_radius
"Drone size"
Definition: domain.h:27
float camera_fov
"Camera field of view (FOV)"
Definition: domain.h:33
int max_steps
"Maximum number of steps per episode"
Definition: domain.h:48
core::ImplementationsSet< DomainFactory > domains
Registered domains.
Definition: darwin.h:288
Interface to a domain implementation.
Definition: darwin.h:229
bool touch_sensor
"Use the drone&#39;s touch sensor"
Definition: domain.h:37
float max_move_force
"Maximum force used to move the drone"
Definition: domain.h:29
bool camera_depth
"Use camera depth channel"
Definition: domain.h:35
float target_distance
"The ideal following distance"
Definition: domain.h:42
Drone Follow domain configuration.
Definition: domain.h:26
float max_lateral_force
"Maximum lateral force"
Definition: domain.h:30
bool scene_columns
"Scene includes a few fixed columns"
Definition: domain.h:44
bool scene_debris
"Scene includes random debris"
Definition: domain.h:45
int test_worlds
"Number of test worlds per generation"
Definition: domain.h:47