Darwin Neuroevolution Framework
ballistics.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 <third_party/box2d/box2d.h>
20 
21 namespace ballistics {
22 
24 struct Config : public core::PropertySet {
25  PROPERTY(gravity, float, 9.8f, "Gravitational acceleration");
26 
27  PROPERTY(range_min_x, float, 0.0f, "Min target x coordinate");
28  PROPERTY(range_max_x, float, 10.0f, "Max target x coordinate");
29  PROPERTY(range_min_y, float, -2.5f, "Min target y coordinate");
30  PROPERTY(range_max_y, float, 2.5f, "Max target y coordinate");
31 
32  PROPERTY(target_radius, float, 0.1f, "Target radius");
33 
34  PROPERTY(target_hit_bonus, float, 0.5f, "Extra score for hitting the target [0..1]");
35 
36  PROPERTY(projectile_radius, float, 0.1f, "Projectile size");
37  PROPERTY(projectile_velocity, float, 12.0f, "Initial projectile velocity");
38 
39  PROPERTY(test_worlds, int, 5, "Number of test worlds per generation");
40 };
41 
74 class Ballistics : public darwin::Domain {
75  public:
76  explicit Ballistics(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 
85  b2Vec2 randomTargetPosition() const;
86 
87  private:
88  void validateConfiguration();
89 
90  private:
91  Config 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>("ballistics");
101 }
102 
103 } // namespace ballistics
float range_min_x
"Min target x coordinate"
Definition: ballistics.h:27
size_t outputs() const override
Number of outputs from a Brain.
Definition: ballistics.cpp:38
float target_hit_bonus
"Extra score for hitting the target [0..1]"
Definition: ballistics.h:34
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 target_radius
"Target radius"
Definition: ballistics.h:32
Registry * registry()
Accessor to the Registry singleton.
Definition: darwin.h:295
Domain: Ballistics.
Definition: ballistics.h:74
int test_worlds
"Number of test worlds per generation"
Definition: ballistics.h:39
float projectile_velocity
"Initial projectile velocity"
Definition: ballistics.h:37
Ballistics domain configuration.
Definition: ballistics.h:24
Interface to the domain factory.
Definition: darwin.h:263
float range_min_y
"Min target y coordinate"
Definition: ballistics.h:29
size_t inputs() const override
Number of inputs to a Brain.
Definition: ballistics.cpp:34
float range_max_x
"Max target x coordinate"
Definition: ballistics.h:28
The foundation for data structures supporting runtime reflection.
Definition: properties.h:388
core::ImplementationsSet< DomainFactory > domains
Registered domains.
Definition: darwin.h:288
float projectile_radius
"Projectile size"
Definition: ballistics.h:36
Interface to a domain implementation.
Definition: darwin.h:229
float gravity
"Gravitational acceleration"
Definition: ballistics.h:25
float range_max_y
"Max target y coordinate"
Definition: ballistics.h:30
bool evaluatePopulation(darwin::Population *population) const override
Assigns fitness values to every genotype.
Definition: ballistics.cpp:42
Definition: agent.cpp:18