添加许多约束时,PuLP非常慢 [英] PuLP very slow when adding many constraints

查看:247
本文介绍了添加许多约束时,PuLP非常慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用PuLP,但是要花 50秒来添加4000个约束(带有67个变量).解决问题只需要几分之一秒.

I'm trying to use PuLP, but it is taking 50 seconds to add 4000 constraints (with 67 variables). Solving the problem only takes a fraction of a second.

我们希望使用PuLP轻松测试大量问题上的多个求解器.

We want to use PuLP to easily test several solvers on a large set of problems.

要花这么长时间的PuLP吗?直接使用PyGLPK只需几分之一秒,包括设置和求解,所以我希望不要.我该怎么做才能提高PuLP中此步骤的效率?

Should it be taking PuLP this long? Using PyGLPK directly takes only a fraction of second including both setup and solving, so I hope not. What can I do to improve the efficiency of this step in PuLP?

更新

我的约束矩阵非常稀疏,并且通过包含非零系数,我能够将此特定问题的建立时间减少到4或5秒.我仍然能够编写自己的.lp或.mps格式的文件,解决cbc或glpsol子进程的问题,并且比PuLP更有效地解析解决方案,这仅仅是因为我可以在输入Pulp时在几毫秒内写入输入文件需要几秒钟.我仍然不确定为什么会这样.

My constraints matrix is very sparse, and I was able to reduce the setup time to 4 or 5 seconds for this particular problem by only including nonzero coefficients. I am still able to write my own .lp or .mps formatted file, solve the problem with a cbc or glpsol subprocess, and parse the solution much more efficiently than PuLP, simply because I can write the input file in a few ms when PuLP takes several seconds. I'm still not sure why this would be.

推荐答案

我的代表不足以发表评论.

I don't have reps enough to comment.

但是您看过这个吗?

https://groups.google.com/forum/#!topic/pulp-or-discuss/p1N2fkVtYyM

问的问题:

"The problem is solved in less than 0.5 second.
However setting it up with PULP takes more than 10 seconds. "

这似乎也是您报告的内容.解决方案是不使用+ =或sum(...)运算符,而是按照链接中的说明进行操作:

This seems to be what you report as well. And the solution is to not use += or sum(...) operators, but instead, as explained in the link as well:

yeah using the += operator with pulp is really slow, as is using sum() 
instead of lpSum()

那么也许您一次将约束1添加到PuLP,而不是先构建约束列表,然后最后将约束添加到PuLP?

So maybe you are adding the constraints 1 at a time to PuLP instead of building the list of constraints first and then, at the end, add the constraints to PuLP?

这篇关于添加许多约束时,PuLP非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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