MPS format

MPS format is the oldest and most widely used format for storing math programming models. There are actually two variants of this format in wide use. In fixed format, the various fields must always start at fixed columns in the file. Free format is very similar, but the fields are separated by whitespace characters instead of appearing in specific columns. One important practical difference between the two formats is in name length. In fixed format, row and column names are exactly 8 characters, and spaces are part of the name. In free format, names can be arbitrarily long (although the Gurobi reader places a 255 character limit on name length), and names may not contain spaces. The Gurobi MPS reader reads both MPS types, and recognizes the format automatically.

Note that any line that begins with the * character is a comment. The contents of that line are ignored.

NAME section

The first section in an MPS format file is the NAME section. It gives the name of the model:

NAME        AFIRO
In fixed format, the model name starts in column 15.

ROWS section

The next section is the ROWS section. It begins with the word ROWS on its own line, and continues with one line for each row in the model. These lines indicate the constraint type (E for equality, L for less-than-or-equal, or G for greater-than-or-equal), and the constraint name. In fixed format, the type appears in column 2 and the row name starts in column 5. Here's a simple example:

ROWS
 E  R09
 E  R10
 L  X05
 N  COST
Note that an N in the type field indicates that the row is a free row. The first free row is used as the objective function.

If the file includes multiple N rows, each including a priority, weight, relative, and absolute tolerance field, then each such row is treated as an objective in a multi-objective model. The additional fields must appear after the name, separated by spaces. For example, the following would capture a pair of objectives, where the first has priority 2 and the second has priority 1 (and both have identical weights, and relative and absolute tolerances):

 N  OBJ0 2 1 0 0
 N  OBJ1 1 1 0 0
Please refer to the multi-objective, ObjNPriority, ObjNWeight, ObjNAbsTol, and ObjNRelTol sections for information on the meanings of these fields. Note that all objectives of a multi-objective optimization problem have to be linear.

LAZYCONS section

The next section is the LAZY CONSTRAINT section. It begins with the line LAZYCONS, optional followed by a space and a laziness level 1-3 (if no laziness level is specified 1 is assumed), and continues with one line for each lazy constraint. The format is the same as that of the ROWS section: each line indicates the constraint type (E for equality, L for less-than-or-equal, or G for greater-than-or-equal), and the constraint name. In fixed format, the type appears in column 2 and the row name starts in column 5. For example:

LAZYCONS
 E  R01
 G  R07
 L  S01
LAZYCONS 2
 E  R02
 G  R03
 L  S11

Lazy constraints are linear constraints, and they are semantically equivalent to standard linear constraints (i.e., entries in the ROWS section). Depending on their laziness level they are enforced differently by the MIP solver. Please refer to the description of the Lazy attribute for details.

This section is optional.

COLUMNS section

The next and typically largest section of an MPS file is the COLUMNS section, which lists the columns in the model and the non-zero coefficients associated with each. Each line in the columns section provides a column name, followed by either zero, one, or two non-zero coefficients from that column. Coefficients are specified using a row name first, followed by a floating-point value. Consider the following example:

COLUMNS
    X01         X48           .301   R09         -1.
    X01         R10          -1.06   X05          1.
    X02         X21            -1.   R09          1.
    X02         COST           -4.
The first line indicates that column X01 has a non-zero in row X48 with coefficient .301, and a non-zero in row R09 with coefficient -1.0. Note that multiple lines associated with the same column must be contiguous in the file.

In fixed format, the column name starts in column 5, the row name for the first non-zero starts in column 15, and the value for the first non-zero starts in column 25. If a second non-zero is present, the row name starts in column 40 and the value starts in column 50.

Integrality markers

The COLUMNS section can optionally include integrality markers. The variables introduced between a pair of markers must take integer values. All variables within markers will have a default lower bound of 0 and a default upper bound of 1 (other bounds can be specified in the BOUNDS section). The beginning of an integer section is marked by an INTORG marker:

    MARK0000  'MARKER'                 'INTORG'
