Skip to content

Commit

Permalink
Avoid some 'unused variable' and 'comparison signedness' warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
glebbelov committed Apr 20, 2021
1 parent 80e3583 commit cffed55
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion include/mp/convert/backend.h
Expand Up @@ -171,7 +171,7 @@ class BasicBackend :
}
}

void AddGeneralConstraint(typename Model::AlgebraicCon con) {
void AddGeneralConstraint(typename Model::AlgebraicCon ) {
throw MakeUnsupportedError("BasicBackend::AddGeneralConstraint");
}

Expand Down
1 change: 1 addition & 0 deletions include/mp/convert/constraint_keeper.h
Expand Up @@ -18,6 +18,7 @@ class BasicConstraintConverter {
// Should at least derive bounds & type for the result
}
void PropagateResult(BasicConstraint& con, double lb, double ub, Context ctx) {
internal::Unused(con, lb, ub, ctx);
throw std::logic_error("This should not be called");
}
/// By default, we complain about someone trying to convert an unknown constraint
Expand Down
16 changes: 14 additions & 2 deletions include/mp/convert/converter_flat.h
Expand Up @@ -266,7 +266,7 @@ class BasicMPFlatConverter
void Exprs2EExprs(const ExprArray& ea, std::array<EExpr, N>& result) {
assert(ea.size() == result.size());
auto itea = ea.begin();
for (int i=0; i<N; ++i, ++itea)
for (size_t i=0; i<N; ++i, ++itea)
result[i] = MP_DISPATCH( Convert2EExpr(*itea) );
}

Expand All @@ -285,7 +285,7 @@ class BasicMPFlatConverter

EExpr VisitCommonExpr(Reference r) {
const auto index = r.index();
if (index >= common_exprs_.size())
if (index >= (int)common_exprs_.size())
common_exprs_.resize(index+1, -1); // init by -1, "no variable"
if (common_exprs_[index]<0) { // not yet converted
auto ce = MP_DISPATCH( GetModel() ).common_expr(index);
Expand Down Expand Up @@ -737,18 +737,21 @@ class BasicMPFlatConverter
/// By default, declare mixed context
template <class Constraint>
void PropagateResult(Constraint& con, double lb, double ub, Context ctx) {
internal::Unused(con, lb, ub, ctx);
con.SetContext(Context::CTX_MIX);
for (const auto a: con.GetArguments())
PropagateResultOfInitExpr(a, this->MinusInfty(), this->Infty(), Context::CTX_MIX);
}

void PropagateResult(LinearDefiningConstraint& con, double lb, double ub, Context ctx) {
internal::Unused(con, lb, ub, ctx);
con.AddContext(ctx);
for (const auto& term: con.GetAffineExpr())
PropagateResultOfInitExpr(term.var_index(), this->MinusInfty(), this->Infty(), Context::CTX_MIX);
}

void PropagateResult(QuadraticDefiningConstraint& con, double lb, double ub, Context ctx) {
internal::Unused(con, lb, ub, ctx);
con.AddContext(ctx);
const auto& args = con.GetArguments();
for (const auto& term: args.GetAE())
Expand All @@ -761,34 +764,40 @@ class BasicMPFlatConverter
}

void PropagateResult(LinearConstraint& con, double lb, double ub, Context ctx) {
internal::Unused(con, lb, ub, ctx);
for (const auto& v: con.vars())
PropagateResultOfInitExpr(v, this->MinusInfty(), this->Infty(), Context::CTX_MIX);
}

void PropagateResult(IndicatorConstraintLinLE& con, double lb, double ub, Context ctx) {
internal::Unused(con, lb, ub, ctx);
for (const auto& v: con.get_lin_vars())
PropagateResultOfInitExpr(v, this->MinusInfty(), this->Infty(), Context::CTX_MIX);
}

void PropagateResult(NotConstraint& con, double lb, double ub, Context ctx) {
internal::Unused(con, lb, ub, ctx);
con.AddContext(ctx);
for (const auto a: con.GetArguments())
PropagateResultOfInitExpr(a, 1.0-ub, 1.0-lb, -ctx);
}

void PropagateResult(ConjunctionConstraint& con, double lb, double ub, Context ctx) {
internal::Unused(con, lb, ub, ctx);
con.AddContext(ctx);
for (const auto a: con.GetArguments())
PropagateResultOfInitExpr(a, lb, 1.0, +ctx);
}

void PropagateResult(DisjunctionConstraint& con, double lb, double ub, Context ctx) {
internal::Unused(con, lb, ub, ctx);
con.AddContext(ctx);
for (const auto a: con.GetArguments())
PropagateResultOfInitExpr(a, 0.0, ub, +ctx);
}

void PropagateResult(IfThenConstraint& con, double lb, double ub, Context ctx) {
internal::Unused(con, lb, ub, ctx);
con.AddContext(ctx);
auto& args = con.GetArguments();
PropagateResultOfInitExpr(args[0], 0.0, 1.0, Context::CTX_MIX);
Expand All @@ -797,15 +806,18 @@ class BasicMPFlatConverter
}

void PropagateResult(AllDiffConstraint& con, double lb, double ub, Context ctx) {
internal::Unused(con, lb, ub, ctx);
con.AddContext(ctx);
// TODO go into arguments
}

void PropagateResult(LE0Constraint& con, double lb, double ub, Context ctx) {
internal::Unused(con, lb, ub, ctx);
con.AddContext(ctx);
}

void PropagateResult(EQ0Constraint& con, double lb, double ub, Context ctx) {
internal::Unused(con, lb, ub, ctx);
con.AddContext(ctx);
}

Expand Down
2 changes: 2 additions & 0 deletions include/mp/convert/interface_app.h
Expand Up @@ -115,6 +115,8 @@ int InterfaceApp<Interface>::RunFromNLFile(char **argv, int nl_reader_flags) {

template <typename Interface>
bool InterfaceApp<Interface>::Init(char **argv, int nl_reader_flags) {
internal::Unused(nl_reader_flags);

// Parse command-line arguments.
const char *filename = p_option_parser_->Parse(argv);
if (!filename) return false;
Expand Down
4 changes: 2 additions & 2 deletions include/mp/problem.h
Expand Up @@ -635,7 +635,7 @@ class BasicProblem : public ExprFactory, public SuffixManager {
std::size_t new_size = val(SafeInt<int>(vars_.size()) + num_vars);
vars_.reserve(new_size);
is_var_int_.reserve(new_size);
for (size_t i=0; i!=num_vars; ++i) {
for (int i=0; i!=num_vars; ++i) {
vars_.push_back(Var(lb[i], ub[i]));
is_var_int_.push_back(type[i] != var::CONTINUOUS);
}
Expand Down Expand Up @@ -1120,7 +1120,7 @@ class BasicProblem : public ExprFactory, public SuffixManager {
}

template <class Backend>
void PushComplementarityConstraintsTo(Backend& backend) const {
void PushComplementarityConstraintsTo(Backend& ) const {
if (HasComplementarity()) {
throw std::logic_error("mp::Problem cannot push complementarity to a backend yet.");
}
Expand Down
2 changes: 2 additions & 0 deletions include/mp/solver.h
Expand Up @@ -1377,6 +1377,8 @@ int SolverApp<Solver, Reader>::Run(char **argv, int nl_reader_flags) {

template <typename Solver, typename Reader>
bool SolverApp<Solver, Reader>::Init(char **argv, int nl_reader_flags) {
internal::Unused(nl_reader_flags);

// Parse command-line arguments.
const char *filename = option_parser_.Parse(argv);
if (!filename) return false;
Expand Down
2 changes: 1 addition & 1 deletion test/converter-flat-test.h
Expand Up @@ -68,7 +68,7 @@ mp::IteratedExpr MakeIterated(mp::ExprFactory& ef, mp::expr::Kind kind,
const std::vector<int> &args) {
const auto N = args.size();
auto builder = ef.BeginIterated(kind, N);
for (int i = 0; i < N; ++i)
for (size_t i = 0; i < N; ++i)
builder.AddArg( ef.MakeVariable(args[i]) );
return ef.EndIterated(builder);
}
Expand Down

0 comments on commit cffed55

Please sign in to comment.