43 std::cout <<
"[SolverProxQP." <<
m_name <<
"] " <<
s << std::endl;
47 const bool resizeVar =
n !=
m_n;
48 const bool resizeEq = (resizeVar ||
neq !=
m_neq);
49 const bool resizeIn = (resizeVar ||
nin !=
m_nin);
81 if (resizeVar || resizeEq || resizeIn) {
97 const bool hessianRegularization) {
98 if (problemData.size() > 2) {
100 false,
"Solver not implemented for more than 2 hierarchical levels.");
104 unsigned int neq = 0,
nin = 0;
107 if (cl0.size() > 0) {
108 const unsigned int n = cl0[0].second->cols();
109 for (ConstraintLevel::const_iterator
it = cl0.begin();
it != cl0.end();
111 auto constr =
it->second;
112 assert(
n == constr->cols());
113 if (constr->isEquality())
114 neq += constr->rows();
116 nin += constr->rows();
121 unsigned int i_eq = 0, i_in = 0;
122 for (ConstraintLevel::const_iterator
it = cl0.begin();
it != cl0.end();
124 auto constr =
it->second;
125 if (constr->isEquality()) {
126 m_qpData.
CE.middleRows(i_eq, constr->rows()) = constr->matrix();
127 m_qpData.
ce0.segment(i_eq, constr->rows()) = constr->vector();
128 i_eq += constr->rows();
129 }
else if (constr->isInequality()) {
130 m_qpData.
CI.middleRows(i_in, constr->rows()) = constr->matrix();
131 m_qpData.
ci_lb.segment(i_in, constr->rows()) = constr->lowerBound();
132 m_qpData.
ci_ub.segment(i_in, constr->rows()) = constr->upperBound();
133 i_in += constr->rows();
134 }
else if (constr->isBound()) {
135 m_qpData.
CI.middleRows(i_in, constr->rows()).setIdentity();
136 m_qpData.
ci_lb.segment(i_in, constr->rows()) = constr->lowerBound();
137 m_qpData.
ci_ub.segment(i_in, constr->rows()) = constr->upperBound();
138 i_in += constr->rows();
148 if (problemData.size() > 1) {
153 for (ConstraintLevel::const_iterator
it = cl1.begin();
it != cl1.end();
155 const double&
w =
it->first;
156 auto constr =
it->second;
157 if (!constr->isEquality())
159 false,
"Inequalities in the cost function are not implemented yet");
163 w * constr->matrix().transpose() * constr->matrix();
167 w * constr->matrix().transpose() * constr->vector();
170 if (hessianRegularization) {
194 QPSolverOutput status =
m_solver.results.info.status;
196 if (status == QPSolverOutput::PROXQP_SOLVED) {
208 if (cl0.size() > 0) {
209 for (ConstraintLevel::const_iterator
it = cl0.begin();
it != cl0.end();
211 auto constr =
it->second;
212 if (constr->checkConstraint(
x) ==
false) {
213 if (constr->isEquality()) {
214 sendMsg(
"Equality " + constr->name() +
" violated: " +
215 toString((constr->matrix() *
x - constr->vector()).norm()));
216 }
else if (constr->isInequality()) {
218 "Inequality " + constr->name() +
" violated: " +
220 (constr->matrix() *
x - constr->lowerBound()).minCoeff()) +
223 (constr->upperBound() - constr->matrix() *
x).minCoeff()));
224 }
else if (constr->isBound()) {
225 sendMsg(
"Bound " + constr->name() +
" violated: " +
226 toString((
x - constr->lowerBound()).minCoeff()) +
"\n" +
227 toString((constr->upperBound() -
x).minCoeff()));
233 }
else if (status == QPSolverOutput::PROXQP_PRIMAL_INFEASIBLE)
235 else if (status == QPSolverOutput::PROXQP_MAX_ITER_REACHED)
237 else if (status == QPSolverOutput::PROXQP_DUAL_INFEASIBLE)
244 return m_solver.results.info.objValue;
249 m_solver.settings.max_iter = maxIter;