READ_MPS

This subroutine reads an MPS file containing a linear programming problem or a quadratic programming problem.

Required Arguments

FILENAME — Character string containing the name of the MPS file to be read. (Input)

MPS— A structure of IMSL defined derived type s_MPS containing the data read from the MPS file. (Output)

The IMSL defined derived type s_MPS consists of the following components:

Component | Description | |
---|---|---|

character, allocatable :: filename | Name of the MPS file. | |

character (len=8) name | Name of the problem. | |

integer nrows | Number of rows in the constraint matrix. | |

integer ncolumns | Number of columns in the constraint matrix. This is also the number of variables. | |

integer nonzeros | Number of non-zeros in the constraint matrix. | |

integer nhessian | Number of non-zeros in the Hessian matrix. If zero, then there is no Hessian matrix. | |

integer ninteger | Number of variables required to be integer. This includes binary variables. | |

integer nbinary | Number of variables required to be binary (0 or 1). | |

real (kind(1e0)), allocatable :: objective(:) | A real array of length ncolumns containing the objective vector. | |

type (s_SparseMatrixElement), allocatable :: constraint(:) | A derived type array of length nonzeros and of type s_SparseMatrixElement containing the sparse matrix representation of the constraint matrix. See below for details. | |

type(s_SparseMatrixElement), allocatable :: hessian(:) | A derived type array of length nhessian and of type s_SparseMatrixElement containing the sparse matrix representation of the Hessian matrix. If nhessian is zero, then this field is not allocated. | |

real (kind(1e0)), allocatable ::lower_range(:) | A real array of length nrows containing the lower constraint bounds. If a constraint is unbounded below, the corresponding entry in lower_range is set to negative_infinity, defined below. | |

real (kind(1e0)), allocatable ::upper_range(:) | A real array of length nrows containing the upper constraint bounds. If a constraint is unbounded above, the corresponding entry in upper_range is set to positive_infinity, defined below. | |

real (kind(1e0)), allocatable :: lower_bound(:) | A real array of length ncolumns containing the lower variable bounds. If a variable is unbounded below, the corresponding entry in lower_bound is set to negative_infinity, defined below. | |

real (kind(1e0)), allocatable :: upper_bound(:) | A real array of length ncolumns containing the upper variable bounds. If a variable is unbounded above, the corresponding entry in upper_bound is set to positive_infinity, defined below. | |

integer, allocatable :: variable_type(:) | An integer array of length ncolumns containing the type of each variable. Variable types are: | |

0 | Continuous | |

1 | Integer | |

2 | Binary (0 or 1) | |

4 | Semicontinuous | |

character (len=8) name_objective | Name of the set in ROWS used for the objective row. | |

character (len=8) name_rhs | Name of the RHS set used. | |

character (len=8) name_ranges | Name of the RANGES set used or the empty string if no RANGES section in the file. | |

character (len=8) name_bounds | Name of the BOUNDS set used or the empty string if no BOUNDS section in the file. | |

character (len=8), allocatable :: name_row(:) | Array of length nrows containing the row names. The name of the i-th constraint row is name_row(i). | |

character (len=8), allocatable :: name_column(:) | Array of length ncolumns containing the column names. The name of the i-th column and variable is name_column(i). | |

real (kind (1e0)) positive_infinity | Value used for a constraint or bound upper limit when the constraint or bound is unbounded above. This can be set using an optional argument. Default is 1.0e+30. | |

real (kind (1e0)) negative_infinity | Value used for a constraint or bound lower limit when the constraint or bound is unbounded below. This can be set using an optional argument. Default is -1.0e+30. |

This derived type stores the constraint and Hessian matrices in a simple sparse matrix format of derived type s_SparseMatrixElement defined in the interface module mp_types. s_SparseMatrixElement consists of three components; a row index, a column index, and a value. For each non-zero element in the constraint and Hessian matrices an element of derived type s_SparseMatrixElement is stored. The following code fragment expands the sparse constraint matrix of the derived type s_SparseMatrixElement contained in mps, a derived type of type s_MPS, into a dense matrix:

! allocate a matrix

integer nr = mps%nrows

integer nc = mps%ncolumns

real (kind(1e0)), allocatable :: matrix(:,:)

allocate(matrix(nr,nc))

matrix = 0.0e0

! expand the sparse matrix

do k = 1, mps%nonzeros

i = mps%constraint(k)%row

j = mps%constraint(k)%column

matrix(i,j) = mps%constraint(k)%value

end do

The IMSL derived type d_MPS is the double precision counterpart to s_MPS. The IMSL derived type d_SparseMatrixElement is the double precision counterpart to s_SparseMatrixElement.

To release the space allocated for this derived type use the following statement:

call mps_free(mps)

Optional Arguments

NUNIT— The unit number for reading an MPS file opened by the user. If NUNIT is not used, this subroutine opens the file indicated by FILENAME for reading and then closes it after reading. (Input)

By default, 7 is used.

By default, 7 is used.

OBJ — Character string of length 8 containing the name of the objective function set to be used. (Input)

An MPS file can contain multiple objective function sets.

By default, the first objective function set in the MPS file is used. This name is case sensitive.

By default, the first objective function set in the MPS file is used. This name is case sensitive.

RHS — Character string of length 8 containing the name of the RHS set to be used. (Input)

An MPS file can contain multiple RHS sets.

By default, the first RHS set in the MPS file is used. This name is case sensitive.

An MPS file can contain multiple RHS sets.

By default, the first RHS set in the MPS file is used. This name is case sensitive.

RANGES — Character string of length 8 containing the name of the RANGES set to be used. (Input)

An MPS file can contain multiple RANGES sets.

By default, the first RANGES set in the MPS file is used. This name is case sensitive.

An MPS file can contain multiple RANGES sets.

By default, the first RANGES set in the MPS file is used. This name is case sensitive.

BOUNDS — Character string of length 8 containing the name of the BOUNDS set to be used. (Input)

An MPS file can contain multiple BOUNDS sets.

By default, the first BOUNDS set in the MPS file is used. This name is case sensitive.

An MPS file can contain multiple BOUNDS sets.

By default, the first BOUNDS set in the MPS file is used. This name is case sensitive.

POS_INF — Value used for a constraint or bound upper limit when the constraint or bound is unbounded above. (Input)

Default: 1.0e+30.

Default: 1.0e+30.

NEG_INF — Value used for a constraint or bound lower limit when the constraint or bound is unbounded below. (Input)

Default: -1.0e+30.

Default: -1.0e+30.

FORTRAN 90 Interface

Generic: CALL READ_MPS (FILENAME, MPS [, …])

Specific: The specific interface names are S_READ_MPS and D_READ_MPS.

Description

An MPS file defines a linear or quadratic programming problem.

A linear programming problem is assumed to have the form:

A quadratic programming problem is assumed to have the form:

The following table maps this notation into the components in the derived type returned by READ_MPS:

C | Objective |

A | Constraint |

Q | Hessian |

bl | lower_range |

bu | upper_range |

xl | lower_bound |

xu | upper_bound |

If the MPS file specifies an equality constraint or bound, the corresponding lower and upper values in the returned derived type will be exactly equal.

The problem formulation assumes that the constraints and bounds are two-sided. If a particular constraint or bound has no lower limit, then the corresponding component of the derived type is set to -1.0e+30. If the upper limit is missing, then the corresponding component of the derived type is set to +1.0e+30.

MPS File Format

There is some variability in the MPS format. This section describes the MPS format accepted by this reader.

An MPS file consists of a number of sections. Each section begins with a name in column 1. With the exception of the NAME section, the rest of this line is ignored. Lines with a ‘*’ or ‘$’ in column 1 are considered comment lines and are ignored.

The body of each section consists of lines divided into fields, as follows:

Field Number | Columns | Contents |
---|---|---|

1 | 2-3 | Indicator |

2 | 5-12 | Name |

3 | 15-22 | Name |

4 | 25-36 | Value |

5 | 40-47 | Name |

6 | 50-61 | Value |

The format limits MPS names to 8 characters and values to 12 characters. The names in fields 2, 3 and 5 are case sensitive. Leading and trailing blanks are ignored, but internal spaces are significant.

The sections in an MPS file are as follows.

NAME

ROWS

COLUMNS

RHS

RANGES (optional)

BOUNDS (optional)

QUADRATIC (optional)

ENDATA

Sections must occur in the above order.

MPS keywords, section names and indicator values, are case insensitive. Row, column and set names are case sensitive.

NAME Section

The NAME section contains a single line. A problem name can occur anywhere on the line after NAME and before column 62. The problem name is truncated to 8 characters.

ROWS Section

The ROWS section defines the name and type for each row. Field 1 contains the row type and field 2 contains the row name. Row type values are not case sensitive. Row names are case sensitive. The following row types are allowed:

Row Type | Meaning |
---|---|

E | Equality Constraint. |

L | Less than or equal constraint |

G | Greater than or equal constraint. |

N | Objective or a free row. |

COLUMNS Section

The COLUMNS section defines the nonzero entries in the objective and the constraint matrix. The row names here must have been defined in the ROWS section.

Field | Contents |
---|---|

2 | Column name. |

3 | Row name. |

4 | Value for the entry whose row and column are given by fields 3 and 2. |

5 | Row name. |

6 | Value for the entry whose row and column are given by fields 5 and 2. |

NOTE: Fields 5 and 6 are optional. |

The COLUMNS section can also contain markers. These are indicated by the name ‘MARKER’ (with the quotes) in field 3 and the marker type in field 4 or 5.

Marker type ‘INTORG’ (with the quotes) begins an integer group. The marker type ‘INTEND’ (with the quotes) ends this group. The variables corresponding to the columns defined within this group are required to be integer.

RHS Section

The RHS section defines the right-hand side of the constraints. An MPS file can contain more than one RHS set, distinguished by the RHS set name. The row names here must be defined in the ROWS section.

Field | Contents |
---|---|

2 | RHS set name. |

3 | Row name. |

4 | Value for the entry whose set and row are given by fields 2 and 3. |

5 | Row name. |

6 | Value for the entry whose set and row are given by fields 2 and 5. |

NOTE: Fields 5 and 6 are optional. |

RANGES Section

The optional RANGES section defines two-sided constraints. An MPS file can contain more than one range set, distinguished by the range set name. The row names here must have been defined in the ROWS section.

Field | Contents |
---|---|

2 | Range set name. |

3 | Row name. |

4 | Value for the entry whose set and row are given by fields 2 and 3. |

5 | Row name. |

6 | Value for the entry whose set and row are given by fields 2 and 5. |

NOTE: Fields 5 and 6 are optional. |

Ranges change one-sided constraints, defined in the RHS section, into two-sided constraints. The two-sided constraint for row i depends on the range value, ri, defined in this section. The right-hand side value, bi, is defined in the RHS section. The two-sided constraints for row i are given in the following table:

Row Type | Lower Constraint | Upper Constraint |
---|---|---|

G | bi | bi + ∣ri∣ |

L | bi‑∣ri∣ | bi |

E | bi + min (0,ri) | bi + max (0,ri) |

BOUNDS Section

The optional BOUNDS section defines bounds on the variables. By default, the bounds are 0 ≤ xi ≤ ∞. The bounds can also be used to indicate that a variable must be an integer.

More than one bound can be set for a single variable. For example, to set 2 ≤ xi ≤ 6, use a LO bound with value 2 to set 2 ≤ xi and a UP bound with value 6 to add the condition xi ≤ 6.

An MPS file can contain more than one bounds set, distinguished by the bound set name.

Field | Contents |
---|---|

1 | Bounds type. |

2 | Bounds set name. |

3 | Column name |

4 | Value for the entry whose set and column are given by fields 2 and 3. |

5 | Column name. |

6 | Value for the entry whose set and column are given by fields 2 and 5. |

NOTE: Fields 5 and 6 are optional. |

The bound types are as follows. Here bi are the bound values defined in this section, the xi are the variables, and I is the set of integers.

Bounded Type | Definition | Formula |
---|---|---|

LO | Lower bound | |

UP | Upper bound | |

FX | Fixed variable | |

FR | Free variable | |

MI | Lower bound is minus infinity | |

PL | Upper bound is positive infinity | |

BV | Binary variable (variable must be 0 or 1). | |

UI | Upper bound and integer | and |

LI | Lower bound and integer | and |

SC | Semicontinuous | 0 or |

The bound type names are not case sensitive.

If the bound type is UP or UI and bj < 0 then the lower bound is set to ‑∞.

QUADRATIC Section

The optional QUADRATIC section defines the Hessian for quadratic programming problems. The names HESSIAN, QUADS, QUADOBJ, QSECTION, and QMATRIX are also recognized as beginning the QUADRATIC section.

Field | Contents |
---|---|

2 | Column name. |

3 | Column name. |

4 | Value for the entry specified by fields 2 and 3. |

5 | Column name. |

6 | Value for the entry specified by fields 2 and 5. |

NOTE: Fields 5 and 6 are optional. |

ENDATA Section

The ENDATA section ends the MPS file.

Comments

Informational errors

Type | Code | |

3 | 5 | No objective coefficients found. |

3 | 6 | No RHS values found. |

3 | 8 | No range values found. |

3 | 9 | No bounds found. |

4 | 3 | Missing section title. |

4 | 4 | Error reading input file. |

4 | 7 | Invalid number. |

4 | 11 | Unexpected section header. |

4 | 12 | Unknown row type. |

4 | 13 | Out-of-order marker. |

4 | 14 | Unknown marker type. |

4 | 15 | Unknown column name. |

4 | 16 | Unknown bound type. |

4 | 17 | Unknown row name. |

4 | 18 | Unexpected section name. |

Examples

Example 1

use read_mps_int

implicit none

TYPE(S_MPS) mps

CALL read_mps ('test.mps', mps)

End

Example 2

See Example 2 of DENSE_LP.