Python中的线性编程? [英] linear programming in python?
问题描述
我需要建立一个线性规划模型.这是我正在使用的不平等现象(例如):
I need to make a linear programming model. Here are the inequalities I'm using (for example):
6x + 4y <= 24
x + 2y <= 6
-x + y <= 1
y <= 2
我需要找到由这些不等式描述的区域,并在图形中对其进行阴影处理,并跟踪该区域的边界线的顶点,并以不同的颜色绘制边界线.请参见下图,以了解我要寻找的示例.
I need to find the area described by these inequalities, and shade it in a graph, as well as keep track of the vertices of the bounding lines of this area, and draw the bounding line in a different color. See the graph below for an example of what I'm looking for.
.
我正在使用Python 3.2,numpy和matplotlib.是否有更好的Python线性编程模块?
I'm using Python 3.2, numpy, and matplotlib. Are there better modules for linear programming in Python?
推荐答案
更新:在过去的4年中,答案已经有些过时了, 这是一个更新.您有很多选择:
UPDATE: The answer has become somewhat outdated in the past 4 years, here is an update. You have many options:
-
如果您不需要 使用Python,则它更容易实现 以建模语言进行此操作,请参见解决问题的任何好的工具 Linux上的整数程序?
If you do not have to do it Python then it is a lot more easier to do this in a modeling langage, see Any good tools to solve integer programs on linux?
我个人使用 Gurobi 这些 天通过其Python API.这是一个商业的,封闭源代码的 产品,但可免费用于学术研究.
I personally use Gurobi these days through its Python API. It is a commercial, closed-source product but free for academic research.
SciPy提供了线性编程: scipy. optimize.linprog . (我有 从来没有尝试过这个.)
SciPy offers linear programming: scipy.optimize.linprog. (I have never tried this one.)
使用 PuLP ,您可以创建 LP文件,然后 通过他们的GLPK,COIN CLP/CBC,CPLEX或XPRESS解决他们 命令行界面.这种方法有其优点,并且 缺点.
With PuLP you can create MPS and LP files and then solve them with GLPK, COIN CLP/CBC, CPLEX, or XPRESS through their command-line interface. This approach has its advantages and disadvantages.
显然, CVXOPT 提供了 GLPK 8年了,我可以 强烈推荐GLPK. CVXOPT的示例和教程看起来非常好!
Apparently, CVXOPT offers a Python interface to GLPK, I did not know that. I have been using GLPK for 8 years now and I can highly recommend GLPK. The examples and tutorial of CVXOPT seem really nice!
您可以在Wikibook的以下位置找到其他可能性 GLPK/Python .请注意,其中许多未必会被限制 到GLPK.
You can find other possibilites at in the Wikibook under GLPK/Python. Note that many of these are not necessarily resticted to GLPK.
这篇关于Python中的线性编程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!