25 #include "daqp_interface.hpp"
26 #include "casadi/core/nlp_tools.hpp"
28 #include <daqp_runtime_str.h>
32 int CASADI_CONIC_DAQP_EXPORT
35 plugin->name =
"daqp";
37 plugin->version = CASADI_VERSION;
50 const std::map<std::string, Sparsity>& st)
58 "Options to be passed to Daqp."
68 for (
auto&& op : opts) {
69 if (op.first==
"daqp") {
89 g <<
"p.qp = &p_qp;\n";
90 g <<
"daqp_default_settings(&p.settings);\n";
91 for (
auto&& op :
opts_) {
92 if (op.first==
"primal_tol") {
93 g <<
"p.settings.primal_tol = " << op.second.to_double() <<
";\n";
94 }
else if (op.first==
"dual_tol") {
95 g <<
"p.settings.dual_tol = " << op.second.to_double() <<
";\n";
96 }
else if (op.first==
"zero_tol") {
97 g <<
"p.settings.zero_tol = " << op.second.to_double() <<
";\n";
98 }
else if (op.first==
"pivot_tol") {
99 g <<
"p.settings.pivot_tol = " << op.second.to_double() <<
";\n";
100 }
else if (op.first==
"progress_tol") {
101 g <<
"p.settings.progress_tol = " << op.second.to_double() <<
";\n";
102 }
else if (op.first==
"cycle_tol") {
103 g <<
"p.settings.cycle_tol = " << op.second.to_int() <<
";\n";
104 }
else if (op.first==
"iter_limit") {
105 g <<
"p.settings.iter_limit = " << op.second.to_int() <<
";\n";
106 }
else if (op.first==
"fval_bound") {
107 g <<
"p.settings.fval_bound = " << op.second.to_double() <<
";\n";
108 }
else if (op.first==
"eps_prox") {
109 g <<
"p.settings.eps_prox = " << op.second.to_double() <<
";\n";
110 }
else if (op.first==
"eta_prox") {
111 g <<
"p.settings.eta_prox = " << op.second.to_double() <<
";\n";
112 }
else if (op.first==
"rho_soft") {
113 g <<
"p.settings.rho_soft = " << op.second.to_double() <<
";\n";
114 }
else if (op.first==
"rel_subopt") {
115 g <<
"p.settings.rel_subopt = " << op.second.to_double() <<
";\n";
116 }
else if (op.first==
"abs_subopt") {
117 g <<
"p.settings.abs_subopt = " << op.second.to_double() <<
";\n";
119 casadi_error(
"Unknown option '" + op.first +
"'.");
123 g <<
"casadi_daqp_setup(&p);\n";
138 DAQPSettings* settings = &p_.
settings;
140 daqp_default_settings(settings);
142 for (
auto&& op :
opts_) {
143 if (op.first==
"primal_tol") {
144 settings->primal_tol = op.second.to_double();
145 }
else if (op.first==
"dual_tol") {
146 settings->dual_tol = op.second.to_double();
147 }
else if (op.first==
"zero_tol") {
148 settings->zero_tol = op.second.to_double();
149 }
else if (op.first==
"pivot_tol") {
150 settings->pivot_tol = op.second.to_double();
151 }
else if (op.first==
"progress_tol") {
152 settings->progress_tol = op.second.to_double();
153 }
else if (op.first==
"cycle_tol") {
154 settings->cycle_tol = op.second.to_int();
155 }
else if (op.first==
"iter_limit") {
156 settings->iter_limit = op.second.to_int();
157 }
else if (op.first==
"fval_bound") {
158 settings->fval_bound = op.second.to_double();
159 }
else if (op.first==
"eps_prox") {
160 settings->eps_prox = op.second.to_double();
161 }
else if (op.first==
"eta_prox") {
162 settings->eta_prox = op.second.to_double();
163 }
else if (op.first==
"rho_soft") {
164 settings->rho_soft = op.second.to_double();
165 }
else if (op.first==
"rel_subopt") {
166 settings->rel_subopt = op.second.to_double();
167 }
else if (op.first==
"abs_subopt") {
168 settings->abs_subopt = op.second.to_double();
170 casadi_error(
"Unknown option '" + op.first +
"'.");
174 casadi_daqp_setup(&p_);
181 daqp_init_mem(&m->d);
183 m->add_stat(
"preprocessing");
184 m->add_stat(
"solver");
185 m->add_stat(
"postprocessing");
192 daqp_free_mem(&m->d);
198 casadi_int*& iw,
double*& w)
const {
207 casadi_daqp_init(&m->d, &arg, &res, &iw, &w);
212 solve(
const double** arg,
double** res, casadi_int* iw,
double* w,
void* mem)
const {
216 m->
fstats.at(
"solver").tic();
218 casadi_daqp_solve(&m->d, arg, res, iw, w);
219 m->fstats.at(
"solver").toc();
237 g.
local(
"d",
"struct casadi_daqp_data*");
239 g.
local(
"p",
"struct casadi_daqp_prob");
243 g <<
"d->prob = &p;\n";
244 g <<
"d->qp = &d_qp;\n";
245 g <<
"casadi_daqp_init(d, &arg, &res, &iw, &w);\n";
247 g <<
"casadi_daqp_solve(d, arg, res, iw, w);\n";
249 g <<
"if (!d_qp.success) {\n";
251 g <<
"return -1000;\n";
Helper class for C code generation.
void local(const std::string &name, const std::string &type, const std::string &ref="")
Declare a local variable.
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::stringstream auxiliaries
void add_auxiliary(Auxiliary f, const std::vector< std::string > &inst={"casadi_real"})
Add a built-in auxiliary function.
static const Options options_
Options.
int init_mem(void *mem) const override
Initalize memory block.
void init(const Dict &opts) override
Initialize.
void serialize_body(SerializingStream &s) const override
Serialize an object without type information.
void set_work(void *mem, const double **&arg, double **&res, casadi_int *&iw, double *&w) const override
Set the (persistent) work vectors.
Dict get_stats(void *mem) const override
Get all statistics.
casadi_qp_prob< double > p_qp_
void qp_codegen_body(CodeGenerator &g) const
Generate code for the function body.
static Conic * creator(const std::string &name, const std::map< std::string, Sparsity > &st)
Create a new QP Solver.
void codegen_body(CodeGenerator &g) const override
Generate code for the function body.
void init(const Dict &opts) override
Initialize.
Dict get_stats(void *mem) const override
Get all statistics.
void codegen_init_mem(CodeGenerator &g) const override
Codegen decref for init_mem.
Dict opts_
All Daqp options.
void serialize_body(SerializingStream &s) const override
Serialize an object without type information.
void set_work(void *mem, const double **&arg, double **&res, casadi_int *&iw, double *&w) const override
Set the (persistent) work vectors.
static const Options options_
Options.
~DaqpInterface() override
Destructor.
static const std::string meta_doc
A documentation string.
void codegen_free_mem(CodeGenerator &g) const override
Codegen for free_mem.
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize with type disambiguation.
void free_mem(void *mem) const override
Free memory block.
int solve(const double **arg, double **res, casadi_int *iw, double *w, void *mem) const override
Solve the QP.
DaqpInterface(const std::string &name, const std::map< std::string, Sparsity > &st)
Constructor using sparsity patterns.
int init_mem(void *mem) const override
Initalize memory block.
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.
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?
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.
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.
void CASADI_CONIC_DAQP_EXPORT casadi_load_conic_daqp()
int CASADI_CONIC_DAQP_EXPORT casadi_register_conic_daqp(Conic::Plugin *plugin)
casadi_daqp_data< double > d
Options metadata for a class.
std::map< std::string, FStats > fstats
const casadi_qp_prob< T1 > * qp