PaGMO  1.1.5
gsl_gradient.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_ALGORITHM_GSL_GRADIENT_H
26 #define PAGMO_ALGORITHM_GSL_GRADIENT_H
27 
28 #include <cstddef>
29 #include <gsl/gsl_multimin.h>
30 #include <gsl/gsl_vector.h>
31 #include <string>
32 
33 #include "../config.h"
34 #include "../population.h"
35 #include "../problem/base.h"
36 #include "../serialization.h"
37 #include "../types.h"
38 #include "base_gsl.h"
39 
40 namespace pagmo { namespace algorithm {
41 
43 
51 class __PAGMO_VISIBLE gsl_gradient: public base_gsl
52 {
53  public:
54  void evolve(population &) const;
55  std::string human_readable_extra() const;
56  protected:
57  gsl_gradient(int, const double &, const double &, const double &, const double &);
59 
64  virtual const gsl_multimin_fdfminimizer_type *get_gsl_minimiser_ptr() const = 0;
65  private:
66  // Structure to feed parameters to the numerical differentiation wrapper.
67  struct objfun_numdiff_wrapper_params
68  {
69  // Pointer to the problem.
70  problem::base const *prob;
71  // Decision vector.
73  // Fitness vector.
75  // Coordinate of the gradient being computed.
77  };
78  static double objfun_numdiff_wrapper(double, void *);
79  static void objfun_numdiff_central(gsl_vector *, const problem::base &, const decision_vector &, const double &);
80  static void d_objfun_wrapper(const gsl_vector *, void *, gsl_vector *);
81  static void fd_objfun_wrapper(const gsl_vector *, void *, double *, gsl_vector *);
82  static void cleanup(gsl_vector *, gsl_multimin_fdfminimizer *);
83  static void check_allocs(gsl_vector *, gsl_multimin_fdfminimizer *);
84  private:
85  friend class boost::serialization::access;
86  template <class Archive>
87  void serialize(Archive &ar, const unsigned int)
88  {
89  ar & boost::serialization::base_object<base_gsl>(*this);
90  ar & const_cast<std::size_t &>(m_max_iter);
91  ar & const_cast<double &>(m_grad_tol);
92  ar & const_cast<double &>(m_numdiff_step_size);
93  ar & const_cast<double &>(m_step_size);
94  ar & const_cast<double &>(m_tol);
95  }
96  const std::size_t m_max_iter;
97  const double m_grad_tol;
98  const double m_numdiff_step_size;
99  const double m_step_size;
100  const double m_tol;
101 };
102 
103 }}
104 
105 BOOST_SERIALIZATION_ASSUME_ABSTRACT(pagmo::algorithm::gsl_gradient)
106 
107 #endif
Root PaGMO namespace.
std::vector< double > decision_vector
Decision vector type.
Definition: types.h:40
Base problem class.
Definition: problem/base.h:148
Population class.
Definition: population.h:70
Base class for GSL algorithms.
Definition: base_gsl.h:56
std::vector< double > fitness_vector
Fitness vector type.
Definition: types.h:42
Wrapper for GSL minimisers with derivatives.
Definition: gsl_gradient.h:51
decision_vector::size_type size_type
Problem's size type: the same as pagmo::decision_vector's size type.
Definition: problem/base.h:160