LP file format: uses and intricacies

LP is one of the most popular formats for explicit description of an optimization model (the other contender being MPS). It uses an algebraic format where you enter the problem’s objective function and constraints line by line. For the last few years I’ve been using that format quite regularly, and I’d say I both hate and like it.  Here is an example taken from the LPSolve documentation:

Maximize
 obj: x1 + 2 x2 + 3 x3 + x4
Subject To
 c1: - x1 + x2 + x3 + 10 x4 <= 20
 c2: x1 - 3 x2 + x3 <= 30
 c3: x2 - 3.5 x4 = 0
Bounds
 0 <= x1 <= 40
 2 <= x4 <= 3
General
 x4
End

Pros

  • LP file format is really easy to read and write.
  • Most mathematical programming solvers are able to read the format (but see con’s below).

Cons

  • The format’s syntax is a bit fuzzy. Each solver has its own implementation. For instance, CPLEX allows you to omit spaces between coefficients and variables (as in 2X_4) whereas in Gurobi you have to put a space (2 X_4). CPLEX and Gurobi allow unnamed constraints, while Sulum requires you to name each constraint.
  • Large models equals very large files, especially when compared to more compact formats such as AMPL.

Uses for LP files

I use LP files for three things, mostly:

  1. Toy models. It’s really easy and quick to write LP files. If a model is small enough to be written by hand, I’ll use LP.
  2. Prototyping. The format is quite easy to write and read, and errors (especially programming errors) are easier to find.
  3. Sharing models. Since I usually code a LP formulation for most models I create as part of the debugging process, I use the same files when sharing my models with other people.

What do you use LP files for?

Trackbacks

  1. […] were fine, so I did not check the solutions out of Gurobi. What is very ironic is that I wrote a blog post about this very issue less than two years ago and I failed to follow my own advice this time. The corrected LP files are […]

Speak Your Mind

*