1 /* Copyright 2017-2021 PaGMO development team
2 
3 This file is part of the PaGMO library.
4 
5 The PaGMO library is free software; you can redistribute it and/or modify
6 it under the terms of either:
7 
8   * the GNU Lesser General Public License as published by the Free
9     Software Foundation; either version 3 of the License, or (at your
10     option) any later version.
11 
12 or
13 
14   * the GNU General Public License as published by the Free Software
15     Foundation; either version 3 of the License, or (at your option) any
16     later version.
17 
18 or both in parallel, as here.
19 
20 The PaGMO library is distributed in the hope that it will be useful, but
21 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
22 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
23 for more details.
24 
25 You should have received copies of the GNU General Public License and the
26 GNU Lesser General Public License along with the PaGMO library.  If not,
27 see https://www.gnu.org/licenses/. */
28 
29 #ifndef PAGMO_UTILS_HV_HV2D_HPP
30 #define PAGMO_UTILS_HV_HV2D_HPP
31 
32 #include <memory>
33 #include <string>
34 #include <vector>
35 
36 #include <pagmo/detail/visibility.hpp>
37 #include <pagmo/types.hpp>
38 #include <pagmo/utils/hv_algos/hv_algorithm.hpp>
39 
40 namespace pagmo
41 {
42 
43 /// hv2d hypervolume algorithm class
44 /**
45  * This is the class containing the implementation of the hypervolume algorithm for the 2-dimensional fronts.
46  * This method achieves the lower bound of n*log(n) time by sorting the initial set of points and then computing the
47  * partial areas linearly.
48  *
49  */
50 class PAGMO_DLL_PUBLIC hv2d final : public hv_algorithm
51 {
52 public:
53     /// Constructor
54     /**
55      * @param initial_sorting Turn initial sorting on-off
56      */
57     hv2d(const bool initial_sorting = true);
58 
59     // Compute hypervolume method.
60     double compute(std::vector<vector_double> &, const vector_double &) const override;
61 
62     // Compute hypervolume method.
63     double compute(double **, vector_double::size_type, double *) const;
64 
65     // Contributions method
66     std::vector<double> contributions(std::vector<vector_double> &, const vector_double &) const override;
67 
68     // Clone method.
69     std::shared_ptr<hv_algorithm> clone() const override;
70 
71     // Verify input method.
72     void verify_before_compute(const std::vector<vector_double> &, const vector_double &) const override;
73 
74     // Algorithm name
75     std::string get_name() const override;
76 
77 private:
78     // Flag stating whether the points should be sorted in the first step of the algorithm.
79     const bool m_initial_sorting;
80 };
81 } // namespace pagmo
82 
83 #endif
84