27 #include "fatrop_interface.hpp"
28 #include "casadi/core/casadi_misc.hpp"
29 #include "../../core/global_options.hpp"
30 #include "../../core/casadi_interrupt.hpp"
31 #include "../../core/convexify.hpp"
32 #include "casadi/casadi_c.h"
40 #include <fatrop_runtime_str.h>
44 int CASADI_NLPSOL_FATROP_EXPORT
47 plugin->name =
"fatrop";
49 plugin->version = CASADI_VERSION;
68 Sparsity FatropInterface::blocksparsity(casadi_int rows, casadi_int cols,
69 const std::vector<casadi_ocp_block>& blocks,
bool eye) {
71 for (
auto && b : blocks) {
73 r(
range(b.offset_r, b.offset_r+b.rows),
75 casadi_assert_dev(b.rows==b.cols);
77 r(
range(b.offset_r, b.offset_r+b.rows),
86 casadi_warning(
"Structure detection error on row " +
str(idx) +
". " + msg);
96 "Number of states, length N+1"}},
99 "Number of controls, length N+1"}},
102 "Number of non-dynamic constraints, length N+1"}},
105 "Options to be passed to fatrop"}},
106 {
"structure_detection",
108 "NONE | auto | manual"}},
109 {
"convexify_strategy",
111 "NONE|regularize|eigen-reflect|eigen-clip. "
112 "Strategy to convexify the Lagrange Hessian before passing it to the solver."}},
115 "When using a convexification strategy, make sure that "
116 "the smallest eigenvalue is at least this (default: 1e-7)."}},
119 "Produce debug information (default: false)"}},
122 "Options to be passed to fatrop"
131 casadi_int struct_cnt=0;
134 std::string convexify_strategy =
"none";
135 double convexify_margin = 1e-7;
136 casadi_int max_iter_eig = 200;
137 structure_detection_ = STRUCTURE_NONE;
144 for (
auto&& op : opts) {
148 }
else if (op.first==
"nx") {
151 }
else if (op.first==
"nu") {
154 }
else if (op.first==
"ng") {
157 }
else if (op.first==
"convexify_strategy") {
158 convexify_strategy = op.second.to_string();
159 }
else if (op.first==
"convexify_margin") {
160 convexify_margin = op.second;
161 }
else if (op.first==
"max_iter_eig") {
162 max_iter_eig = op.second;
163 }
else if (op.first==
"fatrop") {
165 }
else if (op.first==
"structure_detection") {
166 std::string v = op.second;
168 structure_detection_ = STRUCTURE_AUTO;
169 }
else if (v==
"manual") {
170 structure_detection_ = STRUCTURE_MANUAL;
171 }
else if (v==
"none") {
172 structure_detection_ = STRUCTURE_NONE;
174 casadi_error(
"Unknown option for structure_detection: '" + v +
"'.");
176 }
else if (op.first==
"debug") {
183 auto hessian_approximation =
opts_.find(
"hessian_approximation");
184 if (hessian_approximation!=
opts_.end()) {
205 {
"grad:gamma:x",
"hess:gamma:x:x"}, {{
"gamma", {
"f",
"g"}}});
209 if (convexify_strategy!=
"none") {
212 opts[
"strategy"] = convexify_strategy;
213 opts[
"margin"] = convexify_margin;
214 opts[
"max_iter_eig"] = max_iter_eig;
220 const std::vector<casadi_int>& nx = nxs_;
221 const std::vector<casadi_int>& ng = ngs_;
222 const std::vector<casadi_int>& nu = nus_;
224 Sparsity lamg_csp_, lam_ulsp_, lam_uusp_, lam_xlsp_, lam_xusp_, lam_clsp_;
228 A_.
to_file(
"debug_fatrop_actual.mtx");
231 std::set<casadi_int> errors;
233 casadi_int na_ = A_.
size1();
236 casadi_assert(structure_detection_ == STRUCTURE_MANUAL,
237 "You must set structure_detection to 'manual' if you set N, nx, nu, ng.");
240 if (structure_detection_==STRUCTURE_MANUAL) {
241 casadi_assert(struct_cnt==4,
242 "You must set all of N, nx, nu, ng.");
243 }
else if (structure_detection_==STRUCTURE_NONE) {
248 }
else if (structure_detection_==STRUCTURE_AUTO) {
250 "Structure detection auto requires the 'equality' option to be set");
258 std::vector<casadi_int> A_skyline;
259 std::vector<casadi_int> A_skyline2;
260 std::vector<casadi_int> A_bottomline;
262 std::vector<casadi_int> AT_colind = AT.
get_colind();
263 std::vector<casadi_int> AT_row = AT.
get_row();
264 for (casadi_int i=0;i<AT.
size2();++i) {
265 casadi_int pivot = AT_colind.at(i+1);
266 if (pivot>AT_colind.at(i)) {
267 A_bottomline.push_back(AT_row.at(AT_colind.at(i)));
269 A_bottomline.push_back(-1);
271 if (pivot>AT_colind.at(i)) {
272 A_skyline.push_back(AT_row.at(pivot-1));
273 if (pivot>AT_colind.at(i)+1) {
274 A_skyline2.push_back(AT_row.at(pivot-2));
276 A_skyline2.push_back(-1);
279 A_skyline.push_back(-1);
280 A_skyline2.push_back(-1);
285 "Constraint Jcobian must start with gap-closing constraint "
286 "(tagged 'true' in equality vector).");
288 casadi_int pivot = A_skyline[0];
289 casadi_int start_pivot = pivot;
290 casadi_int prev_start_pivot = 0;
297 for (casadi_int i=1;i<na_;++i) {
298 bool is_gap_closing =
true;
299 if (A_bottomline[i]!=-1 && A_bottomline[i]<prev_start_pivot) {
301 report_issue(i,
"Constraint found depending on a state of the previous interval.");
305 if (A_skyline[i]>pivot+1) {
306 if (A_bottomline[i]!=-1 && A_bottomline[i]<start_pivot) {
308 report_issue(i,
"Constraint found depending on a state of the previous interval.");
315 nus_.push_back(A_skyline[i]-pivot-1);
317 prev_start_pivot = start_pivot;
318 start_pivot = A_skyline[i];
319 pivot = A_skyline[i];
321 }
else if (A_skyline[i]==pivot+1) {
322 if (A_skyline2[i]<start_pivot) {
323 if (A_bottomline[i]>=prev_start_pivot) {
328 if (A_bottomline[i]!=-1 && A_bottomline[i]<start_pivot) {
331 "on a state of the previous interval.");
333 is_gap_closing =
false;
339 if (A_bottomline[i]!=-1 && A_bottomline[i]<start_pivot) {
341 report_issue(i,
"Gap-closing constraint found depending "
342 "on a state of the previous interval.");
344 prev_start_pivot = start_pivot;
345 start_pivot = A_skyline[i];
346 pivot = A_skyline[i];
350 is_gap_closing =
false;
353 is_gap_closing =
false;
356 if (!is_gap_closing) {
358 if (A_skyline[i]>=start_pivot) {
371 if (nxs_.back()!=0) {
378 nxs_.insert(nxs_.begin(), std::min(A_skyline[0], nxs_.front()));
381 nus_.front() += std::max(A_skyline[0]-nxs_.front(),
static_cast<casadi_int
>(0));
384 casadi_assert_dev(nxs_.back()==0);
387 casadi_assert_dev(nx.size()==nu.size());
388 casadi_assert_dev(nx.size()==ng.size());
390 casadi_assert_dev(
sum(ng)+
sum(nx)==na_+nx.front());
396 casadi_assert(nx.size()==N_+1,
"nx must have length N+1.");
397 casadi_assert(nu.size()==N_+1,
"nu must have length N+1.");
398 casadi_assert(ng.size()==N_+1,
"ng must have length N+1.");
401 casadi_message(
"Using structure: N " +
str(N_) +
", nx " +
str(nx) +
", "
402 "nu " +
str(nu) +
", ng " +
str(ng) +
".");
406 std::vector< casadi_ocp_block > A_blocks, B_blocks, C_blocks, D_blocks;
415 casadi_int offset_r = 0, offset_c = 0;
416 for (casadi_int k=0;k<N_;++k) {
417 AB_blocks_.push_back({offset_r, offset_c, nx[k+1], nx[k]+nu[k]});
418 CD_blocks_.push_back({offset_r+nx[k+1], offset_c, ng[k], nx[k]+nu[k]});
419 A_blocks.push_back({offset_r, offset_c, nx[k+1], nx[k]});
420 B_blocks.push_back({offset_r, offset_c+nx[k], nx[k+1], nu[k]});
421 C_blocks.push_back({offset_r+nx[k+1], offset_c, ng[k], nx[k]});
422 D_blocks.push_back({offset_r+nx[k+1], offset_c+nx[k], ng[k], nu[k]});
423 offset_c+= nx[k]+nu[k];
425 I_blocks_.push_back({offset_r, offset_c, nx[k+1], nx[k+1]});
431 I_blocks_.push_back({offset_r, offset_c, nx[k+1], nx[k+1]});
432 offset_r+= nx[k+1]+ng[k];
434 CD_blocks_.push_back({offset_r, offset_c, ng[N_], nx[N_]+nu[N_]});
435 C_blocks.push_back({offset_r, offset_c, ng[N_], nx[N_]});
436 D_blocks.push_back({offset_r, offset_c+nx[N_], ng[N_], nu[N_]});
438 casadi_int offset = 0;
439 AB_offsets_.push_back(0);
440 for (
auto e : AB_blocks_) {
441 offset += e.rows*e.cols;
442 AB_offsets_.push_back(offset);
445 CD_offsets_.push_back(0);
446 for (
auto e : CD_blocks_) {
447 offset += e.rows*e.cols;
448 CD_offsets_.push_back(offset);
451 ABsp_ = blocksparsity(na_,
nx_, AB_blocks_);
452 CDsp_ = blocksparsity(na_,
nx_, CD_blocks_);
453 Isp_ = blocksparsity(na_,
nx_, I_blocks_,
true);
455 Sparsity total = ABsp_ + CDsp_ + Isp_;
458 total.
to_file(
"debug_fatrop_expected.mtx");
459 blocksparsity(na_,
nx_, A_blocks).
to_file(
"debug_fatrop_A.mtx");
460 blocksparsity(na_,
nx_, B_blocks).
to_file(
"debug_fatrop_B.mtx");
461 blocksparsity(na_,
nx_, C_blocks).
to_file(
"debug_fatrop_C.mtx");
462 blocksparsity(na_,
nx_, D_blocks).
to_file(
"debug_fatrop_D.mtx");
463 Isp_.to_file(
"debug_fatrop_I.mtx");
464 std::vector<casadi_int> errors_vec(errors.begin(), errors.end());
465 std::vector<casadi_int> colind = {0,
static_cast<casadi_int
>(errors_vec.size())};
466 Sparsity(na_, 1, colind, errors_vec).
to_file(
"debug_fatrop_errors.mtx");
469 casadi_assert(errors.empty() && (A_ + total).nnz() == total.
nnz(),
470 "HPIPM: specified structure of A does not correspond to what the interface can handle. "
471 "Structure is: N " +
str(N_) +
", nx " +
str(nx) +
", nu " +
str(nu) +
", "
472 "ng " +
str(ng) +
".\n"
473 "Note that debug_fatrop_expected.mtx and debug_fatrop_actual.mtx are written "
474 "to the current directory when 'debug' option is true.\n"
475 "These can be read with Sparsity.from_file(...)."
476 "For a ready-to-use script, "
477 "see https://gist.github.com/jgillis/dec56fa16c90a8e4a69465e8422c5459");
478 casadi_assert_dev(total.
nnz() == ABsp_.
nnz() + CDsp_.
nnz() + Isp_.nnz());
489 for (casadi_int k=0;k<N_+1;++k) {
490 RSQ_blocks_.push_back({offset, offset, nx[k]+nu[k], nx[k]+nu[k]});
491 offset+= nx[k]+nu[k];
493 RSQsp_ = blocksparsity(
nx_,
nx_, RSQ_blocks_);
496 RSQ_offsets_.push_back(0);
497 for (
auto e : RSQ_blocks_) {
498 offset += e.rows*e.cols;
499 RSQ_offsets_.push_back(offset);
518 fatrop_init_mem(&m->d);
525 fatrop_free_mem(&m->d);
531 casadi_int*& iw,
double*& w)
const {
538 m->d.
nlp = &m->d_nlp;
540 casadi_fatrop_init(&m->d, &arg, &res, &iw, &w);
542 m->d.nlp->oracle->m =
static_cast<void*
>(m);
550 casadi_fatrop_presolve(&m->d);
552 for (
const auto& kv :
opts_) {
553 switch (fatrop_ocp_c_option_type(kv.first.c_str())) {
555 fatrop_ocp_c_set_option_double(m->d.solver, kv.first.c_str(), kv.second);
558 fatrop_ocp_c_set_option_int(m->d.solver, kv.first.c_str(), kv.second.to_int());
561 fatrop_ocp_c_set_option_bool(m->d.solver, kv.first.c_str(), kv.second.to_bool());
565 std::string s = kv.second.to_string();
566 fatrop_ocp_c_set_option_string(m->d.solver, kv.first.c_str(), s.c_str());
570 casadi_error(
"Fatrop option not supported: " + kv.first);
572 casadi_error(
"Unknown option type.");
576 casadi_fatrop_solve(&m->d);
578 m->success = m->d.success;
588 fatrop[
"compute_sd_time"] = m->
d.
stats.compute_sd_time;
589 fatrop[
"duinf_time"] = m->d.stats.duinf_time;
590 fatrop[
"eval_hess_time"] = m->d.stats.eval_hess_time;
591 fatrop[
"eval_jac_time"] = m->d.stats.eval_jac_time;
592 fatrop[
"eval_cv_time"] = m->d.stats.eval_cv_time;
593 fatrop[
"eval_grad_time"] = m->d.stats.eval_grad_time;
594 fatrop[
"eval_obj_time"] = m->d.stats.eval_obj_time;
595 fatrop[
"initialization_time"] = m->d.stats.initialization_time;
596 fatrop[
"time_total"] = m->d.stats.time_total;
597 fatrop[
"eval_hess_count"] = m->d.stats.eval_hess_count;
598 fatrop[
"eval_jac_count"] = m->d.stats.eval_jac_count;
599 fatrop[
"eval_cv_count"] = m->d.stats.eval_cv_count;
600 fatrop[
"eval_grad_count"] = m->d.stats.eval_grad_count;
601 fatrop[
"eval_obj_count"] = m->d.stats.eval_obj_count;
602 fatrop[
"iterations_count"] = m->d.stats.iterations_count;
603 fatrop[
"return_flag"] = m->d.stats.return_flag;
604 stats[
"fatrop"] = fatrop;
605 stats[
"iter_count"] = m->d.stats.iterations_count;
610 stats[
"return_status"] = m->d.return_status;
615 g <<
"fatrop_init_mem(&" +
codegen_mem(g) +
");\n";
620 g <<
"fatrop_free_mem(&" +
codegen_mem(g) +
");\n";
648 std::string name =
"fatrop_cb_write";
652 <<
"(const char* msg, int num) {\n";
655 g <<
"CASADI_PRINTF(\"%.*s\", num, msg);\n";
659 name =
"fatrop_cb_flush";
674 g.
local(
"d",
"struct casadi_fatrop_data*");
676 g.
local(
"p",
"struct casadi_fatrop_prob");
679 g <<
"casadi_fatrop_init(d, &arg, &res, &iw, &w);\n";
680 g <<
"casadi_oracle_init(d->nlp->oracle, &arg, &res, &iw, &w);\n";
681 g <<
"casadi_fatrop_presolve(d);\n";
683 for (
const auto& kv :
opts_) {
684 switch (fatrop_ocp_c_option_type(kv.first.c_str())) {
686 g <<
"fatrop_ocp_c_set_option_double(d->solver, \"" + kv.first +
"\", "
687 +
str(kv.second) +
");\n";
690 g <<
"fatrop_ocp_c_set_option_int(d->solver, \"" + kv.first +
"\", "
691 +
str(kv.second.to_int()) +
");\n";
694 g <<
"fatrop_ocp_c_set_option_bool(d->solver, \"" + kv.first +
"\", "
695 +
str(
static_cast<int>(kv.second.to_bool())) +
");\n";
699 std::string s = kv.second.to_string();
700 g <<
"fatrop_ocp_c_set_option_bool(d->solver, \"" + kv.first +
"\", \""
705 casadi_error(
"Fatrop option not supported: " + kv.first);
707 casadi_error(
"Unknown option type.");
712 g <<
"casadi_fatrop_solve(d);\n";
717 g <<
"return d->unified_return_status;\n";
723 std::vector<casadi_int>
fatrop_blocks_pack(
const std::vector<casadi_ocp_block>& blocks) {
724 size_t N = blocks.size();
725 std::vector<casadi_int> ret(4*N+1);
728 for (casadi_int i=0;i<N;++i) {
729 *r++ = blocks[i].offset_r;
730 *r++ = blocks[i].offset_c;
731 *r++ = blocks[i].rows;
732 *r++ = blocks[i].cols;
766 p_.
write = &casadi_c_logger_write;
767 p_.
flush = &casadi_c_logger_flush;
769 casadi_fatrop_setup(&p_);
773 const std::vector<casadi_ocp_block>& blocks) {
774 casadi_int sz = blocks.size();
776 std::string n =
"block_" + name +
"[" +
str(sz) +
"]";
777 g.
local(n,
"static struct casadi_ocp_block");
778 g <<
"p." << name <<
" = block_" + name +
";\n";
779 g <<
"casadi_unpack_ocp_blocks(" <<
"p." << name
783 void unpack_block(
const std::vector<casadi_int>& p, std::vector<casadi_ocp_block>& blocks) {
784 const casadi_int* packed =
get_ptr(p);
785 casadi_int N = *packed++;
787 for (casadi_int i=0;i<N;++i) {
788 blocks[i].offset_r = *packed++;
789 blocks[i].offset_c = *packed++;
790 blocks[i].rows = *packed++;
791 blocks[i].cols = *packed++;
797 casadi_error(
"Empty sparsity pattern not supported in FATROP C interface");
799 g <<
"d->nlp = &d_nlp;\n";
800 g <<
"d->prob = &p;\n";
801 g <<
"p.nlp = &p_nlp;\n";
803 g <<
"p.nx = " << g.
constant(nxs_) <<
";\n";
804 g <<
"p.nu = " << g.
constant(nus_) <<
";\n";
805 g <<
"p.ABsp = " << g.
sparsity(ABsp_) <<
";\n";
806 g <<
"p.AB_offsets = " << g.
constant(AB_offsets_) <<
";\n";
807 g <<
"p.CDsp = " << g.
sparsity(CDsp_) <<
";\n";
808 g <<
"p.CD_offsets = " << g.
constant(CD_offsets_) <<
";\n";
809 g <<
"p.RSQsp = " << g.
sparsity(RSQsp_) <<
";\n";
810 g <<
"p.RSQ_offsets = " << g.
constant(RSQ_offsets_) <<
";\n";
811 g <<
"p.Isp = " << g.
sparsity(Isp_) <<
";\n";
812 g <<
"p.I_offsets = " << g.
constant(I_offsets_) <<
";\n";
818 g <<
"p.N = " << N_ <<
";\n";
830 g <<
"p.sp_h = 0;\n";
833 g <<
"p.write = &" << g.
shorthand(
"fatrop_cb_write") <<
";\n";
834 g <<
"p.flush = &" << g.
shorthand(
"fatrop_cb_flush") <<
";\n";
836 g <<
"casadi_fatrop_setup(&p);\n";
841 s.
version(
"FatropInterface", 1);
849 s.
unpack(
"FatropInterface::Isp", Isp_);
850 s.
unpack(
"FatropInterface::ABsp", ABsp_);
851 s.
unpack(
"FatropInterface::CDsp", CDsp_);
852 s.
unpack(
"FatropInterface::RSQsp", RSQsp_);
854 std::vector<casadi_int> AB_blocks;
855 s.
unpack(
"FatropInterface::AB_blocks", AB_blocks);
857 std::vector<casadi_int> CD_blocks;
858 s.
unpack(
"FatropInterface::CD_blocks", CD_blocks);
860 std::vector<casadi_int> RSQ_blocks;
861 s.
unpack(
"FatropInterface::RSQ_blocks", RSQ_blocks);
863 std::vector<casadi_int> I_blocks;
864 s.
unpack(
"FatropInterface::I_blocks", I_blocks);
867 s.
unpack(
"FatropInterface::nxs", nxs_);
868 s.
unpack(
"FatropInterface::nus", nus_);
869 s.
unpack(
"FatropInterface::ngs", ngs_);
870 s.
unpack(
"FatropInterface::N", N_);
872 casadi_int structure_detection;
873 s.
unpack(
"FatropInterface::structure_detection", structure_detection);
874 structure_detection_ =
static_cast<StructureDetection
>(structure_detection);
877 s.
unpack(
"FatropInterface::AB_offsets", AB_offsets_);
878 s.
unpack(
"FatropInterface::CD_offsets", CD_offsets_);
879 s.
unpack(
"FatropInterface::RSQ_offsets", RSQ_offsets_);
880 s.
unpack(
"FatropInterface::I_offsets", I_offsets_);
881 s.
unpack(
"FatropInterface::debug", debug_);
888 s.
version(
"FatropInterface", 1);
896 s.
pack(
"FatropInterface::Isp", Isp_);
897 s.
pack(
"FatropInterface::ABsp", ABsp_);
898 s.
pack(
"FatropInterface::CDsp", CDsp_);
899 s.
pack(
"FatropInterface::RSQsp", RSQsp_);
906 s.
pack(
"FatropInterface::nxs", nxs_);
907 s.
pack(
"FatropInterface::nus", nus_);
908 s.
pack(
"FatropInterface::ngs", ngs_);
909 s.
pack(
"FatropInterface::N", N_);
910 s.
pack(
"FatropInterface::structure_detection",
static_cast<casadi_int
>(structure_detection_));
911 s.
pack(
"FatropInterface::AB_offsets", AB_offsets_);
912 s.
pack(
"FatropInterface::CD_offsets", CD_offsets_);
913 s.
pack(
"FatropInterface::RSQ_offsets", RSQ_offsets_);
914 s.
pack(
"FatropInterface::I_offsets", I_offsets_);
915 s.
pack(
"FatropInterface::debug", debug_);
Helper class for C code generation.
std::string add_dependency(const Function &f)
Add a function dependency.
void scope_enter()
Enter a local scope.
std::string constant(const std::vector< casadi_int > &v)
Represent an array constant; adding it when new.
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 setup_callback(const std::string &s, const Function &f)
Setup a callback.
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 Sparsity setup(ConvexifyData &d, const Sparsity &H, const Dict &opts=Dict(), bool inplace=true)
Helper class for Serialization.
void unpack(Sparsity &e)
Reconstruct an object from the input stream.
void version(const std::string &name, int v)
void codegen_init_mem(CodeGenerator &g) const override
Codegen alloc_mem.
void codegen_body(CodeGenerator &g) const override
Generate code for the function body.
void free_mem(void *mem) const override
Free memory block.
void init(const Dict &opts) override
Initialize.
Dict get_stats(void *mem) const override
Get all statistics.
void codegen_declarations(CodeGenerator &g) const override
Generate code for the declarations of the C function.
~FatropInterface() override
int init_mem(void *mem) const override
Initalize memory block.
Dict opts_
All FATROP options.
bool convexify_
convexify?
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize into MX.
void set_work(void *mem, const double **&arg, double **&res, casadi_int *&iw, double *&w) const override
Set the (persistent) work vectors.
ConvexifyData convexify_data_
Data for convexification.
FatropInterface(const std::string &name, const Function &nlp)
void codegen_free_mem(CodeGenerator &g) const override
Codegen free_mem.
static const Options options_
Options.
void serialize_body(SerializingStream &s) const override
Serialize an object without type information.
static const std::string meta_doc
A documentation string.
bool exact_hessian_
Exact Hessian?
int solve(void *mem) const override
static Nlpsol * creator(const std::string &name, const Function &nlp)
Create a new NLP Solver.
void alloc_iw(size_t sz_iw, bool persistent=false)
Ensure required length of iw field.
void alloc_res(size_t sz_res, bool persistent=false)
Ensure required length of res field.
void alloc_arg(size_t sz_arg, bool persistent=false)
Ensure required length of arg field.
std::string codegen_mem(CodeGenerator &g, const std::string &index="mem") const
Get thread-local memory object.
size_t sz_res() const
Get required length of res field.
size_t sz_w() const
Get required length of w field.
void alloc_w(size_t sz_w, bool persistent=false)
Ensure required length of w field.
size_t sz_arg() const
Get required length of arg field.
size_t sz_iw() const
Get required length of iw field.
static MatType zeros(casadi_int nrow=1, casadi_int ncol=1)
Create a dense matrix or a matrix with specified sparsity with all entries zero.
static casadi_int start_index
static Matrix< double > eye(casadi_int n)
create an n-by-n identity matrix
NLP solver storage class.
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.
std::vector< bool > equality_
Options.
casadi_nlpsol_prob< double > p_nlp_
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 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.
Sparsity T() const
Transpose the matrix.
casadi_int nnz() const
Get the number of (structural) non-zeros.
casadi_int size2() const
Get the number of columns.
std::vector< casadi_int > get_colind() const
Get the column index for each column.
void to_file(const std::string &filename, const std::string &format_hint="") const
std::vector< casadi_int > get_row() const
Get the row for each non-zero entry.
bool is_symmetric() const
Is symmetric?
void unpack_block(const std::vector< casadi_int > &p, std::vector< casadi_ocp_block > &blocks)
std::vector< casadi_int > range(casadi_int start, casadi_int stop, casadi_int step, casadi_int len)
Range function.
std::vector< casadi_int > fatrop_blocks_pack(const std::vector< casadi_ocp_block > &blocks)
void CASADI_NLPSOL_FATROP_EXPORT casadi_load_nlpsol_fatrop()
std::string str(const T &v)
String representation, any type.
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.
int CASADI_NLPSOL_FATROP_EXPORT casadi_register_nlpsol_fatrop(Nlpsol::Plugin *plugin)
T * get_ptr(std::vector< T > &v)
Get a pointer to the data contained in the vector.
T sum(const std::vector< T > &values)
sum
void report_issue(casadi_int i, const std::string &msg)
void codegen_unpack_block(CodeGenerator &g, const std::string &name, const std::vector< casadi_ocp_block > &blocks)
casadi_fatrop_data< double > d
struct FatropOcpCStats stats
OracleCallback nlp_grad_f
const casadi_int * I_offsets
OracleCallback nlp_hess_l
const casadi_int * RSQ_offsets
const casadi_int * CD_offsets
const casadi_nlpsol_prob< T1 > * nlp
const casadi_int * AB_offsets