C. The LP file format

MOSEK supports the LP file format with some extensions i.e. MOSEK can read and write LP formatted files.

C.1. A warning

The LP format is not a well-defined standard and hence different optimization packages may interpretate a specific LP formatted file differently.

C.2. The LP file format

The LP file format can specify problems on the form

\begin{displaymath}\nonumber{}\begin{array}{lccccl}\nonumber{}\mbox{minimize/maximize} &  &  & c^{T}x+\frac{1}{2}q^{o}(x) &  & \\\nonumber{}\mbox{subject to} & l^{c} & \leq{} & Ax+\frac{1}{2}q(x) & \leq{} & u^{c},\\\nonumber{} & l^{x} & \leq{} & x & \leq{} & u^{x},\\\nonumber{} &  &  & x_{\mathcal{J}}\mbox{integer}, &  &\end{array}\end{displaymath}


C.2.1. The sections

An LP formatted file contains a number of sections specifying the objective, constraints, variable bounds, and variable types. The section keywords may be any mix of upper and lower case letters.

C.2.1.1. The objective

The first section beginning with one of the keywords


defines the objective sense and the objective function, i.e.


The objective may be given a name by writing


before the expressions. If no name is given, then the objective is named obj.

The objective function contains linear and quadratic terms. The linear terms are written as in the example

4 x1 + x2 - 0.1 x3

and so forth. The quadratic terms are written in square brackets ([ ]) and are either squared or multiplied as in the examples

x1 ^ 2


x1 * x2

There may be zero or more pairs of brackets containing quadratic expressions.

An example of an objective section is:

  myobj: 4 x1 + x2 - 0.1 x3 + [ x1 ^ 2 + 2.1 x1 * x2 ]/2

Please note that the quadratic expressions are multiplied with [[MathCmd 968]], so that the above expression means

\begin{displaymath}\nonumber{}\mathrm{minimize}4x_{1}+x_{2}-0.1\cdot x_{3}+\frac{1}{2}(x_{1}^{2}+2.1\cdot x_{1}\cdot x_{2})\end{displaymath}

If the same variable occurs more than once in the linear part, the coefficients are added, so that 4 x1 + 2 x1 is equivalent to 6 x1. In the quadratic expressions x1 * x2 is equivalent to x2 * x1 and as in the linear part , if the same variables multiplied or squared occur several times their coefficients are added.

C.2.1.2. The constraints

The second section beginning with one of the keywords

subj to
subject to

defines the linear constraint matrix (A) and the quadratic matrices ([[MathCmd 893]]).

A constraint contains a name (optional), expressions adhering to the same rules as in the objective and a bound:

subject to
  con1: x1 + x2 + [ x3 ^ 2 ]/2 <= 5.1

The bound type (here <=) may be any of <, <=, =, >, >= (< and <= mean the same), and the bound may be any number.

In the standard LP format it is not possible to define more than one bound, but MOSEK supports defining ranged constraints by using double-colon (“::”) instead of a single-colon (“:”) after the constraint name, i.e.

\begin{math}\nonumber{}-5\leq{}x_{1}+x_{2}\leq{}5\end{math} (C.2.3)

may be written as

con:: -5 < x_1 + x_2 < 5

By default MOSEK writes ranged constraints this way.

If the files must adhere to the LP standard, ranged constraints must either be split into upper bounded and lower bounded constraints or be written as en equality with a slack variable. For example the expression (C.2.3) may be written as


C.2.1.3. Bounds

Bounds on the variables can be specified in the bound section beginning with one of the keywords


The bounds section is optional but should, if present, follow the subject to section. All variables listed in the bounds section must occur in either the objective or a constraint.

The default lower and upper bounds are 0 and +. A variable may be declared free with the keyword free, which means that the lower bound is - and the upper bound is +. Furthermore it may be assigned a finite lower and upper bound. The bound definitions for a given variable may be written in one or two lines, and bounds can be any number or [[MathCmd 973]] (written as +inf/-inf/+infinity/-infinity) as in the example

  x1 free
  x2 <= 5
  0.1 <= x2
  x3 = 42
  2 <= x4 < +inf

