ccopt_interface.cpp
1 /*
2  * This file is part of CasADi.
3  *
4  * CasADi -- A symbolic framework for dynamic optimization.
5  * Copyright (C) 2010-2023 Joel Andersson, Joris Gillis, Moritz Diehl,
6  * KU Leuven. All rights reserved.
7  * Copyright (C) 2011-2014 Greg Horn
8  *
9  * CasADi is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 3 of the License, or (at your option) any later version.
13  *
14  * CasADi is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with CasADi; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  *
23  */
24 
25 
26 #include "ccopt_interface.hpp"
27 #include <ccopt_runtime_str.h>
28 
29 #include "casadi/core/casadi_misc.hpp"
30 #include "../../core/global_options.hpp"
31 #include "../../core/casadi_interrupt.hpp"
32 #include "../../core/convexify.hpp"
33 
34 #include <ctime>
35 #include <stdlib.h>
36 #include <iostream>
37 #include <iomanip>
38 #include <chrono>
39 #include <cstring>
40 #include <string>
41 
42 namespace casadi {
43 
44 extern "C"
45 int CASADI_NLPSOL_CCOPT_EXPORT
46 casadi_register_nlpsol_ccopt(Nlpsol::Plugin* plugin) {
47  plugin->creator = MadmpecInterface::creator;
48  plugin->name = "ccopt";
49  plugin->doc = MadmpecInterface::meta_doc.c_str();
50  plugin->version = CASADI_VERSION;
51  plugin->options = &MadmpecInterface::options_;
52  plugin->deserialize = &MadmpecInterface::deserialize;
53  return 0;
54 }
55 
56 extern "C"
57 void CASADI_NLPSOL_CCOPT_EXPORT casadi_load_nlpsol_ccopt() {
59 }
60 
61 MadmpecInterface::MadmpecInterface(const std::string& name, const Function& nlp)
62  : Nlpsol(name, nlp) {
63 }
64 
66  clear_mem();
67 }
68 
70 = {{&Nlpsol::options_},
71  {{"ccopt",
72  {OT_DICT,
73  "Options to be passed to ccopt relaxation algorithm"}},
74  {"madnlp",
75  {OT_DICT,
76  "Options to be passed to madnlp"}},
77  {"convexify_strategy",
78  {OT_STRING,
79  "NONE|regularize|eigen-reflect|eigen-clip. "
80  "Strategy to convexify the Lagrange Hessian before passing it to the solver."}},
81  {"convexify_margin",
82  {OT_DOUBLE,
83  "When using a convexification strategy, make sure that "
84  "the smallest eigenvalue is at least this (default: 1e-7)."}},
85  {"cc_pairs",
87  "List of complementary constraints on simple bounds. "
88  "Pair (i, j) encodes complementarity between the bounds on variable i and variable j."}},
89  {"cc_types",
90  {OT_INTVECTOR,
91  "Type of cc pairs (default: 0). "}},
92  }
93 };
94 
95 // Recursively flatten options for libmad options dict.
96 void flatten_opts(Dict& ret, const Dict& opts, const std::string& prefix) {
97  for (const auto& kv : opts) {
98  switch (kv.second.getType()) {
99  case OT_DICT:
100  flatten_opts(ret, kv.second, prefix + kv.first + ".");
101  break;
102  default:
103  ret[prefix + kv.first] = kv.second;
104  }
105  }
106 }
107 
108 void MadmpecInterface::init(const Dict& opts) {
109  // Call the init method of the base class
110  Nlpsol::init(opts);
111  casadi_int struct_cnt=0;
112 
113  // Default options
114  std::string convexify_strategy = "none";
115  double convexify_margin = 1e-7;
116  casadi_int max_iter_eig = 200;
117  std::vector< std::vector<casadi_int> > cc_pairs;
118  std::vector<casadi_int> cc_types;
119  convexify_ = false;
120 
121  calc_g_ = true;
122  calc_f_ = true;
123 
124  // Read options
125  for (auto&& op : opts) {
126  if (op.first=="convexify_strategy") {
127  convexify_strategy = op.second.to_string();
128  } else if (op.first=="convexify_margin") {
129  convexify_margin = op.second;
130  } else if (op.first=="max_iter") {
131  max_iter_eig = op.second;
132  } else if (op.first=="madnlp") {
133  flatten_opts(opts_, op.second, "");
134  } else if (op.first=="ccopt") {
135  flatten_opts(mpcc_opts_, op.second, "");
136  } else if (op.first=="cc_pairs") {
137  cc_pairs = op.second;
138  } else if (op.first=="cc_types") {
139  cc_types = op.second;
140  }
141  }
142  ind_cc1_.reserve(cc_pairs.size());
143  ind_cc2_.reserve(cc_pairs.size());
144  cctypes_.reserve(cc_pairs.size());
145  if (cc_types.empty()) {
146  cc_types.resize(cc_pairs.size(), 0);
147  }
148  casadi_assert(cc_pairs.size()==cc_types.size(),
149  "Options 'cc_pairs' and 'cc_types' must have the same length.");
150  for (auto && e : cc_types) {
151  cctypes_.push_back(e);
152  }
153  // CCType: VarVar=0, VarCon=1, ConVar=2, ConCon=3
154  const libmad_int* type = get_ptr(cctypes_);
155  for (auto && e : cc_pairs) {
156  casadi_assert(e.size()==2, "Complementary constraints must come in pairs.");
157  casadi_assert(e[0]>=0, "Invalid index.");
158  casadi_assert(e[1]>=0, "Invalid index.");
159  bool first_is_var = (*type == 0 || *type == 1);
160  bool second_is_var = (*type == 0 || *type == 2);
161  casadi_int n_first = first_is_var ? nx_ : ng_;
162  casadi_int n_second = second_is_var ? nx_ : ng_;
163  casadi_assert(e[0]<n_first, "Invalid index for first slot of cc_pair "
164  "(type " + str(*type) + ", limit " + str(n_first) + ").");
165  casadi_assert(e[1]<n_second, "Invalid index for second slot of cc_pair "
166  "(type " + str(*type) + ", limit " + str(n_second) + ").");
167  ind_cc1_.push_back(e[0]+1);
168  ind_cc2_.push_back(e[1]+1);
169  type++;
170  }
171  // Do we need second order derivatives?
172  exact_hessian_ = true;
173  auto hessian_approximation = opts_.find("hessian_approximation");
174  if (hessian_approximation!=opts_.end()) {
175  exact_hessian_ = hessian_approximation->second == "exact";
176  }
177 
178  // Setup NLP functions
179 
180  create_function("nlp_f", {"x", "p"}, {"f"});
181  create_function("nlp_g", {"x", "p"}, {"g"});
182 
183  if (!has_function("nlp_grad_f")) {
184  create_function("nlp_grad_f", {"x", "p"}, {"grad:f:x"});
185  }
186 
187  if (!has_function("nlp_jac_g")) {
188  create_function("nlp_jac_g", {"x", "p"}, {"jac:g:x"});
189  }
190  jacg_sp_ = get_function("nlp_jac_g").sparsity_out(0);
191 
192  if (!has_function("nlp_hess_l")) {
193  create_function("nlp_hess_l", {"x", "p", "lam:f", "lam:g"},
194  {"tril:hess:gamma:x:x"}, {{"gamma", {"f", "g"}}});
195  }
196  hesslag_sp_ = get_function("nlp_hess_l").sparsity_out(0);
197  casadi_assert(hesslag_sp_.is_tril(), "Hessian must be lower triangular");
198 
199  if (convexify_strategy!="none") {
200  convexify_ = true;
201  Dict opts;
202  opts["strategy"] = convexify_strategy;
203  opts["margin"] = convexify_margin;
204  opts["max_iter_eig"] = max_iter_eig;
205  opts["verbose"] = verbose_;
207  }
208 
209  set_ccopt_prob();
210 
211  // Allocate memory
212  casadi_int sz_arg, sz_res, sz_w, sz_iw;
213  casadi_ccopt_work(&p_, &sz_arg, &sz_res, &sz_iw, &sz_w);
214 
215  alloc_arg(sz_arg, true);
216  alloc_res(sz_res, true);
217  alloc_iw(sz_iw, true);
218  alloc_w(sz_w, true);
219 
220  std::vector<char*> _argv = {};
221  std::string s;
222 
223  int argc = _argv.size();
224  char** argv = reinterpret_cast<char**>(_argv.data());
225 
226 }
227 
228 int MadmpecInterface::init_mem(void* mem) const {
229  if (Nlpsol::init_mem(mem)) return 1;
230  if (!mem) return 1;
231  auto m = static_cast<MadmpecMemory*>(mem);
232  // Now create the new options struct
233  libmad_create_options_dict(&(m->d.nlp_opts));
234  for (const auto& kv : opts_) {
235  switch (kv.second.getType()) {
236  case OT_DOUBLE:
237  libmad_set_double_option(m->d.nlp_opts, kv.first.c_str(), kv.second);
238  break;
239  case OT_INT:
240  libmad_set_int64_option(m->d.nlp_opts, kv.first.c_str(), kv.second.to_int());
241  break;
242  case OT_STRING:
243  {
244  std::string s = kv.second.to_string();
245  libmad_set_string_option(m->d.nlp_opts, kv.first.c_str(), s.c_str());
246  }
247  break;
248  case OT_BOOL:
249  libmad_set_bool_option(m->d.nlp_opts, kv.first.c_str(), kv.second.to_bool());
250  break;
251  default:
252  casadi_error("Unknown option type.");
253  }
254  }
255  // Now create the new options struct
256  libmad_create_options_dict(&(m->d.mpcc_opts));
257  for (const auto& kv : mpcc_opts_) {
258  switch (kv.second.getType()) {
259  case OT_DOUBLE:
260  libmad_set_double_option(m->d.mpcc_opts, kv.first.c_str(), kv.second);
261  break;
262  case OT_INT:
263  libmad_set_int64_option(m->d.mpcc_opts, kv.first.c_str(), kv.second.to_int());
264  break;
265  case OT_STRING:
266  {
267  std::string s = kv.second.to_string();
268  libmad_set_string_option(m->d.mpcc_opts, kv.first.c_str(), s.c_str());
269  }
270  break;
271  case OT_BOOL:
272  libmad_set_bool_option(m->d.mpcc_opts, kv.first.c_str(), kv.second.to_bool());
273  break;
274  default:
275  casadi_error("Unknown option type.");
276  }
277  }
278 
279  m->d.ind_cc1 = ind_cc1_.data();
280  m->d.ind_cc2 = ind_cc2_.data();
281  m->d.cctypes = cctypes_.data();
282  m->d.ncc = ind_cc1_.size();
283  casadi_ccopt_init_mem(&m->d);
284 
285  return 0;
286 }
287 
288 void MadmpecInterface::free_mem(void* mem) const {
289  auto m = static_cast<MadmpecMemory*>(mem);
290  casadi_ccopt_free_mem(&m->d);
291  delete static_cast<MadmpecMemory*>(mem);
292 }
293 
295 void MadmpecInterface::set_work(void* mem, const double**& arg, double**& res,
296  casadi_int*& iw, double*& w) const {
297  auto m = static_cast<MadmpecMemory*>(mem);
298 
299  // Set work in base classes
300  Nlpsol::set_work(mem, arg, res, iw, w);
301 
302  m->d.prob = &p_;
303  m->d.nlp = &m->d_nlp;
304 
305  casadi_ccopt_set_work(&m->d, &arg, &res, &iw, &w);
306 
307  m->d.nlp->oracle->m = static_cast<void*>(m);
308 }
309 
310 int MadmpecInterface::solve(void* mem) const {
311  auto m = static_cast<MadmpecMemory*>(mem);
312 
313  int ret = casadi_ccopt_presolve(&m->d);
314  if (ret) throw CasadiException("CCOPTError");
315  ret = casadi_ccopt_solve(&m->d);
316  if (ret) throw CasadiException("CCOPTError");
317 
318  m->success = m->d.success;
319  m->unified_return_status = static_cast<UnifiedReturnStatus>(m->d.unified_return_status);
320 
321  return 0;
322 }
323 
325  Dict stats = Nlpsol::get_stats(mem);
326  auto m = static_cast<MadmpecMemory*>(mem);
327  libmad_int iter, status;
328  double primal_feas, dual_feas, cc_feas, total_wall_time;
329  std::vector<libmad_real> multipliers_x1, multipliers_x2;
330  multipliers_x1.resize(ind_cc1_.size());
331  multipliers_x2.resize(ind_cc2_.size());
332  ccopt_relaxation_get_iters(m->d.stats, &iter);
333  ccopt_relaxation_get_total_wall_time(m->d.stats, &total_wall_time);
334  ccopt_relaxation_get_status(m->d.stats, &status);
335  ccopt_relaxation_get_dual_feas(m->d.stats, &dual_feas);
336  ccopt_relaxation_get_primal_feas(m->d.stats, &primal_feas);
337  ccopt_relaxation_get_cc_feas(m->d.stats, &cc_feas);
338  ccopt_relaxation_get_multipliers_x1(m->d.stats, multipliers_x1.data());
339  ccopt_relaxation_get_multipliers_x2(m->d.stats, multipliers_x2.data());
340 
341  stats["iter_count"] = static_cast<casadi_int>(iter);
342  Dict ccopt;
343  ccopt["dual_feas"] = dual_feas;
344  ccopt["cc_feas"] = cc_feas;
345  ccopt["primal_feas"] = primal_feas;
346  ccopt["status"] = static_cast<casadi_int>(status);
347  ccopt["multipliers_x1"] = multipliers_x1;
348  ccopt["multipliers_x2"] = multipliers_x2;
349  ccopt["total_wall_time"] = total_wall_time;
350  stats["ccopt"] = ccopt;
351  return stats;
352 }
353 
355  // assign pointer to internal structur casadi_nlp_prob
356  // p_nlp_ ~ casadi_nlp_prob casadi internal
357  p_.nlp = &p_nlp_;
358  // p_ casadi_ccopt_prob
359 
360  p_.sp_a = jacg_sp_;
361  p_.sp_h = hesslag_sp_;
362 
363  p_.nlp_hess_l = OracleCallback("nlp_hess_l", this);
364  p_.nlp_jac_g = OracleCallback("nlp_jac_g", this);
365  p_.nlp_grad_f = OracleCallback("nlp_grad_f", this);
366  p_.nlp_f = OracleCallback("nlp_f", this);
367  p_.nlp_g = OracleCallback("nlp_g", this);
368 
369  casadi_ccopt_setup(&p_);
370 }
371 
373  const std::string& field) const {
374  g << "libmad_create_options_dict(&(" + codegen_mem(g) + "." + field + "));\n";
375  for (const auto& kv : dict) {
376  switch (kv.second.getType()) {
377  case OT_DOUBLE:
378  g << "libmad_set_double_option(" + codegen_mem(g) + "." + field + ", \""
379  + kv.first + "\", " + str(kv.second) + ");\n";
380  break;
381  case OT_INT:
382  g << "libmad_set_int64_option(" + codegen_mem(g) + "." + field + ", \""
383  + kv.first + "\", " + str(kv.second) + ");\n";
384  break;
385  case OT_STRING:
386  {
387  std::string s = kv.second.to_string();
388  g << "libmad_set_string_option(" + codegen_mem(g) + "." + field + ", \""
389  + kv.first + "\", \"" + s + "\");\n";
390  }
391  break;
392  case OT_BOOL:
393  g << "libmad_set_bool_option(" + codegen_mem(g) + "." + field + ", \""
394  + kv.first + "\", " + str(kv.second) + ");\n";
395  break;
396  default:
397  casadi_error("Unknown option type.");
398  }
399  }
400 }
401 
403  codegen_options(g, opts_, "nlp_opts");
404  codegen_options(g, mpcc_opts_, "mpcc_opts");
405 
406  g << codegen_mem(g) + ".ind_cc1 = " + g.constant(ind_cc1_) + ";\n";
407  g << codegen_mem(g) + ".ind_cc2 = " + g.constant(ind_cc2_) + ";\n";
408  g << codegen_mem(g) + ".cctypes = " + g.constant(cctypes_) + ";\n";
409  g << codegen_mem(g) + ".ncc = " + str(ind_cc1_.size()) + ";\n";
410 
411  g << "casadi_ccopt_init_mem(&" + codegen_mem(g) + ");\n";
412  g << "return 0;\n";
413 }
414 
416  // memory deallocation
417  g << "casadi_ccopt_free_mem(&" + codegen_mem(g) + ");\n";
418 }
419 
432  g.add_dependency(get_function("nlp_f"));
433  g.add_dependency(get_function("nlp_grad_f"));
434  g.add_dependency(get_function("nlp_g"));
435  g.add_dependency(get_function("nlp_jac_g"));
436  g.add_dependency(get_function("nlp_hess_l"));
437  g.add_include("libMad.h");
438 }
439 
442  g.auxiliaries << g.sanitize_source(ccopt_runtime_str, {"casadi_real"});
443 
444  g.local("d", "struct casadi_ccopt_data*");
445  g.init_local("d", "&" + codegen_mem(g));
446  g.local("p", "struct casadi_ccopt_prob");
447  set_ccopt_prob(g);
448 
449  g << "casadi_ccopt_set_work(d, &arg, &res, &iw, &w);\n";
450  g << "casadi_oracle_set_work(d->nlp->oracle, &arg, &res, &iw, &w);\n";
451  g << "casadi_ccopt_presolve(d);\n";
452 
453  g << "casadi_ccopt_solve(d);\n";
454 
456 
457  if (error_on_fail_) {
458  g << "return d->unified_return_status;\n";
459  } else {
460  g << "return 0;\n";
461  }
462 }
463 
465  if (jacg_sp_.size1()>0 && jacg_sp_.nnz()==0) {
466  casadi_error("Empty sparsity pattern not supported in CCOPT C interface");
467  }
468  g << "d->nlp = &d_nlp;\n";
469  g << "d->prob = &p;\n";
470  g << "p.nlp = &p_nlp;\n";
471 
472  g.setup_callback("p.nlp_jac_g", get_function("nlp_jac_g"));
473  g.setup_callback("p.nlp_grad_f", get_function("nlp_grad_f"));
474  g.setup_callback("p.nlp_f", get_function("nlp_f"));
475  g.setup_callback("p.nlp_g", get_function("nlp_g"));
476  g.setup_callback("p.nlp_hess_l", get_function("nlp_hess_l"));
477 
478  g << "p.sp_a = " << g.sparsity(jacg_sp_) << ";\n";
479  if (exact_hessian_) {
480  g << "p.sp_h = " << g.sparsity(hesslag_sp_) << ";\n";
481  } else {
482  g << "p.sp_h = 0;\n";
483  }
484 
485  g << "casadi_ccopt_setup(&p);\n";
486 }
487 
489  s.version("MadmpecInterface", 1);
490  s.unpack("MadmpecInterface::jacg_sp", jacg_sp_);
491  s.unpack("MadmpecInterface::hesslag_sp", hesslag_sp_);
492  s.unpack("MadmpecInterface::exact_hessian", exact_hessian_);
493  s.unpack("MadmpecInterface::opts", opts_);
494  s.unpack("MadmpecInterface::convexify", convexify_);
495  s.unpack("MadmpecInterface::ind_cc1", ind_cc1_);
496  s.unpack("MadmpecInterface::ind_cc2", ind_cc2_);
497  s.unpack("MadmpecInterface::cctypes", cctypes_);
498 
499  set_ccopt_prob();
500 }
501 
504  s.version("MadmpecInterface", 1);
505 
506  s.pack("MadmpecInterface::jacg_sp", jacg_sp_);
507  s.pack("MadmpecInterface::hesslag_sp", hesslag_sp_);
508  s.pack("MadmpecInterface::exact_hessian", exact_hessian_);
509  s.pack("MadmpecInterface::opts", opts_);
510  s.pack("MadmpecInterface::convexify", convexify_);
511  s.pack("MadmpecInterface::ind_cc1", ind_cc1_);
512  s.pack("MadmpecInterface::ind_cc2", ind_cc2_);
513  s.pack("MadmpecInterface::cctypes", cctypes_);
514 
515 }
516 
517 } // namespace casadi
Casadi exception class.
Definition: exception.hpp:77
Helper class for C code generation.
std::string add_dependency(const Function &f)
Add a function dependency.
std::string constant(const std::vector< casadi_int > &v)
Represent an array constant; adding it when new.
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 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 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)
Definition: convexify.cpp:167
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.
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.
Function object.
Definition: function.hpp:60
bool exact_hessian_
Exact Hessian?
std::vector< libmad_int > cctypes_
ConvexifyData convexify_data_
Data for convexification.
MadmpecInterface(const std::string &name, const Function &nlp)
Dict opts_
All CCOPT options.
void init(const Dict &opts) override
Initialize.
void codegen_free_mem(CodeGenerator &g) const override
Codegen free_mem.
int init_mem(void *mem) const override
Initalize memory block.
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize into MX.
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.
Dict get_stats(void *mem) const override
Get all statistics.
std::vector< libmad_int > ind_cc1_
Complementarity.
void codegen_init_mem(CodeGenerator &g) const override
Codegen alloc_mem.
static const Options options_
Options.
void codegen_options(CodeGenerator &g, const Dict &dict, const std::string &field) const
void serialize_body(SerializingStream &s) const override
Serialize an object without type information.
static const std::string meta_doc
A documentation string.
int solve(void *mem) const override
void free_mem(void *mem) const override
Free memory block.
std::vector< libmad_int > ind_cc2_
void set_work(void *mem, const double **&arg, double **&res, casadi_int *&iw, double *&w) const override
Set the (persistent) work vectors.
void codegen_declarations(CodeGenerator &g) const override
Generate code for the declarations of the C function.
NLP solver storage class.
Definition: nlpsol_impl.hpp:59
void codegen_body_exit(CodeGenerator &g) const override
Generate code for the function body.
Definition: nlpsol.cpp:1368
Dict get_stats(void *mem) const override
Get all statistics.
Definition: nlpsol.cpp:1251
static const Options options_
Options.
void codegen_body_enter(CodeGenerator &g) const override
Generate code for the function body.
Definition: nlpsol.cpp:1268
void codegen_declarations(CodeGenerator &g) const override
Generate code for the declarations of the C function.
Definition: nlpsol.cpp:1348
void init(const Dict &opts) override
Initialize.
Definition: nlpsol.cpp:499
casadi_int ng_
Number of constraints.
Definition: nlpsol_impl.hpp:69
int init_mem(void *mem) const override
Initalize memory block.
Definition: nlpsol.cpp:692
casadi_nlpsol_prob< double > p_nlp_
Definition: nlpsol_impl.hpp:63
void serialize_body(SerializingStream &s) const override
Serialize an object without type information.
Definition: nlpsol.cpp:1409
bool calc_f_
Options.
Definition: nlpsol_impl.hpp:97
bool calc_g_
Options.
Definition: nlpsol_impl.hpp:97
casadi_int nx_
Number of variables.
Definition: nlpsol_impl.hpp:66
void set_work(void *mem, const double **&arg, double **&res, casadi_int *&iw, double *&w) const override
Set the (persistent) work vectors.
Definition: nlpsol.cpp:884
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.
Definition: sparsity.cpp:124
bool is_tril(bool strictly=false) const
Is lower triangular?
Definition: sparsity.cpp:321
casadi_int nnz() const
Get the number of (structural) non-zeros.
Definition: sparsity.cpp:148
The casadi namespace.
Definition: archiver.cpp:28
@ OT_INTVECTOR
@ OT_INTVECTORVECTOR
std::string str(const T &v)
String representation, any type.
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.
T * get_ptr(std::vector< T > &v)
Get a pointer to the data contained in the vector.
void flatten_opts(Dict &ret, const Dict &opts, const std::string &prefix)
void CASADI_NLPSOL_CCOPT_EXPORT casadi_load_nlpsol_ccopt()
int CASADI_NLPSOL_CCOPT_EXPORT casadi_register_nlpsol_ccopt(Nlpsol::Plugin *plugin)
UnifiedReturnStatus
Options metadata for a class.
Definition: options.hpp:40
const casadi_int * sp_h
OracleCallback nlp_grad_f
OracleCallback nlp_jac_g
OracleCallback nlp_g
OracleCallback nlp_hess_l
OracleCallback nlp_f
const casadi_int * sp_a
const casadi_nlpsol_prob< T1 > * nlp