naginterfaces.library.opt.miqp_​mps_​read

naginterfaces.library.opt.miqp_mps_read(infile, maxn, maxm, maxnnz, maxncolh, maxnnzh, maxlintvar, pnames, mpslst=0, io_manager=None)[source]

miqp_mps_read reads data for sparse linear programming, mixed integer linear programming, quadratic programming or mixed integer quadratic programming problems from an external file which is in standard or compatible MPS input format.

For full information please refer to the NAG Library document for e04mx

https://www.nag.com/numeric/nl/nagdoc_28.5/flhtml/e04/e04mxf.html

Parameters
infileint

The ID of the MPSX data file to be read as returned by a call to the FileObjManager method unit_from_fileobj().

maxnint

An upper limit for the number of variables in the problem.

If , miqp_mps_read will start in query mode (see Query Mode).

maxmint

An upper limit for the number of general linear constraints (including the objective row) in the problem.

If , miqp_mps_read will start in query mode (see Query Mode).

maxnnzint

An upper limit for the number of nonzeros (including the objective row) in the problem.

If , miqp_mps_read will start in query mode (see Query Mode).

maxncolhint

An upper limit for the dimension of the matrix .

If , miqp_mps_read will start in query mode (see Query Mode).

maxnnzhint

An upper limit for the number of nonzeros of the matrix .

If , miqp_mps_read will start in query mode (see Query Mode).

maxlintvarint

If , an upper limit for the number of integer variables.

If , miqp_mps_read will treat all integer variables in the file as continuous variables.

pnamesstr, length 8, array-like, shape

A set of names associated with the MPSX form of the problem.

Must either contain the name of the problem or be blank.

Must either be blank or contain the name of the objective row (in which case it overrides OBJNAME section and the default choice of the first objective free row).

Must either contain the name of the RHS set to be used or be blank (in which case the first RHS set is used).

Must either contain the name of the RANGE set to be used or be blank (in which case the first RANGE set (if any) is used).

Must either contain the name of the BOUNDS set to be used or be blank (in which case the first BOUNDS set (if any) is used).

mpslstint, optional

If , summary messages are sent to the file object associated with the advisory I/O unit (see FileObjManager) as miqp_mps_read reads through the data file. This can be useful for debugging the file. If , then no summary is produced.

io_managerFileObjManager, optional

Manager for I/O in this routine.

Returns
nint

If miqp_mps_read was run in query mode (see Query Mode), or returned with = 2, an upper estimate of the number of variables of the problem. Otherwise, , the actual number of variables in the problem.

mint

If miqp_mps_read was run in query mode (see Query Mode), or returned with = 2, an upper estimate of the number of general linear constraints in the problem (including the objective row). Otherwise, , the actual number of general linear constraints of the problem.

nnzint

If miqp_mps_read was run in query mode (see Query Mode), or returned with = 2, an upper estimate of the number of nonzeros in the problem (including the objective row). Otherwise, the actual number of nonzeros in the problem (including the objective row).

ncolhint

If miqp_mps_read was run in query mode (see Query Mode), or returned with = 2, an upper estimate of the value of required by qpconvex1_sparse_solve() and qpconvex2_sparse_solve(). In this context is the number of leading nonzero columns of the Hessian matrix . Otherwise, the actual dimension of the matrix .

nnzhint

If miqp_mps_read was run in query mode (see Query Mode), or returned with = 2, an upper estimate of the number of nonzeros of the matrix . Otherwise, the actual number of nonzeros of the matrix .

lintvarint

If on entry , all integer variables are treated as continuous and .

If miqp_mps_read was run in query mode (see Query Mode), or returned with = 2, an upper estimate of the number of integer variables of the problem.

Otherwise, the actual number of integer variables of the problem.

iobjint

If , row of is a free row containing the nonzero coefficients of the vector .

If , the coefficients of are assumed to be zero.

If miqp_mps_read is run in query mode (see Query Mode) is not referenced.

