Commit 92e74c87 authored by Andreas Fabri's avatar Andreas Fabri

int -> std::size_t

parent 77a83d0c
......@@ -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
......
......@@ -34,7 +34,7 @@ std::vector<double>& FiniteElementProblem::x()
}
std::size_t FiniteElementProblem::n_unknowns()
int FiniteElementProblem::n_unknowns()
{
return n_;
}
......@@ -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());
}
......
......@@ -226,7 +226,7 @@ public:
std::vector<double>& x();
// problem definition
virtual std::size_t n_unknowns ( );
virtual int n_unknowns ( );
virtual void initial_x ( double* _x );
......
......@@ -66,7 +66,7 @@ eval_term(const unsigned int _i)
//-----------------------------------------------------------------------------
std::size_t
int
LeastSquaresProblem::
n_unknowns ( )
{
......
......@@ -57,7 +57,7 @@ public:
std::vector<double>& x() {return x_;}
// problem definition
virtual std::size_t n_unknowns ( );
virtual int n_unknowns ( );
virtual void initial_x ( double* _x );
virtual double eval_f ( const double* _x );
virtual void eval_gradient( const double* _x, double* _g);
......
......@@ -48,7 +48,7 @@ int LinearConstraint::n_unknowns()
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());
......
......@@ -19,9 +19,9 @@ LinearProblem::~LinearProblem()
{
}
std::size_t LinearProblem::n_unknowns()
int LinearProblem::n_unknowns()
{
return coeffs_.size();
return static_cast<int>(coeffs_.size());
}
void LinearProblem::initial_x(double* _x)
......
......@@ -49,7 +49,7 @@ public:
virtual ~LinearProblem();
// problem definition
virtual std::size_t n_unknowns();
virtual int n_unknowns();
virtual void initial_x(double* _x);
......
......@@ -26,7 +26,7 @@ NPTiming::NPTiming(NProblemInterface* _base) : base_(_base) {start_timing();}
/// Destructor
NPTiming::~NPTiming() {}
std::size_t NPTiming::n_unknowns ()
int NPTiming::n_unknowns ()
{
return base_->n_unknowns();
}
......
......@@ -42,7 +42,7 @@ public:
/// Destructor
~NPTiming();
virtual std::size_t n_unknowns ();
virtual int n_unknowns ();
virtual void initial_x( double* _x );
......
......@@ -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;
}
}
......
......@@ -59,7 +59,7 @@ public:
virtual ~NProblemInterface();
// problem definition
virtual std::size_t n_unknowns ( ) = 0;
virtual int n_unknowns ( ) = 0;
virtual void initial_x ( double* _x ) = 0;
virtual double eval_f ( const double* _x ) = 0;
virtual void eval_gradient( const double* _x, double* _g) = 0;
......
......@@ -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,
......
......@@ -349,8 +349,8 @@ resolve(
gmm::mult(rhs_update_table_.D_, *_constraint_rhs, rhs_update_table_.cur_constraint_rhs_);
// update rhs of stored constraints
unsigned int nc = gmm::mat_ncols(rhs_update_table_.constraints_p_);
for(unsigned int i=0; i<rhs_update_table_.cur_constraint_rhs_.size(); ++i)
gmm::size_type nc = gmm::mat_ncols(rhs_update_table_.constraints_p_);
for(gmm::size_type i=0; i<rhs_update_table_.cur_constraint_rhs_.size(); ++i)
rhs_update_table_.constraints_p_(i,nc-1) = -rhs_update_table_.cur_constraint_rhs_[i];
}
if(_rhs)
......@@ -404,7 +404,7 @@ make_constraints_independent(
// Base::StopWatch sw;
// number of variables
int n_vars = gmm::mat_ncols(_constraints);
const gmm::size_type n_vars = gmm::mat_ncols(_constraints);
// TODO Check: HZ added 14.08.09
_c_elim.clear();
......@@ -453,7 +453,7 @@ make_constraints_independent(
for(; row_it != row_end; ++row_it)
{
int cur_j = row_it.index();
int cur_j = static_cast<int>(row_it.index());
// do not use the constant part
if( cur_j != n_vars - 1 )
{
......@@ -480,12 +480,12 @@ make_constraints_independent(
gcd_update_valid = false;
}
v_gcd[n_ints] = cur_row_val;
v_gcd[n_ints] = static_cast<int>(cur_row_val);
++n_ints;
// store integer closest to 1, must be greater than epsilon_
if( fabs(cur_row_val-1.0) < elim_val && cur_row_val > epsilon_)
{
{
elim_int_j = cur_j;
elim_val = fabs(cur_row_val-1.0);
}
......@@ -593,8 +593,8 @@ make_constraints_independent_reordering(
// Base::StopWatch sw;
// number of variables
// AF: Why is n_vars signed? Can it be zero? Later we subtract 1
int n_vars = gmm::mat_ncols(_constraints);
// AF: Why was n_vars signed? Can it be zero? Later we subtract 1
const gmm::size_type n_vars = gmm::mat_ncols(_constraints);
// TODO Check: HZ added 14.08.09
_c_elim.clear();
......@@ -614,13 +614,13 @@ make_constraints_independent_reordering(
// init priority queue
MutablePriorityQueueT<unsigned int, unsigned int> queue;
queue.clear( nr );
queue.clear( static_cast<int>(nr) );
for(unsigned int i=0; i<nr; ++i)
{
int cur_nnz = gmm::nnz( gmm::mat_row(_constraints,i));
gmm::size_type cur_nnz = gmm::nnz( gmm::mat_row(_constraints,i));
if( _constraints(i,n_vars-1) != 0.0) --cur_nnz;
queue.update(i, cur_nnz);
queue.update(i, static_cast<int>(cur_nnz));
}
std::vector<bool> row_visited(nr, false);
......@@ -664,7 +664,7 @@ make_constraints_independent_reordering(
for(; row_it != row_end; ++row_it)
{
int cur_j = row_it.index();
int cur_j = static_cast<int>(row_it.index());
// do not use the constant part
if( cur_j != n_vars - 1 )
{
......@@ -691,7 +691,7 @@ make_constraints_independent_reordering(
gcd_update_valid = false;
}
v_gcd[n_ints] = cur_row_val;
v_gcd[n_ints] = static_cast<int>(cur_row_val);
++n_ints;
// store integer closest to 1, must be greater than epsilon_
......@@ -779,11 +779,12 @@ make_constraints_independent_reordering(
_constraints( c_it.index(), elim_j) = 0;
constraints_c(c_it.index(), elim_j) = 0;
int cur_idx = c_it.index();
int cur_nnz = gmm::nnz( gmm::mat_row(_constraints,cur_idx));
gmm::size_type cur_idx = c_it.index();
gmm::size_type cur_nnz = gmm::nnz( gmm::mat_row(_constraints,cur_idx));
if( _constraints(cur_idx,n_vars-1) != 0.0) --cur_nnz;
queue.update(cur_idx, cur_nnz);
queue.update(static_cast<int>(cur_idx),
static_cast<int>(cur_nnz));
// update linear transition of rhs
gmm::add(gmm::scaled(gmm::mat_row(rhs_update_table_.D_, i), val),
......@@ -861,7 +862,7 @@ update_constraint_gcd( RMatrixT& _constraints,
gmm::size_type cur_j = row_it.index();
_constraints(_row_i, cur_j) = (*row_it)/i_gcd;
}
gmm::size_type elim_coeff = abs(_constraints(_row_i, _elim_j));
gmm::size_type elim_coeff = static_cast<gmm::size_type>(abs(_constraints(_row_i, _elim_j)));
DEB_error_if( elim_coeff != 1, "elimination coefficient " << elim_coeff
<< " will (most probably) NOT lead to an integer solution!")
return true;
......@@ -1027,7 +1028,7 @@ eliminate_constraints(
//_rhs[con_it.index()] -= cur_rhs * (( *con_it )/cur_val);
// rhs_update_table_.append(con_it.index(), -1.0 * (( *con_it )/cur_val), cur_j);
rhs_update_table_.append(con_it.index(), -1.0 * (( *con_it )/cur_val), cur_j, false);
rhs_update_table_.append(static_cast<int>(con_it.index()), -1.0 * (( *con_it )/cur_val), static_cast<int>(cur_j), false);
//std::cerr << con_it.index() << " += " << -1.0*(( *con_it )/cur_val) << " * " << cur_rhs << " (["<<cur_j<<"] = "<<_rhs[cur_j]<<") " << std::endl;
}
......@@ -1048,7 +1049,7 @@ eliminate_constraints(
_A( col_it.index(), con_it.index() ) -= ( *col_it )*(( *con_it )/cur_val);
//_rhs[col_it.index()] += constraint_rhs*( *col_it )/cur_val;
// rhs_update_table_.append(col_it.index(), constraint_rhs*( *col_it )/cur_val);
rhs_update_table_.append(col_it.index(), -( *col_it )/cur_val, i, true);
rhs_update_table_.append(static_cast<int>(col_it.index()), -( *col_it )/cur_val, i, true);
//std::cerr << col_it.index() << " += " << constraint_rhs*( *col_it )/cur_val << std::endl;
}
......@@ -1109,7 +1110,7 @@ eliminate_constraints(
template<class RowT, class MatrixT>
void
ConstrainedSolver::
add_row( int _row_i,
add_row( gmm::size_type _row_i,
double _coeff,
RowT _row,
MatrixT& _mat )
......@@ -1129,11 +1130,11 @@ add_row( int _row_i,
template<class RowT, class RMatrixT, class CMatrixT>
void
ConstrainedSolver::
add_row_simultaneously( int _row_i,
double _coeff,
RowT _row,
RMatrixT& _rmat,
CMatrixT& _cmat )
add_row_simultaneously( gmm::size_type _row_i,
double _coeff,
RowT _row,
RMatrixT& _rmat,
CMatrixT& _cmat )
{
typedef typename gmm::linalg_traits<RowT>::const_iterator RIter;
RIter r_it = gmm::vect_const_begin(_row);
......@@ -1249,7 +1250,7 @@ restore_eliminated_vars( RMatrixT& _constraints,
_x.back() = 1.0;
// reverse iterate from prelast element
for(int i=_new_idx.size()-2; i>= 0; --i)
for(int i= static_cast<int>(_new_idx.size())-2; i>= 0; --i) // AF: Can this be negative?
{
if( _new_idx[i] != -1)
{
......@@ -1260,7 +1261,7 @@ restore_eliminated_vars( RMatrixT& _constraints,
}
// reverse iterate
for(int i=_c_elim.size()-1; i>=0; --i)
for(int i= static_cast<int>(_c_elim.size())-1; i>=0; --i) // AF: Can this be negative?
{
int cur_var = _c_elim[i];
......
......@@ -754,7 +754,7 @@ void eliminate_vars_idx( const std::vector<IntegerT >& _evar,
// precompute update
IntegerT2 range = _range;
if( range == -1 )
range = _idx.size();
range = static_cast<int>(_idx.size()); // AF: what can an IntegerT2 be?
std::vector<int> update_map( range );
typename std::vector<IntegerT>::iterator cur_var = evar.begin();
......
......@@ -496,7 +496,7 @@ MISolver::solve_iterative(
ColIter ite = gmm::vect_const_end ( col);
for(; it!=ite; ++it)
if(it.index() != i_best)
neigh_i.push_back(it.index());
neigh_i.push_back(static_cast<int>(it.index()));
// eliminate var
COMISO_GMM::fix_var_csc_symmetric(i_best, rnd_x, _A, xr, _rhs);
......@@ -715,7 +715,7 @@ void MISolver::solve_multiple_rounding(
ColIter ite = gmm::vect_const_end ( col);
for(; it!=ite; ++it)
if(it.index() != (unsigned int)i_cur)
neigh_i.push_back(it.index());
neigh_i.push_back(static_cast<int>(it.index()));
// eliminate var
COMISO_GMM::fix_var_csc_symmetric( i_cur, rnd_x, _A, xr, _rhs);
......
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