我如何限制COINCBC的运行时间,因为maxSeconds参数似乎不适合我?

2024-05-17 05:07:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用COIN-CBC(或任何其他免费的MIP解算器,可从纸浆中获得)解决一个小的ish混合整数程序,但时间限制为,比如说,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,我不能使用它们;我需要一个免费的解算器。)

我做错什么了吗


Tags: cmd时间整数解决方案纸浆pulp算器coin
1条回答
网友
1楼 · 发布于 2024-05-17 05:07:25

谢谢你的建议。我想我的问题得到了回答

我查看了日志文件。(为了完整性:我升级到了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)正在注册中。显然,时间限制并没有切断预解,但我想如果预解时间超过10秒,我会遇到更大的问题

相关问题 更多 >