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 #ifdef CASADI_WITH_THREAD
41 #ifdef CASADI_WITH_THREAD_MINGW
42 #include <mingw.mutex.h>
48 #include <fatrop_runtime_str.h>
52 int CASADI_NLPSOL_FATROP_EXPORT
55 plugin->name =
"fatrop";
57 plugin->version = CASADI_VERSION;
76 Sparsity FatropInterface::blocksparsity(casadi_int rows, casadi_int cols,
77 const std::vector<casadi_ocp_block>& blocks,
bool eye) {
79 for (
auto && b : blocks) {
81 r(
range(b.offset_r, b.offset_r+b.rows),
83 casadi_assert_dev(b.rows==b.cols);
85 r(
range(b.offset_r, b.offset_r+b.rows),
94 casadi_warning(
"Structure detection error on row " +
str(idx) +
". " + msg);
104 "Number of states, length N+1"}},
107 "Number of controls, length N+1"}},
110 "Number of non-dynamic constraints, length N+1"}},
113 "Options to be passed to fatrop"}},
114 {
"structure_detection",
116 "NONE | auto | manual"}},
117 {
"convexify_strategy",
119 "NONE|regularize|eigen-reflect|eigen-clip. "
120 "Strategy to convexify the Lagrange Hessian before passing it to the solver."}},
123 "When using a convexification strategy, make sure that "
124 "the smallest eigenvalue is at least this (default: 1e-7)."}},
127 "Produce debug information (default: false)"}},
130 "Options to be passed to fatrop"
139 casadi_int struct_cnt=0;
142 std::string convexify_strategy =
"none";
143 double convexify_margin = 1e-7;
144 casadi_int max_iter_eig = 200;
145 structure_detection_ = STRUCTURE_NONE;
152 for (
auto&& op : opts) {
156 }
else if (op.first==
"nx") {
159 }
else if (op.first==
"nu") {
162 }
else if (op.first==
"ng") {
165 }
else if (op.first==
"convexify_strategy") {
166 convexify_strategy = op.second.to_string();
167 }
else if (op.first==
"convexify_margin") {
168 convexify_margin = op.second;
169 }
else if (op.first==
"max_iter_eig") {
170 max_iter_eig = op.second;
171 }
else if (op.first==
"fatrop") {
173 }
else if (op.first==
"structure_detection") {
174 std::string v = op.second;
176 structure_detection_ = STRUCTURE_AUTO;
177 }
else if (v==
"manual") {
178 structure_detection_ = STRUCTURE_MANUAL;
179 }
else if (v==
"none") {
180 structure_detection_ = STRUCTURE_NONE;
182 casadi_error(
"Unknown option for structure_detection: '" + v +
"'.");
184 }
else if (op.first==
"debug") {
191 auto hessian_approximation =
opts_.find(
"hessian_approximation");
192 if (hessian_approximation!=
opts_.end()) {
213 {
"grad:gamma:x",
"hess:gamma:x:x"}, {{
"gamma", {
"f",
"g"}}});
217 if (convexify_strategy!=
"none") {
220 opts[
"strategy"] = convexify_strategy;
221 opts[
"margin"] = convexify_margin;
222 opts[
"max_iter_eig"] = max_iter_eig;
228 const std::vector<casadi_int>& nx = nxs_;
229 const std::vector<casadi_int>& ng = ngs_;
230 const std::vector<casadi_int>& nu = nus_;
232 Sparsity lamg_csp_, lam_ulsp_, lam_uusp_, lam_xlsp_, lam_xusp_, lam_clsp_;
236 A_.
to_file(
"debug_fatrop_actual.mtx");
239 std::set<casadi_int> errors;
241 casadi_int na_ = A_.
size1();
244 casadi_assert(structure_detection_ == STRUCTURE_MANUAL,
245 "You must set structure_detection to 'manual' if you set N, nx, nu, ng.");
248 if (structure_detection_==STRUCTURE_MANUAL) {
249 casadi_assert(struct_cnt==4,
250 "You must set all of N, nx, nu, ng.");
251 }
else if (structure_detection_==STRUCTURE_NONE) {
256 }
else if (structure_detection_==STRUCTURE_AUTO) {
258 "Structure detection auto requires the 'equality' option to be set");
266 std::vector<casadi_int> A_skyline;
267 std::vector<casadi_int> A_skyline2;
268 std::vector<casadi_int> A_bottomline;
270 std::vector<casadi_int> AT_colind = AT.
get_colind();
271 std::vector<casadi_int> AT_row = AT.
get_row();
272 for (casadi_int i=0;i<AT.
size2();++i) {
273 casadi_int pivot = AT_colind.at(i+1);
274 if (pivot>AT_colind.at(i)) {
275 A_bottomline.push_back(AT_row.at(AT_colind.at(i)));
277 A_bottomline.push_back(-1);
279 if (pivot>AT_colind.at(i)) {
280 A_skyline.push_back(AT_row.at(pivot-1));
281 if (pivot>AT_colind.at(i)+1) {
282 A_skyline2.push_back(AT_row.at(pivot-2));
284 A_skyline2.push_back(-1);
287 A_skyline.push_back(-1);
288 A_skyline2.push_back(-1);
293 "Constraint Jcobian must start with gap-closing constraint "
294 "(tagged 'true' in equality vector).");
296 casadi_int pivot = A_skyline[0];
297 casadi_int start_pivot = pivot;
298 casadi_int prev_start_pivot = 0;
305 for (casadi_int i=1;i<na_;++i) {
306 bool is_gap_closing =
true;
307 if (A_bottomline[i]!=-1 && A_bottomline[i]<prev_start_pivot) {
309 report_issue(i,
"Constraint found depending on a state of the previous interval.");
313 if (A_skyline[i]>pivot+1) {
314 if (A_bottomline[i]!=-1 && A_bottomline[i]<start_pivot) {
316 report_issue(i,
"Constraint found depending on a state of the previous interval.");
323 nus_.push_back(A_skyline[i]-pivot-1);
325 prev_start_pivot = start_pivot;
326 start_pivot = A_skyline[i];
327 pivot = A_skyline[i];
329 }
else if (A_skyline[i]==pivot+1) {
330 if (A_skyline2[i]<start_pivot) {
331 if (A_bottomline[i]>=prev_start_pivot) {
336 if (A_bottomline[i]!=-1 && A_bottomline[i]<start_pivot) {
339 "on a state of the previous interval.");
341 is_gap_closing =
false;
347 if (A_bottomline[i]!=-1 && A_bottomline[i]<start_pivot) {
349 report_issue(i,
"Gap-closing constraint found depending "
350 "on a state of the previous interval.");
352 prev_start_pivot = start_pivot;
353 start_pivot = A_skyline[i];
354 pivot = A_skyline[i];
358 is_gap_closing =
false;
361 is_gap_closing =
false;
364 if (!is_gap_closing) {
366 if (A_skyline[i]>=start_pivot) {
379 if (nxs_.back()!=0) {
386 nxs_.insert(nxs_.begin(), std::min(A_skyline[0], nxs_.front()));
389 nus_.front() += std::max(A_skyline[0]-nxs_.front(),
static_cast<casadi_int
>(0));
392 casadi_assert_dev(nxs_.back()==0);
395 casadi_assert_dev(nx.size()==nu.size());
396 casadi_assert_dev(nx.size()==ng.size());
398 casadi_assert_dev(
sum(ng)+
sum(nx)==na_+nx.front());
404 casadi_assert(nx.size()==N_+1,
"nx must have length N+1.");
405 casadi_assert(nu.size()==N_+1,
"nu must have length N+1.");
406 casadi_assert(ng.size()==N_+1,
"ng must have length N+1.");
409 casadi_message(
"Using structure: N " +
str(N_) +
", nx " +
str(nx) +
", "
410 "nu " +
str(nu) +
", ng " +
str(ng) +
".");
414 std::vector< casadi_ocp_block > A_blocks, B_blocks, C_blocks, D_blocks;
423 casadi_int offset_r = 0, offset_c = 0;
424 for (casadi_int k=0;k<N_;++k) {
425 AB_blocks_.push_back({offset_r, offset_c, nx[k+1], nx[k]+nu[k]});
426 CD_blocks_.push_back({offset_r+nx[k+1], offset_c, ng[k], nx[k]+nu[k]});
427 A_blocks.push_back({offset_r, offset_c, nx[k+1], nx[k]});
428 B_blocks.push_back({offset_r, offset_c+nx[k], nx[k+1], nu[k]});
429 C_blocks.push_back({offset_r+nx[k+1], offset_c, ng[k], nx[k]});
430 D_blocks.push_back({offset_r+nx[k+1], offset_c+nx[k], ng[k], nu[k]});
431 offset_c+= nx[k]+nu[k];
433 I_blocks_.push_back({offset_r, offset_c, nx[k+1], nx[k+1]});
439 I_blocks_.push_back({offset_r, offset_c, nx[k+1], nx[k+1]});
440 offset_r+= nx[k+1]+ng[k];
442 CD_blocks_.push_back({offset_r, offset_c, ng[N_], nx[N_]+nu[N_]});
443 C_blocks.push_back({offset_r, offset_c, ng[N_], nx[N_]});
444 D_blocks.push_back({offset_r, offset_c+nx[N_], ng[N_], nu[N_]});
446 casadi_int offset = 0;
447 AB_offsets_.push_back(0);
448 for (
auto e : AB_blocks_) {
449 offset += e.rows*e.cols;
450 AB_offsets_.push_back(offset);
453 CD_offsets_.push_back(0);
454 for (
auto e : CD_blocks_) {
455 offset += e.rows*e.cols;
456 CD_offsets_.push_back(offset);
459 ABsp_ = blocksparsity(na_,
nx_, AB_blocks_);
460 CDsp_ = blocksparsity(na_,
nx_, CD_blocks_);
461 Isp_ = blocksparsity(na_,
nx_, I_blocks_,
true);
463 Sparsity total = ABsp_ + CDsp_ + Isp_;
466 total.
to_file(
"debug_fatrop_expected.mtx");
467 blocksparsity(na_,
nx_, A_blocks).
to_file(
"debug_fatrop_A.mtx");
468 blocksparsity(na_,
nx_, B_blocks).
to_file(
"debug_fatrop_B.mtx");
469 blocksparsity(na_,
nx_, C_blocks).
to_file(
"debug_fatrop_C.mtx");
470 blocksparsity(na_,
nx_, D_blocks).
to_file(
"debug_fatrop_D.mtx");
471 Isp_.to_file(
"debug_fatrop_I.mtx");
472 std::vector<casadi_int> errors_vec(errors.begin(), errors.end());
473 std::vector<casadi_int> colind = {0,
static_cast<casadi_int
>(errors_vec.size())};
474 Sparsity(na_, 1, colind, errors_vec).
to_file(
"debug_fatrop_errors.mtx");
477 casadi_assert(errors.empty() && (A_ + total).nnz() == total.
nnz(),
478 "Fatrop: specified structure of A does not correspond to what the interface can handle. "
479 "Structure is: N " +
str(N_) +
", nx " +
str(nx) +
", nu " +
str(nu) +
", "
480 "ng " +
str(ng) +
".\n"
481 "Note that debug_fatrop_expected.mtx and debug_fatrop_actual.mtx are written "
482 "to the current directory when 'debug' option is true.\n"
483 "These can be read with Sparsity.from_file(...)."
484 "For a ready-to-use script, "
485 "see https://gist.github.com/jgillis/dec56fa16c90a8e4a69465e8422c5459");
486 casadi_assert_dev(total.
nnz() == ABsp_.
nnz() + CDsp_.
nnz() + Isp_.nnz());
497 for (casadi_int k=0;k<N_+1;++k) {
498 RSQ_blocks_.push_back({offset, offset, nx[k]+nu[k], nx[k]+nu[k]});
499 offset+= nx[k]+nu[k];
501 RSQsp_ = blocksparsity(
nx_,
nx_, RSQ_blocks_);
504 RSQ_offsets_.push_back(0);
505 for (
auto e : RSQ_blocks_) {
506 offset += e.rows*e.cols;
507 RSQ_offsets_.push_back(offset);
526 casadi_fatrop_init_mem(&m->d);
533 casadi_fatrop_free_mem(&m->d);
539 casadi_int*& iw,
double*& w)
const {
546 m->d.
nlp = &m->d_nlp;
548 casadi_fatrop_set_work(&m->d, &arg, &res, &iw, &w);
550 m->d.nlp->oracle->m =
static_cast<void*
>(m);
559 bool new_solver = (m->d.solver == 0);
564 #ifdef CASADI_WITH_THREAD
565 static std::mutex mutex_fatrop_create;
566 std::lock_guard<std::mutex> lock(mutex_fatrop_create);
568 casadi_fatrop_presolve(&m->d);
573 for (
const auto& kv :
opts_) {
574 switch (fatrop_ocp_c_option_type(kv.first.c_str())) {
576 fatrop_ocp_c_set_option_double(m->d.solver, kv.first.c_str(), kv.second);
579 fatrop_ocp_c_set_option_int(m->d.solver, kv.first.c_str(), kv.second.to_int());
582 fatrop_ocp_c_set_option_bool(m->d.solver, kv.first.c_str(), kv.second.to_bool());
586 std::string s = kv.second.to_string();
587 fatrop_ocp_c_set_option_string(m->d.solver, kv.first.c_str(), s.c_str());
591 casadi_error(
"Fatrop option not supported: " + kv.first);
593 casadi_error(
"Unknown option type.");
598 casadi_fatrop_solve(&m->d);
600 m->success = m->d.success;
610 fatrop[
"compute_sd_time"] = m->
d.
stats.compute_sd_time;
611 fatrop[
"duinf_time"] = m->d.stats.duinf_time;
612 fatrop[
"eval_hess_time"] = m->d.stats.eval_hess_time;
613 fatrop[
"eval_jac_time"] = m->d.stats.eval_jac_time;
614 fatrop[
"eval_cv_time"] = m->d.stats.eval_cv_time;
615 fatrop[
"eval_grad_time"] = m->d.stats.eval_grad_time;
616 fatrop[
"eval_obj_time"] = m->d.stats.eval_obj_time;
617 fatrop[
"initialization_time"] = m->d.stats.initialization_time;
618 fatrop[
"time_total"] = m->d.stats.time_total;
619 fatrop[
"eval_hess_count"] = m->d.stats.eval_hess_count;
620 fatrop[
"eval_jac_count"] = m->d.stats.eval_jac_count;
621 fatrop[
"eval_cv_count"] = m->d.stats.eval_cv_count;
622 fatrop[
"eval_grad_count"] = m->d.stats.eval_grad_count;
623 fatrop[
"eval_obj_count"] = m->d.stats.eval_obj_count;
624 fatrop[
"iterations_count"] = m->d.stats.iterations_count;
625 fatrop[
"return_flag"] = m->d.stats.return_flag;
626 stats[
"fatrop"] = fatrop;
627 stats[
"iter_count"] = m->d.stats.iterations_count;
632 stats[
"return_status"] = m->d.return_status;
637 g <<
"casadi_fatrop_init_mem(&" +
codegen_mem(g) +
");\n";
642 g <<
"casadi_fatrop_free_mem(&" +
codegen_mem(g) +
");\n";
670 std::string name =
"fatrop_cb_write";
674 <<
"(const char* msg, int num) {\n";
677 g <<
"CASADI_PRINTF(\"%.*s\", num, msg);\n";
681 name =
"fatrop_cb_flush";
696 g.
local(
"d",
"struct casadi_fatrop_data*");
698 g.
local(
"p",
"struct casadi_fatrop_prob");
701 g <<
"casadi_fatrop_set_work(d, &arg, &res, &iw, &w);\n";
702 g <<
"casadi_oracle_set_work(d->nlp->oracle, &arg, &res, &iw, &w);\n";
706 g <<
"int new_solver = (d->solver == 0);\n";
711 Function F = shared_from_this<Function>();
712 std::string mutex_name =
codegen_name(g,
false) +
"_fatrop_create_mutex";
715 g <<
"CASADI_MUTEX_LOCK(&" << mtx <<
");\n";
716 g <<
"casadi_fatrop_presolve(d);\n";
717 g <<
"CASADI_MUTEX_UNLOCK(&" << mtx <<
");\n";
719 g <<
"casadi_fatrop_presolve(d);\n";
721 g <<
"if (new_solver) {\n";
723 for (
const auto& kv :
opts_) {
724 switch (fatrop_ocp_c_option_type(kv.first.c_str())) {
726 g <<
"fatrop_ocp_c_set_option_double(d->solver, \"" + kv.first +
"\", "
727 + g.
constant(kv.second.to_double()) +
");\n";
730 g <<
"fatrop_ocp_c_set_option_int(d->solver, \"" + kv.first +
"\", "
731 +
str(kv.second.to_int()) +
");\n";
734 g <<
"fatrop_ocp_c_set_option_bool(d->solver, \"" + kv.first +
"\", "
735 +
str(
static_cast<int>(kv.second.to_bool())) +
");\n";
739 std::string s = kv.second.to_string();
740 g <<
"fatrop_ocp_c_set_option_bool(d->solver, \"" + kv.first +
"\", \""
745 casadi_error(
"Fatrop option not supported: " + kv.first);
747 casadi_error(
"Unknown option type.");
753 g <<
"casadi_fatrop_solve(d);\n";
758 g <<
"return d->unified_return_status;\n";
764 std::vector<casadi_int>
fatrop_blocks_pack(
const std::vector<casadi_ocp_block>& blocks) {
765 size_t N = blocks.size();
766 std::vector<casadi_int> ret(4*N+1);
769 for (casadi_int i=0;i<N;++i) {
770 *r++ = blocks[i].offset_r;
771 *r++ = blocks[i].offset_c;
772 *r++ = blocks[i].rows;
773 *r++ = blocks[i].cols;
807 p_.
write = &casadi_c_logger_write;
808 p_.
flush = &casadi_c_logger_flush;
810 casadi_fatrop_setup(&p_);
814 const std::vector<casadi_ocp_block>& blocks) {
815 casadi_int sz = blocks.size();
817 std::string n =
"block_" + name +
"[" +
str(sz) +
"]";
818 g.
local(n,
"static struct casadi_ocp_block");
819 g <<
"p." << name <<
" = block_" + name +
";\n";
820 g <<
"casadi_unpack_ocp_blocks(" <<
"p." << name
824 void unpack_block(
const std::vector<casadi_int>& p, std::vector<casadi_ocp_block>& blocks) {
825 const casadi_int* packed =
get_ptr(p);
826 casadi_int N = *packed++;
828 for (casadi_int i=0;i<N;++i) {
829 blocks[i].offset_r = *packed++;
830 blocks[i].offset_c = *packed++;
831 blocks[i].rows = *packed++;
832 blocks[i].cols = *packed++;
838 casadi_error(
"Empty sparsity pattern not supported in FATROP C interface");
840 g <<
"d->nlp = &d_nlp;\n";
841 g <<
"d->prob = &p;\n";
842 g <<
"p.nlp = &p_nlp;\n";
844 g <<
"p.nx = " << g.
constant(nxs_) <<
";\n";
845 g <<
"p.nu = " << g.
constant(nus_) <<
";\n";
846 g <<
"p.ABsp = " << g.
sparsity(ABsp_) <<
";\n";
847 g <<
"p.AB_offsets = " << g.
constant(AB_offsets_) <<
";\n";
848 g <<
"p.CDsp = " << g.
sparsity(CDsp_) <<
";\n";
849 g <<
"p.CD_offsets = " << g.
constant(CD_offsets_) <<
";\n";
850 g <<
"p.RSQsp = " << g.
sparsity(RSQsp_) <<
";\n";
851 g <<
"p.RSQ_offsets = " << g.
constant(RSQ_offsets_) <<
";\n";
852 g <<
"p.Isp = " << g.
sparsity(Isp_) <<
";\n";
853 g <<
"p.I_offsets = " << g.
constant(I_offsets_) <<
";\n";
859 g <<
"p.N = " << N_ <<
";\n";
871 g <<
"p.sp_h = 0;\n";
874 g <<
"p.write = &" << g.
shorthand(
"fatrop_cb_write") <<
";\n";
875 g <<
"p.flush = &" << g.
shorthand(
"fatrop_cb_flush") <<
";\n";
877 g <<
"casadi_fatrop_setup(&p);\n";
882 s.
version(
"FatropInterface", 1);
890 s.
unpack(
"FatropInterface::Isp", Isp_);
891 s.
unpack(
"FatropInterface::ABsp", ABsp_);
892 s.
unpack(
"FatropInterface::CDsp", CDsp_);
893 s.
unpack(
"FatropInterface::RSQsp", RSQsp_);
895 std::vector<casadi_int> AB_blocks;
896 s.
unpack(
"FatropInterface::AB_blocks", AB_blocks);
898 std::vector<casadi_int> CD_blocks;
899 s.
unpack(
"FatropInterface::CD_blocks", CD_blocks);
901 std::vector<casadi_int> RSQ_blocks;
902 s.
unpack(
"FatropInterface::RSQ_blocks", RSQ_blocks);
904 std::vector<casadi_int> I_blocks;
905 s.
unpack(
"FatropInterface::I_blocks", I_blocks);
908 s.
unpack(
"FatropInterface::nxs", nxs_);
909 s.
unpack(
"FatropInterface::nus", nus_);
910 s.
unpack(
"FatropInterface::ngs", ngs_);
911 s.
unpack(
"FatropInterface::N", N_);
913 casadi_int structure_detection;
914 s.
unpack(
"FatropInterface::structure_detection", structure_detection);
915 structure_detection_ =
static_cast<StructureDetection
>(structure_detection);
918 s.
unpack(
"FatropInterface::AB_offsets", AB_offsets_);
919 s.
unpack(
"FatropInterface::CD_offsets", CD_offsets_);
920 s.
unpack(
"FatropInterface::RSQ_offsets", RSQ_offsets_);
921 s.
unpack(
"FatropInterface::I_offsets", I_offsets_);
922 s.
unpack(
"FatropInterface::debug", debug_);
929 s.
version(
"FatropInterface", 1);
937 s.
pack(
"FatropInterface::Isp", Isp_);
938 s.
pack(
"FatropInterface::ABsp", ABsp_);
939 s.
pack(
"FatropInterface::CDsp", CDsp_);
940 s.
pack(
"FatropInterface::RSQsp", RSQsp_);
947 s.
pack(
"FatropInterface::nxs", nxs_);
948 s.
pack(
"FatropInterface::nus", nus_);
949 s.
pack(
"FatropInterface::ngs", ngs_);
950 s.
pack(
"FatropInterface::N", N_);
951 s.
pack(
"FatropInterface::structure_detection",
static_cast<casadi_int
>(structure_detection_));
952 s.
pack(
"FatropInterface::AB_offsets", AB_offsets_);
953 s.
pack(
"FatropInterface::CD_offsets", CD_offsets_);
954 s.
pack(
"FatropInterface::RSQ_offsets", RSQ_offsets_);
955 s.
pack(
"FatropInterface::I_offsets", I_offsets_);
956 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.
bool thread_safe() const
Emit thead safe code chekout/release?
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 local_mutex(const Function &f, const std::string &name) const
Access a static mutex associated with a function.
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.
void define_local_mutex(const Function &f, const std::string &name)
Declare a static mutex associated with a 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.
virtual std::string codegen_name(const CodeGenerator &g, bool ns=true) const
Get name in codegen.
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