我刚刚继承了一段代码,它使用 OR 工具解决了一个混合整数规划问题。将 OR 工具集成到 VS 2019 本身就是一件令人头疼的事情(好吧,我不太习惯 C++)。现在程序正在运行,但我得到:
Access violation reading location 0x0000000000000020
根据调试器,看起来 solver.MutableObjective()
正在返回 null。
MakeRowConstraint
等其他函数似乎工作正常,但它们不会返回 null。知道发生了什么事吗?可能是我在安装库时配置错误吗?
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();
编辑:更多细节,我在 Windows 10 和 Visual Studio 2019 上使用 ORTools 64bit_v8.1.8487。
我还尝试运行 sample MIP problem from GitHub , 并且在第 54 行出现了同样的错误。
最佳答案
我有完全相同的设置:ORTools 64bit_v8.1.8487,在 Windows 10 和 Visual Studio 2019 上。
要重现问题,请在 Visual Studio 2019 中运行示例代码“examples/cpp/linear_programming_example.cc”。(属性中包含 .lib 和 includes/。)
我通过-解决问题-
- 将 C++ 编译器更改为 C++17(默认值:14)和
- 添加标志“/D_SILENCE_CXX17_OLD_ALLOCATOR_MEMBERS_DEPRECATION_WARNING/D_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS” 编译时。
关于c++ - OR 工具 C++ : solver. MutableObjective() 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66020741/