afloat, ndarray, shape

The nonzero elements of , ordered by increasing column index.

If miqp_mps_read is run in query mode (see Query Mode), is not referenced.

irowaint, ndarray, shape

The row indices of the nonzero elements stored in .

If miqp_mps_read is run in query mode (see Query Mode), is not referenced.

iccolaint, ndarray, shape

A set of pointers to the beginning of each column of . More precisely, contains the index in of the start of the th column, for . Note that and .

If miqp_mps_read is run in query mode (see Query Mode), is not referenced.

blfloat, ndarray, shape

contains the vector (the lower bounds) for all the variables and constraints

bufloat, ndarray, shape

contains the vector (the upper bounds) for all the variables and constraints

pnamesstr, length 8, ndarray, shape

A set of names associated with the problem as defined in the MPSX data file as follows:

Contains the name of the problem (or blank if none).

Contains the name of the objective row (or blank if none).

Contains the name of the RHS set (or blank if none).

Contains the name of the RANGE set (or blank if none).

Contains the name of the BOUNDS set (or blank if none).

If miqp_mps_read is run in query mode (see Query Mode), is not referenced.

nnameint

, the total number of variables and constraints in the problem (including the objective row).

If miqp_mps_read was run in query mode (see Query Mode), or returned with = 2, is not set.

crnamestr, length 8, ndarray, shape

The MPS names of all the variables and constraints in the problem in the following order. The first elements contain the MPS names for the variables and the next elements contain the MPS names for the objective row and general linear constraints (if any). Note that the MPS name for the objective row is stored in .

If miqp_mps_read is run in query mode (see Query Mode), is not referenced.

hfloat, ndarray, shape

The nonzero elements of , arranged by increasing column index.

If miqp_mps_read is run in query mode (see Query Mode), is not referenced.

irowhint, ndarray, shape

The row indices of the elements stored in .

If miqp_mps_read is run in query mode (see Query Mode), is not referenced.

iccolhint, ndarray, shape

A set of pointers to the beginning of each column of . More precisely, contains the index in of the start of the th column, for . Note that and .

If miqp_mps_read is run in query mode (see Query Mode), is not referenced.

minmaxint

defines the direction of the optimization as read from the MPS file. By default the function assumes the objective function should be minimized and will return . If the function discovers in the OBJSENSE section that the objective function should be maximized it will return . If the function discovers that there is neither the linear objective term (the objective row) nor the Hessian matrix , the problem is considered as a feasible point problem and is returned.

If miqp_mps_read was run in query mode (see Query Mode), or returned with = 2, is not set.

intvarint, ndarray, shape

If on entry, contains pointers to the columns that are defined as integer variables. More precisely, , where is the index of a column that is defined as an integer variable, for .

If on entry, or miqp_mps_read was run in query mode (see Query Mode), or it returned with = 2, is not set.

Raises
NagValueError
(errno )

Line : Incorrect ordering of indicator lines.

OBJNAME indicator line found after ROWS indicator line.

(errno )

Line : Incorrect ordering of indicator lines.

COLUMNS indicator line found before ROWS indicator line.

(errno )

Line : Incorrect ordering of indicator lines.

RHS indicator line found before COLUMNS indicator line.

(errno )

Line : Incorrect ordering of indicator lines.

RANGES indicator line found before RHS indicator line.

(errno )

Line : Incorrect ordering of indicator lines.

BOUNDS indicator line found before COLUMNS indicator line.

(errno )

Line : Incorrect ordering of indicator lines.

QUADOBJ indicator line found before BOUNDS indicator line.

(errno )

Line : Incorrect ordering of indicator lines.

QUADOBJ indicator line found before COLUMNS indicator line.

(errno )

Line : Unknown indicator line .

(errno )

Line : Indicator line ‘’ has been found more than once in the MPS file.

(errno )

End of file found before ENDATA indicator line.

(errno )

No indicator line found in file. It may be an empty file.

(errno )

