Skip to content

cplex_interface.cc: Check failed: last_variable_index_ == cols #3757

@rajgoel

Description

@rajgoel

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

Which solver are you using (e.g. CP-SAT, Routing Solver, GLOP, BOP, Gurobi)
CPLEX 22.10

What operating system (Linux, Windows, ...) and version?
Ubuntu Linux 18.04

What did you do?

  • I use the API to create a solver
  #define MIPSOLVER "CPLEX"
  solver = std::unique_ptr<ORTools::MPSolver>( ORTools::MPSolver::CreateSolver(MIPSOLVER) );

and add variables, constraints, and objective function.

  • I can successfully write the model to a file
  std::string MIP;
  solver->ExportModelAsLpFormat(false,&MIP); 
  std::ofstream myfile;
  myfile.open ("MIP.lp");
  myfile << MIP;
  myfile.close();

and solve the problem using the interactive prompt of cplex.

  • When I solve the problem programmtically, however, via
const ORTools::MPSolver::ResultStatus result_status = solver->Solve();

the check in

DCHECK_EQ(last_variable_index_, cols);

fails because last_variable_index_ is zero.

What did you expect to see

The solver should run without problem. It does so if I use

  #define MIPSOLVER "SCIP"
  solver = std::unique_ptr<ORTools::MPSolver>( ORTools::MPSolver::CreateSolver(MIPSOLVER) );

What did you see instead?

I got an error message like this

cplex_interface.cc:866
Check failed: last_variable_index_ == cols (0 vs. 450)

Anything else we should know about your project / environment

When I removed

DCHECK_EQ(last_variable_index_, cols);

and
DCHECK_EQ(last_variable_index_, cols);

the solver worked as expected.

At other places incplex_interface.cc the code can deal with last_variable_index_ being zero, e.g.

CHECK(last_variable_index_ == 0 ||
last_variable_index_ == solver_->variables_.size());

Probably, a similar check should be used in lines 866 and 953.

Possibly the root cause of the problem is here:

// TODO(user): remove this method.
void MPSolverInterface::ResetExtractionInformation() {
sync_status_ = MUST_RELOAD;
last_constraint_index_ = 0;
last_variable_index_ = 0;
solver_->variable_is_extracted_.assign(solver_->variables_.size(), false);
solver_->constraint_is_extracted_.assign(solver_->constraints_.size(), false);
}

as last_variable_index_ is set to zero.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions