HypervolumeCalculator.h
Go to the documentation of this file.
1 /*!
2  *
3  *
4  * \brief Implements the frontend for the HypervolumeCalculator algorithms, including the approximations
5  *
6  *
7  * \author O.Krause
8  * \date 2014-2016
9  *
10  *
11  * \par Copyright 1995-2017 Shark Development Team
12  *
13  * <BR><HR>
14  * This file is part of Shark.
15  * <http://shark-ml.org/>
16  *
17  * Shark is free software: you can redistribute it and/or modify
18  * it under the terms of the GNU Lesser General Public License as published
19  * by the Free Software Foundation, either version 3 of the License, or
20  * (at your option) any later version.
21  *
22  * Shark is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  * GNU Lesser General Public License for more details.
26  *
27  * You should have received a copy of the GNU Lesser General Public License
28  * along with Shark. If not, see <http://www.gnu.org/licenses/>.
29  *
30  */
31 #ifndef SHARK_ALGORITHMS_DIRECTSEARCH_HYPERVOLUMECALCULATOR_H
32 #define SHARK_ALGORITHMS_DIRECTSEARCH_HYPERVOLUMECALCULATOR_H
33 
39 
40 namespace shark {
41 /// \brief Frontend for hypervolume calculation algorithms in m dimensions.
42 ///
43 /// Depending on the dimensionality of the problem, one of the specialized algorithms is called.
44 /// For large dimensionalities for which there are no specialized fast algorithms,
45 /// either the exponential time or the approximated algorithm is called based on the choice of algorithm
47 
48  /// \brief Default c'tor.
49  HypervolumeCalculator() : m_useApproximation(false) {}
50 
51  ///\brief True if the hypervolume approximation is to be used in dimensions > 3.
53  m_useApproximation = useApproximation;
54  }
55 
56  double approximationEpsilon()const{
57  return m_approximationAlgorithm.epsilon();
58  }
60  return m_approximationAlgorithm.epsilon();
61  }
62 
63  double approximationDelta()const{
64  return m_approximationAlgorithm.delta();
65  }
66 
67  double& approximationDelta(){
68  return m_approximationAlgorithm.delta();
69  }
70 
71  template<typename Archive>
72  void serialize( Archive & archive, const unsigned int version ) {
73  archive & BOOST_SERIALIZATION_NVP(m_useApproximation);
74  archive & BOOST_SERIALIZATION_NVP(m_approximationAlgorithm);
75  }
76 
77  /// \brief Executes the algorithm.
78  /// \param [in] points The set \f$S\f$ of points for which the following assumption needs to hold: \f$\forall s \in S: \lnot \exists s' \in S: s' \preceq s \f$
79  /// \param [in] refPoint The reference point \f$\vec{r} \in \mathbb{R}^n\f$ for the hypervolume calculation, needs to fulfill: \f$ \forall s \in S: s \preceq \vec{r}\f$. .
80  template<typename Points, typename VectorType>
81  double operator()( Points const& points, VectorType const& refPoint){
82  if(points.size() == 0) return 0;
83  SIZE_CHECK( points.begin()->size() == refPoint.size() );
84  std::size_t numObjectives = refPoint.size();
85  if(numObjectives == 2){
86  HypervolumeCalculator2D algorithm;
87  return algorithm(points, refPoint);
88  }else if(numObjectives == 3){
89  HypervolumeCalculator3D algorithm;
90  return algorithm(points, refPoint);
91  }else if(numObjectives == 4){
93  return algorithm(points, refPoint);
94  }if(m_useApproximation){
95  return m_approximationAlgorithm(points, refPoint);
96  }else {
98  return algorithm(points, refPoint);
99  }
100  }
101 
102 private:
103  bool m_useApproximation;
104  HypervolumeApproximator m_approximationAlgorithm;
105 };
106 
107 }
108 #endif