Skip to content

Commit

Permalink
Merge pull request #35 from robotology/devel
Browse files Browse the repository at this point in the history
Merge Devel into Master
  • Loading branch information
GiulioRomualdi authored Sep 23, 2019
2 parents dec7b7d + aaa6a55 commit c006659
Show file tree
Hide file tree
Showing 16 changed files with 669 additions and 124 deletions.
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED 11)

project(OsqpEigen
LANGUAGES CXX
VERSION 0.3.1)
VERSION 0.4.1)

# add GNU dirs
include(GNUInstallDirs)
Expand Down Expand Up @@ -69,7 +69,7 @@ set(${LIBRARY_TARGET_NAME}_SRC
src/Solver.cpp)

set(${LIBRARY_TARGET_NAME}_HDR
include/OsqpEigen.h
include/OsqpEigen/OsqpEigen.h
include/OsqpEigen/Constants.hpp
include/OsqpEigen/SparseMatrixHelper.hpp
include/OsqpEigen/SparseMatrixHelper.tpp
Expand All @@ -85,6 +85,8 @@ target_include_directories(${LIBRARY_TARGET_NAME} PUBLIC "$<BUILD_INTERFACE:${CM

target_link_libraries(${LIBRARY_TARGET_NAME} PRIVATE osqp::osqp Eigen3::Eigen)

add_library(OsqpEigen::OsqpEigen ALIAS OsqpEigen)

set_target_properties(${LIBRARY_TARGET_NAME} PROPERTIES
VERSION ${PROJECT_VERSION}
PUBLIC_HEADER "${${LIBRARY_TARGET_NAME}_HDR}")
Expand Down
62 changes: 62 additions & 0 deletions include/OsqpEigen/Data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,40 +83,102 @@ namespace OsqpEigen
* @return true/false in case of success/failure.
*/
template<typename T>
[[deprecated("Use setHessianMatrix(const Eigen::SparseCompressedBase<Derived> &hessianMatrix) instead")]]
bool setHessianMatrix(const Eigen::SparseMatrix<T> &hessianMatrix);

/**
* Set the quadratic part of the cost function (Hessian).
* It is assumed to be a simmetric matrix.
* @param hessianMatrix is the Hessian matrix.
* @return true/false in case of success/failure.
*/
template<typename Derived>
bool setHessianMatrix(const Eigen::SparseCompressedBase<Derived> &hessianMatrix);


/**
* Set the linear part of the cost function (Gradient).
* @param gradientVector is the Gradient vector.
* @note the elements of the gradient are not copied inside the library.
* The user has to guarantee that the lifetime of the object passed is the same of the
* OsqpEigen object
* @return true/false in case of success/failure.
*/
template<int n>
[[deprecated("Use setGradient(Eigen::Ref<Eigen::Matrix<c_float, Eigen::Dynamic, 1>> gradientVector) instead")]]
bool setGradient(Eigen::Matrix<c_float, n, 1> &gradientVector);

/**
* Set the linear part of the cost function (Gradient).
* @param gradientVector is the Gradient vector.
* @note the elements of the gradient are not copied inside the library.
* The user has to guarantee that the lifetime of the object passed is the same of the
* OsqpEigen object
* @return true/false in case of success/failure.
*/
bool setGradient(Eigen::Ref<Eigen::Matrix<c_float, Eigen::Dynamic, 1>> gradientVector);

/**
* Set the linear constraint matrix A (size m x n)
* @param linearConstraintsMatrix is the linear constraints matrix A.
* @return true/false in case of success/failure.
*/
template<typename T>
[[deprecated("Use setLinearConstraintsMatrix(const Eigen::SparseCompressedBase<Derived> &linearConstraintsMatrix) instead")]]
bool setLinearConstraintsMatrix(const Eigen::SparseMatrix<T> &linearConstraintsMatrix);

/**
* Set the linear constraint matrix A (size m x n)
* @param linearConstraintsMatrix is the linear constraints matrix A.
* @return true/false in case of success/failure.
*/
template<typename Derived>
bool setLinearConstraintsMatrix(const Eigen::SparseCompressedBase<Derived> &linearConstraintsMatrix);

/**
* Set the array for lower bound (size m).
* @param lowerBoundVector is the lower bound constraint.
* @note the elements of the lowerBoundVector are not copied inside the library.
* The user has to guarantee that the lifetime of the object passed is the same of the
* OsqpEigen object
* @return true/false in case of success/failure.
*/
template<int m>
[[deprecated("Use setLowerBound(Eigen::Ref<Eigen::Matrix<c_float, Eigen::Dynamic, 1>> lowerBoundVector) instead")]]
bool setLowerBound(Eigen::Matrix<c_float, m, 1>& lowerBoundVector);

/**
* Set the array for lower bound (size m).
* @param lowerBoundVector is the lower bound constraint.
* @note the elements of the lowerBoundVector are not copied inside the library.
* The user has to guarantee that the lifetime of the object passed is the same of the
* OsqpEigen object
* @return true/false in case of success/failure.
*/
bool setLowerBound(Eigen::Ref<Eigen::Matrix<c_float, Eigen::Dynamic, 1>> lowerBoundVector);

/**
* Set the array for upper bound (size m).
* @param upperBoundVector is the upper bound constraint.
* @note the elements of the upperBoundVector are not copied inside the library.
* The user has to guarantee that the lifetime of the object passed is the same of the
* OsqpEigen object.
* @return true/false in case of success/failure.
*/
template<int m>
[[deprecated("Use setUpperBound(Eigen::Ref<Eigen::Matrix<c_float, Eigen::Dynamic, 1>> upperBoundVector) instead")]]
bool setUpperBound(Eigen::Matrix<c_float, m, 1>& upperBoundVector);

/**
* Set the array for upper bound (size m).
* @param upperBoundVector is the upper bound constraint.
* @note the elements of the upperBoundVector are not copied inside the library.
* The user has to guarantee that the lifetime of the object passed is the same of the
* OsqpEigen object.
* @return true/false in case of success/failure.
*/
bool setUpperBound(Eigen::Ref<Eigen::Matrix<c_float, Eigen::Dynamic, 1>> upperBoundVector);

/**
* Get the OSQPData struct.
* @return a const point to the OSQPData struct.
Expand Down
77 changes: 76 additions & 1 deletion include/OsqpEigen/Data.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,81 @@ bool OsqpEigen::Data::setHessianMatrix(const Eigen::SparseMatrix<T> &hessianMatr
return true;
}

template<typename Derived>
bool OsqpEigen::Data::setHessianMatrix(const Eigen::SparseCompressedBase<Derived> &hessianMatrix)
{
if(m_isHessianMatrixSet){
std::cerr << "[OsqpEigen::Data::setHessianMatrix] The hessian matrix was already set. "
<< "Please use clearHessianMatrix() method to deallocate memory."
<< std::endl;
return false;
}

if(!m_isNumberOfVariablesSet){
std::cerr << "[OsqpEigen::Data::setHessianMatrix] Please set the number of variables before "
<< "add the hessian matrix."
<< std::endl;
return false;
}

// check if the number of row and columns are equal to the number of the optimization variables
if ((hessianMatrix.rows() != m_data->n) || (hessianMatrix.cols()!= m_data->n)){
std::cerr << "[OsqpEigen::Data::setHessianMatrix] The Hessian matrix has to be a n x n size matrix."
<< std::endl;
return false;
}

//set the hessian matrix
if(!OsqpEigen::SparseMatrixHelper::createOsqpSparseMatrix(hessianMatrix, m_data->P)){
std::cerr << "[OsqpEigen::Data::setHessianMatrix] Unable to instantiate the osqp sparse matrix."
<< std::endl;
return false;
}
m_isHessianMatrixSet = true;
return true;
}

template<typename Derived>
bool OsqpEigen::Data::setLinearConstraintsMatrix(const Eigen::SparseCompressedBase<Derived> &linearConstraintsMatrix)
{
if(m_isLinearConstraintsMatrixSet){
std::cerr << "[OsqpEigen::Data::setLinearConstraintsMatrix] The linear constraint matrix was already set. "
<< "Please use clearLinearConstraintsMatrix() method to deallocate memory."
<< std::endl;
return false;
}

if(!m_isNumberOfConstraintsSet){
std::cerr << "[OsqpEigen::Data::setLinearConstraintsMatrix] Please set the number of constraints before add the constraint matrix."
<< std::endl;
return false;
}

if(!m_isNumberOfVariablesSet){
std::cerr << "[OsqpEigen::Data::setLinearConstraintsMatrix] Please set the number of variables before add the constraint matrix."
<< std::endl;
return false;
}

if ((linearConstraintsMatrix.rows() != m_data->m) || (linearConstraintsMatrix.cols()!= m_data->n)){
std::cerr << "[OsqpEigen::Data::setLinearConstraintsMatrix] The Linear constraints matrix has to be a m x n size matrix."
<< std::endl;
return false;
}

// set the hessian matrix
if(!OsqpEigen::SparseMatrixHelper::createOsqpSparseMatrix(linearConstraintsMatrix,
m_data->A)){
std::cerr << "[OsqpEigen::Data::setLinearConstraintsMatrix] osqp sparse matrix not created."
<< std::endl;
return false;
}

m_isLinearConstraintsMatrixSet = true;

return true;
}

template<int n>
bool OsqpEigen::Data::setGradient(Eigen::Matrix<c_float, n, 1>& gradient)
{
Expand All @@ -56,7 +131,7 @@ bool OsqpEigen::Data::setGradient(Eigen::Matrix<c_float, n, 1>& gradient)

template<typename T>
bool OsqpEigen::Data::setLinearConstraintsMatrix(const Eigen::SparseMatrix<T> &linearConstraintsMatrix)
{
{
if(m_isLinearConstraintsMatrixSet){
std::cerr << "[OsqpEigen::Data::setLinearConstraintsMatrix] The linear constraint matrix was already set. "
<< "Please use clearLinearConstraintsMatrix() method to deallocate memory."
Expand Down
File renamed without changes.
87 changes: 87 additions & 0 deletions include/OsqpEigen/Solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,37 +125,95 @@ namespace OsqpEigen
/**
* Update the linear part of the cost function (Gradient).
* @param gradient is the Gradient vector.
* @note the elements of the gradient are not copied inside the library.
* The user has to guarantee that the lifetime of the objects passed is the same of the
* OsqpEigen object.
* @return true/false in case of success/failure.
*/
template<int n>
[[deprecated("Use updateGradient(const Eigen::Ref<const Eigen::Matrix<c_float, Eigen::Dynamic, 1>>& gradient) instead")]]
bool updateGradient(Eigen::Matrix<c_float, n, 1>& gradient);

/**
* Update the linear part of the cost function (Gradient).
* @param gradient is the Gradient vector.
* @note the elements of the gradient are not copied inside the library.
* The user has to guarantee that the lifetime of the objects passed is the same of the
* OsqpEigen object.
* @return true/false in case of success/failure.
*/
bool updateGradient(const Eigen::Ref<const Eigen::Matrix<c_float, Eigen::Dynamic, 1>>& gradient);

/**
* Update the lower bounds limit (size m).
* @param lowerBound is the lower bound constraint vector.
* @note the elements of the lowerBound are not copied inside the library.
* The user has to guarantee that the lifetime of the object passed is the same of the
* OsqpEigen object.
* @return true/false in case of success/failure.
*/
template<int m>
[[deprecated("Use updateLowerBound(Eigen::Matrix<c_float, m, 1>& lowerBound) instead")]]
bool updateLowerBound(Eigen::Matrix<c_float, m, 1>& lowerBound);

/**
* Update the lower bounds limit (size m).
* @param lowerBound is the lower bound constraint vector.
* @note the elements of the lowerBound are not copied inside the library.
* The user has to guarantee that the lifetime of the object passed is the same of the
* OsqpEigen object.
* @return true/false in case of success/failure.
*/
bool updateLowerBound(const Eigen::Ref<const Eigen::Matrix<c_float, Eigen::Dynamic, 1>>& lowerBound);

/**
* Update the upper bounds limit (size m).
* @param upperBound is the upper bound constraint vector.
* @note the elements of the upperBound are not copied inside the library.
* The user has to guarantee that the lifetime of the object passed is the same of the
* OsqpEigen object.
* @return true/false in case of success/failure.
*/
template<int m>
[[deprecated("Use updateUpperBound(Eigen::Matrix<c_float, m, 1>& upperBound) instead")]]
bool updateUpperBound(Eigen::Matrix<c_float, m, 1>& upperBound);

/**
* Update the upper bounds limit (size m).
* @param upperBound is the upper bound constraint vector.
* @note the elements of the upperBound are not copied inside the library.
* The user has to guarantee that the lifetime of the object passed is the same of the
* OsqpEigen object.
* @return true/false in case of success/failure.
*/
bool updateUpperBound(const Eigen::Ref<const Eigen::Matrix<c_float, Eigen::Dynamic, 1>>& upperBound);

/**
* Update both upper and lower bounds (size m).
* @param lowerBound is the lower bound constraint vector;
* @param upperBound is the upper bound constraint vector.
* @note the elements of the lowerBound and upperBound are not copied inside the library.
* The user has to guarantee that the lifetime of the objects passed is the same of the
* OsqpEigen object
* @return true/false in case of success/failure.
*/
template<int m>
[[deprecated("Use updateBounds(const Eigen::Ref<const Eigen::Matrix<c_float, Eigen::Dynamic, 1>>& lowerBound, const Eigen::Ref<const Eigen::Matrix<c_float, Eigen::Dynamic, 1>>& upperBound) instead")]]
bool updateBounds(Eigen::Matrix<c_float, m, 1>& lowerBound,
Eigen::Matrix<c_float, m, 1>& upperBound);

/**
* Update both upper and lower bounds (size m).
* @param lowerBound is the lower bound constraint vector;
* @param upperBound is the upper bound constraint vector.
* @note the elements of the lowerBound and upperBound are not copied inside the library.
* The user has to guarantee that the lifetime of the objects passed is the same of the
* OsqpEigen object
* @return true/false in case of success/failure.
*/
bool updateBounds(const Eigen::Ref<const Eigen::Matrix<c_float, Eigen::Dynamic, 1>>& lowerBound,
const Eigen::Ref<const Eigen::Matrix<c_float, Eigen::Dynamic, 1>>& upperBound);

/**
* Update the quadratic part of the cost function (Hessian).
* It is assumed to be a simmetric matrix.
Expand All @@ -168,8 +226,23 @@ namespace OsqpEigen
* @return true/false in case of success/failure.
*/
template<typename T>
[[deprecated("Use updateHessianMatrix(const Eigen::SparseCompressedBase<Derived> &hessianMatrix) instead")]]
bool updateHessianMatrix(const Eigen::SparseMatrix<T> &hessianMatrix);

/**
* Update the quadratic part of the cost function (Hessian).
* It is assumed to be a simmetric matrix.
* \note
* If the sparsity pattern is preserved the matrix is simply update
* otherwise the entire solver will be reinitialized. In this case
* the primal and dual variable are copied in the new workspace.
*
* @param hessian is the Hessian matrix.
* @return true/false in case of success/failure.
*/
template<typename Derived>
bool updateHessianMatrix(const Eigen::SparseCompressedBase<Derived> &hessianMatrix);

/**
* Update the linear constraints matrix (A)
* \note
Expand All @@ -181,8 +254,22 @@ namespace OsqpEigen
* @return true/false in case of success/failure.
*/
template<typename T>
[[deprecated("Use updateLinearConstraintsMatrix(const Eigen::SparseCompressedBase<Derived> &linearConstraintsMatrix) instead")]]
bool updateLinearConstraintsMatrix(const Eigen::SparseMatrix<T> &linearConstraintsMatrix);

/**
* Update the linear constraints matrix (A)
* \note
* If the sparsity pattern is preserved the matrix is simply update
* otherwise the entire solver will be reinitialized. In this case
* the primal and dual variable are copied in the new workspace.
*
* @param linearConstraintsMatrix is the linear constraint matrix A
* @return true/false in case of success/failure.
*/
template<typename Derived>
bool updateLinearConstraintsMatrix(const Eigen::SparseCompressedBase<Derived> &linearConstraintsMatrix);

/**
* Set the entire
* @param linearConstraintsMatrix is the linear constraint matrix A
Expand Down
Loading

0 comments on commit c006659

Please sign in to comment.