25 #ifndef PAGMO_ALGORITHM_SPEA2_H
26 #define PAGMO_ALGORITHM_SPEA2_H
28 #include "../config.h"
29 #include "../serialization.h"
30 #include "../util/neighbourhood.h"
33 namespace pagmo {
namespace algorithm {
35 class distance_sorter {
37 distance_sorter(
const std::vector<std::vector<pagmo::population::size_type> > &neighbours,
38 const std::vector<fitness_vector> &fit):
39 m_neighbours(neighbours),
41 bool operator()(
unsigned int a,
unsigned int b) {
42 if(a>=m_fit.size() || a>=m_neighbours.size()){
43 pagmo_throw(value_error,
"SPEA2 sorting of KNN values failure");
45 if(b>=m_fit.size() || b>=m_neighbours.size()){
46 pagmo_throw(value_error,
"SPEA2 sorting of KNN values failure");
48 double delta_a, delta_b;
51 if(m_neighbours[b][i]>=m_fit.size() || m_neighbours[a][i]>=m_fit.size()){
52 pagmo_throw(value_error,
"SPEA2 sorting of KNN values failure");
57 }
while (i<m_neighbours[0].size() && delta_a == delta_b);
58 return delta_a > delta_b;
61 const std::vector<std::vector<pagmo::population::size_type> > &m_neighbours;
62 const std::vector<fitness_vector> &m_fit;
83 spea2(
int gen=100,
double cr = 0.95,
double eta_c = 10,
double m = 0.01,
double eta_m = 50,
int archive_size = 0);
86 std::string get_name()
const;
89 std::string human_readable_extra()
const;
92 struct spea2_individual {
97 void compute_spea2_fitness(std::vector<double> &,
99 const std::vector<spea2_individual> &pop,
101 std::vector<std::vector<population::size_type> > compute_domination_list(
const pagmo::problem::base &,
102 const std::vector<fitness_vector> &,
103 const std::vector<constraint_vector> &)
const;
104 std::vector<population::size_type> compute_pareto_rank(
const std::vector<std::vector<population::size_type> > &)
const;
106 const std::vector<population::size_type> &)
const;
107 std::vector<population::size_type> compute_domination_count(
const std::vector<std::vector<population::size_type> > &)
const;
111 friend class boost::serialization::access;
112 template <
class Archive>
113 void serialize(Archive &ar,
const unsigned int)
115 ar & boost::serialization::base_object<base>(*this);
116 ar &
const_cast<int &
>(m_gen);
117 ar &
const_cast<double &
>(m_cr);
118 ar &
const_cast<double &
>(m_eta_c);
119 ar &
const_cast<double &
>(m_m);
120 ar &
const_cast<double &
>(m_eta_m);
121 ar &
const_cast<int &
>(m_archive_size);
128 const double m_eta_c;
132 const double m_eta_m;
141 #endif // PAGMO_ALGORITHM_SPEA2_H
boost::shared_ptr< base > base_ptr
Alias for shared pointer to base algorithm.
std::vector< double > decision_vector
Decision vector type.
"Strength Pareto Evolutionary Algorithm (SPEA2)"
static double distance(const std::vector< double > &, const std::vector< double > &)
std::vector< double > fitness_vector
Fitness vector type.
std::vector< double > constraint_vector
Constraint vector type.
container_type::size_type size_type
Population size type.