PaGMO  1.1.5
base_nlopt.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_BASE_NLOPT_H
26 #define PAGMO_ALGORITHM_BASE_NLOPT_H
27 
28 #include <cstddef>
29 #include <nlopt.hpp>
30 #include <string>
31 
32 #include "../config.h"
33 #include "../population.h"
34 #include "../problem/base.h"
35 #include "../serialization.h"
36 #include "../types.h"
37 #include "base.h"
38 
39 namespace pagmo { namespace algorithm {
40 
42 
58 class __PAGMO_VISIBLE base_nlopt: public base
59 {
60  protected:
61  base_nlopt(nlopt::algorithm, bool, bool, int, const double &, const double &);
62  void evolve(population &) const;
63  std::string human_readable_extra() const;
64  private:
65  struct nlopt_wrapper_data
66  {
67  problem::base const *prob;
69  decision_vector dx;
73  };
74  int get_last_status() const;
75  static double objfun_wrapper(const std::vector<double> &, std::vector<double> &, void*);
76  static double constraints_wrapper(const std::vector<double> &, std::vector<double> &, void*);
77  virtual void set_local(size_t d) const;
78  private:
79  friend class boost::serialization::access;
80  template <class Archive>
81  void serialize(Archive &ar, const unsigned int)
82  {
83  ar & boost::serialization::base_object<base>(*this);
84  ar & const_cast<nlopt::algorithm &>(m_algo);
85  ar & const_cast<bool &>(m_constrained);
86  ar & const_cast<bool &>(m_only_ineq);
87  ar & const_cast<std::size_t &>(m_max_iter);
88  ar & const_cast<double &>(m_ftol);
89  ar & const_cast<double &>(m_xtol);
90  }
91  const nlopt::algorithm m_algo;
92  protected:
94  mutable nlopt::opt m_opt;
95  private:
96  const bool m_constrained;
97  const bool m_only_ineq;
98  protected:
100  const std::size_t m_max_iter;
102  const double m_ftol;
104  const double m_xtol;
105 };
106 
107 }}
108 
109 #endif
Root PaGMO namespace.
std::vector< double > decision_vector
Decision vector type.
Definition: types.h:40
nlopt::opt m_opt
NLOPT optimization method.
Definition: base_nlopt.h:94
const double m_xtol
Tolerance on the decision_vector variation function (stopping criteria)
Definition: base_nlopt.h:104
Base class for wrapping NLopt's algorithms.
Definition: base_nlopt.h:58
Base algorithm class.
const std::size_t m_max_iter
Maximum number of iterations.
Definition: base_nlopt.h:100
Base problem class.
Definition: problem/base.h:148
Population class.
Definition: population.h:70
const double m_ftol
Tolerance on the fitness function variation (stopping criteria)
Definition: base_nlopt.h:102
std::vector< double > fitness_vector
Fitness vector type.
Definition: types.h:42
std::vector< double > constraint_vector
Constraint vector type.
Definition: types.h:44
constraint_vector::size_type c_size_type
Constraints' size type: the same as pagmo::constraint_vector's size type.
Definition: problem/base.h:164