27 #include "casadi/core/nlpsol.hpp"
32 int CASADI_CONIC_IPQP_EXPORT
35 plugin->name =
"ipqp";
37 plugin->version = CASADI_VERSION;
48 void print_vec(
const std::string&
str,
const double* v, casadi_int n) {
50 for (casadi_int k = 0; k < n; ++k)
uout() <<
" " << v[k];
54 Ipqp::Ipqp(
const std::string& name,
const std::map<std::string, Sparsity> &st)
66 "Maximum number of iterations [1000]."}},
69 "Constraint violation tolerance [1e-8]."}},
72 "Dual feasibility violation tolerance [1e-8]"}},
75 "Print header [true]."}},
78 "Print iterations [true]."}},
81 "Print info [true]."}},
84 "A custom linear solver creator function [default: ldl]"}},
85 {
"linear_solver_options",
87 "Options to be passed to the linear solver"}},
90 "Smallest multiplier treated as inactive for the initial active set [0]."}}
107 for (
auto&& op : opts) {
108 if (op.first==
"max_iter") {
110 }
else if (op.first==
"pr_tol") {
112 }
else if (op.first==
"du_tol") {
114 }
else if (op.first==
"co_tol") {
116 }
else if (op.first==
"mu_tol") {
118 }
else if (op.first==
"print_iter") {
120 }
else if (op.first==
"print_header") {
122 }
else if (op.first==
"print_info") {
124 }
else if (op.first==
"linear_solver") {
126 }
else if (op.first==
"linear_solver_options") {
140 print(
"-------------------------------------------\n");
141 print(
"This is casadi::Ipqp\n");
143 print(
"Number of variables: %12d\n",
nx_);
144 print(
"Number of constraints: %12d\n",
na_);
145 print(
"Number of nonzeros in H: %12d\n",
H_.
nnz());
146 print(
"Number of nonzeros in A: %12d\n",
A_.
nnz());
151 void Ipqp::set_qp_prob() {
163 solve(
const double** arg,
double** res, casadi_int* iw,
double* w,
void* mem)
const {
168 double* nz_kkt = w; w +=
kkt_.
nnz();
174 casadi_ipqp_init(&d, &iw, &w);
175 casadi_ipqp_bounds(&d, arg[
CONIC_G],
179 while (casadi_ipqp(&d)) {
190 if (d.
iter % 10 == 0) {
192 if (casadi_ipqp_print_header(&d, buf,
sizeof(buf)))
break;
193 uout() << buf <<
"\n";
196 if (casadi_ipqp_print_iteration(&d, buf,
sizeof(buf)))
break;
197 uout() << buf <<
"\n";
208 d.
status = IPQP_FACTOR_ERROR;
213 d.
status = IPQP_SOLVE_ERROR;
220 m->return_status = casadi_ipqp_return_status(d.
status);
221 if (d.
status == IPQP_MAX_ITER)
230 if (
verbose_) casadi_warning(m->return_status);
231 m->d_qp.success = d.
status == IPQP_SUCCESS;
static const Options options_
Options.
casadi_int nx_
Number of decision variables.
int init_mem(void *mem) const override
Initalize memory block.
casadi_int na_
The number of constraints (counting both equality and inequality) == A.size1()
Sparsity H_
Problem structure.
void init(const Dict &opts) override
Initialize.
void serialize_body(SerializingStream &s) const override
Serialize an object without type information.
Dict get_stats(void *mem) const override
Get all statistics.
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_w(size_t sz_w, bool persistent=false)
Ensure required length of w field.
static void check()
Raises an error if an interrupt was captured.
Dict get_stats(void *mem) const override
Get all statistics.
void init(const Dict &opts) override
Initialize.
int init_mem(void *mem) const override
Initalize memory block.
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize with type disambiguation.
int solve(const double **arg, double **res, casadi_int *iw, double *w, void *mem) const override
Solve the QP.
~Ipqp() override
Destructor.
Ipqp(const std::string &name, const std::map< std::string, Sparsity > &st)
Create a new Solver.
static const Options options_
Options.
std::string linear_solver_
casadi_ipqp_prob< double > p_
Dict linear_solver_options_
void serialize_body(SerializingStream &s) const override
Serialize an object without type information.
static const std::string meta_doc
A documentation string.
static Conic * creator(const std::string &name, const std::map< std::string, Sparsity > &st)
Create a new QP Solver.
casadi_int checkout() const
Checkout a memory object.
void nfact(const DM &A) const
Numeric factorization of the linear system.
DM solve(const DM &A, const DM &B, bool tr=false) const
void release(int mem) const
Release a memory object.
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.
casadi_int nnz() const
Get the number of (structural) non-zeros.
casadi_int size2() const
Get the number of columns.
static Sparsity kkt(const Sparsity &H, const Sparsity &J, bool with_x_diag=true, bool with_lam_g_diag=true)
Get KKT system sparsity.
@ 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)
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_CONIC_IPQP_EXPORT casadi_load_conic_ipqp()
void print_vec(const std::string &str, const double *v, casadi_int n)
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.
int CASADI_CONIC_IPQP_EXPORT casadi_register_conic_ipqp(Conic::Plugin *plugin)
@ 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.
const char * return_status
Options metadata for a class.
const casadi_ipqp_prob< T1 > * prob
casadi_ipqp_flag_t status