Vita
team.h
Go to the documentation of this file.
1
13#if !defined(VITA_TEAM_H)
14#define VITA_TEAM_H
15
16#include <algorithm>
17
18#include "kernel/cache.h"
19#include "kernel/individual.h"
20
21namespace vita
22{
52template<class T>
53class team
54{
55public:
56 team();
57 explicit team(unsigned);
58 explicit team(const problem &);
59 explicit team(std::vector<T>);
60
61 // Recombination operators.
62 unsigned mutation(double, const problem &);
63
64 const T &operator[](unsigned) const;
65
66 bool empty() const;
67 unsigned individuals() const;
68 unsigned active_symbols() const;
69
70 hash_t signature() const;
71
72 unsigned age() const;
73 void inc_age();
74
75 bool is_valid() const;
76
77 // Iterators.
78 using members_t = std::vector<T>;
79 using const_iterator = typename members_t::const_iterator;
80 using value_type = typename members_t::value_type;
81 const_iterator begin() const;
82 const_iterator end() const;
83
84 // Serialization.
85 bool load(std::istream &, const symbol_set &);
86 bool save(std::ostream &) const;
87
88 template<class U> friend team<U> crossover(const team<U> &, const team<U> &);
89
90private:
91 // Private support methods.
92 hash_t hash() const;
93
94 // Private data members.
95 members_t individuals_;
96
97 mutable hash_t signature_;
98};
99
100// ***********************************************************************
101// * Comparison operators *
102// ***********************************************************************
103template<class T> bool operator==(const team<T> &, const team<T> &);
104template<class T> bool operator!=(const team<T> &, const team<T> &);
105template<class T> unsigned distance(const team<T> &, const team<T> &);
106
107template<class T> team<T> crossover(const team<T> &, const team<T> &);
108
109template<class T> std::ostream &operator<<(std::ostream &, const team<T> &);
110
111// The SFINAE way of recognizing a team.
112template<class T> struct is_team : std::false_type
113{ enum {value = false}; };
114template<class T> struct is_team<team<T>> : std::true_type
115{ enum {value = true}; };
116
117template<class T> struct not_team : std::true_type
118{ enum {value = true}; };
119template<class T> struct not_team<team<T>> : std::false_type
120{ enum {value = false}; };
121
122#include "kernel/gp/team.tcc"
123
124} // namespace vita
125
126#endif // include guard
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
A collection of cooperating individuals used as a member of vita::population.
Definition: team.h:54
The main namespace for the project.
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