Ultra 0.9.4
Loading...
Searching...
No Matches
team.h
Go to the documentation of this file.
1
12
13#if !defined(ULTRA_TEAM_H)
14#define ULTRA_TEAM_H
15
16#include "kernel/cache.h"
18#include "kernel/individual.h"
19#include "kernel/problem.h"
20
21#include <algorithm>
22#include <ranges>
23
24namespace ultra::gp
34{
35 std::size_t ind_index;
36 locus loc;
37 std::size_t arg_index;
38};
54
61///
62/// \note
63/// The team size has to be large enough to cause an improved prediction
64/// compared to the traditional approach, i.e. team size one (but the
65/// complexity of the search space and the training time, respectively,
66/// grow exponentially with the number of coevolved programs).
67///
68/// \see https://github.com/morinim/ultra/wiki/bibliography#16
69///
70template<Individual I>
71class team
72{
73public:
75 static constexpr std::size_t max_team_size {1024};
76
77 team() = default;
78 explicit team(std::size_t);
79 explicit team(const problem &);
80 explicit team(std::vector<I>);
81
82 // ---- Recombination operators ----
83 unsigned mutation(const problem &, double = 1.0);
84 template<Individual U> friend team<U> crossover(const problem &,
85 const team<U> &,
86 const team<U> &);
88
89 // ---- Element access ----
90 [[nodiscard]] const I &operator[](std::size_t) const;
91
92 // ---- Capacity ----
93 [[nodiscard]] bool empty() const noexcept;
94 [[nodiscard]] std::size_t size() const noexcept;
95
96 // ---- Misc ----
97 [[nodiscard]] hash_t signature() const noexcept;
98
99 [[nodiscard]] ultra::individual::age_t age() const;
100 void inc_age(unsigned = 1);
101
102 [[nodiscard]] bool is_valid() const;
103
104 // ---- Iterators ----
105 using members_t = std::vector<I>;
106 using const_iterator = typename members_t::const_iterator;
107 using value_type = typename members_t::value_type;
108 [[nodiscard]] const_iterator begin() const noexcept;
109 [[nodiscard]] const_iterator end() const noexcept;
111 // ---- Serialization ----
112 bool load(std::istream &, const symbol_set &);
113 bool save(std::ostream &) const;
114
115private:
116 // ---- Private support methods ----
117 [[nodiscard]] hash_t hash() const;
118
119 // ---- Private data members ----
120 members_t individuals_ {};
121
122 hash_t signature_ {};
123};
124
125// ***********************************************************************
126// * Comparison operators *
127// ***********************************************************************
128template<Individual I> [[nodiscard]] bool operator==(const team<I> &,
129 const team<I> &) noexcept;
130template<Individual I> [[nodiscard]] unsigned distance(const team<I> &,
131 const team<I> &);
132
133
134template<Individual I> [[nodiscard]] unsigned active_slots(const team<I> &);
135template<Individual I> [[nodiscard]] team<I> crossover(const problem &,
136 const team<I> &,
137 const team<I> &);
138template<Individual I> [[nodiscard]]
140
141template<Individual I> std::ostream &operator<<(std::ostream &,
142 const team<I> &);
143
144
145template<class> inline constexpr bool is_team_v = false;
146template<Individual I> inline constexpr bool is_team_v<team<I>> = true;
147template<class T> concept Team = is_team_v<std::remove_cvref_t<T>>;
148
149#include "kernel/gp/team.tcc"
150
151} // namespace ultra::gp
152
153#endif // include guard
Definition gp/individual.h:66
Definition team.h:72
bool empty() const noexcept
Definition team.h:237
unsigned mutation(const problem &, double=1.0)
Definition team.h:80
const_iterator end() const noexcept
Definition team.h:217
hash_t signature() const noexcept
Definition team.h:286
const I & operator[](std::size_t) const
Definition team.h:227
bool load(std::istream &, const symbol_set &)
Definition team.h:401
void inc_age(unsigned=1)
Definition team.h:370
bool save(std::ostream &) const
Definition team.h:432
std::ostream & operator<<(std::ostream &s, const team< I > &t)
Definition team.h:453
ultra::individual::age_t age() const
Definition team.h:347
const_iterator begin() const noexcept
Definition team.h:208
static constexpr std::size_t max_team_size
Maximum allowed number of individuals in a team.
Definition team.h:75
team_decision_vector extract_decision_vector(const team< I > &t)
Definition team.h:138
void apply_decision_vector(const team_decision_vector &v)
Definition team.h:179
bool is_valid() const
Definition team.h:380
std::size_t size() const noexcept
Definition team.h:246
Definition symbol_set.h:115
Definition team.h:147
double distance(F f1, F f2)
Definition fitness.tcc:117
STL namespace.
Definition decision_vector.h:42
Definition hash_t.h:34
Definition locus.h:26
Definition problem.h:26
ultra::decision_vector< team_decision_coordinate > team_decision_vector
Team-specific decision-vector type used for numerical optimisation.
Definition team.h:41