26 #include "qp_to_nlp.hpp"
27 #include "casadi/core/nlpsol.hpp"
28 #include "casadi/core/nlpsol_impl.hpp"
33 int CASADI_CONIC_NLPSOL_EXPORT
36 plugin->name =
"nlpsol";
38 plugin->version = CASADI_VERSION;
78 "Options to be passed to solver."}}
87 std::string nlpsol_plugin;
91 for (
auto&& op : opts) {
92 if (op.first==
"nlpsol") {
93 nlpsol_plugin = op.second.to_string();
94 }
else if (op.first==
"nlpsol_options") {
114 SXDict nlp = {{
"x",
X}, {
"p", vertcat(par)},
115 {
"f", densify(mtimes(G.
T(),
X) + 0.5*mtimes(mtimes(
X.T(), H),
X))},
116 {
"g", densify(mtimes(A,
X))}};
119 casadi_assert(!nlpsol_plugin.empty(),
"'nlpsol' option has not been set");
128 solve(
const double** arg,
double** res, casadi_int* iw,
double* w,
void* mem)
const {
130 const double *h_, *g_, *a_, *lba_, *uba_, *lbx_, *ubx_, *x0_;
132 double *x_, *f_, *lam_a_, *lam_x_;
151 const double** arg1 = arg +
n_in_;
152 double** res1 = res +
n_out_;
153 std::fill_n(arg1,
static_cast<casadi_int
>(
NLPSOL_NUM_IN),
nullptr);
154 std::fill_n(res1,
static_cast<casadi_int
>(
NLPSOL_NUM_OUT),
nullptr);
169 std::copy_n(h_, nh, w);
171 std::fill_n(w, nh, 0);
178 std::copy_n(g_, ng, w);
180 std::fill_n(w, ng, 0);
187 std::copy_n(a_, na, w);
189 std::fill_n(w, na, 0);
201 int ret =
solver_(arg1, res1, iw, w, m->nlp_mem);
204 m->d_qp.
success = nlp_m->success;
205 m->d_qp.unified_return_status = nlp_m->unified_return_status;
static const Options options_
Options.
casadi_int nx_
Number of decision variables.
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)
Dict get_stats(void *mem) const override
Get all statistics.
size_t n_in_
Number of inputs and outputs.
casadi_int nnz_in() const
Number of input/output nonzeros.
void alloc_w(size_t sz_w, bool persistent=false)
Ensure required length of w field.
void alloc(const Function &f, bool persistent=false, int num_threads=1)
Ensure work vectors long enough to evaluate function.
void release(int mem) const
Release a memory object.
casadi_int checkout() const
Checkout a memory object.
void * memory(int ind) const
Get memory object.
casadi_int nnz_in() const
Get number of input nonzeros.
static Matrix< Scalar > sym(const std::string &name, casadi_int nrow=1, casadi_int ncol=1)
Create an nrow-by-ncol symbolic primitive.
Sparse matrix class. SX and DM are specializations.
std::vector< Scalar > & nonzeros()
Matrix< Scalar > T() const
Transpose the matrix.
static void registerPlugin(const Plugin &plugin, bool needs_lock=true)
Register an integrator in the factory.
void clear_mem()
Clear all memory (called from destructor)
void * alloc_mem() const override
Create memory block.
QpToNlp(const std::string &name, const std::map< std::string, Sparsity > &st)
Create a new Solver.
static Conic * creator(const std::string &name, const std::map< std::string, Sparsity > &st)
Create a new QP Solver.
Function solver_
Solve with.
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize with type disambiguation.
static const Options options_
Options.
~QpToNlp() override
Destructor.
int solve(const double **arg, double **res, casadi_int *iw, double *w, void *mem) const override
Solve the QP.
void serialize_body(SerializingStream &s) const override
Serialize an object without type information.
void init(const Dict &opts) override
Initialize.
Dict get_stats(void *mem) const override
Get all statistics.
static const std::string meta_doc
A documentation string.
void free_mem(void *mem) const override
Free memory block.
Helper class for Serialization.
void version(const std::string &name, int v)
void pack(const Sparsity &e)
Serializes an object to the output stream.
std::vector< std::string > nlpsol_options(const std::string &name)
Get all options for a plugin.
Function nlpsol(const std::string &name, const std::string &solver, const SXDict &nlp, const Dict &opts)
@ NLPSOL_P
Value of fixed parameters (np x 1)
@ NLPSOL_UBX
Decision variables upper bound (nx x 1), default +inf.
@ NLPSOL_X0
Decision variables, initial guess (nx x 1)
@ NLPSOL_UBG
Constraints upper bound (ng x 1), default +inf.
@ NLPSOL_LBG
Constraints lower bound (ng x 1), default -inf.
@ NLPSOL_LBX
Decision variables lower bound (nx x 1), default -inf.
@ NLPSOL_X
Decision variables at the optimal solution (nx x 1)
@ NLPSOL_F
Cost function value at the optimal solution (1 x 1)
@ NLPSOL_LAM_G
Lagrange multipliers for bounds on G at the solution (ng x 1)
@ NLPSOL_LAM_X
Lagrange multipliers for bounds on X at the solution (nx x 1)
@ 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)
std::map< std::string, SX > SXDict
void CASADI_CONIC_NLPSOL_EXPORT casadi_load_conic_nlpsol()
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.
int CASADI_CONIC_NLPSOL_EXPORT casadi_register_conic_nlpsol(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.
Options metadata for a class.