Skip to content

Commit

Permalink
Fix numerical issue in SplineGradientBased
Browse files Browse the repository at this point in the history
  • Loading branch information
jmirabel committed Dec 4, 2023
1 parent 503e1b5 commit 91311af
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion include/hpp/core/path-optimization/quadratic-program.hh
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ struct QuadraticProgram {
/// \param ce equality constraints
/// \param ci inequality constraints: \f$ ci.J * x \ge ci.b \f$
/// \note \ref computeLLT must have been called before.
double solve(const LinearConstraint& ce, const LinearConstraint& ci);
double solve(const LinearConstraint& ce, const LinearConstraint& ci, bool& ok);

/// \}

Expand Down
7 changes: 6 additions & 1 deletion src/path-optimization/quadratic-program.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ void QuadraticProgram::computeLLT() {
}

double QuadraticProgram::solve(const LinearConstraint& ce,
const LinearConstraint& ci) {
const LinearConstraint& ci,
bool& ok) {
if (ce.J.rows() > ce.J.cols())
throw std::runtime_error(
"The QP is over-constrained. QuadProg cannot handle it.");
Expand All @@ -79,10 +80,14 @@ double QuadraticProgram::solve(const LinearConstraint& ce,
switch (status) {
case Eigen::UNBOUNDED:
hppDout(warning, "Quadratic problem is not bounded");
ok = false;
break;
case Eigen::CONVERGED:
ok = true;
break;
case Eigen::CONSTRAINT_LINEARLY_DEPENDENT:
hppDout(error, "Constraint of quadratic problem are linearly dependent.");
ok = false;
break;
}
return cost;
Expand Down
19 changes: 16 additions & 3 deletions src/path-optimization/spline-gradient-based.cc
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,10 @@ PathVectorPtr_t SplineGradientBased<_PB, _SO>::optimize(
// There are no variables left for optimization.
return this->buildPathVector(splines);
QPc.computeLLT();
QPc.solve(collisionReduced, boundConstraintReduced);
bool qpSolved;
QPc.solve(collisionReduced, boundConstraintReduced, qpSolved);
if (!qpSolved)
return this->buildPathVector(splines);

while (!(noCollision && minimumReached) && !this->shouldStop()) {
// 6.1
Expand Down Expand Up @@ -533,7 +536,10 @@ PathVectorPtr_t SplineGradientBased<_PB, _SO>::optimize(
if (linearizeAtEachStep) {
collisionFunctions.linearize(splines, solvers, collision);
constraint.reduceConstraint(collision, collisionReduced);
QPc.solve(collisionReduced, boundConstraintReduced);
QPc.solve(collisionReduced, boundConstraintReduced, qpSolved);
if (!qpSolved) {
hppDout(error, "could not solve qp problem");
}
hppDout(info, "linearized");
computeOptimum = true;
}
Expand Down Expand Up @@ -567,6 +573,13 @@ PathVectorPtr_t SplineGradientBased<_PB, _SO>::optimize(
collisionFunctions.functions.size() - 1,
splines[reports[i].second], solvers[reports[i].second]);
if (!ok) break;
QPc.solve(collisionReduced, boundConstraintReduced, ok);
if (!ok) {
hppDout(info, "could not solve QP. Removing constraint");
collisionFunctions.removeLastConstraint(1, collision);
constraint.reduceConstraint(collision, collisionReduced);
break;
}
if (QPc.H.rows() <= collisionReduced.rank) break;
}

Expand All @@ -583,7 +596,7 @@ PathVectorPtr_t SplineGradientBased<_PB, _SO>::optimize(

computeInterpolatedSpline = true;
} else {
QPc.solve(collisionReduced, boundConstraintReduced);
QPc.solve(collisionReduced, boundConstraintReduced, qpSolved);
hppDout(info, "Added " << reports.size()
<< " constraints. "
"Constraints size "
Expand Down

0 comments on commit 91311af

Please sign in to comment.