26 #ifndef CASADI_NLP_TOOLS_HPP
27 #define CASADI_NLP_TOOLS_HPP
29 #include "casadi/core/function.hpp"
52 const SX& g,
const SX& lbg,
const SX& ubg,
53 std::vector<casadi_int>& SWIG_OUTPUT(gi),
54 SX& SWIG_OUTPUT(lbx),
SX& SWIG_OUTPUT(ubx),
56 Function& SWIG_OUTPUT(lam_backward));
58 const MX& g,
const MX& lbg,
const MX& ubg,
59 std::vector<casadi_int>& SWIG_OUTPUT(gi),
60 MX& SWIG_OUTPUT(lbx),
MX& SWIG_OUTPUT(ubx),
62 Function& SWIG_OUTPUT(lam_backward));
79 void check_sos(casadi_int nx,
const std::vector< std::vector<T> >& groups,
80 std::vector< std::vector<double> >& weights,
81 std::vector< casadi_int >& types) {
84 casadi_assert(weights.empty(),
"Missing sos_groups.");
85 casadi_assert(types.empty(),
"Missing sos_groups.");
89 casadi_int sos_num = groups.size();
91 casadi_assert(weights.empty() || weights.size()==sos_num,
92 "sos_weights has incorrect size");
95 if (!groups.empty() && types.empty())
96 types.resize(sos_num, 1);
99 if (weights.empty()) {
100 for (
const auto& e : groups) {
101 std::vector<double> w(e.size());
102 for (casadi_int i=0;i<w.size();++i) w[i] = i;
103 weights.push_back(w);
107 casadi_assert(types.size()==sos_num,
108 "sos_types has incorrect size");
111 for (casadi_int i=0;i<weights.size();++i) {
112 casadi_assert(weights[i].size()==groups[i].size(),
113 "Dimension mismatch in weights for group " + str(i) +
": "
114 "Expected " + str(groups[i].size()) +
", got " + str(weights[i].size()));
118 for (casadi_int t : types) casadi_assert(t==1 || t==2,
"SOS type must be either 1 or 2.");
119 for (
const auto& v : groups) casadi_assert(
in_range(v, 0, nx),
"Index out of bound");
Sparse matrix class. SX and DM are specializations.
void check_sos(casadi_int nx, const std::vector< std::vector< T > > &groups, std::vector< std::vector< double > > &weights, std::vector< casadi_int > &types)
Check sos structure and generate defaults.
CASADI_EXPORT void detect_simple_bounds(const SX &xX, const SX &p, const SX &g, const SX &lbg, const SX &ubg, std::vector< casadi_int > &gi, SX &lbx, SX &ubx, Function &lam_forward, Function &lam_backward)
Detect simple bounds from general constraints.
bool in_range(const std::vector< T > &v, casadi_int upper)
Check if for each element of v holds: v_i < upper.