我想设置一个间隙值 (GAP),以便在当前间隙低于 GAP 时优化过程停止。我已经阅读了 cplex-python
文档,我发现:
Model.parameters.mip.tolerances.absmipgap(GAP)
但我收到下一个警告:
Model.parameters.mip.tolerances.mipgap(float(0.1))
TypeError: 'NumParameter' object is not callable
有什么想法吗?请帮我。提前致谢。
最佳答案
根据您收到的错误,我认为您可能正在使用 CPLEX Python API 而不是 docplex(如其他答案)。要解决您的问题,请考虑以下示例:
import cplex
Model = cplex.Cplex()
# This will raise a TypeError
#Model.parameters.mip.tolerances.mipgap(float(0.1))
# This is the correct way to set the parameter
Model.parameters.mip.tolerances.mipgap.set(float(0.1))
# Write the parameter file to check that it looks as you expect
Model.parameters.write_file("test.prm")
您需要使用set()
方法。您可以通过使用 write_file 将参数文件写入磁盘来确保参数按预期更改。方法和观察。
关于python - 如何在 cplex-python 中设置间隙公差?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56231397/