当pyomo模型因时间限制而停止时保存当前间隙

2024-06-30 11:20:23 发布

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

我有一个pyomo模型,我想比较一下正常情况下求解它和通过算法生成的简化模型的性能。我想设置一个时间限制,看看哪一个先完成,或者如果一个或两个都没有在时间限制内完成,两个模型中的哪一个通过保存间隙值达到了更好的解决方案

当前我的代码如下所示:

solver_info = optimizer.solve(self.pyM, warmstart=warmstartHeuristic, tee=True, load_solutions=False)
self.solverSpecs['gap'] = solver_info.solution(0).gap
self.pyM.solutions.load_from(solver_info)

第二行代码应该保存间隙值。我对正常求解模型的测试示例使用以下行结束了gurobi的优化:

    Nodes    |    Current Node    |     Objective Bounds      |     Work
 Expl Unexpl |  Obj  Depth IntInf | Incumbent    BestBd   Gap | It/Node Time

     0     0 21125.0674    0    5          - 21125.0674      -     -   60s
H    0     0                    192740.94072 21125.0674  89.0%     -  227s

Explored 1 nodes (56138 simplex iterations) in 300.02 seconds
Thread count was 3 (of 4 available processors)

Solution count 1: 192741 

Time limit reached
Best objective 1.927409407219e+05, best bound 2.112506743254e+04, gap 89.0397%
WARNING: Loading a SolverResults object with an 'aborted' status, but
    containing a solution

Status: aborted
Return code: 0
Message: Optimization terminated because the time expended exceeded the value specified in the TimeLimit parameter.
Termination condition: maxTimeLimit
Termination message: Optimization terminated because the time expended exceeded the value specified in the TimeLimit parameter.
Wall time: 300.0222430229187
Error rc: 0
Time: 301.3100845813751

这说明解决方案的差距在90%左右。但是保存到字典中的值为零。我正在使用:

俾莫5.7.2。 古罗比9.0.2

这个间隙值不是MipGap吗,还是一个bug?我查看了完整的solver_info对象,保存在那里的边界将产生正确的间距,因此我有点困惑


Tags: the代码in模型selfinfotime时间