26 #include "../exceptions.h"
30 #include "ipopt_cpp_wrapper/ipopt_problem.h"
31 #include <coin/IpIpoptApplication.hpp>
32 #include <coin/IpSolveStatistics.hpp>
36 namespace pagmo {
namespace algorithm {
54 const double &constr_viol_tol,
55 const double &dual_inf_tol,
56 const double &compl_inf_tol,
57 const bool &nlp_scaling_method,
58 const double &obj_scaling_factor,
59 const double &mu_init) :
60 m_max_iter(max_iter),m_constr_viol_tol(constr_viol_tol),
61 m_dual_inf_tol(dual_inf_tol), m_compl_inf_tol(compl_inf_tol),
62 m_nlp_scaling_method(nlp_scaling_method), m_obj_scaling_factor(obj_scaling_factor), m_mu_init(mu_init)
66 pagmo_throw(value_error,
"number of maximum iterations cannot be negative");
68 if (constr_viol_tol < 0) {
69 pagmo_throw(value_error,
"tolerance is not in ]0,1[");
71 if (dual_inf_tol < 0) {
72 pagmo_throw(value_error,
"obj_tol is not in ]0,1[");
74 if (compl_inf_tol < 0) {
75 pagmo_throw(value_error,
"obj_tol is not in ]0,1[");
78 pagmo_throw(value_error,
"mu_init is not in ]0, inf[");
104 const std::string name = prob.
get_name();
107 if ( prob_i_dimension != 0 ) {
108 pagmo_throw(value_error,
"No integer part allowed yet....");
112 pagmo_throw(value_error,
"No continuous part....");
115 if ( prob_f_dimension != 1 ) {
116 pagmo_throw(value_error,
"The problem is not single objective and IPOPT is not suitable to solve it");
120 if (NP == 0 || m_max_iter == 0) {
125 ::Ipopt::SmartPtr< ::Ipopt::TNLP> pagmo_nlp =
new ipopt_problem(&pop);
128 ::Ipopt::SmartPtr< ::Ipopt::IpoptApplication> m_app = new ::Ipopt::IpoptApplication(
m_screen_output,
false);
130 if (!m_nlp_scaling_method) {
131 m_app->Options()->SetStringValue(
"nlp_scaling_method",
"none");
133 m_app->Options()->SetStringValue(
"hessian_approximation",
"limited-memory");
134 m_app->Options()->SetIntegerValue(
"print_level", 5);
137 m_app->Options()->SetIntegerValue(
"max_iter", m_max_iter);
140 m_app->Options()->SetNumericValue(
"tol", 1.);
141 m_app->Options()->SetNumericValue(
"dual_inf_tol", m_dual_inf_tol);
142 m_app->Options()->SetNumericValue(
"constr_viol_tol", m_constr_viol_tol);
143 m_app->Options()->SetNumericValue(
"compl_inf_tol", m_compl_inf_tol);
144 m_app->Options()->SetNumericValue(
"obj_scaling_factor", m_obj_scaling_factor);
145 m_app->Options()->SetNumericValue(
"mu_init", m_mu_init);
150 Ipopt::ApplicationReturnStatus status;
151 status = m_app->Initialize();
152 if (status != Ipopt::Solve_Succeeded) {
153 pagmo_throw(value_error,
"Error during IPOPT initialization!");
157 status = m_app->OptimizeTNLP(pagmo_nlp);
172 std::ostringstream s;
173 s <<
"major_iter:" << m_max_iter <<
" ";
174 s <<
"constr_viol_tol:"<< m_constr_viol_tol<<
" ";
175 s <<
"dual_inf_tol:"<< m_dual_inf_tol<<
" ";
176 s <<
"compl_inf_tol:"<< m_compl_inf_tol<<
" ";
177 s <<
"nlp_scaling_method:"<< (m_nlp_scaling_method?
"True":
"False") <<
" ";
178 s <<
"obj_scaling_factor:"<< m_obj_scaling_factor<<
" ";
179 s <<
"mu_init:"<< m_mu_init;
boost::shared_ptr< base > base_ptr
Alias for shared pointer to base algorithm.
void evolve(population &) const
Evolve implementation.
base_ptr clone() const
Clone method.
ipopt(const int &max_iter=100, const double &constr_viol_tol=1e-8, const double &dual_inf_tol=1e-8, const double &compl_inf_tol=1e-8, const bool &nlp_scaling_method=true, const double &obj_scaling_factor=1.0, const double &mu_init=0.1)
Constructor.
size_type get_dimension() const
Return global dimension.
bool m_screen_output
Indicates to the derived class whether to print stuff on screen.
size_type get_i_dimension() const
Return integer dimension.
std::string human_readable_extra() const
Extra human readable algorithm info.
Wrapper for the IPOPT solver.
std::string get_name() const
Algorithm name.
container_type::size_type size_type
Population size type.
f_size_type get_f_dimension() const
Return fitness dimension.
virtual std::string get_name() const
Get problem's name.
decision_vector::size_type size_type
Problem's size type: the same as pagmo::decision_vector's size type.