Skip to content

Math-opt gurobi: SafeGurobiDouble/GRB_INFINITY only checked for lhs/rhs, but not coefficients? #4969

@sschnug

Description

@sschnug

What version of OR-Tools and what language are you using?
Version: main.
Language: C++

The gurobi-wrapper in math-opt has this helper:

absl::Status SafeGurobiDouble(const double d) {
  if (std::isfinite(d) && std::abs(d) >= GRB_INFINITY) {
    return util::InvalidArgumentErrorBuilder()
           << "finite value: " << d << " will be treated as infinite by Gurobi";
  }
  return absl::OkStatus();
}

It's used to guard against finite-but-out-of-range values like 1e123 while:

#define GRB_INFINITY 1e100

These checks ARE EXECUTED in:

  • GurobiSolver::AddNewLinearConstraints
  • GurobiSolver::AddNewQuadraticConstraints
  • GurobiSolver::AddNewIndicatorConstraints

but are only applied to lhs/rhs.

These checks ARE NOT EXECUTED in:

  • GurobiSolver::ChangeCoefficients

Now while i think gurobi-tests are not part of the public repository, there is gscip_solver_test.cc and this test:

TEST(GScipSolverTest, InvalidCoefficient) {
  Model model;
  const Variable x = model.AddVariable("x");
  model.Maximize(x);
  model.AddLinearConstraint(1.0e123 * x <= 2.0, "broken constraint");
  EXPECT_THAT(Solve(model, SolverType::kGscip),
              StatusIs(absl::StatusCode::kInvalidArgument,
                       HasSubstr("broken constraint")));
}

My claim: (which i can't check as i have no access to gurobi):

  • The gurobi wrapper would fail for this test or problems with the same problematic coefficients

(might also be relevant for objective coefficients which i did not check)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions