如何设置 Pyomo 求解器超时? [英] How to set Pyomo solver timeout?

查看:129
本文介绍了如何设置 Pyomo 求解器超时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何设置 Pyomo solve() 方法的超时时间?更具体地说,告诉pyomo,在x秒后,返回当前找到的最优解?

How to set the timeout for Pyomo solve() method ? More specifically, to tell pyomo, after x seconds, return the optimal solution currently found ?

推荐答案

所以我能够通过 pyomo 文档找到答案,我认为分享会有所帮助.

So I was able to find the answer via pyomo documentation and I thought it would be helpful to share.

设置 Pyomo solve() 方法的超时时间:

To set the timeout for Pyomo solve() method:

solver.solve(model, timelimit=5)

然而,如果求解器没有终止,这将抛出 pyutilib.common._exceptions.ApplicationError: "Solver (%s) did not exit normal" % self.name ).我真正想要的是将 timelimit 选项传递给我的求解器.在我的 cplex 求解器的例子中,代码将是这样的:

However this will throw pyutilib.common._exceptions.ApplicationError: "Solver (%s) did not exit normally" % self.name ) if the solver is not terminated. What I really want is to pass the timelimit option to my solver. In my case of cplex solver, the code will be like this:

solver = SolverFactory('cplex')
solver.options['timelimit'] = 5
results = solver.solve(model, tee=True)

更多关于 pyomocplex 文档.

这篇关于如何设置 Pyomo 求解器超时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