问题描述
我有一个 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 (将#修改为@)