27 #include "ipopt_interface.hpp"
28 #include "ipopt_nlp.hpp"
29 #include "casadi/core/casadi_misc.hpp"
30 #include "../../core/global_options.hpp"
31 #include "../../core/casadi_interrupt.hpp"
32 #include "../../core/convexify.hpp"
40 #include <IpIpoptApplication.hpp>
42 #include <ipopt_runtime_str.h>
46 int CASADI_NLPSOL_IPOPT_EXPORT
49 plugin->name =
"ipopt";
51 plugin->version = CASADI_VERSION;
72 {{
"pass_nonlinear_variables",
74 "Pass list of variables entering nonlinearly to IPOPT"}},
75 {
"nonlinear_variables",
77 "Which decision variables enter nonlinearly? (detected automatically by default)"}},
80 "Options to be passed to IPOPT"}},
83 "String metadata (a dictionary with lists of strings) "
84 "about variables to be passed to IPOPT"}},
87 "Integer metadata (a dictionary with lists of integers) "
88 "about variables to be passed to IPOPT"}},
91 "Numeric metadata (a dictionary with lists of reals) about "
92 "variables to be passed to IPOPT"}},
95 "String metadata (a dictionary with lists of strings) about "
96 "constraints to be passed to IPOPT"}},
99 "Integer metadata (a dictionary with lists of integers) "
100 "about constraints to be passed to IPOPT"}},
103 "Numeric metadata (a dictionary with lists of reals) about "
104 "constraints to be passed to IPOPT"}},
107 "Function for calculating the Hessian of the Lagrangian (autogenerated by default)"}},
110 "Function for calculating the Jacobian of the constraints "
111 "(autogenerated by default)"}},
114 "Function for calculating the gradient of the objective "
115 "(column, autogenerated by default)"}},
116 {
"convexify_strategy",
118 "NONE|regularize|eigen-reflect|eigen-clip. "
119 "Strategy to convexify the Lagrange Hessian before passing it to the solver."}},
122 "When using a convexification strategy, make sure that "
123 "the smallest eigenvalue is at least this (default: 1e-7)."}},
126 "Maximum number of iterations to compute an eigenvalue decomposition (default: 50)."}},
127 {
"clip_inactive_lam",
129 "Explicitly set Lagrange multipliers to 0 when bound is deemed inactive "
130 "(default: false)."}},
131 {
"inactive_lam_strategy",
133 "Strategy to detect if a bound is inactive. "
134 "RELTOL: use solver-defined constraint tolerance * inactive_lam_value|"
135 "abstol: use inactive_lam_value"}},
136 {
"inactive_lam_value",
138 "Value used in inactive_lam_strategy (default: 10)."}}
149 std::string convexify_strategy =
"none";
150 double convexify_margin = 1e-7;
151 casadi_int max_iter_eig = 200;
158 for (
auto&& op : opts) {
159 if (op.first==
"ipopt") {
161 }
else if (op.first==
"pass_nonlinear_variables") {
163 }
else if (op.first==
"nonlinear_variables") {
166 +
str(
nl_ex_.size()) +
") for 'nonlinear_variables', expected " +
str(
nx_));
167 }
else if (op.first==
"var_string_md") {
169 }
else if (op.first==
"var_integer_md") {
171 }
else if (op.first==
"var_numeric_md") {
173 }
else if (op.first==
"con_string_md") {
175 }
else if (op.first==
"con_integer_md") {
177 }
else if (op.first==
"con_numeric_md") {
179 }
else if (op.first==
"hess_lag") {
181 casadi_assert_dev(f.
n_in()==4);
182 casadi_assert_dev(f.
n_out()==1);
184 }
else if (op.first==
"jac_g") {
186 casadi_assert_dev(f.
n_in()==2);
187 casadi_assert_dev(f.
n_out()==2);
189 }
else if (op.first==
"grad_f") {
191 casadi_assert_dev(f.
n_in()==2);
192 casadi_assert_dev(f.
n_out()==2);
194 }
else if (op.first==
"convexify_strategy") {
195 convexify_strategy = op.second.to_string();
196 }
else if (op.first==
"convexify_margin") {
197 convexify_margin = op.second;
198 }
else if (op.first==
"max_iter_eig") {
199 max_iter_eig = op.second;
200 }
else if (op.first==
"clip_inactive_lam") {
202 }
else if (op.first==
"inactive_lam_strategy") {
204 }
else if (op.first==
"inactive_lam_value") {
211 auto hessian_approximation =
opts_.find(
"hessian_approximation");
212 if (hessian_approximation!=
opts_.end()) {
237 {
"triu:hess:gamma:x:x"}, {{
"gamma", {
"f",
"g"}}});
241 if (convexify_strategy!=
"none") {
244 opts[
"strategy"] = convexify_strategy;
245 opts[
"margin"] = convexify_margin;
246 opts[
"max_iter_eig"] = max_iter_eig;
272 Ipopt::SmartPtr<Ipopt::IpoptApplication> *app =
new Ipopt::SmartPtr<Ipopt::IpoptApplication>();
273 m->app =
static_cast<void*
>(app);
274 *app =
new Ipopt::IpoptApplication(
false);
277 StreamJournal* jrnl_raw =
new StreamJournal(
"console", J_ITERSUMMARY);
279 jrnl_raw->SetPrintLevel(J_DBG, J_NONE);
280 SmartPtr<Journal> jrnl = jrnl_raw;
281 (*app)->Jnlst()->AddJournal(jrnl);
284 Ipopt::SmartPtr<Ipopt::TNLP> *userclass =
new Ipopt::SmartPtr<Ipopt::TNLP>();
285 m->userclass =
static_cast<void*
>(userclass);
289 uout() <<
"There are " <<
nx_ <<
" variables and " <<
ng_ <<
" constraints." << std::endl;
291 else uout() <<
"Using limited memory Hessian approximation" << std::endl;
295 auto regops = (*app)->RegOptions()->RegisteredOptionsList();
299 auto it = options.find(
"resto");
300 if (it!=options.end()) {
301 Dict resto_options = it->second;
303 for (
auto&& op : resto_options) {
304 options[
"resto." + op.first] = op.second;
309 for (
auto&& op : options) {
312 std::string option_name = op.first;
314 option_name = option_name.substr(6);
318 auto regops_it = regops.find(option_name);
319 if (regops_it==regops.end()) {
320 casadi_error(
"No such IPOPT option: " + op.first);
324 Ipopt::RegisteredOptionType ipopt_type = regops_it->second->Type();
328 switch (ipopt_type) {
329 case Ipopt::OT_Number:
330 ret = (*app)->Options()->SetNumericValue(op.first, op.second.to_double(),
false);
332 case Ipopt::OT_Integer:
333 ret = (*app)->Options()->SetIntegerValue(op.first, op.second.to_int(),
false);
335 case Ipopt::OT_String:
336 ret = (*app)->Options()->SetStringValue(op.first, op.second.to_string(),
false);
338 case Ipopt::OT_Unknown:
340 casadi_warning(
"Cannot handle option \"" + op.first +
"\", ignored");
343 if (!ret) casadi_error(
"Invalid options were detected by Ipopt.");
347 if (
opts_.find(
"linear_solver") ==
opts_.end()) {
348 char * default_solver = getenv(
"IPOPT_DEFAULT_LINEAR_SOLVER");
349 if (default_solver) {
350 bool ret = (*app)->Options()->SetStringValue(
"linear_solver", default_solver,
false);
351 casadi_assert(ret,
"Corrupted IPOPT_DEFAULT_LINEAR_SOLVER environmental variable");
355 bool ret = (*app)->Options()->SetStringValue(
"linear_solver",
"mumps",
false);
356 casadi_assert_dev(ret);
362 Ipopt::ApplicationReturnStatus status = (*app)->Initialize();
363 casadi_assert(status == Solve_Succeeded,
"Error during IPOPT initialization");
370 casadi_int*& iw,
double*& w)
const {
378 m->grad_fk = w; w +=
nx_;
387 case Solve_Succeeded:
388 return "Solve_Succeeded";
389 case Solved_To_Acceptable_Level:
390 return "Solved_To_Acceptable_Level";
391 case Infeasible_Problem_Detected:
392 return "Infeasible_Problem_Detected";
393 case Search_Direction_Becomes_Too_Small:
394 return "Search_Direction_Becomes_Too_Small";
395 case Diverging_Iterates:
396 return "Diverging_Iterates";
397 case User_Requested_Stop:
398 return "User_Requested_Stop";
399 case Maximum_Iterations_Exceeded:
400 return "Maximum_Iterations_Exceeded";
401 case Restoration_Failed:
402 return "Restoration_Failed";
403 case Error_In_Step_Computation:
404 return "Error_In_Step_Computation";
405 case Not_Enough_Degrees_Of_Freedom:
406 return "Not_Enough_Degrees_Of_Freedom";
407 case Invalid_Problem_Definition:
408 return "Invalid_Problem_Definition";
410 return "Invalid_Option";
411 case Invalid_Number_Detected:
412 return "Invalid_Number_Detected";
413 case Unrecoverable_Exception:
414 return "Unrecoverable_Exception";
415 case NonIpopt_Exception_Thrown:
416 return "NonIpopt_Exception_Thrown";
417 case Insufficient_Memory:
418 return "Insufficient_Memory";
420 return "Internal_Error";
421 case Maximum_CpuTime_Exceeded:
422 return "Maximum_CpuTime_Exceeded";
423 case Feasible_Point_Found:
424 return "Feasible_Point_Found";
425 #if (IPOPT_VERSION_MAJOR > 3) || (IPOPT_VERSION_MAJOR == 3 && IPOPT_VERSION_MINOR >= 14)
426 case Maximum_WallTime_Exceeded:
427 return "Maximum_WallTime_Exceeded";
435 auto d_nlp = &m->
d_nlp;
442 m->regularization_size.clear();
446 m->ls_trials.clear();
452 Ipopt::SmartPtr<Ipopt::TNLP> *userclass =
453 static_cast<Ipopt::SmartPtr<Ipopt::TNLP>*
>(m->userclass);
454 Ipopt::SmartPtr<Ipopt::IpoptApplication> *app =
455 static_cast<Ipopt::SmartPtr<Ipopt::IpoptApplication>*
>(m->app);
458 Ipopt::ApplicationReturnStatus status = (*app)->OptimizeTNLP(*userclass);
460 m->success = status==Solve_Succeeded || status==Solved_To_Acceptable_Level
461 || status==Feasible_Point_Found;
462 if (status==Maximum_Iterations_Exceeded ||
465 #if (IPOPT_VERSION_MAJOR > 3) || (IPOPT_VERSION_MAJOR == 3 && IPOPT_VERSION_MINOR >= 14)
478 double constr_viol_tol;
479 (*app)->Options()->GetNumericValue(
"constr_viol_tol", constr_viol_tol,
"");
480 if (status==Solved_To_Acceptable_Level) {
481 (*app)->Options()->GetNumericValue(
"acceptable_constr_viol_tol", constr_viol_tol,
"");
486 "' unknown. Use 'abstol' or reltol'.");
489 for (casadi_int i=0; i<
nx_ +
ng_; ++i) {
491 if (d_nlp->lam[i]>0 && d_nlp->ubz[i] - d_nlp->z[i] > margin) d_nlp->lam[i]=0;
492 if (d_nlp->lam[i]<0 && d_nlp->z[i] - d_nlp->lbz[i] > margin) d_nlp->lam[i]=0;
501 const double* g,
const double* lambda,
double obj_value,
int iter,
502 double inf_pr,
double inf_du,
double mu,
double d_norm,
503 double regularization_size,
double alpha_du,
double alpha_pr,
504 int ls_trials,
bool full_callback)
const {
505 auto d_nlp = &m->
d_nlp;
508 m->
inf_pr.push_back(inf_pr);
509 m->
inf_du.push_back(inf_du);
511 m->
d_norm.push_back(d_norm);
516 m->
obj.push_back(obj_value);
521 for (casadi_int i=0; i<
nx_; ++i) {
522 d_nlp->lam[i] = z_U[i]-z_L[i];
529 <<
"Warning: intermediate_callback is disfunctional in your installation. "
530 "You will only be able to use stats(). "
531 "See https://github.com/casadi/casadi/wiki/enableIpoptCallback to enable it."
552 m->
res[0] = &ret_double;
555 casadi_int ret =
static_cast<casadi_int
>(ret_double);
564 }
catch(std::exception& ex) {
565 casadi_warning(
"intermediate_callback: " + std::string(ex.
what()));
573 const double* g,
const double* lambda,
double obj_value,
574 int iter_count)
const {
575 auto d_nlp = &m->
d_nlp;
581 d_nlp->objective = obj_value;
584 for (casadi_int i=0; i<
nx_; ++i) {
585 d_nlp->lam[i] = z_U[i]-z_L[i];
597 }
catch(std::exception& ex) {
598 uerr() <<
"finalize_solution failed: " << ex.what() << std::endl;
604 double* g_l,
double* g_u)
const {
605 auto d_nlp = &m->
d_nlp;
612 }
catch(std::exception& ex) {
613 uerr() <<
"get_bounds_info failed: " << ex.what() << std::endl;
620 bool init_z,
double* z_L,
double* z_U,
621 bool init_lambda,
double* lambda)
const {
622 auto d_nlp = &m->
d_nlp;
631 for (casadi_int i=0; i<
nx_; ++i) {
632 z_L[i] = std::max(0., -d_nlp->lam[i]);
633 z_U[i] = std::max(0., d_nlp->lam[i]);
643 }
catch(std::exception& ex) {
644 uerr() <<
"get_starting_point failed: " << ex.what() << std::endl;
650 int& nnz_jac_g,
int& nnz_h_lag)
const {
664 }
catch(std::exception& ex) {
665 uerr() <<
"get_nlp_info failed: " << ex.what() << std::endl;
677 for (
auto&& i :
nl_ex_)
if (i) nv++;
680 }
catch(std::exception& ex) {
681 uerr() <<
"get_number_of_nonlinear_variables failed: " << ex.what() << std::endl;
689 for (
int i=0; i<
nl_ex_.size(); ++i) {
690 if (
nl_ex_[i]) *pos_nonlin_vars++ = i;
693 }
catch(std::exception& ex) {
694 uerr() <<
"get_list_of_nonlinear_variables failed: " << ex.what() << std::endl;
701 std::map<std::string, std::vector<int> >& var_integer_md,
702 std::map<std::string, std::vector<double> >& var_numeric_md,
703 std::map<std::string, std::vector<std::string> >& con_string_md,
704 std::map<std::string, std::vector<int> >& con_integer_md,
705 std::map<std::string, std::vector<double> >& con_numeric_md)
const {
706 for (
auto&& op :
var_string_md_) var_string_md[op.first] = op.second;
707 for (
auto&& op :
var_integer_md_) var_integer_md[op.first] = op.second;
708 for (
auto&& op :
var_numeric_md_) var_numeric_md[op.first] = op.second;
709 for (
auto&& op :
con_string_md_) con_string_md[op.first] = op.second;
710 for (
auto&& op :
con_integer_md_) con_integer_md[op.first] = op.second;
711 for (
auto&& op :
con_numeric_md_) con_numeric_md[op.first] = op.second;
723 if (this->
app !=
nullptr) {
724 delete static_cast<Ipopt::SmartPtr<Ipopt::IpoptApplication>*
>(this->
app);
729 delete static_cast<Ipopt::SmartPtr<Ipopt::TNLP>*
>(this->
userclass);
737 stats[
"iter_count"] = m->iter_count;
738 if (!m->inf_pr.empty()) {
740 iterations[
"inf_pr"] = m->inf_pr;
741 iterations[
"inf_du"] = m->inf_du;
742 iterations[
"mu"] = m->mu;
743 iterations[
"d_norm"] = m->d_norm;
744 iterations[
"regularization_size"] = m->regularization_size;
745 iterations[
"obj"] = m->obj;
746 iterations[
"alpha_pr"] = m->alpha_pr;
747 iterations[
"alpha_du"] = m->alpha_du;
748 stats[
"iterations"] = iterations;
754 int version = s.
version(
"IpoptInterface", 1, 3);
785 s.
version(
"IpoptInterface", 3);
808 g <<
"casadi_ipopt_init_mem(&" +
codegen_mem(g) +
");\n";
813 g <<
"casadi_ipopt_free_mem(&" +
codegen_mem(g) +
");\n";
830 std::string name =
"nlp_f";
834 <<
"(ipindex n, ipnumber *x, bool new_x, ipnumber *obj_value, UserDataPtr user_data) {\n";
837 g <<
"struct casadi_ipopt_data* d = (struct casadi_ipopt_data*) user_data;\n";
838 g <<
"d->arg[0] = x;\n";
839 g <<
"d->arg[1] = d->nlp->p;\n";
840 g <<
"d->res[0] = obj_value;\n";
841 std::string flag = g(
get_function(name),
"d->arg",
"d->res",
"d->iw",
"d->w",
"false");
842 g <<
"if (" + flag +
") return false;\n";
843 g <<
"return true;\n";
850 <<
"(ipindex n, ipnumber *x, bool new_x, ipindex m, ipnumber *g, UserDataPtr user_data) {\n";
853 g <<
"struct casadi_ipopt_data* d = (struct casadi_ipopt_data*) user_data;\n";
854 g <<
"d->arg[0] = x;\n";
855 g <<
"d->arg[1] = d->nlp->p;\n";
856 g <<
"d->res[0] = g;\n";
857 flag = g(
get_function(name),
"d->arg",
"d->res",
"d->iw",
"d->w",
"false");
858 g <<
"if (" + flag +
") return false;\n";
859 g <<
"return true;\n";
866 <<
"(ipindex n, ipnumber *x, bool new_x, ipnumber *grad_f, UserDataPtr user_data) {\n";
869 g <<
"struct casadi_ipopt_data* d = (struct casadi_ipopt_data*) user_data;\n";
870 g <<
"d->arg[0] = x;\n";
871 g <<
"d->arg[1] = d->nlp->p;\n";
872 g <<
"d->res[0] = 0;\n";
873 g <<
"d->res[1] = grad_f;\n";
874 flag = g(
get_function(name),
"d->arg",
"d->res",
"d->iw",
"d->w",
"false");
875 g <<
"if (" + flag +
") return false;\n";
876 g <<
"return true;\n";
883 <<
"(ipindex n, ipnumber *x, bool new_x, ipindex m,"
884 <<
" ipindex nele_jac, ipindex *iRow, ipindex *jCol, "
885 <<
"ipnumber *values, UserDataPtr user_data) {\n";
888 g <<
"struct casadi_ipopt_data* d = (struct casadi_ipopt_data*) user_data;\n";
889 g <<
"if (values) {\n";
890 g <<
"d->arg[0] = x;\n";
891 g <<
"d->arg[1] = d->nlp->p;\n";
892 g <<
"d->res[0] = 0;\n";
893 g <<
"d->res[1] = values;\n";
894 flag = g(
get_function(name),
"d->arg",
"d->res",
"d->iw",
"d->w",
"false");
895 g <<
"if (" + flag +
") return false;\n";
897 g <<
"casadi_ipopt_sparsity(d->prob->sp_a, iRow, jCol);\n";
899 g <<
"return true;\n";
906 g <<
"bool " << f <<
"(ipindex n, ipnumber *x, bool new_x, ipnumber obj_factor,"
907 <<
"ipindex m, ipnumber *lambda, bool new_lambda, ipindex nele_hess, "
908 <<
"ipindex *iRow, ipindex *jCol, ipnumber *values, UserDataPtr user_data) {\n";
911 g <<
"struct casadi_ipopt_data* d = (struct casadi_ipopt_data*) user_data;\n";
912 g <<
"if (values) {\n";
913 g <<
"d->arg[0] = x;\n";
914 g <<
"d->arg[1] = d->nlp->p;\n";
915 g <<
"d->arg[2] = &obj_factor;\n";
916 g <<
"d->arg[3] = lambda;\n";
917 g <<
"d->res[0] = values;\n";
918 flag = g(
get_function(name),
"d->arg",
"d->res",
"d->iw",
"d->w",
"false");
919 g <<
"if (" + flag +
") return false;\n";
920 g <<
"return true;\n";
922 g <<
"casadi_ipopt_sparsity(d->prob->sp_h, iRow, jCol);\n";
924 g <<
"return true;\n";
934 g.
local(
"d",
"struct casadi_ipopt_data*");
936 g.
local(
"p",
"struct casadi_ipopt_prob");
939 g <<
"casadi_ipopt_set_work(d, &arg, &res, &iw, &w);\n";
940 g <<
"casadi_ipopt_presolve(d);\n";
943 Ipopt::SmartPtr<Ipopt::IpoptApplication> *app =
new Ipopt::SmartPtr<Ipopt::IpoptApplication>();
944 *app =
new Ipopt::IpoptApplication(
false);
947 auto regops = (*app)->RegOptions()->RegisteredOptionsList();
951 auto it = options.find(
"resto");
952 if (it!=options.end()) {
953 Dict resto_options = it->second;
955 for (
auto&& op : resto_options) {
956 options[
"resto." + op.first] = op.second;
961 for (
auto&& op : options) {
964 std::string option_name = op.first;
966 option_name = option_name.substr(6);
970 auto regops_it = regops.find(option_name);
971 if (regops_it==regops.end()) {
972 casadi_error(
"No such IPOPT option: " + op.first);
976 Ipopt::RegisteredOptionType ipopt_type = regops_it->second->Type();
979 switch (ipopt_type) {
980 case Ipopt::OT_Number:
981 g <<
"AddIpoptNumOption(d->ipopt, \"" << op.first <<
"\""
982 <<
"," << op.second.to_double() <<
");\n";
984 case Ipopt::OT_Integer:
985 g <<
"AddIpoptIntOption(d->ipopt, \"" << op.first <<
"\""
986 <<
"," << op.second.to_int() <<
");\n";
988 case Ipopt::OT_String:
989 g <<
"AddIpoptStrOption(d->ipopt, \"" << op.first <<
"\""
990 <<
",\"" << op.second.to_string() <<
"\");\n";
992 case Ipopt::OT_Unknown:
994 casadi_warning(
"Cannot handle option \"" + op.first +
"\", ignored");
1000 if (
opts_.find(
"linear_solver") ==
opts_.end()) {
1001 char * default_solver = getenv(
"IPOPT_DEFAULT_LINEAR_SOLVER");
1002 if (default_solver) {
1003 g <<
"AddIpoptStrOption(d->ipopt, \"linear_solver\"" <<
",\"" << default_solver <<
"\");\n";
1007 g <<
"AddIpoptStrOption(d->ipopt, \"linear_solver\",\"mumps\");\n";
1015 g <<
"casadi_ipopt_solve(d);\n";
1020 g <<
"return d->unified_return_status;\n";
1028 casadi_error(
"Empty sparsity pattern not supported in IPOPT C interface");
1030 g <<
"d->nlp = &d_nlp;\n";
1031 g <<
"d->prob = &p;\n";
1032 g <<
"p.nlp = &p_nlp;\n";
1037 g <<
"p.sp_h = 0;\n";
1039 g <<
"casadi_ipopt_setup(&p);\n";
1042 g <<
"p.eval_f = " << nlp_f <<
";\n";
1044 g <<
"p.eval_g = " << nlp_g <<
";\n";
1046 g <<
"p.eval_grad_f = " << nlp_grad_f <<
";\n";
1048 g <<
"p.eval_jac_g = " << nlp_jac_g <<
";\n";
1051 g <<
"p.eval_h = " << nlp_hess_l <<
";\n";
1053 g <<
"p.eval_h = casadi_ipopt_hess_l_empty;\n";
const char * what() const override
Display error.
Helper class for C code generation.
std::string add_dependency(const Function &f)
Add a function dependency.
std::string wrapper(const Function &base, const std::string &name)
void scope_enter()
Enter a local scope.
void flush(std::ostream &s)
Flush the buffer to a stream of choice.
void local(const std::string &name, const std::string &type, const std::string &ref="")
Declare a local variable.
void scope_exit()
Exit a local scope.
void init_local(const std::string &name, const std::string &def)
Specify the default value for a local variable.
std::string sanitize_source(const std::string &src, const std::vector< std::string > &inst, bool add_shorthand=true)
Sanitize source files for codegen.
void add_include(const std::string &new_include, bool relative_path=false, const std::string &use_ifdef=std::string())
Add an include file optionally using a relative path "..." instead of an absolute path <....
std::string shorthand(const std::string &name) const
Get a shorthand.
std::string sparsity(const Sparsity &sp, bool canonical=true)
std::stringstream auxiliaries
void add_auxiliary(Auxiliary f, const std::vector< std::string > &inst={"casadi_real"})
Add a built-in auxiliary function.
static void serialize(SerializingStream &s, const std::string &prefix, const ConvexifyData &d)
static Sparsity setup(ConvexifyData &d, const Sparsity &H, const Dict &opts=Dict(), bool inplace=true)
static MXNode * deserialize(DeserializingStream &s)
Deserialize without type information.
Helper class for Serialization.
void unpack(Sparsity &e)
Reconstruct an object from the input stream.
void version(const std::string &name, int v)
void alloc_iw(size_t sz_iw, bool persistent=false)
Ensure required length of iw field.
std::string codegen_mem(CodeGenerator &g, const std::string &index="mem") const
Get thread-local memory object.
void alloc_w(size_t sz_w, bool persistent=false)
Ensure required length of w field.
std::vector< bool > which_depends(const std::string &s_in, const std::vector< std::string > &s_out, casadi_int order=1, bool tr=false) const
Which variables enter with some order.
casadi_int n_out() const
Get the number of function outputs.
casadi_int n_in() const
Get the number of function inputs.
bool is_null() const
Is a null pointer?
void get_nlp_info(IpoptMemory *m, int &nx, int &ng, int &nnz_jac_g, int &nnz_h_lag) const
void finalize_solution(IpoptMemory *m, const double *x, const double *z_L, const double *z_U, const double *g, const double *lambda, double obj_value, int iter_count) const
void set_work(void *mem, const double **&arg, double **&res, casadi_int *&iw, double *&w) const override
Set the (persistent) work vectors.
static const std::string meta_doc
A documentation string.
bool get_bounds_info(IpoptMemory *m, double *x_l, double *x_u, double *g_l, double *g_u) const
void codegen_declarations(CodeGenerator &g) const override
Generate code for the declarations of the C function.
void codegen_init_mem(CodeGenerator &g) const override
Codegen alloc_mem.
bool convexify_
convexify?
void codegen_free_mem(CodeGenerator &g) const override
Codegen free_mem.
~IpoptInterface() override
void serialize_body(SerializingStream &s) const override
Serialize an object without type information.
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize into MX.
bool exact_hessian_
Exact Hessian?
ConvexifyData convexify_data_
Data for convexification.
int get_number_of_nonlinear_variables() const
bool get_var_con_metadata(std::map< std::string, std::vector< std::string > > &var_string_md, std::map< std::string, std::vector< int > > &var_integer_md, std::map< std::string, std::vector< double > > &var_numeric_md, std::map< std::string, std::vector< std::string > > &con_string_md, std::map< std::string, std::vector< int > > &con_integer_md, std::map< std::string, std::vector< double > > &con_numeric_md) const
std::string inactive_lam_strategy_
Dict get_stats(void *mem) const override
Get all statistics.
void set_ipopt_prob(CodeGenerator &g) const
static const Options options_
Options.
Dict opts_
All IPOPT options.
static Nlpsol * creator(const std::string &name, const Function &nlp)
Create a new NLP Solver.
void codegen_body(CodeGenerator &g) const override
Generate code for the function body.
double inactive_lam_value_
int init_mem(void *mem) const override
Initalize memory block.
int solve(void *mem) const override
void init(const Dict &opts) override
Initialize.
friend class IpoptUserClass
bool intermediate_callback(IpoptMemory *m, const double *x, const double *z_L, const double *z_U, const double *g, const double *lambda, double obj_value, int iter, double inf_pr, double inf_du, double mu, double d_norm, double regularization_size, double alpha_du, double alpha_pr, int ls_trials, bool full_callback) const
bool get_list_of_nonlinear_variables(int num_nonlin_vars, int *pos_nonlin_vars) const
bool pass_nonlinear_variables_
std::vector< bool > nl_ex_
IpoptInterface(const std::string &name, const Function &nlp)
bool get_starting_point(IpoptMemory *m, bool init_x, double *x, bool init_z, double *z_L, double *z_U, bool init_lambda, double *lambda) const
NLP solver storage class.
bool iteration_callback_ignore_errors_
Options.
void codegen_body_exit(CodeGenerator &g) const override
Generate code for the function body.
Dict get_stats(void *mem) const override
Get all statistics.
static const Options options_
Options.
void codegen_body_enter(CodeGenerator &g) const override
Generate code for the function body.
void codegen_declarations(CodeGenerator &g) const override
Generate code for the declarations of the C function.
void init(const Dict &opts) override
Initialize.
casadi_int ng_
Number of constraints.
int init_mem(void *mem) const override
Initalize memory block.
void serialize_body(SerializingStream &s) const override
Serialize an object without type information.
casadi_int nx_
Number of variables.
void set_work(void *mem, const double **&arg, double **&res, casadi_int *&iw, double *&w) const override
Set the (persistent) work vectors.
Function fcallback_
callback function, executed at each iteration
void set_function(const Function &fcn, const std::string &fname, bool jit=false)
Function oracle_
Oracle: Used to generate other functions.
Function create_function(const Function &oracle, const std::string &fname, const std::vector< std::string > &s_in, const std::vector< std::string > &s_out, const Function::AuxOut &aux=Function::AuxOut(), const Dict &opts=Dict())
std::vector< std::string > get_function() const override
Get list of dependency functions.
bool has_function(const std::string &fname) const override
static void registerPlugin(const Plugin &plugin, bool needs_lock=true)
Register an integrator in the factory.
bool error_on_fail_
Throw an exception on failure?
bool verbose_
Verbose printout.
void clear_mem()
Clear all memory (called from destructor)
Helper class for Serialization.
void version(const std::string &name, int v)
void pack(const Sparsity &e)
Serializes an object to the output stream.
casadi_int size1() const
Get the number of rows.
casadi_int nnz() const
Get the number of (structural) non-zeros.
casadi_int size2() const
Get the number of columns.
bool is_triu(bool strictly=false) const
Is upper triangular?
@ NLPSOL_G
Constraints function at the optimal solution (ng x 1)
@ NLPSOL_X
Decision variables at the optimal solution (nx x 1)
@ NLPSOL_LAM_P
Lagrange multipliers for bounds on P at the solution (np x 1)
@ NLPSOL_F
Cost function value at the optimal solution (1 x 1)
@ NLPSOL_LAM_G
Lagrange multipliers for bounds on G at the solution (ng x 1)
@ NLPSOL_LAM_X
Lagrange multipliers for bounds on X at the solution (nx x 1)
int CASADI_NLPSOL_IPOPT_EXPORT casadi_register_nlpsol_ipopt(Nlpsol::Plugin *plugin)
bool startswith(const std::string &s, const std::string &p)
Checks if s starts with p.
void casadi_copy(const T1 *x, casadi_int n, T1 *y)
COPY: y <-x.
void CASADI_NLPSOL_IPOPT_EXPORT casadi_load_nlpsol_ipopt()
const char * return_status_string(Bonmin::TMINLP::SolverReturn status)
std::string str(const T &v)
String representation, any type.
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.
IpoptMemory()
Constructor.
std::vector< double > regularization_size
std::vector< double > alpha_pr
const char * return_status
std::vector< double > obj
std::vector< double > inf_du
~IpoptMemory()
Destructor.
std::vector< double > d_norm
std::vector< double > inf_pr
std::vector< double > alpha_du
std::vector< int > ls_trials
casadi_nlpsol_data< double > d_nlp
Options metadata for a class.
static Dict sanitize(const Dict &opts, bool top_level=true)
Sanitize a options dictionary.
std::map< std::string, FStats > fstats