Commit 165dc624 authored by Martin Marinov's avatar Martin Marinov

Merge remote-tracking branch 'origin/master' into marinom/REFORM-922-new-sanitization

parents 6613cb43 0c473dd9
......@@ -10,13 +10,15 @@ my_add_subdir(Utils)
include_directories(${PROJECT_SOURCE_DIR}/..)
inc_3p_dir(Boost)
inc_3p_dir(Eigen)
inc_3p_dir(Gmm)
nuget_inc_3p_dir(IPOPT)
# message(STATUS "${SOURCES}" "${HEADES}")
add_library(CoMISo ${SOURCES} ${HEADERS})
target_link_libraries(CoMISo Base)
target_link_libraries(CoMISo
PUBLIC Eigen
PUBLIC Base
)
# generate dllexport macros on windows
if (MSVC)
......
......@@ -134,10 +134,11 @@ protected:
void pre_factorize(NProblemInterface* _quadratic_problem, const SMatrixD& _A, const VectorD& _b)
{
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;
// get hessian of quadratic problem
SMatrixD H(n,n);
_quadratic_problem->eval_hessian(x_ls_.data(), H);
......@@ -146,21 +147,30 @@ protected:
std::vector< Triplet > trips;
trips.reserve(H.nonZeros() + 2*_A.nonZeros());
// add elements of H
for (int k=0; k<H.outerSize(); ++k)
for (SMatrixD::InnerIterator it(H,k); it; ++it)
trips.push_back(Triplet(it.row(),it.col(),it.value()));
const auto add_triplet = [&trips](
const size_t _i, const size_t _j, const double _v)
{
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
for (int k=0; k<_A.outerSize(); ++k)
for (SMatrixD::InnerIterator it(_A,k); it; ++it)
for (int k = 0; k < _A.outerSize(); ++k)
{
for (SMatrixD::InnerIterator it(_A, k); it; ++it)
{
// 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
trips.push_back(Triplet(it.col(),it.row()+n,it.value()));
add_triplet(it.col(), it.row() + n, it.value());
}
}
// create KKT matrix
SMatrixD KKT(nf,nf);
......@@ -175,8 +185,8 @@ protected:
// DEB_line(2, "-> re-try with regularized constraints...");
std::cerr << "Eigen::SparseLU reported problem while factoring KKT system: " << lu_solver_.lastErrorMessage() << std::endl;
for( int i=0; i<m; ++i)
trips.push_back(Triplet(n+i,n+i,1e-9));
for (int i = 0; i < m; ++i)
add_triplet(n + i, n + i, 1e-9);
// create KKT matrix
KKT.setFromTriplets(trips.begin(), trips.end());
......
......@@ -37,7 +37,7 @@ LinearConstraint::LinearConstraint(const SVectorNC& _coeffs, const double _b, co
int LinearConstraint::n_unknowns()
{
return coeffs_.innerSize();
return static_cast<int>(coeffs_.innerSize());
}
void LinearConstraint::resize(const std::size_t _n)
......@@ -103,7 +103,8 @@ void LinearConstraint::eval_gradient( const double* _x, SVectorNC& _g )
void LinearConstraint::eval_hessian ( const double* _x, SMatrixNC& _h )
{
_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