Vita
i_de.h
Go to the documentation of this file.
1
13#if !defined(VITA_GA_I_DE_H)
14#define VITA_GA_I_DE_H
15
16#include "kernel/individual.h"
17#include "kernel/range.h"
18
19namespace vita
20{
26class i_de : public individual<i_de>
27{
28public:
29 i_de() = default;
30 explicit i_de(const problem &);
31
32 // Iterators.
33 using genome_t = std::vector<double>;
34 using const_iterator = genome_t::const_iterator;
35 using iterator = genome_t::iterator;
36 using value_type = genome_t::value_type;
37
38 const_iterator begin() const;
39 const_iterator end() const;
40
41 iterator begin();
42 iterator end();
43
44 value_type operator[](std::size_t i) const
45 {
46 Expects(i < parameters());
47 return genome_[i];
48 }
49
50 value_type &operator[](std::size_t i)
51 {
52 Expects(i < parameters());
53 signature_.clear();
54 return genome_[i];
55 }
56
57 operator std::vector<value_type>() const;
58 i_de &operator=(const std::vector<value_type> &);
59
60 i_de crossover(double, const range_t<double> &,
61 const i_de &, const i_de &, const i_de &) const;
62
64 bool empty() const { return !parameters(); }
65
67 std::size_t parameters() const { return genome_.size(); }
68
69 hash_t signature() const;
70
71 // Visualization/output methods.
72 void graphviz(std::ostream &) const;
73
74 bool is_valid() const;
75
76 friend class individual<i_de>;
77
78private:
79 // *** Private support methods ***
80 hash_t hash() const;
81
82 // Serialization.
83 bool load_impl(std::istream &, const symbol_set &);
84 bool save_impl(std::ostream &) const;
85
86 // *** Private data members ***
87
88 // This is the genome: the entire collection of genes (the entirety of an
89 // organism's hereditary information).
90 genome_t genome_;
91}; // class i_de
92
93bool operator==(const i_de &, const i_de &);
94double distance(const i_de &, const i_de &);
95
96// Visualization/output functions.
97std::ostream &in_line(const i_de &, std::ostream & = std::cout);
98std::ostream &operator<<(std::ostream &, const i_de &);
99
103inline i_de::const_iterator i_de::begin() const
104{
105 return genome_.begin();
106}
107
111inline i_de::const_iterator i_de::end() const
112{
113 return genome_.end();
114}
115
119inline i_de::iterator i_de::begin()
120{
121 return genome_.begin();
122}
123
127inline i_de::iterator i_de::end()
128{
129 return genome_.end();
130}
131
132} // namespace vita
133
134#endif // include guard
An individual optimized for differential evolution.
Definition: i_de.h:27
bool is_valid() const
Definition: i_de.cc:200
std::size_t parameters() const
Definition: i_de.h:67
void graphviz(std::ostream &) const
Inserts into the output stream the graph representation of the individual.
Definition: i_de.cc:51
hash_t signature() const
Definition: i_de.cc:140
const_iterator begin() const
Definition: i_de.h:103
bool empty() const
Definition: i_de.h:64
i_de crossover(double, const range_t< double > &, const i_de &, const i_de &, const i_de &) const
Differential evolution crossover.
Definition: i_de.cc:104
const_iterator end() const
Definition: i_de.h:111
i_de & operator=(const std::vector< value_type > &)
Sets up the individual with values from a vector.
Definition: i_de.cc:188
A single member of a population.
Definition: individual.h:41
MurmurHash3 (https://github.com/aappleby/smhasher) by Austin Appleby.
Definition: cache_hash.h:101
Aggregates the problem-related data needed by an evolutionary program.
Definition: problem.h:24
A container for the symbols used by the GP engine.
Definition: symbol_set.h:37
The main namespace for the project.
std::pair< T, T > range_t
Right-open interval.
Definition: range.h:25
std::ostream & operator<<(std::ostream &o, hash_t h)
Mainly useful for debugging / testing.
Definition: cache_hash.cc:56
A 128bit unsigned integer used as individual's signature / hash table look-up key.
Definition: cache_hash.h:27
void clear()
Resets the content of the object.
Definition: cache_hash.h:31