26 #include "feasiblesqpmethod.hpp"
28 #include "casadi/core/casadi_misc.hpp"
29 #include "casadi/core/calculus.hpp"
30 #include "casadi/core/conic.hpp"
31 #include "casadi/core/conic_impl.hpp"
32 #include "casadi/core/convexify.hpp"
45 int CASADI_NLPSOL_FEASIBLESQPMETHOD_EXPORT
48 plugin->name =
"feasiblesqpmethod";
50 plugin->version = CASADI_VERSION;
73 "The solver type: Either SQP or SLP. Defaults to SQP"}},
76 "The QP solver to be used by the SQP method [qpoases]"}},
79 "Options to be passed to the QP solver"}},
80 {
"hessian_approximation",
82 "limited-memory|exact"}},
85 "Maximum number of SQP iterations"}},
88 "Minimum number of SQP iterations"}},
91 "Stopping criterion for primal infeasibility"}},
94 "Stopping criterion for dual infeasability"}},
97 "Size of memory to store history of merit function values"}},
100 "Size of L-BFGS memory."}},
103 "Print the header with problem statistics"}},
106 "Print the iterations"}},
109 "Print a status message after solving"}},
112 "Function for calculating the objective function (autogenerated by default)"}},
115 "Function for calculating the constraints (autogenerated by default)"}},
118 "Function for calculating the gradient of the objective (autogenerated by default)"}},
121 "Function for calculating the Jacobian of the constraints (autogenerated by default)"}},
124 "Function for calculating the Hessian of the Lagrangian (autogenerated by default)"}},
125 {
"convexify_strategy",
127 "NONE|regularize|eigen-reflect|eigen-clip. "
128 "Strategy to convexify the Lagrange Hessian before passing it to the solver."}},
131 "When using a convexification strategy, make sure that "
132 "the smallest eigenvalue4 is at least this (default: 1e-7)."}},
135 "Maximum number of iterations to compute an eigenvalue decomposition (default: 50)."}},
138 "Initialize the QP subproblems with a feasible initial value (default: false)."}},
141 "Optimality tolerance. Below this value an iterate is considered to be optimal."}},
144 "Feasibility tolerance. Below this tolerance an iterate is considered to be feasible."}},
147 "Initial trust-region radius."}},
150 "Lower eta in trust-region acceptance criterion."}},
153 "Upper eta in trust-region acceptance criterion."}},
156 "Lower alpha in trust-region size criterion."}},
159 "Upper alpha in trust-region size criterion."}},
162 "Trust-region tolerance. "
163 "Below this value another scalar is equal to the trust region radius."}},
166 "Is the trust-region ratio above this value, the step is accepted."}},
169 "Minimum trust-region radius."}},
172 "Maximum trust-region radius."}},
175 "Vector that tells where trust-region is applied."}},
176 {
"contraction_acceptance_value",
178 "If the empirical contraction rate in the feasibility iterations "
179 "is above this value in the heuristics the iterations are aborted."}},
182 "Number of watchdog iterations in feasibility iterations. "
183 "After this amount of iterations, it is checked with the contraction acceptance value, "
184 "if iterations are converging."}},
187 "Maximum number of inner iterations."}},
190 "Use Anderson Acceleration. (default false)"}},
193 "Anderson memory. If Anderson is used default is 1, else default is 0."}},
207 std::string hessian_approximation =
"exact";
209 std::string solve_type =
"SQP";
210 std::string qpsol_plugin =
"qpoases";
238 std::string convexify_strategy =
"none";
239 double convexify_margin = 1e-7;
240 casadi_int max_iter_eig = 200;
243 for (
auto&& op : opts) {
244 if (op.first==
"max_iter") {
246 }
else if (op.first==
"min_iter") {
249 }
else if (op.first==
"use_anderson") {
251 }
else if (op.first==
"anderson_memory") {
254 }
else if (op.first==
"lbfgs_memory") {
256 }
else if (op.first==
"tol_pr") {
258 }
else if (op.first==
"tol_du") {
260 }
else if (op.first==
"hessian_approximation") {
261 hessian_approximation = op.second.to_string();
262 }
else if (op.first==
"solve_type") {
263 solve_type = op.second.to_string();
264 }
else if (op.first==
"qpsol") {
265 qpsol_plugin = op.second.to_string();
266 }
else if (op.first==
"qpsol_options") {
267 qpsol_options = op.second;
268 }
else if (op.first==
"print_header") {
270 }
else if (op.first==
"print_iteration") {
272 }
else if (op.first==
"print_status") {
274 }
else if (op.first==
"hess_lag") {
276 casadi_assert_dev(f.
n_in()==4);
277 casadi_assert_dev(f.
n_out()==1);
279 }
else if (op.first==
"jac_g") {
281 casadi_assert_dev(f.
n_in()==2);
282 casadi_assert_dev(f.
n_out()==1);
284 }
else if (op.first==
"grad_f") {
286 casadi_assert_dev(f.
n_in()==2);
287 casadi_assert_dev(f.
n_out()==1);
289 }
else if (op.first==
"f") {
291 casadi_assert_dev(f.
n_in()==2);
292 casadi_assert_dev(f.
n_out()==1);
294 }
else if (op.first==
"g") {
296 casadi_assert_dev(f.
n_in()==2);
297 casadi_assert_dev(f.
n_out()==1);
306 }
else if (op.first==
"convexify_strategy") {
307 convexify_strategy = op.second.to_string();
308 }
else if (op.first==
"convexify_margin") {
309 convexify_margin = op.second;
310 }
else if (op.first==
"max_iter_eig") {
311 max_iter_eig = op.second;
312 }
else if (op.first==
"init_feasible") {
316 }
else if (op.first ==
"optim_tol") {
318 }
else if (op.first ==
"feas_tol") {
320 }
else if (op.first ==
"tr_rad0") {
322 }
else if (op.first ==
"tr_eta1") {
324 }
else if (op.first ==
"tr_eta2") {
326 }
else if (op.first ==
"tr_alpha1") {
328 }
else if (op.first ==
"tr_alpha2") {
330 }
else if (op.first ==
"tr_tol") {
332 }
else if (op.first ==
"tr_acceptance") {
334 }
else if (op.first ==
"tr_rad_min") {
336 }
else if (op.first ==
"tr_rad_max") {
338 }
else if (op.first ==
"tr_scale_vector") {
340 }
else if (op.first ==
"contraction_acceptance_value") {
342 }
else if (op.first ==
"watchdog") {
344 }
else if (op.first ==
"max_inner_iter") {
351 uout() <<
"print solve type" << solve_type << std::endl;
388 {
"hess:gamma:x:x"}, {{
"gamma", {
"f",
"g"}}});
391 uout() <<
"Sparsity pattern: " <<
Hsp_ << std::endl;
393 if (convexify_strategy!=
"none") {
396 opts[
"strategy"] = convexify_strategy;
397 opts[
"margin"] = convexify_margin;
398 opts[
"max_iter_eig"] = max_iter_eig;
407 casadi_assert(!qpsol_plugin.empty(),
"'qpsol' option has not been set");
423 uout() <<
"Sparsity pattern: " <<
Hsp_ << std::endl;
424 uout() <<
"Sparsity pattern: " <<
Asp_ << std::endl;
443 print(
"-------------------------------------------\n");
444 print(
"This is casadi::Feasiblesqpmethod.\n");
446 print(
"Using exact Hessian\n");
448 print(
"Using limited memory BFGS Hessian approximation\n");
450 print(
"Number of variables: %9d\n",
nx_);
451 print(
"Number of constraints: %9d\n",
ng_);
452 print(
"Number of nonzeros in constraint Jacobian: %9d\n",
Asp_.
nnz());
453 print(
"Number of nonzeros in Lagrangian Hessian: %9d\n",
Hsp_.
nnz());
458 set_feasiblesqpmethod_prob();
470 void Feasiblesqpmethod::set_feasiblesqpmethod_prob() {
482 casadi_int*& iw,
double*& w)
const {
489 casadi_feasiblesqpmethod_set_work(&m->d, &arg, &res, &iw, &w);
515 return (val_f - val_f_corr) / (-val_m_k);
523 tr_rad =
tr_alpha1_ * casadi_masked_norm_inf(
nx_, d->dx, d->tr_mask);
525 abs(casadi_masked_norm_inf(
nx_, d->dx, d->tr_mask) - tr_rad) <
optim_tol_) {
533 auto d_nlp = &m->
d_nlp;
539 d_nlp->objective = d->f_feas;
542 uout() <<
"ACCEPTED" << std::endl;
545 uout() <<
"REJECTED" << std::endl;
584 print(
"This is not implemented yet!!!");
592 casadi_dense_lsqr_solve(d->z_tmp, d->dx_feas, 1, 1, curr_stage,
nx_, d->gamma);
602 casadi_axpy(curr_stage*
nx_, -1.0, d->anderson_memory_iterate, d->z_tmp);
662 auto d_nlp = &m->
d_nlp;
677 double step_inf_norm = casadi_masked_norm_inf(
nx_, d->dx, d->tr_mask);
678 double prev_step_inf_norm = step_inf_norm;
694 m->arg[0] = d->z_feas;
695 m->arg[1] = d_nlp->p;
696 m->res[0] = d->z_feas +
nx_;
698 uout() <<
"What does it mean that calc_function fails here??" << std::endl;
708 double curr_infeas = prev_infeas;
722 double kappa_watchdog = 0.0;
724 double acc_as_exac = 0.0;
727 double watchdog_prev_inf_norm = prev_step_inf_norm;
738 }
else if (j>0 && (curr_infeas > 1.0 || as_exac > 1.0)) {
771 casadi_clip_min(d->lbdz_feas,
nx_, -tr_rad, d->tr_mask);
784 casadi_vector_fmax(
nx_, d->z_tmp, d->lbdz_feas, d->lbdz_feas);
795 casadi_clip_max(d->ubdz_feas,
nx_, tr_rad, d->tr_mask);
808 casadi_vector_fmin(
nx_, d->z_tmp, d->ubdz_feas, d->ubdz_feas);
835 solve_QP(m, d->Bk, d->gf_feas, d->lbdz_feas, d->ubdz_feas,
836 d->Jk, d->dx_feas, d->dlam_feas, 0);
838 solve_LP(m, d->gf_feas, d->lbdz_feas, d->ubdz_feas,
839 d->Jk, d->dx_feas, d->dlam_feas, 0);
861 step_inf_norm = casadi_masked_norm_inf(
nx_, d->dx_feas, d->tr_mask);
873 m->arg[0] = d->z_feas;
874 m->arg[1] = d_nlp->p;
875 m->res[0] = d->z_feas +
nx_;
877 uout() <<
"What does it mean that calc_function fails here??" << std::endl;
883 curr_infeas = prev_infeas;
886 kappa = step_inf_norm/prev_step_inf_norm;
909 print(
"%6s %9.10f %14s %9.10f %20s %9.10f\n",
"Kappa:", kappa,
910 "Infeasibility:", curr_infeas,
"AsymptoticExactness:", as_exac);
913 acc_as_exac += as_exac;
923 kappa_watchdog = step_inf_norm / watchdog_prev_inf_norm;
924 watchdog_prev_inf_norm = step_inf_norm;
925 print(
"Kappa watchdog: %9.10f\n", kappa_watchdog);
926 if (curr_infeas <
feas_tol_ && as_exac < 0.5) {
951 prev_step_inf_norm = step_inf_norm;
960 auto d_nlp = &m->
d_nlp;
971 int step_accepted = 0;
976 double tr_ratio = 0.0;
984 for (casadi_int i=0;i<
nx_;++i) {
985 d->tr_mask[i] = d->tr_scale_vector[i]!=0;
989 const double one = 1.;
992 std::string
info =
"";
1019 if (m->iter_count == 0) {
1022 m->arg[0] = d_nlp->z;
1023 m->arg[1] = d_nlp->p;
1024 m->res[0] = &d_nlp->objective;
1026 uout() <<
"What does it mean that calc_function fails here??" << std::endl;
1029 m->arg[0] = d_nlp->z;
1030 m->arg[1] = d_nlp->p;
1031 m->res[0] = d_nlp->z +
nx_;
1033 uout() <<
"What does it mean that calc_function fails here??" << std::endl;
1036 m->arg[0] = d_nlp->z;
1037 m->arg[1] = d_nlp->p;
1040 uout() <<
"What does it mean that calc_function fails here??" << std::endl;
1043 m->arg[0] = d_nlp->z;
1044 m->arg[1] = d_nlp->p;
1048 m->return_status =
"Non_Regular_Sensitivities";
1051 print(
"MESSAGE(feasiblesqpmethod): "
1052 "No regularity of sensitivities at current point.\n");
1067 m->arg[0] = d_nlp->z;
1068 m->arg[1] = d_nlp->p;
1070 m->arg[3] = d_nlp->lam +
nx_;
1076 d->Bk, d->Bk, m->iw, m->w))
return 1;
1078 }
else if (m->iter_count==0) {
1082 casadi_bfgs_reset(
Hsp_, d->Bk);
1088 casadi_bfgs(
Hsp_, d->Bk, d->dx, d->gLag, d->gLag_old, m->w);
1094 "No feasible initialization given! "
1095 "Find feasible initialization.\n");
1096 m->return_status =
"No_Feasible_Initialization";
1101 }
else if (step_accepted == 0) {
1103 m->arg[0] = d_nlp->z;
1104 m->arg[1] = d_nlp->p;
1107 uout() <<
"What does it mean that calc_function fails here??" << std::endl;
1110 m->arg[0] = d_nlp->z;
1111 m->arg[1] = d_nlp->p;
1115 m->return_status =
"Non_Regular_Sensitivities";
1118 print(
"MESSAGE(feasiblesqpmethod): "
1119 "No regularity of sensitivities at current point.\n");
1133 m->arg[0] = d_nlp->z;
1134 m->arg[1] = d_nlp->p;
1136 m->arg[3] = d_nlp->lam +
nx_;
1142 d->Bk, d->Bk, m->iw, m->w))
return 1;
1144 }
else if (m->iter_count==0) {
1148 casadi_bfgs_reset(
Hsp_, d->Bk);
1154 casadi_bfgs(
Hsp_, d->Bk, d->dx, d->gLag, d->gLag_old, m->w);
1182 pr_inf, du_inf, dx_norminf, m->reg, tr_rad_prev,
info);
1185 tr_rad_prev = tr_rad;
1190 m->return_status =
"User_Requested_Stop";
1207 print(
"MESSAGE(feasiblesqpmethod): Maximum number of iterations reached.\n");
1209 m->return_status =
"Maximum_Iterations_Exceeded";
1218 casadi_clip_min(d->lbdz,
nx_, -tr_rad, d->tr_mask);
1225 casadi_clip_max(d->ubdz,
nx_, tr_rad, d->tr_mask);
1249 ret =
solve_QP(m, d->Bk, d->gf, d->lbdz, d->ubdz, d->Jk,
1252 ret =
solve_LP(m, d->gf, d->lbdz, d->ubdz, d->Jk,
1261 print(
"MESSAGE(feasiblesqpmethod): "
1262 "Optimal Point Found? Quadratic model is zero. "
1263 "After %d iterations\n", m->iter_count-1);
1264 m->return_status =
"Solve_Succeeded";
1274 if (
print_status_)
print(
"WARNING(feasiblesqpmethod): Indefinite Hessian detected\n");
1283 uout() <<
"Rejected inner iterates" << std::endl;
1286 tr_rad = 0.5 * casadi_masked_norm_inf(
nx_, d->dx, d->tr_mask);
1289 m->arg[0] = d->z_feas;
1290 m->arg[1] = d_nlp->p;
1291 m->res[0] = &d->f_feas;
1293 uout() <<
"What does it mean that calc_function fails here??" << std::endl;
1299 "Trust-region radius smaller than feasibility!! "
1301 m->return_status =
"Trust_Region_Radius_Becomes_Too_Small";
1320 print(
"%4s %9s %14s %9s %9s %9s %9s %7s %5s %7s\n",
1321 "iter",
"m_k",
"objective",
"tr_ratio",
"inf_pr",
1322 "inf_du",
"||d||",
"lg(rg)",
"tr_rad",
"info");
1326 double m_k,
double tr_ratio,
1327 double pr_inf,
double du_inf,
1328 double dx_norm,
double rg,
1330 std::string info)
const {
1331 print(
"%4d %9.2e %14.6e %9.2e %9.2e %9.2e %9.2e ",
1332 iter, m_k, obj, tr_ratio, pr_inf, du_inf, dx_norm);
1334 print(
"%7.2f ", log10(rg));
1339 print(
"%9.5e", tr_rad);
1352 const double* lbdz,
const double* ubdz,
const double* A,
1353 double* x_opt,
double* dlam,
int mode)
const {
1387 const double* lbdz,
const double* ubdz,
const double* A,
1388 double* x_opt,
double* dlam,
int mode)
const {
1434 g.
local(
"m_p",
"const casadi_real",
"*");
1436 g.
local(
"m_f",
"casadi_real");
1437 g.
local(
"m_f_feas",
"casadi_real");
1444 "-casadi_inf",
false);
1446 "casadi_inf",
false);
1447 casadi_assert(
exact_hessian_,
"Codegen implemented for exact Hessian only.",
false);
1453 g.
local(
"d",
"struct casadi_feasiblesqpmethod_data");
1454 g.
local(
"p",
"struct casadi_feasiblesqpmethod_prob");
1456 g <<
"d.prob = &p;\n";
1459 g <<
"p.nlp = &p_nlp;\n";
1461 g <<
"casadi_feasiblesqpmethod_set_work(&d, &arg, &res, &iw, &w);\n";
1463 g.
local(
"m_w",
"casadi_real",
"*");
1465 g.
local(
"m_iw",
"casadi_int",
"*");
1466 g <<
"m_iw = iw;\n";
1467 g.
local(
"m_arg",
"const casadi_real",
"**");
1469 g.
local(
"m_res",
"casadi_real",
"**");
1473 g.
local(
"ret",
"casadi_int");
1477 g.
local(
"iter_count",
"casadi_int");
1482 g.
local(
"step_accepted",
"casadi_int");
1487 g.
local(
"m_k",
"casadi_real");
1491 g.
local(
"tr_ratio",
"casadi_real");
1496 g.
local(
"tr_rad",
"casadi_real");
1497 g <<
"tr_rad = " <<
tr_rad0_ <<
";\n";
1498 g.
local(
"tr_rad_prev",
"casadi_real");
1499 g <<
"tr_rad_prev = " <<
tr_rad0_ <<
";\n";
1510 g <<
"for (casadi_int i = 0; i < " <<
nx_ <<
"; ++i) {\n";
1511 g <<
"d.tr_mask[i] = d.tr_scale_vector != 0;\n";
1518 g.
local(
"one",
"const casadi_real");
1531 g.
comment(
"MAIN OPTIMIZATION LOOP");
1532 g <<
"while (1) {\n";
1534 g <<
"if (iter_count == 0) {;\n";
1544 g <<
"m_arg[0] = d_nlp.z;\n";
1545 g <<
"m_arg[1] = m_p;\n";
1546 g <<
"m_res[0] = &m_f;\n";
1547 std::string nlp_f = g(
get_function(
"nlp_f"),
"m_arg",
"m_res",
"m_iw",
"m_w");
1549 g <<
"if (" + nlp_f +
") return 10;\n";
1559 g <<
"m_arg[0] = d_nlp.z;\n";
1560 g <<
"m_arg[1] = m_p;\n";
1561 g <<
"m_res[0] = d_nlp.z+" +
str(
nx_) +
";\n";
1562 std::string nlp_g = g(
get_function(
"nlp_g"),
"m_arg",
"m_res",
"m_iw",
"m_w");
1564 g <<
"if (" + nlp_g +
") return 20;\n";
1574 g <<
"m_arg[0] = d_nlp.z;\n";
1575 g <<
"m_arg[1] = m_p;\n";
1576 g <<
"m_res[0] = d.gf;\n";
1577 std::string nlp_grad_f = g(
get_function(
"nlp_grad_f"),
"m_arg",
"m_res",
"m_iw",
"m_w");
1579 g <<
"if (" + nlp_grad_f +
") return 30;\n";
1600 g <<
"m_arg[0] = d_nlp.z;\n";
1601 g <<
"m_arg[1] = m_p;\n";
1602 g <<
"m_res[0] = d.Jk;\n";
1603 std::string nlp_jac_g = g(
get_function(
"nlp_jac_g"),
"m_arg",
"m_res",
"m_iw",
"m_w");
1605 g <<
"if (" + nlp_jac_g +
") return 40;\n";
1633 g.
comment(
"Just exact Hessian implemented, GN would be possible!");
1634 g <<
"m_arg[0] = d_nlp.z;\n";
1635 g <<
"m_arg[1] = m_p;\n";
1636 g <<
"m_arg[2] = &one;\n";
1637 g <<
"m_arg[3] = d_nlp.lam+" +
str(
nx_) +
";\n";
1638 g <<
"m_res[0] = d.Bk;\n";
1639 std::string nlp_hess_l = g(
get_function(
"nlp_hess_l"),
"m_arg",
"m_res",
"m_iw",
"m_w");
1641 g <<
"if (" + nlp_hess_l +
") return 70;\n";
1652 std::string viol = g.
max_viol(
nx_+
ng_,
"d_nlp.z",
"d_nlp.lbz",
"d_nlp.ubz");
1653 g <<
"if (" << viol <<
"> " <<
feas_tol_ <<
") {\n";
1654 g <<
"printf(\"MESSAGE(feasiblesqpmethod): "
1655 "No feasible initialization given! Find feasible initialization.\\n\");\n";
1660 g <<
"} else if (step_accepted == 0) {\n";
1669 g <<
"m_arg[0] = d_nlp.z;\n";
1670 g <<
"m_arg[1] = m_p;\n";
1671 g <<
"m_res[0] = d.gf;\n";
1672 nlp_grad_f = g(
get_function(
"nlp_grad_f"),
"m_arg",
"m_res",
"m_iw",
"m_w");
1674 g <<
"if (" + nlp_grad_f +
") return 50;\n";
1694 g <<
"m_arg[0] = d_nlp.z;\n";
1695 g <<
"m_arg[1] = m_p;\n";
1696 g <<
"m_res[0] = d.Jk;\n";
1697 nlp_jac_g = g(
get_function(
"nlp_jac_g"),
"m_arg",
"m_res",
"m_iw",
"m_w");
1699 g <<
"if (" + nlp_jac_g +
") return 60;\n";
1728 g.
comment(
"Just exact Hessian implemented, GN would be possible!");
1729 g <<
"m_arg[0] = d_nlp.z;\n";
1730 g <<
"m_arg[1] = m_p;\n";
1731 g <<
"m_arg[2] = &one;\n";
1732 g <<
"m_arg[3] = d_nlp.lam+" +
str(
nx_) +
";\n";
1733 g <<
"m_res[0] = d.Bk;\n";
1734 nlp_hess_l = g(
get_function(
"nlp_hess_l"),
"m_arg",
"m_res",
"m_iw",
"m_w");
1736 g <<
"if (" + nlp_hess_l +
") return 70;\n";
1745 g.
comment(
"Evaluate the gradient of the Lagrangian");
1746 g << g.
copy(
"d.gf",
nx_,
"d.gLag") <<
"\n";
1747 g << g.
mv(
"d.Jk",
Asp_,
"d_nlp.lam+"+
str(
nx_),
"d.gLag",
true) <<
"\n";
1748 g << g.
axpy(
nx_,
"1.0",
"d_nlp.lam",
"d.gLag") <<
"\n";
1752 g.
comment(
"Primal infeasability");
1753 g.
local(
"pr_inf",
"casadi_real");
1754 g <<
"pr_inf = " << g.
max_viol(
nx_+
ng_,
"d_nlp.z",
"d_nlp.lbz",
"d_nlp.ubz") <<
";\n";
1758 g.
comment(
"inf-norm of lagrange gradient");
1759 g.
local(
"du_inf",
"casadi_real");
1760 g <<
"du_inf = " << g.
norm_inf(
nx_,
"d.gLag") <<
";\n";
1764 g.
comment(
"inf-norm of step");
1765 g.
local(
"dx_norminf",
"casadi_real");
1766 g <<
"dx_norminf = " << g.
norm_inf(
nx_,
"d.dx") <<
";\n";
1777 g <<
"printf(\"%4s %9s %14s %9s %9s %9s %9s %5s\\n\", "
1778 "\"iter\", \"m_k\", \"objective\", \"tr_ratio\", "
1779 "\"inf_pr\",\"inf_du\", \"||d||\", \"tr_rad\");\n";
1780 g <<
"printf(\"%4lld %9.2e %14.6e %9.2e %9.2e %9.2e %9.2e %5.2e\\n\", "
1781 "iter_count, m_k, m_f, tr_ratio, pr_inf, du_inf, dx_norminf, tr_rad_prev);";
1785 g <<
"tr_rad_prev = tr_rad;\n";
1806 g <<
"if (iter_count >= " <<
max_iter_ <<
") {\n";
1808 g << g.
printf(
"MESSAGE(feasiblesqpmethod): "
1809 "Maximum number of iterations reached.\\n") <<
"\n";
1819 g.
comment(
"Formulate the QP");
1820 g.
comment(
"Define the lower bounds");
1821 g << g.
copy(
"d_nlp.lbz",
nx_+
ng_,
"d.lbdz") <<
"\n";
1822 g << g.
axpy(
nx_+
ng_,
"-1.0",
"d_nlp.z",
"d.lbdz") <<
"\n";
1823 g << g.
clip_min(
"d.lbdz",
nx_,
"-tr_rad",
"d.tr_mask") <<
"\n";
1830 g.
comment(
"Define the upper bounds");
1831 g << g.
copy(
"d_nlp.ubz",
nx_+
ng_,
"d.ubdz") <<
"\n";
1832 g << g.
axpy(
nx_+
ng_,
"-1.0",
"d_nlp.z",
"d.ubdz") <<
"\n";
1833 g << g.
clip_max(
"d.ubdz",
nx_,
"tr_rad",
"d.tr_mask") <<
"\n";
1838 g << g.
copy(
"d_nlp.lam",
nx_+
ng_,
"d.dlam") <<
"\n";
1842 g.
comment(
"Increase counter");
1843 g <<
"++iter_count;\n";
1857 codegen_qp_solve(g,
"d.Bk",
"d.gf",
"d.lbdz",
"d.ubdz",
"d.Jk",
"d.dx",
"d.dlam", 0);
1862 g.
comment(
"Eval quadratic model and check for convergence");
1865 g.
comment(
"Checking convergence criteria");
1866 g <<
"if (fabs(m_k) < " <<
optim_tol_ <<
") {\n";
1867 g <<
"printf(\"MESSAGE(feasiblesqpmethod): Optimal Point Found? "
1868 "Quadratic model is zero. After %lld iterations.\\n\", iter_count-1);\n";
1880 g.
comment(
"Detecting indefiniteness");
1885 g.
comment(
"Do the feasibility iterations here");
1888 g <<
"if (ret < 0) {\n";
1889 g <<
"printf(\"Rejected inner iterates\\n\");\n";
1893 g <<
"m_arg[0] = d.z_feas;\n";
1894 g <<
"m_arg[1] = m_p;\n";
1895 g <<
"m_res[0] = &m_f_feas;\n";
1896 nlp_f = g(
get_function(
"nlp_f"),
"m_arg",
"m_res",
"m_iw",
"m_w");
1897 g <<
"if (" + nlp_f +
") return 1;\n";
1902 g <<
"if (tr_rad < "<<
feas_tol_ <<
") {\n";
1904 g <<
"printf(\"MESSAGE: Trust-Region radius smaller than feasibilty!!\\n\");\n";
1910 g.
comment(
"Close the step acceptance loop");
1934 g.
comment(
"Close the loop optimization problem");
1950 const std::string& H,
const std::string& g,
1951 const std::string& lbdz,
const std::string& ubdz,
1952 const std::string& A,
const std::string& x_opt,
1953 const std::string& dlam,
int mode)
const {
1954 for (casadi_int i=0;i<
qpsol_.
n_in();++i) cg <<
"m_arg[" << i <<
"] = 0;\n";
1955 cg <<
"m_arg[" <<
CONIC_H <<
"] = " << H <<
";\n";
1956 cg <<
"m_arg[" <<
CONIC_G <<
"] = " << g <<
";\n";
1957 cg <<
"m_arg[" <<
CONIC_X0 <<
"] = " << x_opt <<
";\n";
1958 cg <<
"m_arg[" <<
CONIC_LAM_X0 <<
"] = " << dlam <<
";\n";
1959 cg <<
"m_arg[" <<
CONIC_LAM_A0 <<
"] = " << dlam <<
"+" <<
nx_ <<
";\n";
1960 cg <<
"m_arg[" <<
CONIC_LBX <<
"] = " << lbdz <<
";\n";
1961 cg <<
"m_arg[" <<
CONIC_UBX <<
"] = " << ubdz <<
";\n";
1962 cg <<
"m_arg[" <<
CONIC_A <<
"] = " << A <<
";\n";
1963 cg <<
"m_arg[" <<
CONIC_LBA <<
"] = " << lbdz <<
"+" <<
nx_ <<
";\n";
1964 cg <<
"m_arg[" <<
CONIC_UBA <<
"] = " << ubdz <<
"+" <<
nx_ <<
";\n";
1965 for (casadi_int i=0;i<
qpsol_.
n_out();++i) cg <<
"m_res[" << i <<
"] = 0;\n";
1966 cg <<
"m_res[" <<
CONIC_X <<
"] = " << x_opt <<
";\n";
1967 cg <<
"m_res[" <<
CONIC_LAM_X <<
"] = " << dlam <<
";\n";
1968 cg <<
"m_res[" <<
CONIC_LAM_A <<
"] = " << dlam <<
"+" <<
nx_ <<
";\n";
1969 std::string flag = cg(
qpsol_,
"m_arg",
"m_res",
"m_iw",
"m_w");
1970 cg <<
"ret = " << flag <<
";\n";
1971 cg <<
"if (ret == -1000) return -1000;\n";
1975 const std::string& tr_rad,
const std::string& tr_ratio)
const {
1976 cg <<
"if (tr_ratio < " <<
tr_eta1_ <<
") {\n";
1978 std::string tol =
"fabs(" + cg.
masked_norm_inf(
nx_,
"d.dx",
"d.tr_mask") +
" - tr_rad)";
1979 cg <<
"} else if (tr_ratio > " <<
tr_eta2_ <<
" && " << tol <<
" < " <<
optim_tol_ <<
" ) {\n";
1982 cg.
comment(
"else: keep trust-region as it is....");
1993 cg <<
"m_k = 0.5*" << cg.
bilin(
"d.Bk",
Hsp_,
"d.dx",
"d.dx")
1994 <<
"+" << cg.
dot(
nx_,
"d.gf",
"d.dx") <<
";\n";
1998 const std::string& val_f,
const std::string& val_f_corr,
const std::string& val_m_k)
const {
2000 cg <<
"tr_ratio = (" + val_f +
"-" + val_f_corr +
") / (-" + val_m_k +
");\n";
2004 const std::string& tr_ratio)
const {
2022 cg << cg.
copy(
"d.z_feas",
nx_ +
ng_,
"d_nlp.z") <<
"\n";
2023 cg <<
"m_f = m_f_feas;\n";
2024 cg << cg.
copy(
"d.dlam_feas",
nx_ +
ng_,
"d_nlp.lam") <<
"\n";
2025 cg <<
"printf(\"ACCEPTED\\n\");\n";
2028 cg <<
"printf(\"REJECTED\\n\");\n";
2029 cg <<
"ret = -1;\n";
2034 const std::string& tr_rad)
const {
2039 cg << cg.
copy(
"d.dx",
nx_,
"d.dx_feas") <<
"\n";
2042 cg << cg.
copy(
"d.dlam",
nx_,
"d.dlam_feas") <<
"\n";
2047 cg << cg.
copy(
"d.dlam",
nx_+
ng_,
"d.z_tmp") <<
"\n";
2048 cg << cg.
axpy(
nx_+
ng_,
"-1.0",
"d_nlp.lam",
"d.z_tmp") <<
"\n";
2053 cg.
local(
"step_inf_norm",
"casadi_real");
2055 cg.
local(
"prev_step_inf_norm",
"casadi_real");
2056 cg <<
"prev_step_inf_norm = step_inf_norm;\n";
2062 cg << cg.
copy(
"d_nlp.z",
nx_+
ng_,
"d.z_feas") <<
"\n";
2063 cg << cg.
axpy(
nx_,
"1.0",
"d.dx_feas",
"d.z_feas") <<
"\n";
2083 cg <<
"m_arg[0] = d.z_feas;\n";
2084 cg <<
"m_arg[1] = m_p;\n";
2085 cg <<
"m_res[0] = d.z_feas+" +
str(
nx_) +
";\n";
2086 std::string nlp_g = cg(
get_function(
"nlp_g"),
"m_arg",
"m_res",
"m_iw",
"m_w");
2088 cg <<
"if (" + nlp_g +
") return 100;\n";
2092 cg.
local(
"inner_iter",
"casadi_int");
2097 cg.
local(
"prev_infeas",
"casadi_real");
2098 cg <<
"prev_infeas =" << cg.
max_viol(
nx_+
ng_,
"d.z_feas",
"d_nlp.lbz",
"d_nlp.ubz") <<
";\n";
2099 cg.
local(
"curr_infeas",
"casadi_real");
2100 cg <<
"curr_infeas = prev_infeas;\n";
2108 cg << cg.
copy(
"d.dx",
nx_,
"d.z_tmp") <<
"\n";
2109 cg << cg.
axpy(
nx_,
"-1.0",
"d.z_feas",
"d.z_tmp") <<
"\n";
2110 cg << cg.
axpy(
nx_,
"1.0",
"d_nlp.z",
"d.z_tmp") <<
"\n";
2111 cg.
local(
"as_exac",
"casadi_real");
2112 cg <<
"as_exac =" << cg.
norm_2(
nx_,
"d.z_tmp") <<
"/" << cg.
norm_2(
nx_,
"d.dx") <<
";\n";
2117 cg.
local(
"kappa_watchdog",
"casadi_real");
2119 cg.
local(
"kappa",
"casadi_real");
2121 cg.
local(
"acc_as_exac",
"casadi_real");
2122 cg <<
"acc_as_exac = 0.0;\n";
2125 cg.
local(
"watchdog_prev_inf_norm",
"casadi_real");
2127 cg <<
"watchdog_prev_inf_norm = prev_step_inf_norm;\n";
2143 cg <<
"if (curr_infeas < " <<
feas_tol_ <<
") {\n";
2144 cg <<
"inner_iter = j;\n";
2145 cg <<
"if (as_exac < 0.5) {\n";
2146 cg <<
"ret = 0; \n";
2149 cg <<
"ret = -1;\n";
2152 cg <<
"} else if (j>0 && (curr_infeas > 1.0 || as_exac > 1.0)) {\n";
2153 cg <<
"ret = -1;\n";
2159 cg <<
"inner_iter =j+1;\n";
2165 cg << cg.
copy(
"d.z_feas",
nx_,
"d.z_tmp") <<
"\n";
2166 cg << cg.
axpy(
nx_,
"-1.0",
"d_nlp.z",
"d.z_tmp") <<
"\n";
2167 cg << cg.
copy(
"d.gf",
nx_,
"d.gf_feas") <<
"\n";
2172 cg.
comment(
"Just SQP implemented so far!");
2174 cg << cg.
mv(
"d.Bk",
Hsp_,
"d.z_tmp",
"d.gf_feas",
true) <<
"\n";
2193 cg << cg.
copy(
"d_nlp.lbz",
nx_,
"d.lbdz_feas") <<
"\n";
2194 cg << cg.
clip_min(
"d.lbdz_feas",
nx_,
"-tr_rad",
"d.tr_mask") <<
"\n";
2199 cg << cg.
axpy(
nx_,
"-1.0",
"d.z_feas",
"d.lbdz_feas") <<
"\n";
2200 cg << cg.
axpy(
nx_,
"1.0",
"d_nlp.z",
"d.lbdz_feas") <<
"\n";
2205 cg << cg.
copy(
"d_nlp.lbz",
nx_,
"d.z_tmp") <<
"\n";
2206 cg << cg.
axpy(
nx_,
"-1.0",
"d.z_feas",
"d.z_tmp") <<
"\n";
2210 cg << cg.
vector_fmax(
nx_,
"d.z_tmp",
"d.lbdz_feas",
"d.lbdz_feas");
2214 cg << cg.
copy(
"d_nlp.ubz",
nx_,
"d.ubdz_feas") <<
"\n";
2215 cg << cg.
clip_max(
"d.ubdz_feas",
nx_,
"tr_rad",
"d.tr_mask") <<
";\n";
2219 cg << cg.
axpy(
nx_,
"-1.0",
"d.z_feas",
"d.ubdz_feas") <<
"\n";
2220 cg << cg.
axpy(
nx_,
"1.0",
"d_nlp.z",
"d.ubdz_feas") <<
"\n";
2226 cg << cg.
copy(
"d_nlp.ubz",
nx_,
"d.z_tmp") <<
"\n";
2227 cg << cg.
axpy(
nx_,
"-1.0",
"d.z_feas",
"d.z_tmp") <<
"\n";
2228 cg << cg.
vector_fmin(
nx_,
"d.z_tmp",
"d.ubdz_feas",
"d.ubdz_feas");
2237 cg.
comment(
"Just SQP implemented. Solve the feasible QP");
2239 "d.Jk",
"d.dx_feas",
"d.dlam_feas", 0);
2243 cg <<
"step_inf_norm = " << cg.
masked_norm_inf(
nx_,
"d.dx_feas",
"d.tr_mask") <<
";\n";
2250 cg.
comment(
"No Anderson Acceleration implemented yet.");
2251 cg << cg.
axpy(
nx_,
"1.0",
"d.dx_feas",
"d.z_feas") <<
"\n";
2261 cg <<
"m_arg[0] = d.z_feas;\n";
2262 cg <<
"m_arg[1] = m_p;\n";
2263 cg <<
"m_res[0] = d.z_feas+" +
str(
nx_) +
";\n";
2264 nlp_g = cg(
get_function(
"nlp_g"),
"m_arg",
"m_res",
"m_iw",
"m_w");
2266 cg <<
"if (" + nlp_g +
") return 100;\n";
2271 cg <<
"prev_infeas =" << cg.
max_viol(
nx_+
ng_,
"d.z_feas",
"d_nlp.lbz",
"d_nlp.ubz") <<
";\n";
2272 cg <<
"curr_infeas = prev_infeas;\n";
2273 cg <<
"kappa = step_inf_norm/prev_step_inf_norm;";
2279 cg << cg.
copy(
"d.dx",
nx_,
"d.z_tmp") <<
"\n";
2280 cg << cg.
axpy(
nx_,
"-1.0",
"d.z_feas",
"d.z_tmp") <<
"\n";
2281 cg << cg.
axpy(
nx_,
"1.0",
"d_nlp.z",
"d.z_tmp") <<
"\n";
2282 cg.
local(
"as_exac",
"casadi_real");
2283 cg <<
"as_exac =" << cg.
norm_2(
nx_,
"d.z_tmp") <<
"/" << cg.
norm_2(
nx_,
"d.dx") <<
";\n";
2285 cg <<
"printf(\"Kappa: %9.10f, Infeasibility: %9.10f, "
2286 "AsymptoticExctness: %9.10f\\n\", kappa, curr_infeas, as_exac);\n";
2289 cg <<
"acc_as_exac += as_exac;\n";
2307 cg <<
"if (inner_iter % " <<
watchdog_ <<
"== 0) {\n";
2308 cg <<
"kappa_watchdog = step_inf_norm / watchdog_prev_inf_norm;\n";
2309 cg <<
"watchdog_prev_inf_norm = step_inf_norm;\n";
2310 cg <<
"printf(\"Kappa watchdog: %9.10f\\n\", kappa_watchdog);\n";
2311 cg <<
"if (curr_infeas < "<<
feas_tol_ <<
"&& as_exac < 0.5) {\n";
2316 <<
"acc_as_exac/" <<
watchdog_ <<
"> 0.5) {\n";
2317 cg <<
"ret = -1;\n";
2321 cg <<
"acc_as_exac = 0.0;\n";
2325 cg <<
"prev_step_inf_norm = step_inf_norm;\n";
2333 cg <<
"ret = -1;\n";
2342 stats[
"iter_count"] = m->iter_count;
2347 int version = s.
version(
"Feasiblesqpmethod", 1, 3);
2381 s.
unpack(
"Feasiblesqpmethod::Hrsp", Hrsp);
2385 double convexify_margin;
2386 s.
unpack(
"Feasiblesqpmethod::convexify_margin", convexify_margin);
2387 char convexify_strategy;
2388 s.
unpack(
"Feasiblesqpmethod::convexify_strategy", convexify_strategy);
2389 casadi_assert(convexify_strategy==0,
"deserializtion failed.");
2391 s.
unpack(
"Feasiblesqpmethod::Hsp_project", Hsp_project);
2393 s.
unpack(
"Feasiblesqpmethod::scc_transform", scc_transform);
2394 std::vector<casadi_int> scc_offset;
2395 s.
unpack(
"Feasiblesqpmethod::scc_offset", scc_offset);
2396 std::vector<casadi_int> scc_mapping;
2397 s.
unpack(
"Feasiblesqpmethod::scc_mapping", scc_mapping);
2398 casadi_int max_iter_eig;
2399 s.
unpack(
"Feasiblesqpmethod::max_iter_eig", max_iter_eig);
2400 casadi_int block_size;
2401 s.
unpack(
"Feasiblesqpmethod::block_size", block_size);
2403 s.
unpack(
"Feasiblesqpmethod::scc_sp", scc_sp);
2410 set_feasiblesqpmethod_prob();
2415 s.
version(
"Feasiblesqpmethod", 3);
2429 s.
pack(
"Feasiblesqpmethod::Hsp",
Hsp_);
2430 s.
pack(
"Feasiblesqpmethod::Asp",
Asp_);
Helper class for C code generation.
std::string axpy(casadi_int n, const std::string &a, const std::string &x, const std::string &y)
Codegen axpy: y += a*x.
std::string clip_min(const std::string &x, casadi_int n, const std::string &min, const std::string &mask)
Codegen clip_min: Clips the smaller entries in a vector than min to the min.
std::string add_dependency(const Function &f)
Add a function dependency.
std::string arg(casadi_int i) const
Refer to argument.
std::string norm_2(casadi_int n, const std::string &x)
norm_2
std::string copy(const std::string &arg, std::size_t n, const std::string &res)
Create a copy operation.
void comment(const std::string &s)
Write a comment line (ignored if not verbose)
std::string masked_norm_inf(casadi_int n, const std::string &x, const std::string &mask)
codegen masked_norm_inf: The mask tells what entry is used in the inf-norm.
std::string constant(const std::vector< casadi_int > &v)
Represent an array constant; adding it when new.
std::string fmin(const std::string &x, const std::string &y)
fmin
std::string printf(const std::string &str, const std::vector< std::string > &arg=std::vector< std::string >())
Printf.
std::string bilin(const std::string &A, const Sparsity &sp_A, const std::string &x, const std::string &y)
Codegen bilinear form.
std::string bound_consistency(casadi_int n, const std::string &x, const std::string &lam, const std::string &lbx, const std::string &ubx)
bound_consistency
std::string vector_fmax(casadi_int n, const std::string &x, const std::string &y, const std::string &z)
Codegen vector_fmax: Takes vectorwise max of a vector and writes the result to second vector.
std::string mv(const std::string &x, const Sparsity &sp_x, const std::string &y, const std::string &z, bool tr)
Codegen sparse matrix-vector multiplication.
void local(const std::string &name, const std::string &type, const std::string &ref="")
Declare a local variable.
std::string res(casadi_int i) const
Refer to resuly.
std::string norm_inf(casadi_int n, const std::string &x)
norm_inf
std::string vector_fmin(casadi_int n, const std::string &x, const std::string &y, const std::string &z)
Codegen vector_fmin: Takes vectorwise min of a vector and writes the result to second vector.
void init_local(const std::string &name, const std::string &def)
Specify the default value for a local variable.
std::string dot(casadi_int n, const std::string &x, const std::string &y)
Codegen inner product.
std::string clip_max(const std::string &x, casadi_int n, const std::string &min, const std::string &mask)
Codegen clip_max: Clips the larger entries in a vector than max to the max.
void copy_check(const std::string &arg, std::size_t n, const std::string &res, bool check_lhs=true, bool check_rhs=true)
std::string max_viol(casadi_int n, const std::string &x, const std::string &lb, const std::string &ub)
max_viol
std::string sparsity(const Sparsity &sp, bool canonical=true)
void copy_default(const std::string &arg, std::size_t n, const std::string &res, const std::string &def, bool check_rhs=true)
std::string clear(const std::string &res, std::size_t n)
Create a fill operation.
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)
~Feasiblesqpmethod() override
void codegen_eval_tr_ratio(CodeGenerator &cg, const std::string &val_f, const std::string &val_f_corr, const std::string &val_m_k) const
void codegen_body(CodeGenerator &g) const override
Generate code for the function body.
Feasiblesqpmethod(const std::string &name, const Function &nlp)
static const std::string meta_doc
A documentation string.
casadi_int max_inner_iter_
void codegen_eval_m_k(CodeGenerator &cg) const
int step_update(void *mem, double tr_ratio) const
static const Options options_
Options.
casadi_int lbfgs_memory_
Memory size of L-BFGS method.
void codegen_step_update(CodeGenerator &cg, const std::string &tr_ratio) const
int init_mem(void *mem) const override
Initalize memory block.
void print_iteration() const
Print iteration header.
bool init_feasible_
Initialize feasible qp's.
ConvexifyData convexify_data_
Data for convexification.
bool use_sqp_
Exact Hessian?
void codegen_declarations(CodeGenerator &g) const override
Generate code for the declarations of the C function.
void codegen_feasibility_iterations(CodeGenerator &cg, const std::string &tr_rad) const
bool use_anderson_
Use Anderson Acceleration.
Dict get_stats(void *mem) const override
Get all statistics.
void init(const Dict &opts) override
Initialize.
int feasibility_iterations(void *mem, double tr_rad) const
int solve(void *mem) const override
virtual int solve_QP(FeasiblesqpmethodMemory *m, const double *H, const double *g, const double *lbdz, const double *ubdz, const double *A, double *x_opt, double *dlam, int mode) const
casadi_int max_iter_
Maximum, minimum number of SQP iterations.
virtual int solve_LP(FeasiblesqpmethodMemory *m, const double *g, const double *lbdz, const double *ubdz, const double *A, double *x_opt, double *dlam, int mode) const
casadi_feasiblesqpmethod_prob< double > p_
void tr_update(void *mem, double &tr_rad, double tr_ratio) const
std::vector< double > tr_scale_vector_
static Nlpsol * creator(const std::string &name, const Function &nlp)
Create a new NLP Solver.
bool convexify_
convexify?
double eval_tr_ratio(double val_f, double val_f_corr, double val_m_k) const
void anderson_acc_step_update(void *mem, casadi_int iter_index) const
casadi_int sz_anderson_memory_
Function qpsol_ela_
QP solver for elastic mode subproblems.
Function qpsol_
QP solver for the subproblems.
void codegen_qp_solve(CodeGenerator &cg, const std::string &H, const std::string &g, const std::string &lbdz, const std::string &ubdz, const std::string &A, const std::string &x_opt, const std::string &dlam, int mode) const
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize into MX.
bool exact_hessian_
Exact Hessian?
double eval_m_k(void *mem) const
void anderson_acc_init_memory(void *mem, double *step, double *iterate) const
void set_work(void *mem, const double **&arg, double **&res, casadi_int *&iw, double *&w) const override
Set the (persistent) work vectors.
void anderson_acc_update_memory(void *mem, double *step, double *iterate) const
double contraction_acceptance_value_
double tol_pr_
Tolerance of primal and dual infeasibility.
void codegen_tr_update(CodeGenerator &cg, const std::string &tr_rad, const std::string &tr_ratio) const
void serialize_body(SerializingStream &s) const override
Serialize an object without type information.
void alloc_iw(size_t sz_iw, bool persistent=false)
Ensure required length of iw field.
size_t sz_w() const
Get required length of w field.
virtual Dict info() const
void alloc_w(size_t sz_w, bool persistent=false)
Ensure required length of w field.
void alloc(const Function &f, bool persistent=false, int num_threads=1)
Ensure work vectors long enough to evaluate function.
size_t sz_iw() const
Get required length of iw field.
casadi_int n_out() const
Get the number of function outputs.
casadi_int n_in() const
Get the number of function inputs.
NLP solver storage class.
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.
casadi_nlpsol_prob< double > p_nlp_
void serialize_body(SerializingStream &s) const override
Serialize an object without type information.
casadi_int np_
Number of parameters.
int callback(NlpsolMemory *m) const
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.
bool bound_consistency_
Options.
void set_function(const Function &fcn, const std::string &fname, bool jit=false)
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())
int calc_function(OracleMemory *m, const std::string &fcn, const double *const *arg=nullptr, int thread_id=0) const
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.
void print(const char *fmt,...) const
C-style formatted printing during evaluation.
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.
static Sparsity dense(casadi_int nrow, casadi_int ncol=1)
Create a dense rectangular sparsity pattern *.
casadi_int nnz() const
Get the number of (structural) non-zeros.
bool is_symmetric() const
Is symmetric?
Function conic(const std::string &name, const std::string &solver, const SpDict &qp, const Dict &opts)
@ NLPSOL_P
Value of fixed parameters (np x 1)
@ NLPSOL_UBX
Decision variables upper bound (nx x 1), default +inf.
@ NLPSOL_X0
Decision variables, initial guess (nx x 1)
@ NLPSOL_LAM_G0
Lagrange multipliers for bounds on G, initial guess (ng x 1)
@ NLPSOL_LAM_X0
Lagrange multipliers for bounds on X, initial guess (nx x 1)
@ NLPSOL_LBG
Constraints lower bound (ng x 1), default -inf.
@ NLPSOL_LBX
Decision variables lower bound (nx x 1), default -inf.
T1 casadi_max_viol(casadi_int n, const T1 *x, const T1 *lb, const T1 *ub)
Largest bound violation.
@ 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)
@ CONIC_UBA
dense, (nc x 1)
@ CONIC_A
The matrix A: sparse, (nc x n) - product with x must be dense.
@ CONIC_G
The vector g: dense, (n x 1)
@ CONIC_LBA
dense, (nc x 1)
@ CONIC_UBX
dense, (n x 1)
@ CONIC_LBX
dense, (n x 1)
T1 casadi_bilin(const T1 *A, const casadi_int *sp_A, const T1 *x, const T1 *y)
void casadi_copy(const T1 *x, casadi_int n, T1 *y)
COPY: y <-x.
void casadi_fill(T1 *x, casadi_int n, T1 alpha)
FILL: x <- alpha.
T1 casadi_norm_2(casadi_int n, const T1 *x)
NORM_2: ||x||_2 -> return.
int CASADI_NLPSOL_FEASIBLESQPMETHOD_EXPORT casadi_register_nlpsol_feasiblesqpmethod(Nlpsol::Plugin *plugin)
std::string str(const T &v)
String representation, any type.
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.
T1 casadi_dot(casadi_int n, const T1 *x, const T1 *y)
Inner product.
void CASADI_NLPSOL_FEASIBLESQPMETHOD_EXPORT casadi_load_nlpsol_feasiblesqpmethod()
T * get_ptr(std::vector< T > &v)
Get a pointer to the data contained in the vector.
void casadi_axpy(casadi_int n, T1 alpha, const T1 *x, T1 *y)
AXPY: y <- a*x + y.
T1 casadi_norm_inf(casadi_int n, const T1 *x)
void casadi_clear(T1 *x, casadi_int n)
CLEAR: x <- 0.
void casadi_mv(const T1 *x, const casadi_int *sp_x, const T1 *y, T1 *z, casadi_int tr)
Sparse matrix-vector multiplication: z <- z + x*y.
@ CONIC_X
The primal solution.
@ CONIC_LAM_A
The dual solution corresponding to linear bounds.
@ CONIC_COST
The optimal cost.
@ CONIC_LAM_X
The dual solution corresponding to simple bounds.
casadi_convexify_config< double > config
const char * return_status
Last return status.
casadi_feasiblesqpmethod_data< double > d
casadi_nlpsol_data< double > d_nlp
Options metadata for a class.
std::map< std::string, FStats > fstats
void add_stat(const std::string &s)
const casadi_nlpsol_prob< T1 > * nlp