python - 如何在 cplex-python 中设置间隙公差?

标签 python optimization mathematical-optimization modeling cplex

我想设置一个间隙值 (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/

相关文章:

python - 是否建议初学者使用 Python 3.1?

python - 使用 Facebook Prophet 在具有多个时间序列的数据框中进行时间序列预测

mysql - 在 MySQL 中查找间隔行

c++ - Ceres 求解器 : using smooth approximations for non-linear least squares

python - 使用 scipy 最小化也采用非变分参数的函数

java - 实现背包的分支定界

python - 提高 numpy 三角函数运算的性能

python - Twisted Socket 立即发送消息

java - 使用空列表比在java中对列表进行空检查更昂贵吗?

java - 我如何(漂亮地)将这部分代码提取到子类中?