Skip to content

Commit

Permalink
Fixed bug when the matrix to update has not changed.
Browse files Browse the repository at this point in the history
Somehow, when the scaling was set to zero, it was segfaulting.
  • Loading branch information
S-Dafarra committed Jun 12, 2018
1 parent 8c19964 commit 38825e5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
20 changes: 12 additions & 8 deletions include/OsqpEigen/Solver.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,12 @@ bool OsqpEigen::Solver::updateHessianMatrix(const Eigen::SparseMatrix<T> &hessia

if(evaluateNewValues(m_oldHessianTriplet, m_newUpperTriangularHessianTriplets,
m_hessianNewIndices, m_hessianNewValues)){
if(osqp_update_P(m_workspace, m_hessianNewValues.data(), m_hessianNewIndices.data(), m_hessianNewIndices.size()) != 0){
std::cerr << "[OsqpEigen::Solver::updateHessianMatrix] Unable to update hessian matrix."
<< std::endl;
return false;
if (m_hessianNewValues.size() > 0) {
if(osqp_update_P(m_workspace, m_hessianNewValues.data(), m_hessianNewIndices.data(), m_hessianNewIndices.size()) != 0){
std::cerr << "[OsqpEigen::Solver::updateHessianMatrix] Unable to update hessian matrix."
<< std::endl;
return false;
}
}
}
else{
Expand Down Expand Up @@ -228,10 +230,12 @@ bool OsqpEigen::Solver::updateLinearConstraintsMatrix(const Eigen::SparseMatrix<

if(evaluateNewValues(m_oldLinearConstraintsTriplet, m_newLinearConstraintsTriplet,
m_constraintsNewIndices, m_constraintsNewValues)){
if(osqp_update_A(m_workspace, m_constraintsNewValues.data(), m_constraintsNewIndices.data(), m_constraintsNewIndices.size()) != 0){
std::cerr << "[OsqpEigen::Solver::updateLinearConstraintsMatrix] Unable to update linear constraints matrix."
<< std::endl;
return false;
if (m_constraintsNewValues.size() > 0) {
if(osqp_update_A(m_workspace, m_constraintsNewValues.data(), m_constraintsNewIndices.data(), m_constraintsNewIndices.size()) != 0){
std::cerr << "[OsqpEigen::Solver::updateLinearConstraintsMatrix] Unable to update linear constraints matrix."
<< std::endl;
return false;
}
}
}
else{
Expand Down
1 change: 1 addition & 0 deletions tests/UpdateMatricesTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ TEST(QPProblem, FirstRun)

solver.data()->setNumberOfVariables(2);
solver.data()->setNumberOfConstraints(3);
solver.settings()->setScaling(0);
ASSERT_TRUE(solver.data()->setHessianMatrix(H_s));
ASSERT_TRUE(solver.data()->setGradient(gradient));
ASSERT_TRUE(solver.data()->setLinearConstraintsMatrix(A_s));
Expand Down

0 comments on commit 38825e5

Please sign in to comment.