At least one mandatory section not found in MPS file.

(errno )

Line : An illegal line was detected in section.

This is neither a comment nor a valid data line.

(errno )

Line : Unknown inequality key in ROWS section.

Expected ‘N’, ‘G’, ‘L’ or ‘E’.

(errno )

Line : Empty ROWS section.

Neither the objective row nor the constraints were defined.

(errno )

The supplied name, in or in OBJNAME, of the objective row was not found among the free rows in the ROWS section.

(errno )

The supplied name, in , of the BOUNDS set to be used was not found in the BOUNDS section.

(errno )

The supplied name, in , of the RHS set to be used was not found in the RHS section.

(errno )

The supplied name, in , of the RANGES set to be used was not found in the RANGES section.

(errno )

Line : Illegal row name.

Row names must consist of printable characters only.

(errno )

Line : Illegal column name.

Column names must consist of printable characters only.

(errno )

Line : Row name has been defined more than once in the ROWS section.

(errno )

Line : Column ‘’ has been defined more than once in the COLUMNS section. Column definitions must be continuous. (See COLUMNS Section).

(errno )

Line : Found 'INTORG' marker within 'INTORG' to 'INTEND' range.

(errno )

Line : Found 'INTEND' marker without previous marker being 'INTORG'.

(errno )

Line : Found 'INTORG' but not 'INTEND' before the end of the COLUMNS section.

(errno )

Line : Illegal marker type .

Should be either 'INTORG' or 'INTEND'.

(errno )

Line : Unknown row name in section.

All row names must be specified in the ROWS section.

(errno )

Line : Unknown column name in section.

All column names must be specified in the COLUMNS section.

(errno )

Inconsistent bounds for row ‘’.

(errno )

Inconsistent bounds for column ‘’.

(errno )

Line : Unknown bound type in BOUNDS section.

(errno )

More than one nonzero of has row name ‘’ and column name ‘’ in the COLUMNS section.

(errno )

Field did not contain a number (see Notes).

(errno )

On entry, .

Constraint: .

Warns
NagAlgorithmicWarning
(errno )

Warning: MPS file not strictly fixed format, although the problem was read anyway. The data may have been read incorrectly. You should set and repeat the call to miqp_mps_read for more details.

(errno )

At least one of , , , or is too small. You must provide , , , , .

(errno )

At least one of , , , , or is too small. You must provide , , , , , .

Notes

miqp_mps_read reads data for Linear Programming (LP) or Quadratic Programming (QP) problems (or their mixed integer variants) from an external file which is prepared in standard or compatible MPS (see IBM (1971)) input format. It then initializes (the number of variables), (the number of general linear constraints), the matrix , the vectors , , (stored in row of ) and the Hessian matrix for use with qpconvex1_sparse_solve() and qpconvex2_sparse_solve(). These functions are designed to solve problems of the form

MPS input format

The input file of data may only contain two types of lines:

  1. Indicator lines (specifying the type of data which is to follow).

  2. Data lines (specifying the actual data).

A section is a combination of an indicator line and its corresponding data line(s). Any characters beyond column 80 are ignored. Indicator lines must not contain leading blank characters (in other words they must begin in column 1). The following displays the order in which the indicator lines must appear in the file:

NAME

user-supplied name

(optional)

OBJSENSE

(optional)

data line

OBJNAME

(optional)

data line

ROWS

data line(s)

COLUMNS

data line(s)

RHS

data line(s)

RANGES

(optional)

data line(s)

BOUNDS

(optional)

data line(s)

QUADOBJ

(optional)

data line(s)

ENDATA

A data line follows a fixed format, being made up of fields as defined below. The contents of the fields may have different significance depending upon the section of data in which they appear.

Field 1

Field 2

Field 3

Field 4

Field 5

Field 6

Columns

Contents

Code

Name

Name

Value

Name

Value

Each name and code must consist of ‘printable’ characters only; names and codes supplied must match the case used in the following descriptions. Values are read using a field width of . This allows values to be entered in several equivalent forms. For example, , , and all represent the same number. It is safest to include an explicit decimal point.

