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/car.h>
20 
21 #include <third_party/box2d/box2d.h>
22 
23 namespace car_track {
24 
26 struct Config : public core::PropertySet {
27  PROPERTY(car_length, float, 1.2f, "Car length");
28  PROPERTY(max_forward_force, float, 2.0f, "Max forward move force");
29  PROPERTY(max_reverse_force, float, 0.5f, "Max reverse move force");
30  PROPERTY(max_steer_angle, float, 40.0f, "Max steering angle");
31  PROPERTY(tire_traction, float, 1.5f, "Tire traction (max lateral impulse)");
32 
33  PROPERTY(camera_fov, float, 90, "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, true, "Use the drone's touch sensor");
38  PROPERTY(touch_resolution, int, 8, "Touch sensor resolution");
39  PROPERTY(accelerometer, bool, true, "Use the drone's accelerometer");
40  PROPERTY(compass, bool, true, "Use the drone's compass");
41 
42  PROPERTY(track_width, float, 2.5f, "Track width");
43  PROPERTY(track_complexity, int, 10, "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, false, "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 CarTrack : public darwin::Domain {
75  public:
76  explicit CarTrack(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::CarConfig& carConfig() const { return car_config_; }
85 
86  private:
87  void validateConfiguration();
88 
89  private:
90  Config config_;
91  sim::CarConfig car_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>("car_track");
101 }
102 
103 } // namespace car_track
float curb_width
"Curb width"
Definition: domain.h:45
int test_worlds
"Number of test worlds per generation"
Definition: domain.h:50
bool touch_sensor
"Use the drone&#39;s touch sensor"
Definition: domain.h:37
size_t outputs() const override
Number of outputs from a Brain.
Definition: domain.cpp:55
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
float car_length
"Car length"
Definition: domain.h:27
float max_forward_force
"Max forward move force"
Definition: domain.h:28
Registry * registry()
Accessor to the Registry singleton.
Definition: darwin.h:295
float track_width
"Track width"
Definition: domain.h:42
float camera_fov
"Camera field of view (FOV)"
Definition: domain.h:33
int track_complexity
"The approximate number of turns"
Definition: domain.h:43
Car Track domain configuration.
Definition: domain.h:26
bool track_gates
"Generate track gates"
Definition: domain.h:47
float tire_traction
"Tire traction (max lateral impulse)"
Definition: domain.h:31
int max_steps
"Maximum number of steps per episode"
Definition: domain.h:51
float max_reverse_force
"Max reverse move force"
Definition: domain.h:29
Interface to the domain factory.
Definition: darwin.h:263
Definition: domain.cpp:28
int track_resolution
"Number of track segments"
Definition: domain.h:44
float curb_friction
"Track&#39;s curb friction"
Definition: domain.h:46
size_t inputs() const override
Number of inputs to a Brain.
Definition: domain.cpp:51
int touch_resolution
"Touch sensor resolution"
Definition: domain.h:38
bool evaluatePopulation(darwin::Population *population) const override
Assigns fitness values to every genotype.
Definition: domain.cpp:59
bool accelerometer
"Use the drone&#39;s accelerometer"
Definition: domain.h:39
int camera_resolution
"Camera resolution"
Definition: domain.h:34
Domain: Car Track.
Definition: domain.h:74
The foundation for data structures supporting runtime reflection.
Definition: properties.h:388
bool camera_depth
"Use camera depth channel"
Definition: domain.h:35
bool compass
"Use the drone&#39;s compass"
Definition: domain.h:40
core::ImplementationsSet< DomainFactory > domains
Registered domains.
Definition: darwin.h:288
Interface to a domain implementation.
Definition: darwin.h:229
float max_steer_angle
"Max steering angle"
Definition: domain.h:30
bool solid_gate_posts
"Solid gate posts"
Definition: domain.h:48