python - 我如何限制 COIN-CBC 的运行时间,因为 maxSeconds 参数似乎对我不起作用?

标签 python linear-programming pulp

我想使用 COIN-CBC(或 PuLP 提供的任何其他免费 MIP 求解器)求解一个小型混合整数程序,但时间限制为 10 秒。但是, maxSeconds 参数似乎对我不起作用。

举个例子,我这​​样调用求解器没有时间限制:

prob.solve(pulp.PULP_CBC_CMD())

我这样调用它有时间限制:

prob.solve(pulp.PULP_CBC_CMD(maxSeconds=10))

前者在 50.89 秒后终止,解值为 15.65287864835175。 后者在 53.53 秒后终止,解值为 15.65287864835175。我预计它会在(大约)10 秒内终止,可能具有更高的解决方案值(value)。

(我知道这篇文章: Time limit for mixed integer programming with Python PuLP 。但它的答案涉及 CPLEX 和 GUROBI,我无法使用它们;我需要一个免费的求解器。)

我做错了什么吗?

最佳答案

感谢您的建议。我想我的问题已经得到解答。

我查看了日志文件。 (为了完整性:我升级到 PuLP 2.3 来这样做,这意味着我现在使用参数 timeLimit 而不是 maxSeconds。)我想我明白发生了什么:也就是说,我认为解决这个问题大约需要 67 秒,并且时间限制不会中断预求解。

这是没有时间限制的日志:

Welcome to the CBC MILP Solver 
Version: 2.9.0 
Build Date: Feb 12 2015 

command line - C:\Users\Dylan\More Programs\WPy64-3771\python-3.7.7.amd64\lib\site-packages\pulp\apis\..\solverdir\cbc\win\64\cbc.exe C:\Users\Dylan\AppData\Local\Temp\17364266f50a4759aa9fb37ebf74bf9a-pulp.mps ratio None allow None threads None presolve on strong None gomory on knapsack on probing on branch printingOptions all solution C:\Users\Dylan\AppData\Local\Temp\17364266f50a4759aa9fb37ebf74bf9a-pulp.sol (default strategy 1)
At line 2 NAME          MODEL
At line 3 ROWS
At line 122856 COLUMNS
At line 613557 RHS
At line 736409 BOUNDS
At line 859260 ENDATA
Problem MODEL has 122851 rows, 122850 columns and 367850 elements
Coin0008I MODEL read with 0 errors
String of None is illegal for double parameter ratioGap value remains 0
String of None is illegal for double parameter allowableGap value remains 0
String of None is illegal for integer parameter threads value remains 0
String of None is illegal for integer parameter strongBranching value remains 5
Option for gomoryCuts changed from ifmove to on
Option for knapsackCuts changed from ifmove to on
Continuous objective value is 15.6529 - 55.52 seconds
Cgl0004I processed model has 122851 rows, 122850 columns (350 integer (350 of which binary)) and 367850 elements
Cbc0038I Initial state - 0 integers unsatisfied sum - 0
Cbc0038I Solution found of 15.6529
Cbc0038I Relaxing continuous gives 15.6529
Cbc0038I Before mini branch and bound, 350 integers at bound fixed and 122500 continuous
Cbc0038I Mini branch and bound did not improve solution (60.18 seconds)
Cbc0038I After 60.41 seconds - Feasibility pump exiting with objective of 15.6529 - took 1.45 seconds
Cbc0012I Integer solution of 15.652879 found by feasibility pump after 0 iterations and 0 nodes (60.56 seconds)
Cbc0001I Search completed - best objective 15.6528786483516, took 0 iterations and 0 nodes (61.35 seconds)
Cbc0035I Maximum depth 0, 0 variables fixed on reduced cost
Cuts at root node changed objective from 15.6529 to 15.6529
Probing was tried 0 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
Gomory was tried 0 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
Knapsack was tried 0 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
Clique was tried 0 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
MixedIntegerRounding2 was tried 0 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
FlowCover was tried 0 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
TwoMirCuts was tried 0 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)