Lines with an asterisk () in column will be considered comment lines and will be ignored by the function.

Columns outside the six fields must be blank, except for columns 72–80, whose contents are ignored by the function. A non-blank character outside the predefined six fields and columns 72–80 is considered to be a major error ( = 16; see Exceptions), unless it is part of a comment.

NAME Section (optional)

The NAME section is the only section where the data must be on the same line as the indicator. The ‘user-supplied name’ must be in field but may be blank.

Field

Required

Description

No

Name of the problem

OBJSENSE Section (optional)

The data line in this section can be used to specify the sense of the objective function. If this section is present it must contain only one data line. If the section is missing or empty, minimization is assumed.

Field

Required

Description

No

Sense of the objective function

Field 2 may contain either MIN, MAX, MINIMIZE or MAXIMIZE.

OBJNAME Section (optional)

The data line in this section can be used to specify the name of a free row (see ROWS Section) that should be used as the objective function. If this section is present it must contain only one data line. If the section is missing or is empty, the first free row will be chosen instead. Alternatively, OBJNAME can be overridden by setting nonempty (see Parameters).

Field

Required

Description

No

Row name to be used as the objective function

Field 2 must contain a valid row name.

ROWS Section

The data lines in this section specify unique row (constraint) names and their inequality types (i.e., unconstrained, , or ).

Field

Required

Description

Yes

Inequality key

Yes

Row name

The inequality key specifies each row’s type. It must be E, G, L or N and can be in either column or .

Inequality Key

Description

N

Free row

G

Greater than or equal to

finite

L

Less than or equal to

finite

E

Equal to

finite

Row type N stands for ‘Not binding’. It can be used to define the objective row. The objective row is a free row that specifies the vector in the linear objective term . If there is more than one free row, the first free row is chosen, unless another free row name is specified by OBJNAME (see OBJNAME Section (optional)) or (see Parameters). Note that is assumed to be zero if either the chosen row does not appear in the COLUMNS section (i.e., has no nonzero elements) or there are no free rows defined in the ROWS section.

COLUMNS Section

Data lines in this section specify the names to be assigned to the variables (columns) in the general linear constraint matrix , and define, in terms of column vectors, the actual values of the corresponding matrix elements.

Field

Required

Description

Yes

Column name

Yes

Row name

Yes

Value

No

Row name

No

Value

Each data line in the COLUMNS section defines the nonzero elements of or . Any elements of or that are undefined are assumed to be zero. Nonzero elements of must be grouped by column, that is to say that all of the nonzero elements in the jth column of must be specified before those in the th column, for . Rows may appear in any order within the column.

Integer Markers

For backward compatibility miqp_mps_read allows you to define the integer variables within the COLUMNS section using integer markers, although this is not recommended as markers can be treated differently by different MPS readers; you should instead define any integer variables in the BOUNDS section (see below). Each marker line must have the following format:

Field

Required

Description

No

Marker ID

Yes

Marker tag

Yes

Marker type

The marker tag must be 'MARKER'. The marker type must be 'INTORG' to start reading integer variables and 'INTEND' to finish reading integer variables. This implies that a row cannot be named 'MARKER', 'INTORG' or 'INTEND'. Please note that both marker tag and marker type comprise of characters as a ' is the mandatory first and last character in the string. You may wish to have several integer marker sections within the COLUMNS section, in which case each marker section must begin with an 'INTORG' marker and end with an 'INTEND' marker and there should not be another marker between them.

Field 2 is ignored by miqp_mps_read. When an integer variable is declared it will keep its default bounds unless they are changed in the BOUNDS section. This may vary between different MPS readers.

RHS Section

This section specifies the right-hand side values (if any) of the general linear constraint matrix .

Field

Required

Description

Yes

RHS name

Yes

Row name

Yes

Value

No

Row name

No

Value