C.2.1.4. Variable types

The final two sections are optional and must begin with one of the keywords




Under general all integer variables are listed, and under binary all binary (integer variables with bounds 0 and 1) are listed:

  x1 x2
  x3 x4

Again, all variables listed in the binary or general sections must occur in either the objective or a constraint.

C.2.1.5. Terminating section

Finally, an LP formatted file must be terminated with the keyword


C.2.1.6. An example

A simple example of an LP file with two variables, four constraints and one integer variable is:

  -10 x1 -9 x2
subject to
  0.7 x1 +       x2 <= 630
  0.5 x1 + 0.833 x2 <= 600
      x1 + 0.667 x2 <= 708
  0.1 x1 + 0.025 x2 <= 135
  10 <= x1
  x1 <= +inf
  20 <= x2 <= 500

C.2.2. LP format peculiarities

C.2.2.1. Comments

Anything on a line after a “[[MathCmd 974]]” is ignored and is treated as a comment.

C.2.2.2. Names

A name for an objective, a constraint or a variable may contain the letters a-z, A-Z, the digits 0-9 and the characters


The first character in a name must not be a number, a period or the letter 'e' or 'E'. Keywords must not be used as names.

It is strongly recommended not to use double quotes (") in names.

C.2.2.3. Variable bounds

Specifying several upper or lower bounds on one variable is possible but MOSEK uses only the tightest bounds. If a variable is fixed (with =), then it is considered the tightest bound.

C.2.2.4. MOSEK specific extensions to the LP format

Some optimization software packages employ a more strict definition of the LP format that the one used by MOSEK. The limitations imposed by the strict LP format are the following:

  • Quadratic terms in the constraints are not allowed.
  • Names can be only 16 characters long.
  • Lines must not exceed 255 characters in length.

If an LP formatted file created by MOSEK should satisfies the strict definition, then the parameter


should be set; note, however, that some problems cannot be written correctly as a strict LP formatted file. For instance, all names are truncated to 16 characters and hence they may loose their uniqueness and change the problem.

To get around some of the inconveniences converting from other problem formats, MOSEK allows lines to contain 1024 characters and names may have any length (shorter than the 1024 characters).

Internally in MOSEK names may contain any (printable) character, many of which cannot be used in LP names. Setting the parameters




allows MOSEK to use quoted names. The first parameter tells MOSEK to remove quotes from quoted names e.g, "x1", when reading LP formatted files. The second parameter tells MOSEK to put quotes around any semi-illegal name (names beginning with a number or a period) and fully illegal name (containing illegal characters). As double quote is a legal character in the LP format, quoting semi-illegal names makes them legal in the pure LP format as long as they are still shorter than 16 characters. Fully illegal names are still illegal in a pure LP file.

C.2.3. The strict LP format

The LP format is not a formal standard and different vendors have slightly different interpretations of the LP format. To make MOSEK's definition of the LP format more compatible whith the definitions of other vendors use the paramter setting


This setting may lead to truncation of some names and hence to an invalid LP file. The simple solution to this problem is to use the paramter setting


which will cause all names to be renamed systematically in the output file.

C.2.4. Formatting of an LP file

A few parameters control the visual formatting of LP files written by MOSEK in order to make it easier to read the files. These parameters are


The first parameter sets the maximum number of characters on a single line. The default value is 80 corresponding roughly to the width of a standard text document.

The second parameter sets the maximum number of terms per line; a term means a sign, a coefficient, and a name (for example “+ 42 elephants”). The default value is 0, meaning that there is no maximum.

C.2.4.1. Speeding up file reading

If the input file should be read as fast as possible using the least amount of memory, then it is important to tell MOSEK how many non-zeros, variables and constraints the problem contains. These values can be set using the parameters


C.2.4.2. Unnamed constraints

Reading and writing an LP file with MOSEK may change it superficially. If an LP file contains unnamed constraints or objective these are given their generic names when the file is read (however unnamed constraints in MOSEK are written without names).

Wed Oct 21 21:17:32 2015