Result - Optimal solution found

Objective value:                15.65287865
Enumerated nodes:               0
Total iterations:               0
Time (CPU seconds):             62.68
Time (Wallclock seconds):       62.68

Option for printingOptions changed from normal to all
Total time (CPU seconds):       66.76   (Wallclock seconds):       66.76

这是有时间限制的日志:

Welcome to the CBC MILP Solver 
Version: 2.9.0 
Build Date: Feb 12 2015 

command line - C:\Users\Dylan\More Programs\WPy64-3771\python-3.7.7.amd64\lib\site-packages\pulp\apis\..\solverdir\cbc\win\64\cbc.exe C:\Users\Dylan\AppData\Local\Temp\df26386989ec445da5518920510d3869-pulp.mps sec 10 ratio None allow None threads None presolve on strong None gomory on knapsack on probing on branch printingOptions all solution C:\Users\Dylan\AppData\Local\Temp\df26386989ec445da5518920510d3869-pulp.sol (default strategy 1)
At line 2 NAME          MODEL
At line 3 ROWS
At line 122856 COLUMNS
At line 613557 RHS
At line 736409 BOUNDS
At line 859260 ENDATA
Problem MODEL has 122851 rows, 122850 columns and 367850 elements
Coin0008I MODEL read with 0 errors
seconds was changed from 1e+100 to 10
String of None is illegal for double parameter ratioGap value remains 0
String of None is illegal for double parameter allowableGap value remains 0
String of None is illegal for integer parameter threads value remains 0
String of None is illegal for integer parameter strongBranching value remains 5
Option for gomoryCuts changed from ifmove to on
Option for knapsackCuts changed from ifmove to on
Continuous objective value is 15.6529 - 56.17 seconds
Cgl0004I processed model has 122851 rows, 122850 columns (350 integer (350 of which binary)) and 367850 elements
Cbc0020I Exiting on maximum time
Cbc0005I Partial search - best objective 1e+050 (best possible 15.652879), took 0 iterations and 0 nodes (60.49 seconds)
Cbc0035I Maximum depth 0, 0 variables fixed on reduced cost
Cuts at root node changed objective from 15.6529 to 15.6529
Probing was tried 0 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
Gomory was tried 0 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
Knapsack was tried 0 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
Clique was tried 0 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
MixedIntegerRounding2 was tried 0 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
FlowCover was tried 0 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
TwoMirCuts was tried 0 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)

Result - Stopped on time limit

No feasible solution found
Lower bound:                    15.653
Enumerated nodes:               0
Total iterations:               0
Time (CPU seconds):             64.34
Time (Wallclock seconds):       64.34

Option for printingOptions changed from normal to all
Total time (CPU seconds):       68.37   (Wallclock seconds):       68.37

从第二条日志中,我们可以看到确实超过了时间限制并得到了确认,并且 CBC 在没有找到可行解决方案的情况下退出,尽快退出。我们还从第一个日志中看到,根本没有进行任何分支:显然,问题已得到解决,这花了大约 67 秒。

这回答了我的问题:maxSeconds(或 timeLimit)正在注册得很好。显然,时间限制并不会阻止预求解,但我想如果预求解需要超过十秒,我就会遇到更大的问题。

关于python - 我如何限制 COIN-CBC 的运行时间,因为 maxSeconds 参数似乎对我不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64211972/

相关文章:

python - 使用 Python PuLP 进行混合整数编程的时间限制

python - PuLP 中的线性整数优化

python - 由于缺少 pandoc,构建文档失败

python - Pandas df.describe() - 如何将值提取到 Dataframe 中?

algorithm - 带有扭曲的二分匹配

linear-programming - 最大化给定场景的效益

python-3.x - 为什么 PulP 对于混合问题返回负值,而 lowBound 设置为零?

python - 无法在 Anaconda 中安装 PuLP,出现 unsatisfiableError

python - anaconda3/bin/python : undefined symbol: archive_errno

python - 用于 python 脚本的 iTunes API