PaGMO  1.1.5
nlopt_aug_lag_eq.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_eq.h"
29 
30 namespace pagmo { namespace algorithm {
31 
33 
49 nlopt_aug_lag_eq::nlopt_aug_lag_eq(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) {
50  if ( (aux_ftol <= 0) || (aux_xtol <= 0) ) {
51  pagmo_throw(value_error,"tolerances for the local optimizer must be positive");
52  }
53  if ((aux_algo_id >2)||(aux_algo_id<1)) {
54  pagmo_throw(value_error,"local algorithm id must be one of 1.2");
55  }
56 }
57 
59 {
60  return base_ptr(new nlopt_aug_lag_eq(*this));
61 }
62 
64 void nlopt_aug_lag_eq::set_local(size_t d) const{
65  nlopt::opt aux_opt(nlopt::LN_COBYLA,1);
66  switch(m_aux_algo_id)
67  {
68  case 1:
69  aux_opt = nlopt::opt(nlopt::LN_COBYLA,d);
70  break;
71  case 2:
72  aux_opt= nlopt::opt(nlopt::LD_MMA,d);
73  break;
74  }
75  aux_opt.set_ftol_abs(m_aux_ftol);
76  aux_opt.set_xtol_abs(m_aux_xtol);
77  aux_opt.set_maxeval(m_aux_max_iter);
78  m_opt.set_local_optimizer(aux_opt);
79 }
80 
82 {
83  std::ostringstream oss;
84  oss << "max_iter: " << m_max_iter << ' ';
85  oss << "ftol: " << m_ftol << " ";
86  oss << "xtol: " << m_xtol << " ";
87  oss << "aux_max_iter: " << m_aux_max_iter << ' ';
88  oss << "aux_ftol: " << m_aux_ftol << " ";
89  oss << "aux_xtol: " << m_aux_xtol;
90 
91  return oss.str();
92 }
93 
95 std::string nlopt_aug_lag_eq::get_name() const
96 {
97  std::string aux;
98  switch(m_aux_algo_id)
99  {
100  case 1:
101  aux = "cobyla";
102  break;
103  case 2:
104  aux = "mma";
105  break;
106  }
107 
108  return "Augmented Lagrangian (EQ) - " + aux + " (NLOPT)";
109 }
110 
111 }}
112 
113 BOOST_CLASS_EXPORT_IMPLEMENT(pagmo::algorithm::nlopt_aug_lag_eq)
boost::shared_ptr< base > base_ptr
Alias for shared pointer to base algorithm.
Root PaGMO namespace.
Wrapper for NLopt's Augmented Lagrangian algorithm (using penalties only for the equalities) ...
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
const std::size_t m_max_iter
Maximum number of iterations.
Definition: base_nlopt.h:100
std::string human_readable_extra() const
Extra information in human readable format.
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_eq(int=1, int=100, const double &=1E-6, const double &=1E-6, int=100, const double &=1E-6, const double &=1E-6)
Constructor.
base_ptr clone() const
Clone method.
std::string get_name() const
Algorithm name.