使用Python PuLP进行混合整数编程的时间限制 [英] Time limit for mixed integer programming with Python PuLP

查看:131
本文介绍了使用Python PuLP进行混合整数编程的时间限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用 PuLP 解决我感兴趣的特定混合整数线性程序(MIP)但是,随着问题规模的扩大,PuLP花费的时间太长.我希望能够运行求解器一段时间,如果需要花费很长时间才能过早终止它,并获得迄今为止计算出的最佳可行解决方案.我尝试用信号手动计时求解器,但是变量全为"None".

I've been using PuLP to solve a particular mixed integer linear program (MIP) I am interested in. However, as the problem size grows, PuLP is taking too long. I want to be able to run the solver for some time and terminate it prematurely if its taking to long and obtain the best feasible solution so-far computed. I have tried manually timing the solver out with signal, but the variables are all "None".

我看过文档,PuLP似乎不支持此功能,尽管据我了解,它调用的大多数求解器例程都支持.有没有对PuLP施加时间限制的方法?

I've looked at the documentation and PuLP does not seem to support this, though as I understand it, most of the solver routines it calls do. Is there a way to impose a time limit for PuLP?

推荐答案

您可以直接调用在solve()中执行的步骤,而不必直接调用solve().这是使用cplex python api时的示例

Instead of directly calling solve(), you can call the steps executed in solve() yourself. Here is an example while using the cplex python api

#Create your problem
P = pulp.LpProblem()

#Build the solverModel for your preferred
solver = pulp.CPLEX_PY()
solver.buildSolverModel(P)

#Modify the solvermodel
solver.solverModel.parameters.timelimit.set(60)

#Solve P
solver.callSolver(P)
status = solver.findSolutionValues(P)

在buildSolverModel()之后,solver.solverModel包含一个求解器API的实例.然后,您可以使用求解器文档中的所有功能.我使用了cplex,但是可以在gurobi中使用相同的方法,如 http://www.gurobi.com/documentation/7.5/refman/python_parameter_examples.html#PythonParameterExamples

After buildSolverModel(), solver.solverModel contains an instance of the solver API. You can then use all functions from the solver documentation. I used cplex, but the same approach can be used in gurobi as seen http://www.gurobi.com/documentation/7.5/refman/python_parameter_examples.html#PythonParameterExamples

这篇关于使用Python PuLP进行混合整数编程的时间限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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