27 namespace pagmo {
namespace util {
namespace hv_algorithm {
43 for(std::vector<fitness_vector>::size_type idx = 0 ; idx < points.size() ; ++idx) {
44 bool outside_bounds =
false;
45 bool all_equal =
true;
47 for(fitness_vector::size_type f_idx = 0 ; f_idx < points[idx].size() ; ++f_idx) {
48 outside_bounds |= (r_point[f_idx] < points[idx][f_idx]);
49 all_equal &= (r_point[f_idx] == points[idx][f_idx]);
51 if (all_equal || outside_bounds) {
54 std::string str_p(
"("), str_r(
"(");
55 for(fitness_vector::size_type f_idx = 0 ; f_idx < points[idx].size() ; ++f_idx) {
56 str_p += boost::lexical_cast<std::string>(points[idx][f_idx]);
57 str_r += boost::lexical_cast<std::string>(r_point[f_idx]);
58 if (f_idx < points[idx].size() - 1) {
66 ss <<
"Reference point is invalid: another point seems to be outside the reference point boundary, or be equal to it:" << std::endl;
67 ss <<
" P[" << idx <<
"]\t= " << str_p << std::endl;
68 ss <<
" R\t= " << str_r << std::endl;
69 pagmo_throw(value_error, ss.str());
88 if (points.size() == 1) {
89 return compute(points, r_point);
91 std::vector<fitness_vector> points_less;
92 points_less.reserve(points.size() - 1);
93 copy(points.begin(), points.begin() + p_idx, back_inserter(points_less));
94 copy(points.begin() + p_idx + 1, points.end(), back_inserter(points_less));
106 if (points.size() == 1) {
112 unsigned int idx_extreme = 0;
115 for(
unsigned int idx = 1 ; idx < c.size() ; ++idx) {
116 if (cmp_func(c[idx], c[idx_extreme])) {
201 std::vector<double> c;
202 c.reserve(points.size());
205 if (points.size() == 1) {
211 std::vector<fitness_vector> points_cpy(points.begin(), points.end());
212 double hv_total =
compute(points_cpy, r_point);
215 points_cpy = std::vector<fitness_vector>(points.begin() + 1, points.end());
216 c.push_back(hv_total -
compute(points_cpy, r_point));
219 for(
unsigned int idx = 1 ; idx < points.size() ; ++idx) {
220 std::vector<fitness_vector> points_less;
221 points_less.reserve(points.size() - 1);
222 copy(points.begin(), points.begin() + idx, back_inserter(points_less));
223 copy(points.begin() + idx + 1, points.end(), back_inserter(points_less));
224 double delta = hv_total -
compute(points_less, r_point);
226 if (fabs(delta) < 1e-8) {
247 if (dim_bound == 0) {
248 dim_bound = a.size();
251 for (fitness_vector::size_type idx = 0; idx < dim_bound ; ++idx) {
252 volume *= (a[idx] - b[idx]);
254 return (volume < 0 ? -volume : volume);
271 volume *= (b[size] - a[size]);
273 return (volume < 0 ? -volume : volume);
287 if (dim_bound == 0) {
288 dim_bound = a.size();
290 for(fitness_vector::size_type i = 0; i < dim_bound ; ++i) {
292 for(fitness_vector::size_type j = i + 1; j < dim_bound ; ++j) {
294 return DOM_CMP_INCOMPARABLE;
297 return DOM_CMP_B_DOMINATES_A;
299 else if (a[i] < b[i]) {
300 for(fitness_vector::size_type j = i + 1 ; j < dim_bound ; ++j) {
302 return DOM_CMP_INCOMPARABLE;
305 return DOM_CMP_A_DOMINATES_B;
308 return DOM_CMP_A_B_EQUAL;
322 for(fitness_vector::size_type i = 0; i < size ; ++i) {
324 for(fitness_vector::size_type j = i + 1; j < size ; ++j) {
326 return DOM_CMP_INCOMPARABLE;
329 return DOM_CMP_B_DOMINATES_A;
331 else if (a[i] < b[i]) {
332 for(fitness_vector::size_type j = i + 1 ; j < size ; ++j) {
334 return DOM_CMP_INCOMPARABLE;
337 return DOM_CMP_A_DOMINATES_B;
340 return DOM_CMP_A_B_EQUAL;
352 if (cmp_type ==
'<') {
353 m_cmp_obj = boost::shared_ptr<cmp_fun>(
new cmp_le(dim));
356 m_cmp_obj = boost::shared_ptr<cmp_fun>(
new cmp_ge(dim));
368 return typeid(*this).name();
virtual ~base()
Destructor required for pure virtual methods.
static bool cmp_least(const double, const double)
Comparison method for the least contributor.
fitness_vector_cmp(int dim, char cmp_type)
Constructor of the comparator object.
static double volume_between(const fitness_vector &, const fitness_vector &, unsigned int=0)
Compute volume between two points.
void assert_minimisation(const std::vector< fitness_vector > &, const fitness_vector &) const
Assert that reference point dominates every other point from the set.
virtual unsigned int greatest_contributor(std::vector< fitness_vector > &, const fitness_vector &) const
Greatest contributor method.
static int dom_cmp(double *, double *, unsigned int)
Dominance comparison method.
static bool cmp_greatest(const double, const double)
Comparison method for the least contributor.
virtual std::string get_name() const
Get algorithm's name.
virtual double compute(std::vector< fitness_vector > &points, const fitness_vector &r_point) const =0
Compute method.
virtual double exclusive(const unsigned int, std::vector< fitness_vector > &, const fitness_vector &) const
Exclusive hypervolume method.
std::vector< double > fitness_vector
Fitness vector type.
virtual unsigned int least_contributor(std::vector< fitness_vector > &, const fitness_vector &) const
Least contributor method.
virtual std::vector< double > contributions(std::vector< fitness_vector > &, const fitness_vector &) const
Contributions method.
virtual unsigned int extreme_contributor(std::vector< fitness_vector > &, const fitness_vector &, bool(*)(double, double)) const
compute the extreme contributor