您如何使CBC在时间限制时返回最佳解决方案?(所罗门)

2024-10-01 22:42:50 发布

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

我试图在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

谢谢你的帮助


Tags: andoftreeonbestnodessecondssolution
1条回答
网友
1楼 · 发布于 2024-10-01 22:42:50

我也有同样的问题,我想我找到了解决办法。问题是解算器退出时状态为“中止”。有两种方法可以更改解算器的状态:

  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)   
    
  2. 在文件“…\pyomo\solvers\plugins\solvers\CBCplugin.py”中,将每个SolverStatus.aborted替换为SolverStatus.warning(在我的例子中有两行)。这可防止解算器处于中止状态

对于我来说,使用pyomo==5.6.9和cbc==2.10.3是可行的

相关问题 更多 >

    热门问题