微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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

我有一个 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% 的差距。但是保存到字典中的值为零。我正在使用:

Pyomo 5.7.2。 古罗比 9.0.2

这个间隙值不是 MipGap 还是一个错误?我查看了完整的solver_info对象,保存在那里的边界会导致正确的间隙,所以我有点困惑。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。