The end of the section is marked by an INTEND marker:
    MARK0000  'MARKER'                 'INTEND'
The first field (beginning in column 5 in fixed format) is the name of the marker (which is ignored). The second field (in column 15 in fixed format) must be equal to the string 'MARKER' (including the single quotes). The third field (in column 40 in fixed format) is 'INTORG' at the start and 'INTEND' at the end of the integer section.

The COLUMNS section can contain an arbitrary number of such marker pairs.

RHS section

The next section of an MPS file is the RHS section, which specifies right-hand side values. Each line in this section may contain one or two right-hand side values.

RHS
    B           X50           310.   X51          300.
    B           X05            80.   X17           80.
The first line above indicates that row X50 has a right-hand side value of 310, and X51 has a right-hand side value of 300. In fixed format, the variable name for the first bound starts in column 15, and the first bound value starts in column 25. For the second bound, the variable name starts in column 40 and the value starts in column 50. The name of the RHS is specified in the first field (column 5 in fixed format), but this name is ignored by the Gurobi reader. If a row is not mentioned anywhere in the RHS section, that row takes a right-hand side value of 0.

BOUNDS section

The next section in an MPS file is the optional BOUNDS section. By default, each variable takes a lower bound of 0 and an infinite upper bound. Each line in this section can modify the lower bound of a variable, the upper bound, or both. Each line indicates a bound type (in column 2 in fixed format), a bound name (ignored), a variable name (in column 15 in fixed format), and a bound value (in columns 25 in fixed format). The different bound types, and the meaning of the associate bound value, are as follows:

LO lower bound
UP upper bound
FX variable is fixed at the specified value
FR free variable (no lower or upper bound)
MI infinite lower bound
PL infinite upper bound
BV variable is binary (equal 0 or 1)
LI lower bound for integer variable
UI upper bound for integer variable
SC upper bound for semi-continuous variable

Consider the following example:

BOUNDS
 UP BND         X50            80.
 LO BND         X51            20.
 FX BND         X52            30.
