26 #include "conic_impl.hpp"
27 #include "nlpsol_impl.hpp"
28 #include "filesystem_impl.hpp"
55 casadi_assert_dev(!f.
is_null());
62 for (
size_t i=0; i<ret.size(); ++i) ret[i]=
conic_in(i);
68 for (
size_t i=0; i<ret.size(); ++i) ret[i]=
conic_out(i);
112 const std::map<std::string, M>& qp,
const Dict& opts) {
122 bool postpone_expand =
false;
124 bool error_on_fail =
get_from_dict(opts,
"error_on_fail",
true);
126 if (expand && !postpone_expand && M::type_name()==
"MX") {
128 std::vector<SX> arg = f.
sx_in();
129 std::vector<SX> res = f(arg);
131 for (casadi_int i=0;i<f.
n_in();++i) qp_mod[f.
name_in(i)] = arg[i];
132 for (casadi_int i=0;i<f.
n_out();++i) qp_mod[f.
name_out(i)] = res[i];
133 return qpsol_nlp(name, solver, qp_mod, opt);
137 for (
auto&& i : qp) {
140 }
else if (i.first==
"p") {
142 }
else if (i.first==
"f") {
144 }
else if (i.first==
"g") {
146 }
else if (i.first==
"h") {
149 casadi_error(
"No such field: " + i.first);
153 if (f.is_empty()) f = 0;
154 if (g.is_empty()) g = M(0, 1);
157 casadi_assert(g.is_dense() && g.is_vector(),
158 "Expected a dense vector 'g', but got " + g.dim() +
".");
160 casadi_assert(f.is_dense() && f.is_scalar(),
161 "Expected a dense scalar 'f', but got " + f.dim() +
".");
163 casadi_assert(x.is_dense() && x.is_vector(),
164 "Expected a dense vector 'x', but got " + x.dim() +
".");
166 casadi_assert(h.is_square(),
167 "Expected a symmetric matrix 'h', but got " + h.dim() +
".");
169 if (g.is_empty(
true)) g = M(0, 1);
172 M gf = M::gradient(f, x);
175 M c = substitute(gf, x, M::zeros(x.sparsity()));
178 M H = M::jacobian(gf, x, {{
"symmetric",
true}});
181 Function r(
"constant_qp", {x, p}, {substitute(f, x, M::zeros(x.sparsity()))});
184 M b = substitute(g, x, M::zeros(x.sparsity()));
187 M A = M::jacobian(g, x);
190 M
P = substitute(h, x, M::zeros(x.sparsity()));
193 M
Q = M::jacobian(h, x);
196 Function prob(name +
"_qp", {x, p}, {H, c, A, b,
Q,
P},
197 {
"x",
"p"}, {
"H",
"c",
"A",
"b",
"Q",
"P"});
198 if (expand && postpone_expand) prob = prob.
expand();
201 casadi_assert(!prob.has_free(),
"Cannot create '" + prob.name() +
"' "
202 "since " +
str(prob.get_free()) +
" are free.");
206 {{
"h", H.sparsity()}, {
"a", A.sparsity()},
207 {
"p",
P.sparsity()}, {
"q",
Q.sparsity()}}, opt);
249 ret_out[
NLPSOL_G] = reshape(mtimes(v.at(2), w[
CONIC_X]), g.size()) + v.at(3);
256 fun_opts[
"error_on_fail"] = error_on_fail;
263 return qpsol_nlp(name, solver, qp, opts);
268 return qpsol_nlp(name, solver, qp, opts);
272 Conic::Conic(
const std::string& name,
const std::map<std::string, Sparsity> &st)
279 for (
auto i=st.begin(); i!=st.end(); ++i) {
282 }
else if (i->first==
"h") {
284 }
else if (i->first==
"q") {
286 }
else if (i->first==
"p") {
289 casadi_error(
"Unrecognized field in QP structure: " +
str(i->first));
295 "Cannot determine dimension");
305 "Got incompatible dimensions.\n"
306 "min x'Hx + G'x s.t. LBA <= Ax <= UBA :\n"
308 "We need: H.size2()==A.size2()");
312 "Got incompatible dimensions. min x'Hx + G'x\n"
314 "We need H square & symmetric");
325 "Got incompatible dimensions.\n"
327 "We need the product Qx to exist.");
328 np_ =
static_cast<casadi_int
>(sqrt(
static_cast<double>(
Q_.
size1())));
330 "Got incompatible dimensions.\n"
332 "We need Q.size1() to have an integer square root.");
337 "Got incompatible dimensions.");
344 "Got incompatible dimensions.\n"
346 "We need P square & symmetric.");
349 "Got incompatible dimensions.\n"
398 "Indicates which of the variables are discrete, i.e. integer-valued"}},
401 "Indicate an upfront hint which of the constraints are equalities. "
402 "Some solvers may be able to exploit this knowledge. "
403 "When true, the corresponding lower and upper bounds are assumed equal. "
404 "When false, the corresponding bounds may be equal or different."}},
407 "Print a numeric description of the problem"}},
408 {
"solver_version_check",
410 "When the plugin loads an externally supplied solver, "
411 "check that its version is compatible with the plugin [Default: true]"}},
414 "Minimum multiplier value for a constraint to be considered active "
415 "in parametric sensitivities [0]."}},
416 {
"sens_force_equality",
418 "Treat constraints with equal bounds as active in parametric sensitivities, "
419 "regardless of the multiplier, see issue #2545 [false]."}},
422 "Linear solver used for parametric sensitivities (default 'qr')."}},
423 {
"sens_linsol_options",
425 "Linear solver options used for parametric sensitivities."}}
440 for (
auto&& op : opts) {
441 if (op.first==
"discrete") {
443 }
else if (op.first==
"equality") {
445 }
else if (op.first==
"print_problem") {
447 }
else if (op.first==
"solver_version_check") {
449 }
else if (op.first==
"sens_min_lam") {
451 }
else if (op.first==
"sens_force_equality") {
453 }
else if (op.first==
"sens_linsol") {
455 }
else if (op.first==
"sens_linsol_options") {
464 casadi_assert(
discrete_.size()==
nx_,
"\"discrete\" option has wrong length");
467 "Discrete variables require a solver with integer support");
472 casadi_assert(
equality_.size()==
na_,
"\"equality\" option has wrong length. "
473 "Expected " +
str(
na_) +
" elements, but got " +
478 "Selected solver does not support psd constraints.");
499 casadi_int*& iw,
double*& w)
const {
529 const double* lba,
const double* uba)
const {
530 for (casadi_int i=0; i<
nx_; ++i) {
531 double lb = lbx ? lbx[i] : 0., ub = ubx ? ubx[i] : 0.;
532 casadi_assert(lb <= ub && lb!=
inf && ub!=-
inf,
533 "Ill-posed problem detected: "
534 "LBX[" +
str(i) +
"] <= UBX[" +
str(i) +
"] was violated. "
535 "Got LBX[" +
str(i) +
"]=" +
str(lb) +
" and UBX[" +
str(i) +
"] = " +
str(ub) +
".");
537 for (casadi_int i=0; i<
na_; ++i) {
538 double lb = lba ? lba[i] : 0., ub = uba ? uba[i] : 0.;
539 casadi_assert(lb <= ub && lb!=
inf && ub!=-
inf,
540 "Ill-posed problem detected: "
541 "LBA[" +
str(i) +
"] <= UBA[" +
str(i) +
"] was violated. "
542 "Got LBA[" +
str(i) +
"] = " +
str(lb) +
" and UBA[" +
str(i) +
"] = " +
str(ub) +
".");
547 casadi_error(
"generateNativeCode not defined for class " +
class_name());
552 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
553 std::mutex Conic::mutex_solvers_;
562 return -std::numeric_limits<double>::infinity();
565 return std::numeric_limits<double>::infinity();
572 eval(
const double** arg,
double** res, casadi_int* iw,
double* w,
void* mem)
const {
592 setup(mem, arg, res, iw, w);
594 int ret =
solve(arg, res, iw, w, mem);
599 casadi_error(
"conic process failed. "
600 "Set 'error_on_fail' option to false to ignore this error.");
621 const MX& lbx,
const MX& ubx,
const MX& lba,
const MX& uba,
622 double min_lam,
bool force_equality,
623 MX& lbIx,
MX& ubIx,
MX& lbIa,
MX& ubIa) {
624 ubIx = lam_x > min_lam;
625 lbIx = lam_x < -min_lam;
626 ubIa = lam_a > min_lam;
627 lbIa = lam_a < -min_lam;
628 if (force_equality) {
629 lbIx =
if_else(lbx==ubx, 1-ubIx, lbIx);
630 lbIa =
if_else(lba==uba, 1-ubIa, lbIa);
632 MX bIx = ubIx + lbIx, iIx = 1-bIx;
633 MX bIa = ubIa + lbIa, iIa = 1-bIa;
634 MX H_11 = mtimes(diag(iIx), H) + diag(bIx);
635 MX H_12 = mtimes(diag(iIx), A.
T());
636 MX H_21 = mtimes(diag(bIa), A);
637 MX H_22 = diag(-iIa);
645 MX cost = 0.5*bilin(h, x, x) +
dot(g, x);
646 MX r = mtimes(0.5*(h + h.
T()), x) + g + mtimes(a.T(), lam_a);
647 return Function(
"conic_kkt_res", {x, lam_a, h, g, a}, {cost, r, mtimes(a, x)});
651 get_forward(casadi_int nfwd,
const std::string& name,
652 const std::vector<std::string>& inames,
653 const std::vector<std::string>& onames,
654 const Dict& opts)
const {
655 casadi_assert(
np_==0,
"Derivatives not supported for psd constraints");
657 "Derivatives not supported for discrete variables");
664 std::string name = arg[i].is_symbolic() ? arg[i].name() :
"tmp_get_forward";
674 MX lbIx, ubIx, lbIa, ubIa;
677 lbIx, ubIx, lbIa, ubIa);
682 fseed[i] =
MX(repmat(
Sparsity(arg[i].size()), 1, nfwd));
685 fseed[i] =
MX::sym(
"fwd_" +
name_in_.at(i), repmat(arg[i].sparsity(), 1, nfwd));
691 std::vector<MX> nom = {x, lam_a, h, g, a, cost, -lam_x, mtimes(a, x)};
694 std::vector<MX> vv = nom;
695 vv.insert(vv.end(), {0, 0, fseed[CONIC_H], fseed[CONIC_G], fseed[CONIC_A]});
700 -
if_else(1-lbIx-ubIx, vv.at(1), 0);
702 -
if_else(lbIa+ubIa, vv.at(2), 0);
704 std::vector<MX> v_split = vertsplit(v, {0,
nx_,
nx_+
na_});
708 vv.insert(vv.end(), {v_split.at(0), v_split.at(1),
709 fseed[CONIC_H], fseed[CONIC_G], fseed[CONIC_A]});
714 fsens[
CONIC_X] = v_split.at(0);
720 arg.insert(arg.end(), res.begin(), res.end());
721 arg.insert(arg.end(), fseed.begin(), fseed.end());
724 options[
"allow_duplicate_io_names"] =
true;
726 return Function(name, arg, fsens, inames, onames, options);
730 get_reverse(casadi_int nadj,
const std::string& name,
731 const std::vector<std::string>& inames,
732 const std::vector<std::string>& onames,
733 const Dict& opts)
const {
734 casadi_assert(
np_==0,
"Derivatives not supported for psd constraints");
736 "Derivatives not supported for discrete variables");
743 std::string name = arg[i].is_symbolic() ? arg[i].name() :
"tmp_get_reverse";
753 MX lbIx, ubIx, lbIa, ubIa;
756 lbIx, ubIx, lbIa, ubIa);
761 aseed[i] =
MX::sym(
"adj_" +
name_out_.at(i), repmat(res[i].sparsity(), 1, nadj));
767 std::vector<MX> nom = {x, lam_a, h, g, a, cost, -lam_x, mtimes(a, x)};
770 std::vector<MX> vv = nom;
771 vv.insert(vv.end(), {aseed[CONIC_COST], -aseed[CONIC_LAM_X], 0});
773 std::vector<MX> adj0 = vv;
778 std::vector<MX> v_split = vertsplit(v, {0,
nx_,
nx_+
na_});
779 MX beta_x = v_split.at(0), beta_a = v_split.at(1);
783 vv.insert(vv.end(), {0, (1-lbIx-ubIx)*beta_x, (lbIa+ubIa)*beta_a});
789 asens[i] =
MX(repmat(
Sparsity(arg[i].size()), 1, nadj));
791 asens[
CONIC_H] = adj0.at(2) - vv.at(2);
792 asens[
CONIC_G] = adj0.at(3) - vv.at(3);
793 asens[
CONIC_A] = adj0.at(4) - vv.at(4);
800 arg.insert(arg.end(), res.begin(), res.end());
801 arg.insert(arg.end(), aseed.begin(), aseed.end());
804 options[
"allow_duplicate_io_names"] =
true;
806 return Function(name, arg, asens, inames, onames, options);
816 std::vector<casadi_int> p;
817 casadi_int nb = aggregate.
scc(p, mem.
r);
819 std::string pattern_message =
"Pattern not recognised";
821 casadi_assert(p==
range(p.size()), pattern_message);
823 const casadi_int* row = aggregate.
row();
824 const casadi_int* colind = aggregate.
colind();
827 for (casadi_int i=0;i<nb;++i) {
828 casadi_int block_size = mem.
r[i+1]-mem.
r[i];
830 casadi_int nz = colind[mem.
r[i+1]]-colind[mem.
r[i+1]-1];
832 casadi_assert(nz==block_size, pattern_message);
833 for (casadi_int k=0;k<block_size-1;++k) {
834 casadi_assert(colind[mem.
r[i]+k+1]-colind[mem.
r[i]+k], pattern_message);
835 casadi_assert(*(row++)==k+mem.
r[i], pattern_message);
836 casadi_assert(*(row++)==mem.
r[i]+block_size-1, pattern_message);
839 for (casadi_int k=0;k<block_size;++k)
840 casadi_assert(*(row++)==k+mem.
r[i], pattern_message);
879 std::vector<casadi_int> target_start(nb), target_stop(nb);
880 for (casadi_int i=0;i<nb;++i) {
881 target_start[i] = (mem.
r[i+1]-1)*aggregate.
size1()+mem.
r[i];
882 target_stop[i] = target_start[i]+mem.
r[i+1]-mem.
r[i];
886 std::vector<casadi_int> q_nz;
888 std::vector<casadi_int> q_row, q_col;
891 for (casadi_int j=0; j<
Q_.
size2(); ++j) {
892 casadi_int block_index = 0;
895 casadi_int i =
Q_.
row(k);
898 while (i>target_stop[block_index] && block_index<nb-1) block_index++;
900 if (i>=target_start[block_index] && i<target_stop[block_index]) {
903 q_row.push_back(mem.
r[block_index]+i-target_start[block_index]);
915 casadi_int max_nnz = 0;
916 for (casadi_int i=0;i<mem.
map_Q.
size2();++i) {
924 mem.
map_P.resize(mem.
r[nb], -1);
925 for (casadi_int i=0;i<nb;++i) {
927 casadi_int r =
P_.
row(k);
933 for (casadi_int i=0;i<nb;++i)
946 stats[
"iter_count"] = m->d_qp.iter_count;
951 s.
pack(
"Conic::SDPToSOCPMem::r", m.
r);
952 s.
pack(
"Conic::SDPToSOCPMem::AT", m.
AT);
954 s.
pack(
"Conic::SDPToSOCPMem::map_Q", m.
map_Q);
955 s.
pack(
"Conic::SDPToSOCPMem::map_P", m.
map_P);
959 s.
unpack(
"Conic::SDPToSOCPMem::r", m.
r);
960 s.
unpack(
"Conic::SDPToSOCPMem::AT", m.
AT);
999 int version = s.
version(
"Conic", 1, 6);
1037 void Conic::set_qp_prob() {
1040 casadi_qp_setup(&
p_qp_);
1045 g.
local(
"d_qp",
"struct casadi_qp_data");
1046 g.
local(
"p_qp",
"struct casadi_qp_prob");
1048 g <<
"d_qp.prob = &p_qp;\n";
1049 g <<
"p_qp.sp_a = " << g.
sparsity(
A_) <<
";\n";
1050 g <<
"p_qp.sp_h = " << g.
sparsity(
H_) <<
";\n";
1051 g <<
"casadi_qp_setup(&p_qp);\n";
1052 g <<
"casadi_qp_set_work(&d_qp, &arg, &res, &iw, &w);\n";
1055 g <<
"d_qp.h = arg[" <<
CONIC_H <<
"];\n";
1056 g <<
"d_qp.g = arg[" <<
CONIC_G <<
"];\n";
1057 g <<
"d_qp.a = arg[" <<
CONIC_A <<
"];\n";
1058 g <<
"d_qp.lbx = arg[" <<
CONIC_LBX <<
"];\n";
1059 g <<
"d_qp.ubx = arg[" <<
CONIC_UBX <<
"];\n";
1060 g <<
"d_qp.lba = arg[" <<
CONIC_LBA <<
"];\n";
1061 g <<
"d_qp.uba = arg[" <<
CONIC_UBA <<
"];\n";
1062 g <<
"d_qp.x0 = arg[" <<
CONIC_X0 <<
"];\n";
1066 g <<
"d_qp.f = res[" <<
CONIC_COST <<
"];\n";
1067 g <<
"d_qp.x = res[" <<
CONIC_X <<
"];\n";
1068 g <<
"d_qp.lam_x = res[" <<
CONIC_LAM_X <<
"];\n";
1069 g <<
"d_qp.lam_a = res[" <<
CONIC_LAM_A <<
"];\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.
std::string sparsity(const Sparsity &sp, bool canonical=true)
void add_auxiliary(Auxiliary f, const std::vector< std::string > &inst={"casadi_real"})
Add a built-in auxiliary function.
Dict sens_linsol_options_
static const Options options_
Options.
casadi_int nx_
Number of decision variables.
bool is_a(const std::string &type, bool recursive) const override
Check if the function is of a particular type.
void finalize() override
Finalize the object creation.
double get_default_in(casadi_int ind) const override
Get default input value.
virtual int solve(const double **arg, double **res, casadi_int *iw, double *w, void *mem) const =0
Solve the QP.
int init_mem(void *mem) const override
Initalize memory block.
casadi_int np_
The shape of psd constraint matrix.
Sparsity get_sparsity_in(casadi_int i) override
Sparsities of function inputs and outputs.
casadi_int na_
The number of constraints (counting both equality and inequality) == A.size1()
static std::map< std::string, Plugin > solvers_
Collection of solvers.
virtual void generateNativeCode(std::ostream &file) const
virtual void check_inputs(const double *lbx, const double *ubx, const double *lba, const double *uba) const
Check if the numerical values of the supplied bounds make sense.
Sparsity H_
Problem structure.
Function get_reverse(casadi_int nadj, const std::string &name, const std::vector< std::string > &inames, const std::vector< std::string > &onames, const Dict &opts) const override
Generate a function that calculates reverse mode derivatives.
void init(const Dict &opts) override
Initialize.
void deserialize(DeserializingStream &s, SDPToSOCPMem &m)
std::vector< bool > discrete_
Options.
std::vector< bool > equality_
Conic(const std::string &name, const std::map< std::string, Sparsity > &st)
Sparsity get_sparsity_out(casadi_int i) override
Sparsities of function inputs and outputs.
static MX sens_kkt(const MX &H, const MX &A, const MX &lam_x, const MX &lam_a, const MX &lbx, const MX &ubx, const MX &lba, const MX &uba, double min_lam, bool force_equality, MX &lbIx, MX &ubIx, MX &lbIa, MX &ubIa)
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.
virtual bool psd_support() const
Can psd constraints be treated.
bool sens_force_equality_
bool solver_version_check_
Dict get_stats(void *mem) const override
Get all statistics.
static const std::string infix_
Infix.
casadi_qp_prob< double > p_qp_
void serialize_type(SerializingStream &s) const override
Serialize type information.
void qp_codegen_body(CodeGenerator &g) const
Generate code for the function body.
Function get_forward(casadi_int nfwd, const std::string &name, const std::vector< std::string > &inames, const std::vector< std::string > &onames, const Dict &opts) const override
Generate a function that calculates forward mode derivatives.
void sdp_to_socp_init(SDPToSOCPMem &mem) const
SDP to SOCP conversion initialization.
virtual bool integer_support() const
Can discrete variables be treated.
int eval(const double **arg, double **res, casadi_int *iw, double *w, void *mem) const final
Solve the QP.
void serialize(SerializingStream &s, const SDPToSOCPMem &m) const
Helper class for Serialization.
void unpack(Sparsity &e)
Reconstruct an object from the input stream.
void version(const std::string &name, int v)
static std::unique_ptr< std::ostream > ofstream_ptr(const std::string &path, std::ios_base::openmode mode=std::ios_base::out)
Internal class for Function.
Dict get_stats(void *mem) const override
Get all statistics.
void init(const Dict &opts) override
Initialize.
void finalize() override
Finalize the object creation.
void serialize_body(SerializingStream &s) const override
Serialize an object without type information.
virtual const std::vector< MX > mx_in() const
Get function input(s) and output(s)
virtual bool is_a(const std::string &type, bool recursive) const
Check if the function is of a particular type.
bool inputs_check_
Errors are thrown if numerical values of inputs look bad.
static const Options options_
Options.
void serialize_type(SerializingStream &s) const override
Serialize type information.
virtual const std::vector< MX > mx_out() const
Get function input(s) and output(s)
void setup(void *mem, const double **arg, double **res, casadi_int *iw, double *w) const
Set the (persistent and temporary) work vectors.
static std::string string_from_UnifiedReturnStatus(UnifiedReturnStatus status)
std::vector< std::string > name_out_
std::vector< std::string > name_in_
Input and output scheme.
Function forward(casadi_int nfwd) const
Get a function computing nfwd forward directional derivatives.
FunctionInternal * get() const
Function expand() const
Convert an MXFunction into an equivalent SXFunction.
const std::vector< std::string > & name_in() const
Get the names of all inputs, in order.
Function reverse(casadi_int nadj) const
Get a function computing nadj reverse (adjoint) directional derivatives.
static Function create(FunctionInternal *node)
Create from node.
const SX sx_in(casadi_int iind) const
Create fresh symbols with the names and sparsity patterns of the inputs.
casadi_int n_out() const
Get the number of function outputs.
casadi_int n_in() const
Get the number of function inputs.
const std::vector< std::string > & name_out() const
Get the names of all outputs, in order.
casadi_int size2() const
Get the second dimension (i.e. number of columns)
static MX sym(const std::string &name, casadi_int nrow=1, casadi_int ncol=1)
Create an nrow-by-ncol symbolic primitive.
const casadi_int * colind() const
Get the sparsity pattern. See the Sparsity class for details.
bool is_null() const
Is a null pointer?
static MX blockcat(const std::vector< std::vector< MX > > &v)
MX T() const
Transpose the matrix.
static MX solve(const MX &a, const MX &b)
static MX nan(const Sparsity &sp)
Create a constant with all nonzeros NaN.
Matrix< Scalar > T() const
Transpose the matrix.
static Matrix< casadi_int > triplet(const std::vector< casadi_int > &row, const std::vector< casadi_int > &col, const Matrix< casadi_int > &d)
Construct a sparse matrix from triplet form (row indices, column indices, values)
void print_dense(std::ostream &stream, bool truncate=true) const
Print as a dense matrix, one row per line, structural zeros as 00.
static Matrix< casadi_int > eye(casadi_int n)
Create an n-by-n identity matrix.
static bool has_plugin(const std::string &pname, bool verbose=false)
Check if a plugin is available or can be loaded.
static Conic * instantiate(const std::string &fname, const std::string &pname, Problem problem)
void serialize_type(SerializingStream &s) const
Serialize type information.
static const Options & plugin_options(const std::string &pname)
Get the plugin options.
static Plugin & getPlugin(const std::string &pname)
Load and get the creator function.
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize with type disambiguation.
virtual void deps_version_check(const std::string &stage) const
static Plugin load_plugin(const std::string &pname, bool register_plugin=true, bool needs_lock=true)
Load a plugin dynamically.
Base class for FunctionInternal and LinsolInternal.
bool error_on_fail_
Throw an exception on failure?
virtual int init_mem(void *mem) const
Initalize 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.
virtual std::string class_name() const =0
Readable name of the internal class.
casadi_int size1() const
Number of rows.
casadi_int scc(std::vector< casadi_int > &index, std::vector< casadi_int > &offset) const
Strongly connected components of the directed graph of a square pattern.
std::string dim(bool with_nz=false) const
Dimensions as a string "nrow x ncol", optionally with the number of nonzeros.
static Sparsity dense(casadi_int nrow, casadi_int ncol=1)
Create a dense rectangular sparsity pattern.
Sparsity transpose(std::vector< casadi_int > &mapping, bool invert_mapping=false) const
Transposed pattern together with the reordering of the nonzeros.
casadi_int size2() const
Number of columns.
const casadi_int * row() const
Get a reference to row-vector,.
static Sparsity scalar(bool dense_scalar=true)
Create a 1-by-1 sparsity pattern.
const casadi_int * colind() const
Get a reference to the colindex of all column element (see class description)
bool is_symmetric() const
Check whether the pattern equals its transpose.
Function qpsol(const std::string &name, const std::string &solver, const SXDict &qp, const Dict &opts)
std::string conic_option_info(const std::string &name, const std::string &op)
Get the documentation string of an option of a QP solver plugin.
Function conic(const std::string &name, const std::string &solver, const SpDict &qp, const Dict &opts)
std::string conic_option_type(const std::string &name, const std::string &op)
Get the type of an option of a QP solver plugin.
bool has_conic(const std::string &name)
Check if a QP solver plugin is available.
std::string doc_conic(const std::string &name)
Get the documentation string of a QP solver plugin.
std::vector< std::string > conic_options(const std::string &name)
Get all options of a QP solver plugin.
std::vector< std::string > conic_out()
Get the output scheme of QP solvers.
casadi_int conic_n_in()
Get the number of QP solver inputs.
casadi_int conic_n_out()
Get the number of QP solver outputs.
void load_conic(const std::string &name)
Explicitly load a QP solver plugin.
std::vector< std::string > conic_in()
Get the input scheme of QP solvers.
void conic_debug(const Function &f, const std::string &filename)
Generate native code in the interfaced language for debugging.
std::vector< std::string > nlpsol_in()
Get the input scheme of NLP solvers.
std::vector< std::string > nlpsol_out()
Get the output scheme of NLP solvers.
double nlpsol_default_in(casadi_int ind)
Default value of an NLP solver input.
@ NLPSOL_P
Value of fixed parameters (np x 1), default 0.
@ NLPSOL_UBX
Decision variables upper bound (nx x 1), default +inf.
@ NLPSOL_X0
Decision variables, initial guess (nx x 1), default 0.
@ NLPSOL_LAM_G0
Lagrange multipliers for bounds on G, initial guess (ng x 1), default 0.
@ NLPSOL_UBG
Constraints upper bound (ng x 1), default +inf.
@ NLPSOL_LAM_X0
Lagrange multipliers for bounds on X, initial guess (nx x 1), default 0.
@ NLPSOL_LBG
Constraints lower bound (ng x 1), default -inf.
@ NLPSOL_LBX
Decision variables lower bound (nx x 1), default -inf.
std::map< std::string, MX > MXDict
std::vector< casadi_int > range(casadi_int start, casadi_int stop, casadi_int step, casadi_int len)
Range function.
@ NLPSOL_G
Constraints function at the optimal solution (ng x 1)
@ 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); same sign convention.
T get_from_dict(const std::map< std::string, T > &d, const std::string &key, const T &default_value)
@ NL_NUM_IN
Number of NLP inputs.
ConicInput
Input arguments of a QP problem.
@ CONIC_UBA
dense, (nc x 1), default +inf
@ CONIC_X0
dense, (n x 1), initial guess, default 0
@ 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_Q
The matrix Q: sparse symmetric, (np^2 x n)
@ CONIC_LBA
dense, (nc x 1), default -inf
@ CONIC_UBX
dense, (n x 1), default +inf
@ CONIC_LAM_A0
dense, (nc x 1), initial guess for the multipliers of the linear constraints, default 0
@ CONIC_LBX
dense, (n x 1), default -inf
@ CONIC_LAM_X0
dense, (n x 1), initial guess for the multipliers of the simple bounds, default 0
@ CONIC_P
The matrix P: sparse symmetric, (np x np)
double if_else(double x, double y, double z)
std::map< std::string, SX > SXDict
void extract_from_dict_inplace(Dict &d, const std::string &key, T &value)
std::string str(const T &v)
String representation, any type.
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.
std::map< std::string, Sparsity > SpDict
T dot(const std::vector< T > &a, const std::vector< T > &b)
static Function conic_kkt_res(const Sparsity &sp_h, const Sparsity &sp_a)
Function qpsol_nlp(const std::string &name, const std::string &solver, const std::map< std::string, M > &qp, const Dict &opts)
std::string filename(const std::string &path)
ConicOutput
Output arguments of an QP Solver.
@ CONIC_X
The primal solution.
@ CONIC_COST
The optimal cost.
@ CONIC_LAM_X
The dual solution corresponding to simple bounds; same sign convention.
casadi_qp_data< double > d_qp
SDP to SOCP conversion memory.
std::vector< casadi_int > r
std::vector< casadi_int > A_mapping
std::vector< casadi_int > map_P
Options metadata for a class.
std::string type(const std::string &name) const
std::vector< std::string > all() const
std::string info(const std::string &name) const
UnifiedReturnStatus unified_return_status