Ultra 0.9.4
Loading...
Searching...
No Matches
layered_population.h
Go to the documentation of this file.
1
12
13#if !defined(ULTRA_LAYERED_POPULATION_H)
14#define ULTRA_LAYERED_POPULATION_H
15
17#include "kernel/problem.h"
18#include "kernel/random.h"
19
20#include "utility/log.h"
21#include "utility/misc.h"
22
23#include <algorithm>
24#include <list>
25#include <numeric>
26#include <ranges>
27
28namespace ultra
29{
30
39template<Individual I>
41{
42public:
43 // ---- Member types ----
44 using layer_t = linear_population<I>;
45 using layer_iter = typename std::list<layer_t>::iterator;
46 using layer_const_iter = typename std::list<layer_t>::const_iterator;
47
48 using value_type = I;
49
50 struct coord
51 {
52 std::size_t layer_index;
53 layer_t::coord individual_coord;
54
55 friend auto operator<=>(const coord &, const coord &) noexcept = default;
56 };
57
58 // ---- Constructors ----
59 explicit layered_population(const ultra::problem &, bool = true);
60
61 // ---- Layer-related / accessors ----
62 [[nodiscard]] const layer_t &front() const;
63 [[nodiscard]] layer_t &front();
64 [[nodiscard]] const layer_t &back() const;
65 [[nodiscard]] layer_t &back();
66
67 [[nodiscard]] std::size_t layers() const noexcept;
68 [[nodiscard]] const layer_t &layer(std::size_t) const;
69 [[nodiscard]] layer_t &layer(std::size_t);
70
71 [[nodiscard]] auto range_of_layers() const;
72 [[nodiscard]] auto range_of_layers();
73
74 [[nodiscard]] const I &operator[](coord) const;
75 [[nodiscard]] I &operator[](coord);
76
77 void init(layer_t &);
78 void add_layer();
79 bool erase(layer_t &);
80 layer_iter erase(layer_iter);
81
82 // ---- Capacity ----
83 [[nodiscard]] std::size_t size() const;
84
85 // ---- Misc ----
86 void inc_age();
87
88 [[nodiscard]] const ultra::problem &problem() const;
89
90 // ---- Iterators ----
91 template<bool> class base_iterator;
92 using const_iterator = base_iterator<true>;
93 using iterator = base_iterator<false>;
95 [[nodiscard]] const_iterator begin() const;
96 [[nodiscard]] const_iterator end() const;
97 [[nodiscard]] iterator begin();
98 [[nodiscard]] iterator end();
99
100 [[nodiscard]] bool is_valid() const;
101
102 // ---- Serialization ----
103 [[nodiscard]] bool load(std::istream &);
104 [[nodiscard]] bool save(std::ostream &) const;
106private:
107 // Holds a non-owning pointer to the associated problem.
108 // The referenced problem must outlive the population.
109 const ultra::problem *prob_;
110
111 std::list<layer_t> layers_ {};
112};
113
114namespace random
116
117template<LayeredPopulation P>
118[[nodiscard]] const auto &subgroup(const P &);
119template<LayeredPopulation P>
120[[nodiscard]] typename P::coord coord(const P &);
121
122} // namespace random
127} // namespace ultra
128
129#endif // include guard
const layer_t & front() const
Definition layered_population.h:105
void inc_age()
Definition layered_population.h:346
void add_layer()
Definition layered_population.h:251
std::size_t layers() const noexcept
Definition layered_population.h:217
const layer_t & layer(std::size_t) const
Definition layered_population.h:82
bool is_valid() const
Definition layered_population.h:434
std::size_t size() const
Definition layered_population.h:226
bool erase(layer_t &)
Definition layered_population.h:271
bool save(std::ostream &) const
Definition layered_population.h:417
const layer_t & back() const
Definition layered_population.h:126
const ultra::problem & problem() const
Definition layered_population.h:239
void init(layer_t &)
Definition layered_population.h:200
const_iterator end() const
Definition layered_population.h:318
layered_population(const ultra::problem &, bool=true)
Definition layered_population.h:61
bool load(std::istream &)
Definition layered_population.h:392
const_iterator begin() const
Definition layered_population.h:307
Definition linear_population.h:70
STL namespace.
auto operator<=>(const model_measurements< F > &, const model_measurements< F > &) noexcept
Definition model_measurements.h:46
Definition layered_population.h:51
Definition problem.h:26