From 38825e5fbe0e1716da8aeea5c1a430f7970a5317 Mon Sep 17 00:00:00 2001 From: Stefano Date: Tue, 12 Jun 2018 18:06:39 +0200 Subject: [PATCH] Fixed bug when the matrix to update has not changed. Somehow, when the scaling was set to zero, it was segfaulting. --- include/OsqpEigen/Solver.tpp | 20 ++++++++++++-------- tests/UpdateMatricesTest.cpp | 1 + 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/include/OsqpEigen/Solver.tpp b/include/OsqpEigen/Solver.tpp index 0a4fb66..94590a8 100644 --- a/include/OsqpEigen/Solver.tpp +++ b/include/OsqpEigen/Solver.tpp @@ -134,10 +134,12 @@ bool OsqpEigen::Solver::updateHessianMatrix(const Eigen::SparseMatrix &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{ @@ -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{ diff --git a/tests/UpdateMatricesTest.cpp b/tests/UpdateMatricesTest.cpp index b788672..e2b1ead 100644 --- a/tests/UpdateMatricesTest.cpp +++ b/tests/UpdateMatricesTest.cpp @@ -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));