PaGMO  1.1.5
bf_approx.h
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 #ifndef PAGMO_UTIL_HV_ALGORITHM_BF_APPROX_H
26 #define PAGMO_UTIL_HV_ALGORITHM_BF_APPROX_H
27 
28 #include <iostream>
29 #include <vector>
30 #include <cmath>
31 #include <algorithm>
32 #include <iterator>
33 #include "../../rng.h"
34 
35 #include "base.h"
36 
37 #include "../hypervolume.h"
38 
39 namespace pagmo { namespace util { namespace hv_algorithm {
40 
42 
50 class __PAGMO_VISIBLE bf_approx : public base
51 {
52 public:
53  bf_approx(const bool use_exact = true, const unsigned int trivial_subcase_size = 1, const double eps = 1e-2, const double delta = 1e-6, const double delta_multiplier = 0.775, const double m_alpha = 0.2, const double initial_delta_coeff = 0.1, const double gamma = 0.25);
54  double compute(std::vector<fitness_vector> &, const fitness_vector &) const;
55  unsigned int least_contributor(std::vector<fitness_vector> &, const fitness_vector &) const;
56  unsigned int greatest_contributor(std::vector<fitness_vector> &, const fitness_vector &) const;
57  void verify_before_compute(const std::vector<fitness_vector> &, const fitness_vector &) const;
58  base_ptr clone() const;
59  std::string get_name() const;
60 
61 private:
62  inline double compute_point_delta(const unsigned int, const unsigned int, const double) const;
63  inline fitness_vector compute_bounding_box(const std::vector<fitness_vector> &, const fitness_vector &, const unsigned int) const;
64  inline int point_in_box(const fitness_vector &p, const fitness_vector &a, const fitness_vector &b) const;
65  inline void sampling_round(const std::vector<fitness_vector>&, const double, const unsigned int, const unsigned int, const double) const;
66  inline bool sample_successful(const std::vector<fitness_vector> &, const unsigned int) const;
67 
68  enum extreme_contrib_type {
69  LEAST = 1,
70  GREATEST = 2
71  };
72 
73  unsigned int approx_extreme_contributor(std::vector<fitness_vector> &points, const fitness_vector &r_point, extreme_contrib_type, bool (*cmp_func)(double, double),
74  bool (*erase_condition)(unsigned int, unsigned int, std::vector<double> &, std::vector<double> &), double (*end_condition)(unsigned int, unsigned int, std::vector<double> &, std::vector<double> &)) const;
75 
76  static double lc_end_condition(unsigned int, unsigned int, std::vector<double>&, std::vector<double>&);
77  static double gc_end_condition(unsigned int, unsigned int, std::vector<double>&, std::vector<double>&);
78  static bool lc_erase_condition(unsigned int, unsigned int, std::vector<double>&, std::vector<double>&);
79  static bool gc_erase_condition(unsigned int, unsigned int, std::vector<double>&, std::vector<double>&);
80 
81  // flag stating whether BF approximation should use exact computation for some exclusive hypervolumes
82  const bool m_use_exact;
83 
84  // if the number of points overlapping the bounding box is small enough we can just compute that exactly
85  // following variable states the number of points for which we perform the optimization
86  const unsigned int m_trivial_subcase_size;
87 
88  // accuracy of the approximation
89  const double m_eps;
90 
91  // confidence of the approximation
92  const double m_delta;
93 
94  // multiplier of the round delta value
95  const double m_delta_multiplier;
96 
97  // alpha coefficient used for pushing on the sampling of the current least contributor
98  const double m_alpha;
99 
100  // initial coefficient of the delta at round 0
101  const double m_initial_delta_coeff;
102 
103  // constant used for the computation of point delta
104  const double m_gamma;
105 
106  mutable rng_double m_drng;
107 
114  // number of elementary operations performed for each point
115  mutable std::vector<unsigned long long> m_no_ops;
116 
117  // number of samples for given box
118  mutable std::vector<unsigned long long> m_no_samples;
119 
120  // number of "successful" samples that fell into the exclusive hypervolume
121  mutable std::vector<unsigned long long> m_no_succ_samples;
122 
123  // stores the indices of points that were not yet removed during the progress of the algorithm
124  mutable std::vector<unsigned int> m_point_set;
125 
126  // exact hypervolumes of the bounding boxes
127  mutable std::vector<double> m_box_volume;
128 
129  // approximated exlusive hypervolume of each point
130  mutable std::vector<double> m_approx_volume;
131 
132  // deltas computed for each point using chernoff inequality component
133  mutable std::vector<double> m_point_delta;
134 
135  // pair (boxes[idx], points[idx]) form a box in which monte carlo sampling is performed
136  mutable std::vector<fitness_vector> m_boxes;
137 
138  // list of indices of points that overlap the bounding box of each point
139  // during monte carlo sampling it suffices to check only these points when deciding whether the sampling was "successful"
140  mutable std::vector<std::vector<unsigned int> > m_box_points;
145  friend class boost::serialization::access;
146  template <class Archive>
147  void serialize(Archive &ar, const unsigned int)
148  {
149  ar & boost::serialization::base_object<base>(*this);
150  ar & const_cast<bool &>(m_use_exact);
151  ar & const_cast<unsigned int &>(m_trivial_subcase_size);
152  ar & const_cast<double &>(m_eps);
153  ar & const_cast<double &>(m_delta);
154  ar & const_cast<double &>(m_delta_multiplier);
155  ar & const_cast<double &>(m_alpha);
156  ar & const_cast<double &>(m_initial_delta_coeff);
157  ar & const_cast<double &>(m_gamma);
158  ar & m_drng;
159  }
160 };
161 
162 } } }
163 
164 BOOST_CLASS_EXPORT_KEY(pagmo::util::hv_algorithm::bf_approx)
165 
166 #endif
Root PaGMO namespace.
Bringmann-Friedrich approximation method.
Definition: bf_approx.h:50
std::vector< double > fitness_vector
Fitness vector type.
Definition: types.h:42
boost::shared_ptr< base > base_ptr
Base hypervolume algorithm class.
This rng returns a double in the [0,1[ range.
Definition: rng.h:89