Commit 0c473dd9 authored by Martin Marinov's avatar Martin Marinov Committed by GitHub Enterprise
Browse files

REFORM-923 Use 3p/eigen (#1)

* Consume Eigen from 3p
* Fix compilation warning
* Fix compiler warnings in AcceleratedQuadraticProxy.hh
parent 2f9a8a6e
...@@ -10,13 +10,15 @@ my_add_subdir(Utils) ...@@ -10,13 +10,15 @@ my_add_subdir(Utils)
include_directories(${PROJECT_SOURCE_DIR}/..) include_directories(${PROJECT_SOURCE_DIR}/..)
inc_3p_dir(Boost) inc_3p_dir(Boost)
inc_3p_dir(Eigen)
inc_3p_dir(Gmm) inc_3p_dir(Gmm)
nuget_inc_3p_dir(IPOPT) nuget_inc_3p_dir(IPOPT)
# message(STATUS "${SOURCES}" "${HEADES}") # message(STATUS "${SOURCES}" "${HEADES}")
add_library(CoMISo ${SOURCES} ${HEADERS}) add_library(CoMISo ${SOURCES} ${HEADERS})
target_link_libraries(CoMISo Base) target_link_libraries(CoMISo
PUBLIC Eigen
PUBLIC Base
)
# generate dllexport macros on windows # generate dllexport macros on windows
if (MSVC) if (MSVC)
......
...@@ -134,10 +134,11 @@ protected: ...@@ -134,10 +134,11 @@ protected:
void pre_factorize(NProblemInterface* _quadratic_problem, const SMatrixD& _A, const VectorD& _b) void pre_factorize(NProblemInterface* _quadratic_problem, const SMatrixD& _A, const VectorD& _b)
{ {
const int n = _quadratic_problem->n_unknowns(); const int n = _quadratic_problem->n_unknowns();
const int m = _A.rows(); const int m = static_cast<int>(_A.rows());
const int nf = n+m; const int nf = n+m;
// get hessian of quadratic problem // get hessian of quadratic problem
SMatrixD H(n,n); SMatrixD H(n,n);
_quadratic_problem->eval_hessian(x_ls_.data(), H); _quadratic_problem->eval_hessian(x_ls_.data(), H);
...@@ -146,21 +147,30 @@ protected: ...@@ -146,21 +147,30 @@ protected:
std::vector< Triplet > trips; std::vector< Triplet > trips;
trips.reserve(H.nonZeros() + 2*_A.nonZeros()); trips.reserve(H.nonZeros() + 2*_A.nonZeros());
// add elements of H const auto add_triplet = [&trips](
for (int k=0; k<H.outerSize(); ++k) const size_t _i, const size_t _j, const double _v)
for (SMatrixD::InnerIterator it(H,k); it; ++it) {
trips.push_back(Triplet(it.row(),it.col(),it.value())); trips.emplace_back(static_cast<int>(_i), static_cast<int>(_j), _v);
};
// add elements of H
for (int k = 0; k < H.outerSize(); ++k)
{
for (SMatrixD::InnerIterator it(H, k); it; ++it)
add_triplet(it.row(), it.col(), it.value());
}
// add elements of _A // add elements of _A
for (int k=0; k<_A.outerSize(); ++k) for (int k = 0; k < _A.outerSize(); ++k)
for (SMatrixD::InnerIterator it(_A,k); it; ++it) {
for (SMatrixD::InnerIterator it(_A, k); it; ++it)
{ {
// insert _A block below // insert _A block below
trips.push_back(Triplet(it.row()+n,it.col(),it.value())); add_triplet(it.row() + n, it.col(), it.value());
// insert _A^T block right // insert _A^T block right
trips.push_back(Triplet(it.col(),it.row()+n,it.value())); add_triplet(it.col(), it.row() + n, it.value());
} }
}
// create KKT matrix // create KKT matrix
SMatrixD KKT(nf,nf); SMatrixD KKT(nf,nf);
...@@ -175,8 +185,8 @@ protected: ...@@ -175,8 +185,8 @@ protected:
// DEB_line(2, "-> re-try with regularized constraints..."); // DEB_line(2, "-> re-try with regularized constraints...");
std::cerr << "Eigen::SparseLU reported problem while factoring KKT system: " << lu_solver_.lastErrorMessage() << std::endl; std::cerr << "Eigen::SparseLU reported problem while factoring KKT system: " << lu_solver_.lastErrorMessage() << std::endl;
for( int i=0; i<m; ++i) for (int i = 0; i < m; ++i)
trips.push_back(Triplet(n+i,n+i,1e-9)); add_triplet(n + i, n + i, 1e-9);
// create KKT matrix // create KKT matrix
KKT.setFromTriplets(trips.begin(), trips.end()); KKT.setFromTriplets(trips.begin(), trips.end());
......
...@@ -37,7 +37,7 @@ LinearConstraint::LinearConstraint(const SVectorNC& _coeffs, const double _b, co ...@@ -37,7 +37,7 @@ LinearConstraint::LinearConstraint(const SVectorNC& _coeffs, const double _b, co
int LinearConstraint::n_unknowns() int LinearConstraint::n_unknowns()
{ {
return coeffs_.innerSize(); return static_cast<int>(coeffs_.innerSize());
} }
void LinearConstraint::resize(const std::size_t _n) void LinearConstraint::resize(const std::size_t _n)
...@@ -103,7 +103,8 @@ void LinearConstraint::eval_gradient( const double* _x, SVectorNC& _g ) ...@@ -103,7 +103,8 @@ void LinearConstraint::eval_gradient( const double* _x, SVectorNC& _g )
void LinearConstraint::eval_hessian ( const double* _x, SMatrixNC& _h ) void LinearConstraint::eval_hessian ( const double* _x, SMatrixNC& _h )
{ {
_h.clear(); _h.clear();
_h.resize(coeffs_.innerSize(), coeffs_.innerSize()); _h.resize(static_cast<unsigned int>(coeffs_.innerSize()),
static_cast<unsigned int>(coeffs_.innerSize()));
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment