MPS format explanation written by John Gregory:


The "readme" file <from netlib> recommends "Advanced Linear Programming" 
by Bruce A. Murtagh, McGraw-Hill, 1981, for documentation of
MPS format. But I can walk you through the main features. 
Here is a model from Linus Schrage, who wrote the commercial 
LINDO code:

NAME    METALS   ( FROM IBM MANUAL) ( MIN)
ROWS
  N VALUE
  E YIELD
  L FE
  L MN
  L CU
  L MG
  G AL
  L SI
COLUMNS
    BIN1      VALUE       0.03         YIELD           1.
    BIN1      FE          0.15         CU             .03
    BIN1      MN          0.02         MG             .02
    BIN1      AL          0.7          SI             .02
    BIN2      VALUE       0.08         YIELD           1.
    BIN2      FE           .04         CU             .05
    BIN2      MN           .04         MG             .03
    BIN2      AL           .75         SI             .06
    BIN3      VALUE       0.17         YIELD         1.
    BIN3      FE           .02         CU             .08
    BIN3      MN           .01         AL             .8
    BIN3      SI           .08
    BIN4      VALUE       0.12         YIELD         1.
    BIN4      FE           .04         CU             .02
    BIN4      MN           .02         AL             .75
    BIN4      SI          0.12
    BIN5      VALUE       0.15         YIELD         1.
    BIN5      FE           .02         CU             .06
    BIN5      MN           .02         MG             .01
    BIN5      SI           .02         AL             .8
    ALUM      VALUE       0.21         YIELD         1.
    ALUM      FE           .01         CU             .01
    ALUM      AL           .97         SI             .01
    SILCON    VALUE       0.38         YIELD         1.
    SILCON    FE           .03         SI             .97
RHS
    ALOY1     YIELD        2000.       FE              60.
    ALOY1     CU            100.       MN              40.
    ALOY1     MG             30.       AL            1500.
    ALOY1     SI            300.
BOUNDS
 UP PROD1     BIN1            200.00
 UP PROD1     BIN2            750.00
 LO PROD1     BIN3            400.00
 UP PROD1     BIN3            800.00
 LO PROD1     BIN4            100.00
 UP PROD1     BIN4            700.00
 UP PROD1     BIN5           1500.00
RANGES
    AL1       SI               50.0
ENDATA

The sections are divided by header cards, which are any
that start in column 1. Any MPS file has the following
structure at least:
NAME
ROWS
COLUMNS
RHS
ENDATA
The BOUNDS and RANGES sets are optional (RANGES sets
are rather uncommon). 

As you expected, MPS format is column-sensitive, just
like a punch card. Fields generally start in columns
1, 5, 15, 25, 40, and 50. Columns 37-39 and 62-beyond
are ignored. Fields starting in columns 25 and 50 are
12 characters wide, to accomodate numerical values,
while the fields in columns 5, 15, and 40 are eight
characters wide (some LP codes permit a full ten
characters, but I think all the Netlib models limit
these fields to eight).

Comment cards are allowed, signified by an asterisk
in column 1, but I don't think any Netlib models have
them.

The contents of the NAME card are irrelvant to your
purposes, and just serve to identify the model. The
ROWS section gives a name (starting in column 5) to 
each row that will appear in the model, and specifies 
the sense of the row in either column 2 or 3. These
entries may be E meaning equality, L meaning less-than,
G meaning greater-than, or N meaning non-constraining
(the first N row is generally taken as the objective
function, and any others can be ignored for your 
purposes). By the way, the default for all the Netlib
set is Minimization, rather than Maximization as your
code expects.

The COLUMNS section is where most of the information
is found, because this is where the contents of the
constraint matrix is entered. Data is segregated by
columns of the matrix, with one or two row entries
per card image. The format is column-name, then row-name
and value, and optionally another row-name and value.

The RHS section is formatted the same way as the 
COLUMNS section, since a right-hand-side is really
just a special column.

The ENDATA card tells the reader the file is complete.

If there is a BOUNDS section, this specifies one or
more sets of bounds for the variables in the problem.
I believe none of the Netlib models has more than one
bounds set. The format is a key in columns 2-3, a
bounds set name in columns 5-14 (just an arbitrary name,
although they should all be the same so that the bounds
will be considered one set), a column name in columns
15-24, and a value in columns 25-36. The key in columns
2-3 can be
  UP     the value field will be an upper bound for the variable
  LO     the value field will be a lower bound for the variable
  FX     equivalent to two UP and LO cards of equal value
  FR     variable is -inf<x<+inf rather than 0<x<+inf
  MI     variable is -inf<x<0 rather than 0<x<+inf
  PL     the default condition of 0<x<+inf

The RANGES section allows a row to have both a lower and
an upper limit. It has a ranges set name in column 5 (again,
I think all the Netlib models will have just one set per
file, though as with BOUNDS you can have multiple entries 
per set), a row name in column 15, and a value in column 25.
(Optionally, another row/value combination in fields 40 and
50.) In the above example, row SI is a < row, with a RHS 
value of 300. The RANGES value of 50 means that the row 
should be constrained thus:
    250 < SI < 300
RANGES can be confusing because the meaning differs depending
on whether the given row is <, >, or =. If < (L), the range
is subtracted and becomes a left-hand limit. If > (G), the
range is added and becomes a right-hand limit. If = (E), 
the meaning depends on the sign of the value field: positive
means add and treat as a right-hand limit; negative means 
subtract and treat as a left-hand limit. No one claims MPS
format is very nice when it comes to RANGES sets, and you
won't miss very much if you ignore them, at least to start 
with.