The MPS file may contain several RHS sets distinguished by RHS name. If an RHS name is defined in (see Parameters) then miqp_mps_read will read in only that RHS vector, otherwise the first RHS set will be used.

Only the nonzero RHS elements need to be specified. Note that if an RHS is given to the objective function it will be ignored by miqp_mps_read. An RHS given to the objective function is dealt with differently by different MPS readers, therefore, it is safer to not define an RHS of the objective function in your MPS file. Note that this section may be empty, in which case the RHS vector is assumed to be zero.

RANGES Section (optional)

Ranges are used to modify the interpretation of constraints defined in the ROWS section (see ROWS Section) to the form , where both and are finite. The range of the constraint is .

Field

Required

Description

Yes

Range name

Yes

Row name

Yes

Value

No

Row name

No

Value

The range of each constraint implies an upper and lower bound dependent on the inequality key of each constraint, on the RHS of the constraint (as defined in the RHS section), and on the range .

Inequality Key

Sign of

E

E

G

L

N

If a range name is defined in (see Parameters) then the function will read in only the range set of that name, otherwise the first set will be used.

BOUNDS Section (optional)

These lines specify limits on the values of the variables (the quantities and in ). If a variable is not specified in the bound set then it is automatically assumed to lie between and .

Field

Required

Description

Yes

Bound type identifier

Yes

Bound name

Yes

Column name

Yes/No

Value

Note: field 4 is required only if the bound type identifier is one of UP, LO, FX, UI or LI in which case it gives the value below. If the bound type identifier is FR, MI, PL or BV, field 4 is ignored and it is recommended to leave it blank.

The table below describes the acceptable bound type identifiers and how each determines the variables’ bounds.

Bound Type Identifier

Integer Variable?

UP

unchanged

No

LO

unchanged

No

FX

No

FR

No

MI

unchanged

No

PL

unchanged

No

BV

Yes

UI

unchanged

Yes

LI

unchanged

Yes

If a bound name is defined in (see Parameters) then the function will read in only the bound set of that name, otherwise the first set will be used.

QUADOBJ Section (optional)

The QUADOBJ section defines nonzero elements of the upper or lower triangle of the Hessian matrix .

Field

Required

Description

Yes

Column name (HColumn Index)

Yes

Column name (HRow Index)

Yes

Value

No

Column name (HRow Index)

No

Value

Each data line in the QUADOBJ section defines one (or optionally two) nonzero elements of the matrix . Each element is given as a triplet of row index , column index and a value. The column names (as defined in the COLUMNS section) are used to link the names of the variables and the indices and . More precisely, the matrix on output will have a nonzero element

where index belongs to HColumn Index and index to one of the HRow Indices such that

and

.

It is only necessary to define either the upper or lower triangle of the matrix; either will suffice. Any elements that have been defined in the upper triangle of the matrix will be moved to the lower triangle of the matrix, then any repeated nonzeros will be summed.

Note: it is much more efficient for qpconvex1_sparse_solve() and qpconvex2_sparse_solve() to have the matrix defined by the first column names. If the nonzeros of are defined by any columns that are not in the first of then miqp_mps_read will rearrange the matrices and so that they are.

Query Mode

miqp_mps_read offers a ‘query mode’ to quickly give upper estimates on the sizes of user arrays. In this mode any expensive checks of the data and of the file format are skipped, providing a prompt count of the number of variables, constraints and matrix nonzeros. This might be useful in the common case where the size of the problem is not known in advance.

You may activate query mode by setting any of the following: , , , or . If no major formatting error is detected in the data file, no exception or warning is raised is returned and the upper estimates are given as stated in Table [label omitted]. Alternatively, the function switches to query mode while the file is being read if it is discovered that the provided space is insufficient (that is, if , , , , or ). In this case = 2 is returned.

Argument Name

Upper Estimate for

References

IBM, 1971, MPSX – Mathematical programming system, Program Number 5734 XM4, IBM Trade Corporation, New York