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

问题描述

我想使用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秒钟后终止,可能会有更高的解决方案值。

(我知道这篇文章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)正在被很好地注册。显然,时间限制并不能解决预解决问题,但是如果预解决过程花费的时间超过十秒钟,我想我会遇到更大的问题。