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"}},
77 "Options to be passed to IPOPT"}},
80 "String metadata (a dictionary with lists of strings) "
81 "about variables to be passed to IPOPT"}},
84 "Integer metadata (a dictionary with lists of integers) "
85 "about variables to be passed to IPOPT"}},
88 "Numeric metadata (a dictionary with lists of reals) about "
89 "variables to be passed to IPOPT"}},
92 "String metadata (a dictionary with lists of strings) about "
93 "constraints to be passed to IPOPT"}},
96 "Integer metadata (a dictionary with lists of integers) "
97 "about constraints to be passed to IPOPT"}},
100 "Numeric metadata (a dictionary with lists of reals) about "
101 "constraints to be passed to IPOPT"}},
104 "Function for calculating the Hessian of the Lagrangian (autogenerated by default)"}},
107 "Function for calculating the Jacobian of the constraints "
108 "(autogenerated by default)"}},
111 "Function for calculating the gradient of the objective "
112 "(column, autogenerated by default)"}},
113 {
"convexify_strategy",
115 "NONE|regularize|eigen-reflect|eigen-clip. "
116 "Strategy to convexify the Lagrange Hessian before passing it to the solver."}},
119 "When using a convexification strategy, make sure that "
120 "the smallest eigenvalue is at least this (default: 1e-7)."}},
123 "Maximum number of iterations to compute an eigenvalue decomposition (default: 50)."}},
124 {
"clip_inactive_lam",
126 "Explicitly set Lagrange multipliers to 0 when bound is deemed inactive "
127 "(default: false)."}},
128 {
"inactive_lam_strategy",
130 "Strategy to detect if a bound is inactive. "
131 "RELTOL: use solver-defined constraint tolerance * inactive_lam_value|"
132 "abstol: use inactive_lam_value"}},
133 {
"inactive_lam_value",
135 "Value used in inactive_lam_strategy (default: 10)."}}
146 std::string convexify_strategy =
"none";
147 double convexify_margin = 1e-7;
148 casadi_int max_iter_eig = 200;
155 for (
auto&& op : opts) {
156 if (op.first==
"ipopt") {
158 }
else if (op.first==
"pass_nonlinear_variables") {
160 }
else if (op.first==
"var_string_md") {
162 }
else if (op.first==
"var_integer_md") {
164 }
else if (op.first==
"var_numeric_md") {
166 }
else if (op.first==
"con_string_md") {
168 }
else if (op.first==
"con_integer_md") {
170 }
else if (op.first==
"con_numeric_md") {
172 }
else if (op.first==
"hess_lag") {
174 casadi_assert_dev(f.
n_in()==4);
175 casadi_assert_dev(f.
n_out()==1);
177 }
else if (op.first==
"jac_g") {
179 casadi_assert_dev(f.
n_in()==2);
180 casadi_assert_dev(f.
n_out()==2);
182 }
else if (op.first==
"grad_f") {
184 casadi_assert_dev(f.
n_in()==2);
185 casadi_assert_dev(f.
n_out()==2);
187 }
else if (op.first==
"convexify_strategy") {
188 convexify_strategy = op.second.to_string();
189 }
else if (op.first==
"convexify_margin") {
190 convexify_margin = op.second;
191 }
else if (op.first==
"max_iter_eig") {
192 max_iter_eig = op.second;
193 }
else if (op.first==
"clip_inactive_lam") {
195 }
else if (op.first==
"inactive_lam_strategy") {
197 }
else if (op.first==
"inactive_lam_value") {
204 auto hessian_approximation =
opts_.find(
"hessian_approximation");
205 if (hessian_approximation!=
opts_.end()) {
226 {
"triu:hess:gamma:x:x"}, {{
"gamma", {
"f",
"g"}}});
230 if (convexify_strategy!=
"none") {
233 opts[
"strategy"] = convexify_strategy;
234 opts[
"margin"] = convexify_margin;
235 opts[
"max_iter_eig"] = max_iter_eig;
261 Ipopt::SmartPtr<Ipopt::IpoptApplication> *app =
new Ipopt::SmartPtr<Ipopt::IpoptApplication>();
262 m->app =
static_cast<void*
>(app);
263 *app =
new Ipopt::IpoptApplication(
false);
266 StreamJournal* jrnl_raw =
new StreamJournal(
"console", J_ITERSUMMARY);
268 jrnl_raw->SetPrintLevel(J_DBG, J_NONE);
269 SmartPtr<Journal> jrnl = jrnl_raw;
270 (*app)->Jnlst()->AddJournal(jrnl);
273 Ipopt::SmartPtr<Ipopt::TNLP> *userclass =
new Ipopt::SmartPtr<Ipopt::TNLP>();
274 m->userclass =
static_cast<void*
>(userclass);
278 uout() <<
"There are " <<
nx_ <<
" variables and " <<
ng_ <<
" constraints." << std::endl;
280 else uout() <<
"Using limited memory Hessian approximation" << std::endl;
284 auto regops = (*app)->RegOptions()->RegisteredOptionsList();
288 auto it = options.find(
"resto");
289 if (it!=options.end()) {
290 Dict resto_options = it->second;
292 for (
auto&& op : resto_options) {
293 options[
"resto." + op.first] = op.second;
298 for (
auto&& op : options) {
301 std::string option_name = op.first;
303 option_name = option_name.substr(6);
307 auto regops_it = regops.find(option_name);
308 if (regops_it==regops.end()) {
309 casadi_error(
"No such IPOPT option: " + op.first);
313 Ipopt::RegisteredOptionType ipopt_type = regops_it->second->Type();
317 switch (ipopt_type) {
318 case Ipopt::OT_Number:
319 ret = (*app)->Options()->SetNumericValue(op.first, op.second.to_double(),
false);
321 case Ipopt::OT_Integer:
322 ret = (*app)->Options()->SetIntegerValue(op.first, op.second.to_int(),
false);
324 case Ipopt::OT_String:
325 ret = (*app)->Options()->SetStringValue(op.first, op.second.to_string(),
false);
327 case Ipopt::OT_Unknown:
329 casadi_warning(
"Cannot handle option \"" + op.first +
"\", ignored");
332 if (!ret) casadi_error(
"Invalid options were detected by Ipopt.");
336 if (
opts_.find(
"linear_solver") ==
opts_.end()) {
337 char * default_solver = getenv(
"IPOPT_DEFAULT_LINEAR_SOLVER");
338 if (default_solver) {
339 bool ret = (*app)->Options()->SetStringValue(
"linear_solver", default_solver,
false);
340 casadi_assert(ret,
"Corrupted IPOPT_DEFAULT_LINEAR_SOLVER environmental variable");
344 bool ret = (*app)->Options()->SetStringValue(
"linear_solver",
"mumps",
false);
345 casadi_assert_dev(ret);
351 Ipopt::ApplicationReturnStatus status = (*app)->Initialize();
352 casadi_assert(status == Solve_Succeeded,
"Error during IPOPT initialization");
359 casadi_int*& iw,
double*& w)
const {
367 m->grad_fk = w; w +=
nx_;
376 case Solve_Succeeded:
377 return "Solve_Succeeded";
378 case Solved_To_Acceptable_Level:
379 return "Solved_To_Acceptable_Level";
380 case Infeasible_Problem_Detected:
381 return "Infeasible_Problem_Detected";
382 case Search_Direction_Becomes_Too_Small:
383 return "Search_Direction_Becomes_Too_Small";
384 case Diverging_Iterates:
385 return "Diverging_Iterates";
386 case User_Requested_Stop:
387 return "User_Requested_Stop";
388 case Maximum_Iterations_Exceeded:
389 return "Maximum_Iterations_Exceeded";
390 case Restoration_Failed:
391 return "Restoration_Failed";
392 case Error_In_Step_Computation:
393 return "Error_In_Step_Computation";
394 case Not_Enough_Degrees_Of_Freedom:
395 return "Not_Enough_Degrees_Of_Freedom";
396 case Invalid_Problem_Definition:
397 return "Invalid_Problem_Definition";
399 return "Invalid_Option";
400 case Invalid_Number_Detected:
401 return "Invalid_Number_Detected";
402 case Unrecoverable_Exception:
403 return "Unrecoverable_Exception";
404 case NonIpopt_Exception_Thrown:
405 return "NonIpopt_Exception_Thrown";
406 case Insufficient_Memory:
407 return "Insufficient_Memory";
409 return "Internal_Error";
410 case Maximum_CpuTime_Exceeded:
411 return "Maximum_CpuTime_Exceeded";
412 case Feasible_Point_Found:
413 return "Feasible_Point_Found";
414 #if (IPOPT_VERSION_MAJOR > 3) || (IPOPT_VERSION_MAJOR == 3 && IPOPT_VERSION_MINOR >= 14)
415 case Maximum_WallTime_Exceeded:
416 return "Maximum_WallTime_Exceeded";
424 auto d_nlp = &m->
d_nlp;
431 m->regularization_size.clear();
435 m->ls_trials.clear();
441 Ipopt::SmartPtr<Ipopt::TNLP> *userclass =
442 static_cast<Ipopt::SmartPtr<Ipopt::TNLP>*
>(m->userclass);
443 Ipopt::SmartPtr<Ipopt::IpoptApplication> *app =
444 static_cast<Ipopt::SmartPtr<Ipopt::IpoptApplication>*
>(m->app);
447 Ipopt::ApplicationReturnStatus status = (*app)->OptimizeTNLP(*userclass);
449 m->success = status==Solve_Succeeded || status==Solved_To_Acceptable_Level
450 || status==Feasible_Point_Found;
451 if (status==Maximum_Iterations_Exceeded ||
454 #if (IPOPT_VERSION_MAJOR > 3) || (IPOPT_VERSION_MAJOR == 3 && IPOPT_VERSION_MINOR >= 14)
467 double constr_viol_tol;
468 (*app)->Options()->GetNumericValue(
"constr_viol_tol", constr_viol_tol,
"");
469 if (status==Solved_To_Acceptable_Level) {
470 (*app)->Options()->GetNumericValue(
"acceptable_constr_viol_tol", constr_viol_tol,
"");
475 "' unknown. Use 'abstol' or reltol'.");
478 for (casadi_int i=0; i<
nx_ +
ng_; ++i) {
480 if (d_nlp->lam[i]>0 && d_nlp->ubz[i] - d_nlp->z[i] > margin) d_nlp->lam[i]=0;
481 if (d_nlp->lam[i]<0 && d_nlp->z[i] - d_nlp->lbz[i] > margin) d_nlp->lam[i]=0;
490 const double* g,
const double* lambda,
double obj_value,
int iter,
491 double inf_pr,
double inf_du,
double mu,
double d_norm,
492 double regularization_size,
double alpha_du,
double alpha_pr,
493 int ls_trials,
bool full_callback)
const {
494 auto d_nlp = &m->
d_nlp;
497 m->
inf_pr.push_back(inf_pr);
498 m->
inf_du.push_back(inf_du);
500 m->
d_norm.push_back(d_norm);
505 m->
obj.push_back(obj_value);
510 for (casadi_int i=0; i<
nx_; ++i) {
511 d_nlp->lam[i] = z_U[i]-z_L[i];
518 <<
"Warning: intermediate_callback is disfunctional in your installation. "
519 "You will only be able to use stats(). "
520 "See https://github.com/casadi/casadi/wiki/enableIpoptCallback to enable it."
541 m->
res[0] = &ret_double;
544 casadi_int ret =
static_cast<casadi_int
>(ret_double);
553 }
catch(std::exception& ex) {
554 casadi_warning(
"intermediate_callback: " + std::string(ex.
what()));
562 const double* g,
const double* lambda,
double obj_value,
563 int iter_count)
const {
564 auto d_nlp = &m->
d_nlp;
570 d_nlp->objective = obj_value;
573 for (casadi_int i=0; i<
nx_; ++i) {
574 d_nlp->lam[i] = z_U[i]-z_L[i];
586 }
catch(std::exception& ex) {
587 uerr() <<
"finalize_solution failed: " << ex.what() << std::endl;
593 double* g_l,
double* g_u)
const {
594 auto d_nlp = &m->
d_nlp;
601 }
catch(std::exception& ex) {
602 uerr() <<
"get_bounds_info failed: " << ex.what() << std::endl;
609 bool init_z,
double* z_L,
double* z_U,
610 bool init_lambda,
double* lambda)
const {
611 auto d_nlp = &m->
d_nlp;
620 for (casadi_int i=0; i<
nx_; ++i) {
621 z_L[i] = std::max(0., -d_nlp->lam[i]);
622 z_U[i] = std::max(0., d_nlp->lam[i]);
632 }
catch(std::exception& ex) {
633 uerr() <<
"get_starting_point failed: " << ex.what() << std::endl;
639 int& nnz_jac_g,
int& nnz_h_lag)
const {
653 }
catch(std::exception& ex) {
654 uerr() <<
"get_nlp_info failed: " << ex.what() << std::endl;
666 for (
auto&& i :
nl_ex_)
if (i) nv++;
669 }
catch(std::exception& ex) {
670 uerr() <<
"get_number_of_nonlinear_variables failed: " << ex.what() << std::endl;
678 for (
int i=0; i<
nl_ex_.size(); ++i) {
679 if (
nl_ex_[i]) *pos_nonlin_vars++ = i;
682 }
catch(std::exception& ex) {
683 uerr() <<
"get_list_of_nonlinear_variables failed: " << ex.what() << std::endl;
690 std::map<std::string, std::vector<int> >& var_integer_md,
691 std::map<std::string, std::vector<double> >& var_numeric_md,
692 std::map<std::string, std::vector<std::string> >& con_string_md,
693 std::map<std::string, std::vector<int> >& con_integer_md,
694 std::map<std::string, std::vector<double> >& con_numeric_md)
const {
695 for (
auto&& op :
var_string_md_) var_string_md[op.first] = op.second;
696 for (
auto&& op :
var_integer_md_) var_integer_md[op.first] = op.second;
697 for (
auto&& op :
var_numeric_md_) var_numeric_md[op.first] = op.second;
698 for (
auto&& op :
con_string_md_) con_string_md[op.first] = op.second;
699 for (
auto&& op :
con_integer_md_) con_integer_md[op.first] = op.second;
700 for (
auto&& op :
con_numeric_md_) con_numeric_md[op.first] = op.second;
712 if (this->
app !=
nullptr) {
713 delete static_cast<Ipopt::SmartPtr<Ipopt::IpoptApplication>*
>(this->
app);
718 delete static_cast<Ipopt::SmartPtr<Ipopt::TNLP>*
>(this->
userclass);
726 stats[
"iter_count"] = m->iter_count;
727 if (!m->inf_pr.empty()) {
729 iterations[
"inf_pr"] = m->inf_pr;
730 iterations[
"inf_du"] = m->inf_du;
731 iterations[
"mu"] = m->mu;
732 iterations[
"d_norm"] = m->d_norm;
733 iterations[
"regularization_size"] = m->regularization_size;
734 iterations[
"obj"] = m->obj;
735 iterations[
"alpha_pr"] = m->alpha_pr;
736 iterations[
"alpha_du"] = m->alpha_du;
737 stats[
"iterations"] = iterations;
743 int version = s.
version(
"IpoptInterface", 1, 3);
774 s.
version(
"IpoptInterface", 3);
819 std::string name =
"nlp_f";
823 <<
"(ipindex n, ipnumber *x, bool new_x, ipnumber *obj_value, UserDataPtr user_data) {\n";
826 g <<
"struct casadi_ipopt_data* d = (struct casadi_ipopt_data*) user_data;\n";
827 g <<
"d->arg[0] = x;\n";
828 g <<
"d->arg[1] = d->nlp->p;\n";
829 g <<
"d->res[0] = obj_value;\n";
830 std::string flag = g(
get_function(name),
"d->arg",
"d->res",
"d->iw",
"d->w",
"false");
831 g <<
"if (" + flag +
") return false;\n";
832 g <<
"return true;\n";
839 <<
"(ipindex n, ipnumber *x, bool new_x, ipindex m, ipnumber *g, UserDataPtr user_data) {\n";
842 g <<
"struct casadi_ipopt_data* d = (struct casadi_ipopt_data*) user_data;\n";
843 g <<
"d->arg[0] = x;\n";
844 g <<
"d->arg[1] = d->nlp->p;\n";
845 g <<
"d->res[0] = g;\n";
846 flag = g(
get_function(name),
"d->arg",
"d->res",
"d->iw",
"d->w",
"false");
847 g <<
"if (" + flag +
") return false;\n";
848 g <<
"return true;\n";
855 <<
"(ipindex n, ipnumber *x, bool new_x, ipnumber *grad_f, UserDataPtr user_data) {\n";
858 g <<
"struct casadi_ipopt_data* d = (struct casadi_ipopt_data*) user_data;\n";
859 g <<
"d->arg[0] = x;\n";
860 g <<
"d->arg[1] = d->nlp->p;\n";
861 g <<
"d->res[0] = 0;\n";
862 g <<
"d->res[1] = grad_f;\n";
863 flag = g(
get_function(name),
"d->arg",
"d->res",
"d->iw",
"d->w",
"false");
864 g <<
"if (" + flag +
") return false;\n";
865 g <<
"return true;\n";
872 <<
"(ipindex n, ipnumber *x, bool new_x, ipindex m,"
873 <<
" ipindex nele_jac, ipindex *iRow, ipindex *jCol, "
874 <<
"ipnumber *values, UserDataPtr user_data) {\n";
877 g <<
"struct casadi_ipopt_data* d = (struct casadi_ipopt_data*) user_data;\n";
878 g <<
"if (values) {\n";
879 g <<
"d->arg[0] = x;\n";
880 g <<
"d->arg[1] = d->nlp->p;\n";
881 g <<
"d->res[0] = 0;\n";
882 g <<
"d->res[1] = values;\n";
883 flag = g(
get_function(name),
"d->arg",
"d->res",
"d->iw",
"d->w",
"false");
884 g <<
"if (" + flag +
") return false;\n";
886 g <<
"casadi_ipopt_sparsity(d->prob->sp_a, iRow, jCol);\n";
888 g <<
"return true;\n";
895 g <<
"bool " << f <<
"(ipindex n, ipnumber *x, bool new_x, ipnumber obj_factor,"
896 <<
"ipindex m, ipnumber *lambda, bool new_lambda, ipindex nele_hess, "
897 <<
"ipindex *iRow, ipindex *jCol, ipnumber *values, UserDataPtr user_data) {\n";
900 g <<
"struct casadi_ipopt_data* d = (struct casadi_ipopt_data*) user_data;\n";
901 g <<
"if (values) {\n";
902 g <<
"d->arg[0] = x;\n";
903 g <<
"d->arg[1] = d->nlp->p;\n";
904 g <<
"d->arg[2] = &obj_factor;\n";
905 g <<
"d->arg[3] = lambda;\n";
906 g <<
"d->res[0] = values;\n";
907 flag = g(
get_function(name),
"d->arg",
"d->res",
"d->iw",
"d->w",
"false");
908 g <<
"if (" + flag +
") return false;\n";
909 g <<
"return true;\n";
911 g <<
"casadi_ipopt_sparsity(d->prob->sp_h, iRow, jCol);\n";
913 g <<
"return true;\n";
923 g.
local(
"d",
"struct casadi_ipopt_data*");
925 g.
local(
"p",
"struct casadi_ipopt_prob");
928 g <<
"casadi_ipopt_init(d, &arg, &res, &iw, &w);\n";
929 g <<
"casadi_ipopt_presolve(d);\n";
932 Ipopt::SmartPtr<Ipopt::IpoptApplication> *app =
new Ipopt::SmartPtr<Ipopt::IpoptApplication>();
933 *app =
new Ipopt::IpoptApplication(
false);
936 auto regops = (*app)->RegOptions()->RegisteredOptionsList();
940 auto it = options.find(
"resto");
941 if (it!=options.end()) {
942 Dict resto_options = it->second;
944 for (
auto&& op : resto_options) {
945 options[
"resto." + op.first] = op.second;
950 for (
auto&& op : options) {
953 std::string option_name = op.first;
955 option_name = option_name.substr(6);
959 auto regops_it = regops.find(option_name);
960 if (regops_it==regops.end()) {
961 casadi_error(
"No such IPOPT option: " + op.first);
965 Ipopt::RegisteredOptionType ipopt_type = regops_it->second->Type();
968 switch (ipopt_type) {
969 case Ipopt::OT_Number:
970 g <<
"AddIpoptNumOption(d->ipopt, \"" << op.first <<
"\""
971 <<
"," << op.second.to_double() <<
");\n";
973 case Ipopt::OT_Integer:
974 g <<
"AddIpoptIntOption(d->ipopt, \"" << op.first <<
"\""
975 <<
"," << op.second.to_int() <<
");\n";
977 case Ipopt::OT_String:
978 g <<
"AddIpoptStrOption(d->ipopt, \"" << op.first <<
"\""
979 <<
",\"" << op.second.to_string() <<
"\");\n";
981 case Ipopt::OT_Unknown:
983 casadi_warning(
"Cannot handle option \"" + op.first +
"\", ignored");
989 if (
opts_.find(
"linear_solver") ==
opts_.end()) {
990 char * default_solver = getenv(
"IPOPT_DEFAULT_LINEAR_SOLVER");
991 if (default_solver) {
992 g <<
"AddIpoptStrOption(d->ipopt, \"linear_solver\"" <<
",\"" << default_solver <<
"\");\n";
996 g <<
"AddIpoptStrOption(d->ipopt, \"linear_solver\",\"mumps\");\n";
1004 g <<
"casadi_ipopt_solve(d);\n";
1009 g <<
"return d->unified_return_status;\n";
1017 casadi_error(
"Empty sparsity pattern not supported in IPOPT C interface");
1019 g <<
"d->nlp = &d_nlp;\n";
1020 g <<
"d->prob = &p;\n";
1021 g <<
"p.nlp = &p_nlp;\n";
1026 g <<
"p.sp_h = 0;\n";
1028 g <<
"casadi_ipopt_setup(&p);\n";
1031 g <<
"p.eval_f = " << nlp_f <<
";\n";
1033 g <<
"p.eval_g = " << nlp_g <<
";\n";
1035 g <<
"p.eval_grad_f = " << nlp_grad_f <<
";\n";
1037 g <<
"p.eval_jac_g = " << nlp_jac_g <<
";\n";
1040 g <<
"p.eval_h = " << nlp_hess_l <<
";\n";
1042 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.
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)
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