Brush C++ API
A flexible interpretable machine learning framework
Loading...
Searching...
No Matches
selection.cpp
Go to the documentation of this file.
1#include "selection.h"
2
3namespace Brush {
4namespace Sel {
5
6using namespace Brush;
7using namespace Pop;
8
9template<ProgramType T>
11{
12 this->type = "nsga2";
13 this->survival = false;
14 this->set_operator();
15}
16
17
18template<ProgramType T>
19Selection<T>::Selection(string type, bool survival)
20{
24 this->type = type;
25 this->survival = survival;
26 this->set_operator();
27}
28
29template<ProgramType T>
31{
32 if (this->type == "nsga2")
33 pselector = new NSGA2<T>(survival);
34 else if (this->type == "lexicase")
35 pselector = new Lexicase<T>(survival);
36 else
37 HANDLE_ERROR_THROW("Undefined Selection Operator " + this->type + "\n");
38
39}
40
42template<ProgramType T>
43string Selection<T>::get_type(){ return pselector->name; }
44
46template<ProgramType T>
47void Selection<T>::set_type(string in){ type = in; set_operator();}
48
50template<ProgramType T>
51vector<size_t> Selection<T>::select(Population<T>& pop, int island,
52 const Parameters& params)
53{
54 return pselector->select(pop, island, params);
55}
56
58template<ProgramType T>
59vector<size_t> Selection<T>::survive(Population<T>& pop, int island,
60 const Parameters& params)
61{
62 return pselector->survive(pop, island, params);
63}
64
65} // Sel
66} // Brush
void bind_engine(py::module &m, string name)
#define HANDLE_ERROR_THROW(err)
Definition error.h:27
bool in(const V &v, const T &i)
check if element is in vector.
Definition utils.h:192
< nsga2 selection operator for getting the front
Definition data.cpp:12
vector< size_t > select(Population< T > &pop, int island, const Parameters &params)
perform selection. selection uses a pop that has no offspring space
Definition selection.cpp:51
string get_type()
return type of selectionoperator
Definition selection.cpp:43
void set_type(string)
set type of selectionoperator
Definition selection.cpp:47
vector< size_t > survive(Population< T > &pop, int island, const Parameters &params)
perform survival. uses a pop with offspring space
Definition selection.cpp:59