PaGMO  1.1.5
nlopt_aug_lag.cpp
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 #include <nlopt.hpp>
26 
27 #include "base_nlopt.h"
28 #include "nlopt_aug_lag.h"
29 
30 namespace pagmo { namespace algorithm {
31 
33 
48 nlopt_aug_lag::nlopt_aug_lag(int aux_algo_id, int max_iter, const double &ftol, const double &xtol, int aux_max_iter, const double &aux_ftol, const double &aux_xtol):base_nlopt(nlopt::AUGLAG,true,false,max_iter,ftol,xtol), m_aux_algo_id(aux_algo_id), m_aux_max_iter(aux_max_iter), m_aux_ftol(aux_ftol), m_aux_xtol(aux_xtol) {
49  if ( (aux_ftol <= 0) || (aux_xtol <= 0) ) {
50  pagmo_throw(value_error,"tolerances for the local optimizer must be positive");
51  }
52  if ((aux_algo_id >4)||(aux_algo_id<1)) {
53  pagmo_throw(value_error,"local algorithm id must be one of 1.2.3.4");
54  }
55 }
56 
58 {
59  return base_ptr(new nlopt_aug_lag(*this));
60 }
61 
63 void nlopt_aug_lag::set_local(size_t d) const{
64  nlopt::opt aux_opt(nlopt::LN_SBPLX,1);
65  switch(m_aux_algo_id)
66  {
67  case 1:
68  aux_opt = nlopt::opt(nlopt::LN_SBPLX,d);
69  break;
70  case 2:
71  aux_opt= nlopt::opt(nlopt::LN_COBYLA,d);
72  break;
73  case 3:
74  aux_opt = nlopt::opt(nlopt::LN_BOBYQA,d);
75  break;
76  case 4:
77  aux_opt = nlopt::opt(nlopt::LD_LBFGS,d);
78  break;
79  }
80  aux_opt.set_ftol_abs(m_aux_ftol);
81  aux_opt.set_xtol_abs(m_aux_xtol);
82  aux_opt.set_maxeval(m_aux_max_iter);
83  m_opt.set_local_optimizer(aux_opt);
84 }
85 
87 {
88  std::ostringstream oss;
89  oss << "max_iter: " << m_max_iter << ' ';
90  oss << "ftol: " << m_ftol << " ";
91  oss << "xtol: " << m_xtol << " ";
92  oss << "aux_max_iter: " << m_aux_max_iter << ' ';
93  oss << "aux_ftol: " << m_aux_ftol << " ";
94  oss << "aux_xtol: " << m_aux_xtol;
95 
96  return oss.str();
97 }
98 
100 std::string nlopt_aug_lag::get_name() const
101 {
102  std::string local;
103  switch(m_aux_algo_id)
104  {
105  case 1:
106  local = "sbplx";
107  break;
108  case 2:
109  local = "cobyla";
110  break;
111  case 3:
112  local = "bobyqa";
113  break;
114  case 4:
115  local = "lbfgs";
116  break;
117  }
118 
119  return "Augmented Lagrangian - " + local + " (NLOPT)";
120 }
121 
122 }}
123 
124 BOOST_CLASS_EXPORT_IMPLEMENT(pagmo::algorithm::nlopt_aug_lag)
boost::shared_ptr< base > base_ptr
Alias for shared pointer to base algorithm.
Root PaGMO namespace.
Wrapper for NLopt's Augmented Lagrangian algorithm.
Definition: nlopt_aug_lag.h:56
std::string get_name() const
Algorithm name.
nlopt::opt m_opt
NLOPT optimization method.
Definition: base_nlopt.h:94
std::string human_readable_extra() const
Extra information in human readable format.
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
const std::size_t m_max_iter
Maximum number of iterations.
Definition: base_nlopt.h:100
base_ptr clone() const
Clone method.
void set_local(size_t) const
Set the local optimizer.
const double m_ftol
Tolerance on the fitness function variation (stopping criteria)
Definition: base_nlopt.h:102
nlopt_aug_lag(int=1, int=100, const double &=1E-6, const double &=1E-6, int=100, const double &=1E-6, const double &=1E-6)
Constructor.