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_vision {
24 
26 struct Config : public core::PropertySet {
27  PROPERTY(drone_radius, float, 0.5f, "Drone size");
28  PROPERTY(max_move_force, float, 1.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, 1.0f, "Maximum torque used to rotate the drone");
31 
32  PROPERTY(camera_fov, float, 60, "Camera field of view (FOV)");
33  PROPERTY(camera_resolution, int, 64, "Camera resolution");
34  PROPERTY(camera_depth, bool, false, "Use camera depth channel");
35 
36  PROPERTY(target_radius, float, 0.3f, "Target size");
37  PROPERTY(target_speed, float, 10.0f, "Target velocity");
38 
39  PROPERTY(scene_columns, bool, false, "Scene includes a few fixed columns");
40  PROPERTY(scene_debris, bool, false, "Scene includes random debris");
41 
42  PROPERTY(test_worlds, int, 3, "Number of test worlds per generation");
43  PROPERTY(max_steps, int, 1000, "Maximum number of steps per episode");
44 };
45 
65 class DroneVision : public darwin::Domain {
66  public:
67  explicit DroneVision(const core::PropertySet& config);
68 
69  size_t inputs() const override;
70  size_t outputs() const override;
71 
72  bool evaluatePopulation(darwin::Population* population) const override;
73 
74  const Config& config() const { return config_; }
75  const sim::DroneConfig& droneConfig() const { return drone_config_; }
76 
77  b2Vec2 randomTargetVelocity() const;
78 
79  private:
80  void validateConfiguration();
81 
82  private:
83  Config config_;
84  sim::DroneConfig drone_config_;
85 };
86 
87 class Factory : public darwin::DomainFactory {
88  unique_ptr<darwin::Domain> create(const core::PropertySet& config) override;
89  unique_ptr<core::PropertySet> defaultConfig(darwin::ComplexityHint hint) const override;
90 };
91 
92 inline void init() {
93  darwin::registry()->domains.add<Factory>("drone_vision");
94 }
95 
96 } // namespace drone_vision
size_t outputs() const override
Number of outputs from a Brain.
Definition: domain.cpp:49
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
size_t inputs() const override
Number of inputs to a Brain.
Definition: domain.cpp:45
bool scene_debris
"Scene includes random debris"
Definition: domain.h:40
Registry * registry()
Accessor to the Registry singleton.
Definition: darwin.h:295
bool camera_depth
"Use camera depth channel"
Definition: domain.h:34
int max_steps
"Maximum number of steps per episode"
Definition: domain.h:43
int camera_resolution
"Camera resolution"
Definition: domain.h:33
bool scene_columns
"Scene includes a few fixed columns"
Definition: domain.h:39
float max_lateral_force
"Maximum lateral force"
Definition: domain.h:29
bool evaluatePopulation(darwin::Population *population) const override
Assigns fitness values to every genotype.
Definition: domain.cpp:53
Definition: domain.cpp:27
Interface to the domain factory.
Definition: darwin.h:263
float camera_fov
"Camera field of view (FOV)"
Definition: domain.h:32
float drone_radius
"Drone size"
Definition: domain.h:27
The foundation for data structures supporting runtime reflection.
Definition: properties.h:388
Drone Vision domain configuration.
Definition: domain.h:26
Domain: Drone Vision.
Definition: domain.h:65
core::ImplementationsSet< DomainFactory > domains
Registered domains.
Definition: darwin.h:288
Interface to a domain implementation.
Definition: darwin.h:229
float target_speed
"Target velocity"
Definition: domain.h:37
float max_rotate_torque
"Maximum torque used to rotate the drone"
Definition: domain.h:30
float target_radius
"Target size"
Definition: domain.h:36
float max_move_force
"Maximum force used to move the drone"
Definition: domain.h:28
int test_worlds
"Number of test worlds per generation"
Definition: domain.h:42