23

A quick search on "python linear programming" turns up a lot of hits (e.g. this one). Looking through them, I see a fair number of complaints about outdated dependencies, poor documentation, etc.

Can anybody recommend a headache-free (e.g. fast, well-documented, easy-to-install, clean API) linear programming library for python?

solvingPuzzles
  • 8,541
  • 16
  • 69
  • 112
Abe
  • 22,738
  • 26
  • 82
  • 111

6 Answers6

10

I'd recommend looking at PULP and/or Pyomo.

solvingPuzzles
  • 8,541
  • 16
  • 69
  • 112
  • 3
    Are these suitable for large instances, lets say at least hundereds of variables and thousands of constraints. – Andreas Mueller Nov 07 '12 at 16:15
  • 1
    Good question. I'm not sure about how PULP and Pyomo scale for large problems. However, I can say that most of my friends who do huge optimization problems (mostly for integrated circuit layouts) use IBM CPLEX as their optimization solver. Based on a quick google search, there is a CPLEX API for Python. However, CPLEX isn't free for non-academic use. – solvingPuzzles Nov 08 '12 at 01:43
  • ...I just checked your stackexchange profile, Andreas, and it looks like you're a graduate student. You can get a free CPLEX license. :) – solvingPuzzles Nov 08 '12 at 01:44
  • @solvingPuzzles, would you know offhand if either of these has an API to NumPy arrays, along the lines `lpmin( x, A, c, lo, hi )` ? – denis Jul 25 '13 at 15:20
  • Good question. I'm not really sure...I haven't hacked around with optimization stuff in a few months, so I'm a bit out of touch at this point. – solvingPuzzles Jul 25 '13 at 20:01
5

cvxopt is written by Lieven Vandenberghe and some of his collaborators. (This is the same Vandenberghe of the widely used convex optimization textbook by Boyd and Vandenberghe.) It's a general convex conic programming solver, and uses an interior point method. On the plus side it's well-documented, has many examples, and is easy to use. I believe it scales fairly well, though not as well as commercial products like Xpress, Gurobi, or cplex.

Looks like there's a pull request to scipy containing a (pure python) linear programming implementation, though. So a linear programming solver could be in scipy in the future.

cjordan1
  • 277
  • 1
  • 4
  • 11
2

You might look at PuLP from the coin-or set of libraries.

http://www.coin-or.org/projects/

Andrew Prock
  • 6,900
  • 6
  • 40
  • 60
1

You can also take a look at or-tools, which includes a wrapper around widely used linear solvers such as GLPK.

simleo
  • 2,775
  • 22
  • 23
1

As of 2015, scipy includes a method to solve linear programming models directly through scipy.optimize.linprog. It uses the Simplex algorithm.

igordsm
  • 464
  • 2
  • 8
1

I don't know what you are specifically trying to do, but NumPy/SciPy are the usually first places to look for anything math related in Python.

guidoism
  • 7,820
  • 8
  • 41
  • 59
  • Numpy is an array library, with some extra functionality tossed in for backwards compatibility. Scipy has some optimization routines, but as of now I think it's only general non-linear solvers. Scipy does not currently have a solver specialized for linear programs. – cjordan1 Jan 23 '13 at 17:43