Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OR tools C++: solver.MutableObjective() returns null

Tags:

c++

null

or-tools

I just inherited a piece of code, which solves a mixed integer programming problem using OR Tools. Integrating OR Tools into VS 2019 was a headache of its own (well, I'm not that used to C++). Now the program is running, but I am getting:

Access violation reading location 0x0000000000000020

According to the debugger, it looks like solver.MutableObjective() is returning null.

Other functions like MakeRowConstraint seem to work fine though, and they don't return null. Any clue what's going on? Could it be something I misconfigured when installing the library maybe?

MPSolver solver("simple_mip_program", MPSolver::SCIP_MIXED_INTEGER_PROGRAMMING);
//...
MPObjective* FObj = solver.MutableObjective(); // <-- NULL

//therefore the below throws exception.
//The arrays `variables` and `F` are populated as expected
for (int i = 0; i < n; i++) FObj->SetCoefficient(variables[i], F[i]);
FObj->SetMaximization();

Edit: A little more details, I am using ORTools 64bit_v8.1.8487, on Windows 10 and Visual Studio 2019.

I also tried running the sample MIP problem from GitHub, and same error occurred on line 54.

like image 456
Anis R. Avatar asked Jun 16 '26 06:06

Anis R.


1 Answers

I have the exactly same settings: ORTools 64bit_v8.1.8487, on Windows 10 and Visual Studio 2019.

To reproduce the question, run the sample code "examples/cpp/linear_programming_example.cc" in Visual Studio 2019. (with .lib and includes/ included into the property.)

I solve the problem by-

  1. changing the C++ compiler to C++17 (default: 14) and
  2. adding flags " /D_SILENCE_CXX17_OLD_ALLOCATOR_MEMBERS_DEPRECATION_WARNING /D_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS " when compiling.
like image 51
IChihWang Avatar answered Jun 18 '26 21:06

IChihWang



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!