Ultra 0.9.4
Loading...
Searching...
No Matches
evolution_recombination.h
Go to the documentation of this file.
1
12
13#if !defined(ULTRA_EVOLUTION_RECOMBINATION_H)
14#define ULTRA_EVOLUTION_RECOMBINATION_H
15
16#include "kernel/evaluator.h"
18#include "kernel/fitness.h"
19#include "kernel/individual.h"
20#include "kernel/population.h"
21#include "kernel/problem.h"
23
24namespace ultra::recombination
25{
26
29/// the evolution class.
30///
31/// A recombination acts upon sets of individuals to generate offspring
32/// (this definition generalizes the traditional mutation and crossover
33/// operators).
34///
35/// Operator application is atomic from the point of view of the
36/// evolutionary algorithm and every recombination is applied to a well
37/// defined list of individuals, without dependencies upon past history.
38///
39/// In the strategy design pattern, this class is the strategy interface and
40/// ultra::evolution is the context.
41///
42/// This is an abstract class: introduction of new operators or redefinition
43/// of existing ones is obtained implementing recombination::strategy.
44///
45/// \see
46/// - https://en.wikipedia.org/wiki/Strategy_pattern
47///
48template<Evaluator E>
50{
51public:
52 using scored_t =
53 scored_individual<evaluator_individual_t<E>, evaluator_fitness_t<E>>;
54
55 strategy(E &, const problem &);
56
57protected:
58 E &eva_;
59 const problem &prob_;
60};
61
69template<Evaluator E>
70class base : public strategy<E>
71{
72public:
73 using typename strategy<E>::scored_t;
74
75 using base::strategy::strategy;
76
77 template<class R> [[nodiscard]] auto operator()(const R &) const
78 requires std::ranges::random_access_range<const R>
79 && std::ranges::sized_range<const R>
80 && std::same_as<std::ranges::range_value_t<const R>, scored_t>;
81};
82
83template<Evaluator E> base(E &, const problem &) -> base<E>;
84
88class de
89{
90public:
91 explicit de(const problem &prob) : prob_(prob) {}
92
93 template<Individual I>
94 [[nodiscard]] I operator()(const selection::de::selected_refs<I> &) const;
95
96private:
97 const problem &prob_;
98};
99
101
102} // namespace ultra::recombination
103
104#endif // include guard
Definition evolution_recombination.h:71
auto operator()(const R &) const
Definition evolution_recombination.h:41
I operator()(const selection::de::selected_refs< I > &) const
Definition evolution_recombination.h:116
strategy(E &, const problem &)
Definition evolution_recombination.h:29
Definition problem.h:26
Definition scored_individual.h:48
Definition evolution_selection.h:104