30 #include "../population.h"
32 #include "base_s_policy.h"
33 #include "hv_best_s_policy.h"
34 #include "best_s_policy.h"
35 #include "../exceptions.h"
36 #include "../util/hypervolume.h"
40 namespace pagmo {
namespace migration {
50 hv_best_s_policy::hv_best_s_policy(
const double &rate,
rate_type type,
const double nadir_eps):
base_s_policy(rate,type), m_nadir_eps(nadir_eps) { }
57 bool hv_best_s_policy::sort_point_pairs_desc(
const std::pair<unsigned int, double> &a,
const std::pair<unsigned int, double> &b)
59 return a.second > b.second;
75 std::vector<population::individual_type> result;
81 std::vector< std::vector< fitness_vector> > fronts_f (fronts_i.size());
86 for (
unsigned int f_idx = 0 ; f_idx < fronts_i.size() ; ++f_idx) {
87 fronts_f[f_idx].resize(fronts_i[f_idx].size());
88 for (
unsigned int p_idx = 0 ; p_idx < fronts_i[f_idx].size() ; ++p_idx) {
92 for (
unsigned int d_idx = 0 ; d_idx < fronts_f[f_idx][p_idx].size() ; ++d_idx) {
93 refpoint[d_idx] = std::max(refpoint[d_idx], fronts_f[f_idx][p_idx][d_idx]);
99 for (
unsigned int d_idx = 0 ; d_idx < refpoint.size() ; ++d_idx) {
100 refpoint[d_idx] += m_nadir_eps;
104 unsigned int front_idx = 0;
105 unsigned int remaining_individuals = migration_rate;
107 while (remaining_individuals > 0) {
108 unsigned int front_size = fronts_f[front_idx].size();
111 if (remaining_individuals >= front_size) {
112 for(
unsigned int i = 0 ; i < front_size ; ++i) {
115 remaining_individuals -= front_size;
118 unsigned int true_front_size = fronts_f[front_idx].size();
121 if (front_idx + 1 < fronts_f.size()) {
123 fronts_f[front_idx].resize(true_front_size + fronts_f[front_idx + 1].size());
124 for(
unsigned int i = 0 ; i < fronts_f[front_idx + 1].size() ; ++i) {
125 fronts_f[front_idx][true_front_size + i] = fronts_f[front_idx + 1][i];
132 std::vector<std::pair<unsigned int, double> > point_pairs;
133 point_pairs.resize(true_front_size);
135 for(
unsigned int i = 0 ; i < true_front_size ; ++i) {
136 point_pairs[i] = std::make_pair(i, c[i]);
139 std::sort(point_pairs.begin(), point_pairs.end(), sort_point_pairs_desc);
142 for(
unsigned int i = 0 ; i < remaining_individuals ; ++i) {
143 result.push_back(pop.
get_individual(fronts_i[front_idx][point_pairs[i].first]));
145 remaining_individuals = 0;
hv_best_s_policy(const double &rate=1, rate_type type=absolute, double nadir_eps=1.0)
Constructor from migration rate and type.
fitness_vector cur_f
Current fitness vector.
Base class for migration selection policies.
const individual_type & get_individual(const size_type &) const
Get constant reference to individual at position n.
std::vector< population::individual_type > select(population &) const
Select individuals to emigrate from the given population.
"Choose best" migration selection policy.
population::size_type get_n_individuals(const population &) const
Get number of individuals to migrate from/to input population.
Choose 'n' greatest contributors migration policy.
std::vector< double > contributions(const fitness_vector &, const hv_algorithm::base_ptr) const
Contributions method.
base_s_policy_ptr clone() const
Clone method.
std::vector< double > fitness_vector
Fitness vector type.
boost::shared_ptr< base_s_policy > base_s_policy_ptr
Shared pointer to base selection policy.
container_type::size_type size_type
Population size type.
rate_type m_type
Migration rate type.
f_size_type get_f_dimension() const
Return fitness dimension.
std::vector< population::individual_type > select(population &) const
Select individuals to emigrate from the given population.
double m_rate
Migration rate.
std::vector< std::vector< size_type > > compute_pareto_fronts() const
Computes and returns the population Pareto fronts.
rate_type
Type of migration rate.