In this BOUNDS section, variable X50 gets a upper bound of 80 (lower bound is unchanged at 0, X51 gets a lower bound of 20 (infinite upper bound is unchanged), and X52 is fixed at 30.

QUADOBJ section

The next section in an MPS file is the optional QUADOBJ section, which contains quadratic objective terms. Each line in this section represents a single non-zero value in the lower triangle of the Q matrix. The names of the two variable that participate in the quadratic term are found first (starting in columns 5 and 15 in fixed format), followed by the numerical value of the coefficient (in column 25 in fixed format). By convention, the Q matrix has an implicit one-half multiplier associated with it. Here's an example containing three quadratic terms:

QUADOBJ
    X01       X01       10.0
    X01       X02       2.0
    X02       X02       2.0
These three terms would represent the quadratic function <span>$</span>(10 X01^2 + 2 X01 * X02 + 2 X02 * X01 + 2 X02^2)/2<span>$</span> (recall that the single off-diagonal term actually represents a pair of non-zero values in the symmetric Q matrix).

QCMATRIX section

The next section in an MPS file contains zero or more QCMATRIX blocks. These blocks contain the quadratic terms associated with the quadratic constraints. There should be one block for each quadratic constraint in the model.

Each QCMATRIX block starts with a line that indicates the name of the associated quadratic constraint (starting in column 12 in fixed format). This is followed by one of more quadratic terms. Each term is described on one line, which gives the names of the two involved variables (starting in columns 5 and 15 in fixed format), followed by the coefficient (in column 25 in fixed format). For example:

QCMATRIX   QC0
    X01       X01       10.0
    X01       X02       2.0
    X02       X01       2.0
    X02       X02       2.0
These four lines describe three quadratic terms: quadratic constraint QC0 contains terms <span>$</span>10 X01^2<span>$</span>, <span>$</span>4 X01*X02<span>$</span>, and <span>$</span>2 X02^2<span>$</span>. Note that a QCMATRIX block must contain a symmetric matrix, so for example an X01*X02 term must be accompanied by a matching X02*X01 term.

Linear terms for quadratic constraint QC0 appear in the COLUMNS section. The sense and right-hand side value appear in the ROWS and RHS sections, respectively.

PWLOBJ section

The next section in an MPS file is the optional PWLOBJ section, which contains piecewise-linear objective functions. Each line in this section represents a single point in a piecewise-linear objective function. The name of the associated variable appears first (starting in column 4), followed by the x and y coordinates of the point (starting in columns 14 and 17). Here's an example containing two piecewise-linear expressions, for variables X01 and X02, each with three points:

   X01       1  1
   X01       2  2
   X01       3  4
   X02       1  1
   X02       3  5
   X02       7  10

SOS section

The next section in an MPS file is the optional SOS section. The representation for a single SOS constraint contains one line that provides the type of the SOS set (S1 for SOS type 1 or S2 for SOS type 2, found in column 2 in fixed format) and the name of the SOS set (column 5 in fixed format) of the SOS set. This is followed by one line for each SOS member. The member line gives the name of the member (column 5 in fixed format) and the associated weight (column 15 in fixed format). Here's an example containing two SOS2 sets.

SOS
 S2 sos1
    x1           1
    x2           2
    x3           3
 S2 sos2
    x3           1
    x4           2
    x5           3

Indicator Constraint section

The indicator constraint section is optional in the MPS format. It starts with the keyword INDICATORS. Each subsequent line of the indicator section starts with the keyword IF (placed at column 2 in fixed format) followed by a space and a row name (the row must have already been defined in the ROWS section). The line continues with a binary variable (placed at column 15 in fixed format) and finally a value 0 or 1 (placed at column 25 in fixed format).

Here a simple example:

INDICATORS
 IF row1      x1        0
 IF row2      y1        1

The first indicator constraint in this example states that row1 has to be fulfilled if the x1 takes a value of 0.

General Constraint section

An MPS file may contain an optional section that captures more general constraints. The general constraint section starts with the keyword GENCONS.

Each general constraint in this section starts with a general constraint type specifier, such as MIN, MAX, OR, AND, or ABS (found in column 2 in fixed format). Optionally a space and a name may follow.

What follows this line depends on the general constraint type. All general constraints start with the so-called resultant variable, placed on it's own line (starting at column 5 in fixed format). For MIN or MAX constraints, a non empty list of variables or values follows this (each on its own line). For OR and AND constraints, a list of binary variables follows (each on its own line). For ABS constraints, one additional variable follows (on its own line). In fixed format all of these variables or values are placed at column 5.

The other general constraint type, the INDICATOR constraint, appears in a separate Indicator section, which is described above.

The following shows an example of a general constraint section:

GENCONS
 MAX gc0
    r1
    x1
    x2
    x10
    0.7
 MIN gencons1
    r2
    y0
    10
    y1
    r1
 AND and1
    r
    b1
    b2
 OR or1
    r
    b3
    b4
 ABS GC14
    xabs
    x

For more information, consult the general constraint discussion.

ENDATA

The final line in an MPS file must be an ENDATA statement.

Additional notes

Note that in the Gurobi optimizer, MPS models are always written in full precision. That means that if you write a model and then read it back, the data associated with the resulting model will be bit-for-bit identical to the original data.

Try Gurobi for Free

Choose the evaluation license that fits you best, and start working with our Expert Team for technical guidance and support.

Evaluation License
Get a free, full-featured license of the Gurobi Optimizer to experience the performance, support, benchmarking and tuning services we provide as part of our product offering.
Academic License
Gurobi supports the teaching and use of optimization within academic institutions. We offer free, full-featured copies of Gurobi for use in class, and for research.
Cloud Trial

Request free trial hours, so you can see how quickly and easily a model can be solved on the cloud.

Search