25 #include "hypervolume.h"
26 #include "hv_algorithm/base.h"
27 #include "hv_algorithm/hv2d.h"
28 #include "hv_algorithm/hv3d.h"
29 #include "hv_algorithm/hv4d.h"
30 #include "hv_algorithm/wfg.h"
31 #include "hv_algorithm/bf_approx.h"
32 #include "hv_algorithm/bf_fpras.h"
33 #include "hv_algorithm/hoy.h"
34 #include "hv_algorithm/fpl.h"
36 namespace pagmo {
namespace util {
47 m_points.resize(pop->size());
53 verify_after_construct();
64 hypervolume::hypervolume(
const std::vector<fitness_vector> &points,
const bool verify) : m_points(points), m_copy_points(true), m_verify(verify)
67 verify_after_construct();
101 m_copy_points = copy_points;
107 return m_copy_points;
137 void hypervolume::verify_after_construct()
const
139 if ( m_points.size() == 0 ) {
140 pagmo_throw(value_error,
"Point set cannot be empty.");
142 fitness_vector::size_type f_dim = m_points[0].size();
144 pagmo_throw(value_error,
"Points of dimension > 1 required.");
146 for (std::vector<fitness_vector>::size_type idx = 1 ; idx < m_points.size() ; ++idx) {
147 if ( m_points[idx].size() != f_dim ) {
148 pagmo_throw(value_error,
"All point set dimensions must be equal.");
163 if ( m_points[0].size() != r_point.size() ) {
164 pagmo_throw(value_error,
"Point set dimensions and reference point dimension must be equal.");
166 hv_algorithm->verify_before_compute(m_points, r_point);
176 unsigned int fdim = r_point.size();
177 unsigned int n = m_points.size();
179 return hv_algorithm::hv2d().clone();
180 }
else if (fdim == 3) {
181 return hv_algorithm::hv3d().clone();
182 }
else if (fdim == 4) {
183 return hv_algorithm::hv4d().clone();
184 }
else if (fdim == 5 && n < 80) {
185 return hv_algorithm::fpl().clone();
187 return hv_algorithm::wfg().clone();
195 return get_best_compute(r_point);
200 unsigned int fdim = r_point.size();
202 return hv_algorithm::hv2d().clone();
203 }
else if (fdim == 3) {
204 return hv_algorithm::hv3d().clone();
206 return hv_algorithm::wfg().clone();
222 verify_before_compute(r_point, hv_algorithm);
227 std::vector<fitness_vector> points_cpy(m_points.begin(), m_points.end());
228 return hv_algorithm->compute(points_cpy, r_point);
230 return hv_algorithm->compute(
const_cast<std::vector<fitness_vector> &
>(m_points), r_point);
245 return compute(r_point, get_best_compute(r_point));
261 verify_before_compute(r_point, hv_algorithm);
264 if (p_idx >= m_points.size()) {
265 pagmo_throw(value_error,
"Index of the individual is out of bounds.");
271 std::vector<fitness_vector> points_cpy(m_points.begin(), m_points.end());
272 return hv_algorithm->exclusive(p_idx, points_cpy, r_point);
274 return hv_algorithm->exclusive(p_idx,
const_cast<std::vector<fitness_vector> &
>(m_points), r_point);
290 return exclusive(p_idx, r_point, get_best_exclusive(p_idx, r_point));
305 verify_before_compute(r_point, hv_algorithm);
309 if (m_points.size() == 1) {
315 std::vector<fitness_vector> points_cpy(m_points.begin(), m_points.end());
316 return hv_algorithm->least_contributor(points_cpy, r_point);
318 return hv_algorithm->least_contributor(
const_cast<std::vector<fitness_vector> &
>(m_points), r_point);
348 verify_before_compute(r_point, hv_algorithm);
353 std::vector<fitness_vector> points_cpy(m_points.begin(), m_points.end());
354 return hv_algorithm->greatest_contributor(points_cpy, r_point);
356 return hv_algorithm->greatest_contributor(
const_cast<std::vector<fitness_vector> &
>(m_points), r_point);
386 verify_before_compute(r_point, hv_algorithm);
390 if (m_points.size() == 1) {
391 std::vector<double> c;
398 std::vector<fitness_vector> points_cpy(m_points.begin(), m_points.end());
399 return hv_algorithm->contributions(points_cpy, r_point);
401 return hv_algorithm->contributions(
const_cast<std::vector<fitness_vector> &
>(m_points), r_point);
416 return contributions(r_point, get_best_contributions(r_point));
432 return d * n * log(n);
436 return 0.0005 * d * pow(n, d * 0.5);
450 fitness_vector nadir_point(m_points[0].begin(), m_points[0].end());
451 for (std::vector<fitness_vector>::size_type idx = 1 ; idx < m_points.size() ; ++ idx){
452 for (fitness_vector::size_type f_idx = 0 ; f_idx < m_points[0].size() ; ++f_idx){
454 nadir_point[f_idx] = std::max(nadir_point[f_idx], m_points[idx][f_idx]);
457 for (fitness_vector::size_type f_idx = 0 ; f_idx < nadir_point.size() ; ++f_idx) {
458 nadir_point[f_idx] += epsilon;
bool get_verify()
Getter for the 'verify' flag.
double compute(const fitness_vector &, const hv_algorithm::base_ptr) const
Compute hypervolume.
boost::shared_ptr< hypervolume > hypervolume_ptr
Alias for the shared pointer to a pagmo::util::hypervolume.
static double volume_between(const fitness_vector &, const fitness_vector &, unsigned int=0)
Compute volume between two points.
hypervolume_ptr clone() const
Clone method.
bool get_copy_points()
Getter for 'copy_points' flag.
unsigned int least_contributor(const fitness_vector &, const hv_algorithm::base_ptr) const
Find the least contributing individual.
void set_verify(const bool)
Setter for the 'verify' flag.
static double get_expected_operations(const unsigned int n, const unsigned int d)
Get expected numer of operations.
std::vector< double > contributions(const fitness_vector &, const hv_algorithm::base_ptr) const
Contributions method.
fitness_vector get_nadir_point(const double epsilon=0.0) const
Calculate the nadir point.
std::vector< double > fitness_vector
Fitness vector type.
boost::shared_ptr< base > base_ptr
Base hypervolume algorithm class.
hypervolume()
Default constructor.
const std::vector< fitness_vector > get_points() const
Get points.
container_type::size_type size_type
Population size type.
unsigned int greatest_contributor(const fitness_vector &, const hv_algorithm::base_ptr) const
Find the most contributing individual.
double exclusive(const unsigned int, const fitness_vector &, const hv_algorithm::base_ptr) const
Compute exclusive contribution.
void set_copy_points(const bool)
Setter for 'copy_points' flag.