Ultra 0.9.4
Loading...
Searching...
No Matches
scored_individual.h
Go to the documentation of this file.
1
12
13#if !defined(ULTRA_SCORED_INDIVIDUAL_H)
14#define ULTRA_SCORED_INDIVIDUAL_H
15
16#include "kernel/individual.h"
17#include "kernel/fitness.h"
18#include "kernel/problem.h"
19
20#include <utility>
21
22namespace ultra
23{
24
28/// \tparam I type modelling an individual
29/// \tparam F type modelling a fitness value
30///
31/// `scored_individual` is a lightweight value type used to represent the
32/// result of evaluating an individual. It is primarily intended for **ranking,
33/// selection, and replacement** operations in evolutionary algorithms.
34///
35/// The class supports *ordering by fitness* (via `operator<=>`) but
36/// deliberately does **not** define equality. Fitness values are typically
37/// floating-point and exact equality comparisons would be semantically
38/// misleading.
39///
40/// \note
41/// Since equality is not defined, `scored_individual` does not model a totally
42/// ordered type and cannot be used with default `std::ranges::less`.
43/// Algorithms that require ordering should provide an explicit comparator or
44/// projection (e.g. comparing the `fit` member).
45///
46template<Individual I, Fitness F>
47struct scored_individual
48{
49 // ---- Constructor and support functions ----
50 scored_individual() = default;
52
53 // ---- Capacity ----
54 [[nodiscard]] bool empty() const noexcept;
55
56 // ---- Serialization ----
57 [[nodiscard]] bool load(std::istream &, const problem &);
58 [[nodiscard]] bool save(std::ostream &) const;
59
60 // ---- Data members ----
61 I ind {};
62 F fit {lowest<F>()};
63};
64
65
66// ---- Non-member functions ----
67template<Individual I, Fitness F>
68[[nodiscard]] auto operator<=>(const scored_individual<I, F> &,
69 const scored_individual<I, F> &) noexcept;
70
72
73} // namespace ultra
74
75#endif // include guard
STL namespace.
auto operator<=>(const model_measurements< F > &, const model_measurements< F > &) noexcept
Definition model_measurements.h:46
Definition problem.h:26
scored_individual(I, F)
Definition scored_individual.h:28
bool empty() const noexcept
Definition scored_individual.h:38