PaGMO  1.1.5
hv4d.cpp
1 /*****************************************************************************
2  * Copyright (C) 2004-2015 The PaGMO development team, *
3  * Advanced Concepts Team (ACT), European Space Agency (ESA) *
4  * *
5  * https://github.com/esa/pagmo *
6  * *
7  * act@esa.int *
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  * This program is distributed in the hope that it will be useful, *
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
17  * GNU General Public License for more details. *
18  * *
19  * You should have received a copy of the GNU General Public License *
20  * along with this program; if not, write to the *
21  * Free Software Foundation, Inc., *
22  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
23  *****************************************************************************/
24 
25 
26 #include "hv4d.h"
27 
28 namespace pagmo { namespace util { namespace hv_algorithm {
29 
31 
37 double hv4d::compute(std::vector<fitness_vector> &points, const fitness_vector &r_point) const
38 {
39  // Prepare the initial data to suit the original code
40  double* data = new double[points.size() * 4];
41  double refpoint[4];
42  for (unsigned int d_idx = 0 ; d_idx < 4 ; ++d_idx) {
43  refpoint[d_idx] = r_point[d_idx];
44  }
45  unsigned int data_idx = 0;
46  for (unsigned int p_idx = 0 ; p_idx < points.size() ; ++p_idx) {
47  for (unsigned int d_idx = 0 ; d_idx < 4 ; ++d_idx) {
48  data[data_idx++] = points[p_idx][d_idx];
49  }
50  }
51 
52  double hv = guerreiro_hv4d(data, points.size(), refpoint);
53  delete[] data;
54  return hv;
55 }
56 
58 
66 void hv4d::verify_before_compute(const std::vector<fitness_vector> &points, const fitness_vector &r_point) const
67 {
68  if (r_point.size() != 4) {
69  pagmo_throw(value_error, "Algorithm HV4D works only for 4-dimensional cases");
70  }
71  base::assert_minimisation(points, r_point);
72 }
73 
76 {
77  return base_ptr(new hv4d(*this));
78 }
79 
81 std::string hv4d::get_name() const
82 {
83  return "Four-dimensional hypervolume by Andreia P. Guerreiro";
84 }
85 
86 } } }
87 
88 BOOST_CLASS_EXPORT_IMPLEMENT(pagmo::util::hv_algorithm::hv4d)
Root PaGMO namespace.
double compute(std::vector< fitness_vector > &, const fitness_vector &) const
Compute hypervolume.
Definition: hv4d.cpp:37
void assert_minimisation(const std::vector< fitness_vector > &, const fitness_vector &) const
Assert that reference point dominates every other point from the set.
hv4d hypervolume algorithm
Definition: hv4d.h:60
std::string get_name() const
Algorithm name.
Definition: hv4d.cpp:81
std::vector< double > fitness_vector
Fitness vector type.
Definition: types.h:42
boost::shared_ptr< base > base_ptr
Base hypervolume algorithm class.
void verify_before_compute(const std::vector< fitness_vector > &, const fitness_vector &) const
Verify before compute.
Definition: hv4d.cpp:66
base_ptr clone() const
Clone method.
Definition: hv4d.cpp:75