您如何使 CBC 在时间限制时返回最佳解决方案? (皮莫)
Posted
技术标签:
【中文标题】您如何使 CBC 在时间限制时返回最佳解决方案? (皮莫)【英文标题】:How you enable CBC to return best solution when timelimit? (Pyomo) 【发布时间】:2020-06-21 01:03:32 【问题描述】:我正在尝试在 Pyomo 上使用 CBC(v2.10.3) 来解决整数线性问题。
在执行求解器时,我当前设置的时间限制为 600 秒。
opt = SolverFactory ("cbc")
opt.options['seconds'] =600
在这个时限内,求解器设法找到多个可行的解决方案。但是,当它在 600 秒结束时超时,它不会返回找到的最佳整数解。相反,它返回一个非整数解。
有没有办法在 pyomo 上使用 CBC 在时间限制结束时返回最佳整数解?
(我知道设置最优差距。但是,最好在给定时间内求解并返回找到的最佳解决方案。)
Cbc0010I After 144000 nodes, 17010 on tree, 51.908959 best solution, best possible 5.2447218 (566.79 seconds)
Cbc0010I After 145000 nodes, 16985 on tree, 51.908959 best solution, best possible 5.2447218 (568.59 seconds)
Cbc0010I After 146000 nodes, 17412 on tree, 51.908959 best solution, best possible 5.2447218 (576.34 seconds)
Cbc0010I After 147000 nodes, 17433 on tree, 51.908959 best solution, best possible 5.2447218 (578.44 seconds)
Cbc0010I After 148000 nodes, 17486 on tree, 51.908959 best solution, best possible 5.2447218 (580.85 seconds)
Cbc0010I After 149000 nodes, 17542 on tree, 51.908959 best solution, best possible 5.2447218 (583.95 seconds)
Cbc0010I After 150000 nodes, 17983 on tree, 51.908959 best solution, best possible 5.2447218 (592.30 seconds)
Cbc0010I After 151000 nodes, 18070 on tree, 51.908959 best solution, best possible 5.2447218 (595.20 seconds)
Cbc0010I After 152000 nodes, 18138 on tree, 51.908959 best solution, best possible 5.2447218 (599.62 seconds)
Cbc0020I Exiting on maximum time
Cbc0005I Partial search - best objective 51.908959 (best possible 5.2447218), took 2633537 iterations and 152193 nodes (600.40 seconds)
Cbc0032I Strong branching done 27294 times (118365 iterations), fathomed 967 nodes and fixed 3958 variables
Cbc0035I Maximum depth 321, 459 variables fixed on reduced cost
0 Obj 3.5097934 Primal inf 30287.686 (125) Dual inf 3.9849334e+15 (82)
Stopped - objective value 4.7188173e+14
Cuts at root node changed objective from 5.22475 to 5.24432
Probing was tried 187648 times and created 142527 cuts of which 0 were active after adding rounds of cuts (35.562 seconds)
Gomory was tried 89556 times and created 384764 cuts of which 0 were active after adding rounds of cuts (40.036 seconds)
Knapsack was tried 361 times and created 4 cuts of which 0 were active after adding rounds of cuts (0.233 seconds)
Clique was tried 361 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.001 seconds)
MixedIntegerRounding2 was tried 89572 times and created 84177 cuts of which 0 were active after adding rounds of cuts (33.927 seconds)
FlowCover was tried 361 times and created 14 cuts of which 0 were active after adding rounds of cuts (0.473 seconds)
TwoMirCuts was tried 89556 times and created 342658 cuts of which 0 were active after adding rounds of cuts (51.857 seconds)
ZeroHalf was tried 361 times and created 136 cuts of which 0 were active after adding rounds of cuts (0.365 seconds)
Result - Stopped on time limit
Objective value: 100000000000000007629769841091887003294964970946560.00000000
Lower bound: 5.245
Gap: 19066788138679049496143571255167978698885048565760.00
Enumerated nodes: 152193
Total iterations: 2633537
Time (CPU seconds): 600.48
Time (Wallclock seconds): 600.48
Total time (CPU seconds): 600.50 (Wallclock seconds): 600.51
感谢您的帮助!
【问题讨论】:
【参考方案1】:我遇到了同样的问题,我想我找到了解决方案。问题是求解器以“已中止”状态退出。有两种方法可以改变求解器的状态:
解决问题后,加载解决方案之前,只需更改状态:
from pyomo.opt.results import SolverStatus
...
optimizer = SolverFactory('cbc')
result = optimizer.solve(prob,tee=True)
result.Solver.Status = SolverStatus.warning
prob.solutions.load_from(result)
在文件“...\pyomo\solvers\plugins\solvers\CBCplugin.py”中,将每个 SolverStatus.aborted 替换为 SolverStatus.warning(在我的情况有2行)。这可以防止求解器处于中止状态。
它适用于我使用 pyomo==5.6.9 和 cbc==2.10.3
【讨论】:
以上是关于您如何使 CBC 在时间限制时返回最佳解决方案? (皮莫)的主要内容,如果未能解决你的问题,请参考以下文章