29 namespace pagmo {
namespace util {
namespace hv_algorithm {
32 hv2d::hv2d(
const bool initial_sorting) : m_initial_sorting(initial_sorting) { }
47 if (points.size() == 0) {
49 }
else if (points.size() == 1) {
53 if (m_initial_sorting) {
60 double w = r_point[0] - points[0][0];
61 for(
unsigned int idx = 0 ; idx < points.size() - 1 ; ++idx) {
62 hypervolume += (points[idx + 1][1] - points[idx][1]) * w;
63 w = std::max(w, r_point[0] - points[idx+1][0]);
65 hypervolume += (r_point[1] - points[points.size() - 1][1]) * w;
74 bool hv2d::cmp_double_2d(
double* a,
double* b)
92 double hv2d::compute(
double** points,
unsigned int n_points,
double* r_point)
const
97 else if (n_points == 1) {
101 if (m_initial_sorting) {
102 std::sort(points, points + n_points, hv2d::cmp_double_2d);
108 double w = r_point[0] - points[0][0];
109 for(
unsigned int idx = 0 ; idx < n_points - 1 ; ++idx) {
110 hypervolume += (points[idx + 1][1] - points[idx][1]) * w;
111 w = std::max(w, r_point[0] - points[idx+1][0]);
113 hypervolume += (r_point[1] - points[n_points - 1][1]) * w;
128 std::vector<fitness_vector> new_points(points.size(),
fitness_vector(3, 0.0));
130 new_r.push_back(1.0);
132 for(
unsigned int i = 0 ; i < points.size() ; ++i) {
133 new_points[i][0] = points[i][0];
134 new_points[i][1] = points[i][1];
135 new_points[i][2] = 0.0;
146 bool hv2d::point_pairs_cmp(
const std::pair<fitness_vector, unsigned int> &a,
const std::pair<fitness_vector, unsigned int> &b)
148 return a.first[1] > b.first[1];
160 return "hv2d algorithm";
174 if (r_point.size() != 2) {
175 pagmo_throw(value_error,
"Algorithm hv2d works only for 2-dimensional cases.");
Fitness vector comparator class.
std::vector< double > contributions(std::vector< fitness_vector > &, const fitness_vector &) const
Contributions method.
double compute(std::vector< fitness_vector > &, const fitness_vector &) const
Computes hypervolume method.
hv2d hypervolume algorithm class
static double volume_between(const fitness_vector &, const fitness_vector &, unsigned int=0)
Compute volume between two points.
hv2d(const bool initial_sorting=true)
Constructor.
void assert_minimisation(const std::vector< fitness_vector > &, const fitness_vector &) const
Assert that reference point dominates every other point from the set.
std::string get_name() const
Algorithm name.
std::vector< double > fitness_vector
Fitness vector type.
void verify_before_compute(const std::vector< fitness_vector > &, const fitness_vector &) const
Verify input method.
boost::shared_ptr< base > base_ptr
Base hypervolume algorithm class.
hv3d hypervolume algorithm class
base_ptr clone() const
Clone method.
std::vector< double > contributions(std::vector< fitness_vector > &, const fitness_vector &) const
Contributions method.