user24562 - 3 years ago 125

Python Question

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.

.

I'm using Python 3.2, numpy, and matplotlib. Are there better modules for linear programming in Python?

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

**UPDATE:** The answer has become somewhat outdated in the past 4 years,
here is an update. You have many options:

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?I personally use Gurobi these days through its Python API. It is a commercial, closed-source product but free for academic research.

SciPy offers linear programming: scipy.optimize.linprog. (I have never tried this one.)

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.

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!

You can find other possibilites at in the Wikibook under GLPK/Python. Note that many of these are not necessarily resticted to GLPK.

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**