Commit dea8257e authored by Martin Marinov's avatar Martin Marinov

Merge remote-tracking branch 'origin/warning_fixes'

parents 957aeb32 54dc54db
......@@ -28,7 +28,7 @@ if (MSVC)
add_definitions(-DNOMINMAX)
# add_definitions(-DIL_STD) #set CPLEX to use its STL interface, change this?!
add_definitions(/W1) #add appropriate warnings flags for this project, the compilation raises to too may warnings
add_definitions(/W3) #add appropriate warnings flags for this project, the compilation raises to too may warnings
add_definitions(/MP) #build on all cores
endif (MSVC)
......
......@@ -17,6 +17,9 @@
//== INCLUDES =================================================================
#include <iostream>
#include <Base/Code/Quality.hh>
LOW_CODE_QUALITY_SECTION_BEGIN
#include <Eigen/Eigen>
#if EIGEN_VERSION_AT_LEAST(3,1,0)
......@@ -26,6 +29,7 @@
#include <unsupported/Eigen/CholmodSupport>
#endif
#include <Eigen/Sparse>
LOW_CODE_QUALITY_SECTION_END
//== FORWARDDECLARATIONS ======================================================
......
......@@ -63,9 +63,9 @@ public:
COMISO::StopWatch sw; sw.start();
// number of unknowns
int n = _quadratic_problem->n_unknowns();
size_t n = _quadratic_problem->n_unknowns();
// number of constraints
int m = _b.size();
size_t m = _b.size();
std::cerr << "optmize via AQP with " << n << " unknowns and " << m << " linear constraints" << std::endl;
......@@ -193,7 +193,7 @@ protected:
double backtracking_line_search(NProblemInterface* _quadratic_problem, NProblemInterface* _nonlinear_problem, VectorD& _x, VectorD& _g, VectorD& _dx, double& _rel_df, double _t_start = 1.0)
{
int n = _x.size();
size_t n = _x.size();
// pre-compute objective
double fx = _quadratic_problem->eval_f(_x.data()) + _nonlinear_problem->eval_f(_x.data());
......
......@@ -150,7 +150,7 @@ bool solve_impl(
DEB_warning_if(!_problem->constant_gradient(), 1,
"CBCSolver received a problem with non-constant gradient!");
const int n_rows = _constraints.size(); // Constraints #
const size_t n_rows = _constraints.size(); // Constraints #
const int n_cols = _problem->n_unknowns(); // Unknowns #
// expand the variable types from discrete mtrx array
......
......@@ -50,7 +50,7 @@ solve(NProblemInterface* _problem,
//----------------------------------------------
// 2. setup constraints
//----------------------------------------------
int n = _problem->n_unknowns();
std::size_t n = _problem->n_unknowns();
gmm::row_matrix< gmm::wsvector< double > > C(_constraints.size(), n+1);
int n_constraints = 0;
......
......@@ -26,11 +26,10 @@ namespace COMISO {
/// Default constructor
ConeConstraint::ConeConstraint()
: NConstraintInterface(NConstraintInterface::NC_GREATER_EQUAL)
: NConstraintInterface(NConstraintInterface::NC_GREATER_EQUAL),
i_(1), c_(1.0)
{
Q_.clear();
i_ = 1.0;
c_ = 1.0;
}
// cone constraint of the form -> 0.5*(c_ * x(i_)^2 - x^T Q_ x) >= 0
......
......@@ -62,8 +62,8 @@ remove_dependent_linear_constraints_only_linear_equality( std::vector<NConstrain
if(_constraints.empty()) return;
// 1. copy (normalized) data into gmm dynamic sparse matrix
unsigned int n(_constraints[0]->n_unknowns());
unsigned int m(_constraints.size());
size_t n(_constraints[0]->n_unknowns());
size_t m(_constraints.size());
std::vector<double> x(n, 0.0);
NConstraintInterface::SVectorNC g;
RMatrixGMM A;
......@@ -92,27 +92,28 @@ remove_dependent_linear_constraints_only_linear_equality( std::vector<NConstrain
// 3. initialize priorityqueue for sorting
// init priority queue
MutablePriorityQueueT<unsigned int, unsigned int> queue;
MutablePriorityQueueT<gmm::size_type, gmm::size_type> queue;
queue.clear(m);
for(unsigned int i=0; i<m; ++i)
for (gmm::size_type i = 0; i<m; ++i)
{
int cur_nnz = gmm::nnz( gmm::mat_row(A,i));
if( A(i,n) != 0.0) --cur_nnz;
gmm::size_type cur_nnz = gmm::nnz( gmm::mat_row(A,i));
if (A(i,n) != 0.0)
--cur_nnz;
queue.update(i, cur_nnz);
}
// track row status -1=undecided, 0=remove, 1=keep
std::vector<int> row_status(m, -1);
std::vector<int> keep;
std::vector<gmm::size_type> keep;
// std::vector<int> remove;
// for all conditions
while(!queue.empty())
{
// get next row
unsigned int i = queue.get_next();
unsigned int j = find_max_abs_coeff(A.row(i));
gmm::size_type i = queue.get_next();
gmm::size_type j = find_max_abs_coeff(A.row(i));
double aij = A(i,j);
if(std::abs(aij) <= _eps)
{
......@@ -145,7 +146,7 @@ remove_dependent_linear_constraints_only_linear_equality( std::vector<NConstrain
if( row_status[c_it.index()] == -1) // only process unvisited rows
{
// row idx
int k = c_it.index();
gmm::size_type k = c_it.index();
double s = -(*c_it)/aij;
add_row_simultaneously( k, s, row, A, Ac, _eps);
......@@ -153,8 +154,9 @@ remove_dependent_linear_constraints_only_linear_equality( std::vector<NConstrain
A( k, j) = 0;
Ac(k, j) = 0;
int cur_nnz = gmm::nnz( gmm::mat_row(A,k));
if( A(k,n) != 0.0) --cur_nnz;
gmm::size_type cur_nnz = gmm::nnz( gmm::mat_row(A,k));
if( A(k,n) != 0.0)
--cur_nnz;
queue.update(k, cur_nnz);
}
......@@ -177,12 +179,12 @@ remove_dependent_linear_constraints_only_linear_equality( std::vector<NConstrain
//-----------------------------------------------------------------------------
unsigned int
gmm::size_type
ConstraintTools::
find_max_abs_coeff(SVectorGMM& _v)
{
unsigned int n = _v.size();
unsigned int imax(0);
size_t n = _v.size();
gmm::size_type imax(0);
double vmax(0.0);
gmm::linalg_traits<SVectorGMM>::const_iterator c_it = gmm::vect_const_begin(_v);
......@@ -205,7 +207,7 @@ find_max_abs_coeff(SVectorGMM& _v)
void
ConstraintTools::
add_row_simultaneously( int _row_i,
add_row_simultaneously( gmm::size_type _row_i,
double _coeff,
SVectorGMM& _row,
RMatrixGMM& _rmat,
......
......@@ -58,13 +58,13 @@ public:
static void remove_dependent_linear_constraints(std::vector<NConstraintInterface*>& _constraints, const double _eps = 1e-8);
// same as above but assumes already that all constraints are linear equality constraints
static void remove_dependent_linear_constraints_only_linear_equality( std::vector<NConstraintInterface*>& _constraints, const double _eps = 1e-8);
static void remove_dependent_linear_constraints_only_linear_equality(std::vector<NConstraintInterface*>& _constraints, const double _eps = 1e-8);
private:
static unsigned int find_max_abs_coeff(SVectorGMM& _v);
static gmm::size_type find_max_abs_coeff(SVectorGMM& _v);
static void add_row_simultaneously( int _row_i,
static void add_row_simultaneously( gmm::size_type _row_i,
double _coeff,
SVectorGMM& _row,
RMatrixGMM& _rmat,
......
......@@ -72,7 +72,7 @@ void FiniteElementProblem::eval_hessian ( const double* _x, SMatrixNP& _H)
fe_sets_[i]->accumulate_hessian(_x, triplets_);
// set data
_H.resize(n_unknowns(), n_unknowns());
_H.resize(static_cast<int>(n_unknowns()), static_cast<int>(n_unknowns()));
_H.setFromTriplets(triplets_.begin(), triplets_.end());
}
......
......@@ -187,8 +187,8 @@ public:
for(unsigned int j=0; j<triplets_.size(); ++j)
{
// add re-indexed Triplet
_triplets.push_back(Triplet( instances_.index(i,triplets_[j].row()),
instances_.index(i,triplets_[j].col()),
_triplets.push_back(Triplet( (int)instances_.index(i,triplets_[j].row()),
(int)instances_.index(i,triplets_[j].col()),
triplets_[j].value() ));
}
}
......
......@@ -43,12 +43,12 @@ int LinearConstraint::n_unknowns()
return coeffs_.innerSize();
}
void LinearConstraint::resize(const unsigned int _n)
void LinearConstraint::resize(const std::size_t _n)
{
if(coeffs_.innerSize() != (int)_n)
if(coeffs_.innerSize() != static_cast<std::ptrdiff_t>(_n))
{
// resize while maintaining all values in range
SVectorNC coeffs_new(_n);
SVectorNC coeffs_new(static_cast<int>(_n));
coeffs_new.setZero();
coeffs_new.reserve(coeffs_.nonZeros());
......
......@@ -55,7 +55,7 @@ public:
// resize coefficient vector = #unknowns
// maintain all values in range
void resize(const unsigned int _n);
void resize(const std::size_t _n);
// clear to zero constraint 0 =_type 0
void clear();
......
......@@ -14,9 +14,13 @@
#include <CoMISo/Config/CoMISoDefines.hh>
#include "NConstraintInterface.hh"
#include "LinearConstraint.hh"
#include <Base/Code/Quality.hh>
LOW_CODE_QUALITY_SECTION_BEGIN
#include <Eigen/StdVector>
#include <Eigen/Dense>
#include <Eigen/Sparse>
LOW_CODE_QUALITY_SECTION_END
//== FORWARDDECLARATIONS ======================================================
......
......@@ -8,7 +8,7 @@
namespace COMISO {
LinearProblem::LinearProblem (unsigned int _dimension)
LinearProblem::LinearProblem (std::size_t _dimension)
{
// resize and zero elements
coeffs_.resize(_dimension,0.0);
......@@ -19,9 +19,9 @@ LinearProblem::~LinearProblem()
{
}
int LinearProblem::n_unknowns()
int LinearProblem::n_unknowns()
{
return coeffs_.size();
return static_cast<int>(coeffs_.size());
}
void LinearProblem::initial_x(double* _x)
......
......@@ -43,7 +43,7 @@ class COMISODLLEXPORT LinearProblem : public NProblemInterface
public:
/// Default constructor
LinearProblem (unsigned int _dimension = 0);
LinearProblem (std::size_t _dimension = 0);
/// Destructor
virtual ~LinearProblem();
......
......@@ -18,8 +18,11 @@
#include "SuperSparseMatrixT.hh"
#include <Base/Code/Quality.hh>
LOW_CODE_QUALITY_SECTION_BEGIN
#define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET
#include <Eigen/Sparse>
LOW_CODE_QUALITY_SECTION_END
//== FORWARDDECLARATIONS ======================================================
......
......@@ -101,10 +101,10 @@ bool NProblemIPOPT::get_nlp_info(Index& n, Index& m, Index& nnz_jac_g,
Index& nnz_h_lag, IndexStyleEnum& index_style)
{
// number of variables
n = problem_->n_unknowns();
n = static_cast<Index>(problem_->n_unknowns());
// number of constraints
m = constraints_.size();
m = static_cast<Index>(constraints_.size());
// get non-zeros of hessian of lagrangian and jacobi of constraints
nnz_jac_g = 0;
......@@ -546,7 +546,7 @@ bool NProblemGmmIPOPT::get_nlp_info(Index& n, Index& m, Index& nnz_jac_g,
n = problem_->n_unknowns();
// number of constraints
m = constraints_.size();
m = static_cast<Index>(constraints_.size());
// get nonzero structure
std::vector<double> x(n);
......@@ -582,7 +582,7 @@ bool NProblemGmmIPOPT::get_nlp_info(Index& n, Index& m, Index& nnz_jac_g,
if( i >= (int)v_it.index())
{
h_lag_iRow_.push_back(i);
h_lag_jCol_.push_back(v_it.index());
h_lag_jCol_.push_back(static_cast<int>(v_it.index()));
++nnz_h_lag;
}
}
......
......@@ -15,14 +15,17 @@
//== INCLUDES =================================================================
#include <Base/Code/Quality.hh>
#include <iostream>
#include <cfloat>
LOW_CODE_QUALITY_SECTION_BEGIN
#include <Eigen/Eigen>
#if !(EIGEN_VERSION_AT_LEAST(3,1,0))
#define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET
#endif
#include <Eigen/Sparse>
LOW_CODE_QUALITY_SECTION_END
#include <CoMISo/Config/CoMISoDefines.hh>
......
......@@ -122,9 +122,9 @@ int NewtonSolver::solve(NProblemInterface* _problem, const SMatrixD& _A,
DEB_time_func_def;
// number of unknowns
const int n = _problem->n_unknowns();
size_t n = _problem->n_unknowns();
// number of constraints
const int m = _b.size();
size_t m = _b.size();
DEB_line(2, "optimize via Newton with " << n << " unknowns and " << m <<
" linear constraints");
......@@ -311,7 +311,7 @@ double NewtonSolver::backtracking_line_search(NProblemInterface* _problem,
double& _fx, const double _t_start)
{
DEB_enter_func;
int n = _x.size();
size_t n = _x.size();
// pre-compute objective
double fx = _problem->eval_f(_x.data());
......
......@@ -5,9 +5,12 @@
#include <CoMISo/Utils/StopWatch.hh>
#include <vector>
#include <CoMISo/NSolver/NProblemInterface.hh>
#include <Base/Code/Quality.hh>
LOW_CODE_QUALITY_SECTION_BEGIN
#include <Eigen/Eigen>
#include <Eigen/Core>
#include <Eigen/Sparse>
LOW_CODE_QUALITY_SECTION_END
//== NAMESPACES ===============================================================
......
......@@ -82,7 +82,7 @@ bool CholmodSolver::calc_system( const std::vector<int>& _colptr,
rowind_ = _rowind;
values_ = _values;
int n = colptr_.size()-1;
size_t n = colptr_.size()-1;
cholmod_sparse matA;
......@@ -167,7 +167,7 @@ bool CholmodSolver::calc_system_prepare_pattern( const std::vector<int>& _col
rowind_ = _rowind;
values_ = _values;
int n = colptr_.size()-1;
size_t n = colptr_.size() - 1;
// setup matrix matA
cholmod_sparse matA;
......@@ -282,7 +282,7 @@ bool CholmodSolver::update_system( const std::vector<int>& _colptr,
colptr_ = _colptr;
rowind_ = _rowind;
values_ = _values;
int n = colptr_.size()-1;
size_t n = colptr_.size() - 1;
cholmod_sparse matA;
......@@ -329,7 +329,7 @@ bool CholmodSolver::update_downdate_factor( const std::vector<int>& _colptr,
rowind_ = _rowind;
values_ = _values;
int n = colptr_.size()-1;
size_t n = colptr_.size() - 1;
cholmod_sparse matA;
......@@ -387,7 +387,7 @@ bool CholmodSolver::update_downdate_factor( const std::vector<int>& _colptr,
bool CholmodSolver::solve( double * _x, double * _b)
{
const unsigned int n = mp_L->n;
const size_t n = mp_L->n;
cholmod_dense *x, b;
......
......@@ -303,13 +303,13 @@ public:
private:
template<class RowT, class MatrixT>
void add_row( int _row_i,
double _coeff,
RowT _row,
MatrixT& _mat );
void add_row( gmm::size_type _row_i,
double _coeff,
RowT _row,
MatrixT& _mat );
template<class RowT, class RMatrixT, class CMatrixT>
void add_row_simultaneously( int _row_i,
void add_row_simultaneously( gmm::size_type _row_i,
double _coeff,
RowT _row,
RMatrixT& _rmat,
......
This diff is collapsed.
......@@ -45,9 +45,12 @@
#include <vector>
#include <Base/Code/Quality.hh>
LOW_CODE_QUALITY_SECTION_BEGIN
#include <Eigen/Eigen>
#include <Eigen/Sparse>
#include <Eigen/SparseCholesky>
LOW_CODE_QUALITY_SECTION_END
//== NAMESPACES ===============================================================
......@@ -55,44 +58,46 @@
namespace COMISO {
//== CLASS DEFINITION =========================================================
class COMISODLLEXPORT EigenLDLTSolver
class EigenLDLTSolver
{
public:
// _size is maximal size this instance can handle (smaller problems are possible!!!)
EigenLDLTSolver();
~EigenLDLTSolver();
COMISODLLEXPORT EigenLDLTSolver();
COMISODLLEXPORT ~EigenLDLTSolver();
COMISODLLEXPORT
bool calc_system( const std::vector<int>& _colptr,
const std::vector<int>& _rowind,
const std::vector<double>& _values );
template< class GMM_MatrixT>
bool calc_system_gmm( const GMM_MatrixT& _mat);
template< class Eigen_MatrixT>
bool calc_system_eigen( const Eigen_MatrixT& _mat);
COMISODLLEXPORT
bool update_system( const std::vector<int>& _colptr,
const std::vector<int>& _rowind,
const std::vector<double>& _values );
template< class GMM_MatrixT>
bool update_system_gmm( const GMM_MatrixT& _mat);
template< class Eigen_MatrixT>
bool update_system_eigen( const Eigen_MatrixT& _mat);
COMISODLLEXPORT
bool solve ( double * _x0, double * _b);
COMISODLLEXPORT
bool solve ( std::vector<double>& _x0, std::vector<double>& _b);
COMISODLLEXPORT
bool& show_timings();
COMISODLLEXPORT
int dimension();
private:
......
......@@ -33,16 +33,18 @@
//== INCLUDES =================================================================
#include <Base/Code/Quality.hh>
#include <iostream>
#include <vector>
#include <algorithm>
#include <limits>
#include <cmath>
LOW_CODE_QUALITY_SECTION_BEGIN
#include <Eigen/Dense>
#define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET
#include <Eigen/Sparse>
LOW_CODE_QUALITY_SECTION_END
#if COMISO_SUITESPARSE_AVAILABLE
#include <cholmod.h>
......
......@@ -340,7 +340,7 @@ void cholmod_to_eigen( const cholmod_sparse& _AC, MatrixT& _A)
typedef Eigen::Triplet< Scalar > Triplet;
size_t nzmax( _AC.nzmax);
std::cerr << __FUNCTION__ << " row " << _AC.nrow << " col " << _AC.ncol << " stype " << _AC.stype << std::endl;
_A = MatrixT(_AC.nrow, _AC.ncol);
_A = MatrixT((int)_AC.nrow, (int)_AC.ncol);
std::vector< Triplet > triplets;
triplets.reserve(nzmax);
......@@ -365,7 +365,7 @@ void cholmod_to_eigen( const cholmod_sparse& _AC, MatrixT& _A)
for(SuiteSparse_long i=0; i<(SuiteSparse_long)_AC.ncol; ++i)
for(SuiteSparse_long j= P[i]; j< P[i+1]; ++j)
//_A( I[j], i) += X[j]; // += really needed?
triplets.push_back( Triplet( I[j], i, X[j]));
triplets.push_back(Triplet((int)I[j], (int)i, X[j]));
}
else
{
......@@ -374,7 +374,7 @@ void cholmod_to_eigen( const cholmod_sparse& _AC, MatrixT& _A)
for(int i=0; i<(int)_AC.ncol; ++i)
for(int j= P[i]; j< P[i+1]; ++j)
triplets.push_back( Triplet( I[j], i, X[j]));
triplets.push_back(Triplet((int)I[j], (int)i, X[j]));
//_A( I[j], i) += X[j];
}
......@@ -391,11 +391,11 @@ void cholmod_to_eigen( const cholmod_sparse& _AC, MatrixT& _A)
for(SuiteSparse_long j=P[i]; j<P[i+1]; ++j)
{
//_A(I[j], i) += X[j];
triplets.push_back( Triplet( I[j], i, X[j]));
triplets.push_back(Triplet((int)I[j], (int)i, X[j]));
// add up symmetric part
if( I[j] != i)
triplets.push_back( Triplet( i, I[j], X[j]));
triplets.push_back(Triplet((int)i, (int)I[j], X[j]));
//_A(i,I[j]) += X[j];
}
}
......@@ -731,19 +731,21 @@ void f(const gmm::row_matrix<GMM_VectorT>& _G, EIGEN_MatrixT& _E)
std::vector< Triplet > triplets;
triplets.reserve(gmm::nnz(_G));
for(unsigned int i=0; i<gmm::mat_nrows(_G); ++i)
for(gmm::size_type i=0; i<gmm::mat_nrows(_G); ++i)
{
RowT row = mat_const_row( _G, i );
CIter it = gmm::vect_const_begin( row );
CIter ite = gmm::vect_const_end( row );
for ( ; it!=ite; ++it )
triplets.push_back( Triplet( i, it.index(), *it));
triplets.push_back(
Triplet( static_cast<int>(i), static_cast<int>(it.index()), *it));
}
// generate eigen matrix
_E = EIGEN_MatrixT( gmm::mat_nrows(_G), gmm::mat_ncols(_G));
_E = EIGEN_MatrixT( static_cast<int>(gmm::mat_nrows(_G)),
static_cast<int>(gmm::mat_ncols(_G)));
_E.setFromTriplets( triplets.begin(), triplets.end());
}
......@@ -769,11 +771,12 @@ void f(const gmm::csc_matrix<GMM_RealT,0>& _G, EIGEN_MatrixT& _E)
CIter it = gmm::vect_const_begin( col );
CIter ite = gmm::vect_const_end( col );
for ( ; it!=ite; ++it )
triplets.push_back( Triplet( it.index(), i, *it));
triplets.push_back( Triplet( static_cast<int>(it.index()), i, *it));
}
// generate eigen matrix
_E = EIGEN_MatrixT( gmm::mat_nrows(_G), gmm::mat_ncols(_G));
_E = EIGEN_MatrixT( static_cast<int>(gmm::mat_nrows(_G)),
static_cast<int>( gmm::mat_ncols(_G)));
_E.setFromTriplets( triplets.begin(), triplets.end());
}
......
......@@ -65,13 +65,13 @@ void eliminate_csc_vars(
typedef unsigned int uint;
typedef typename gmm::csc_matrix<RealT> MatrixT;
unsigned int nc = _A.nc;
unsigned int nr = _A.nr;
gmm::size_type nc = _A.nc;
gmm::size_type nr = _A.nr;
unsigned int n_new = nc - _evar.size();
gmm::size_type n_new = nc - _evar.size();
// modify rhs
for ( unsigned int k=0; k<_evar.size(); ++k )
for ( gmm::size_type k=0; k<_evar.size(); ++k )
{
IntegerT i = _evar[k];
......@@ -95,7 +95,7 @@ void eliminate_csc_vars(
// build subindex set and update rhs
std::vector<size_t> si( n_new );
int cur_evar_idx=0;
for ( unsigned int i=0; i<nc; ++i )
for ( gmm::size_type i=0; i<nc; ++i )
{
unsigned int next_i = evar[cur_evar_idx];
if ( i != next_i )
......@@ -119,7 +119,7 @@ void eliminate_csc_vars(
uint last_jc = _A.jc[0];
uint col_offset(0);
uint offset_update(0);
uint last_evar_idx=evar.size()-2;
uint last_evar_idx= static_cast<uint>(evar.size())-2;
for( uint c = 0; c < nc; ++c)
{
......@@ -173,13 +173,13 @@ void eliminate_csc_vars2(
typedef unsigned int uint;
typedef typename gmm::csc_matrix<RealT> MatrixT;
unsigned int nc = _A.nc;
unsigned int nr = _A.nr;
gmm::size_type nc = _A.nc;
gmm::size_type nr = _A.nr;
unsigned int n_new = nc - _evar.size();
gmm::size_type n_new = nc - _evar.size();
// modify rhs
for ( unsigned int k=0; k<_evar.size(); ++k )
for ( std::size_t k=0; k<_evar.size(); ++k )
{
IntegerT i = _evar[k];
......@@ -289,8 +289,8 @@ void get_ccs_symmetric_data( const MatrixT& _mat,
std::vector<INTT>& _rowind,
std::vector<INTT>& _colptr )
{