naginterfaces.library.mip.ilp_​mpsx_​convert

naginterfaces.library.mip.ilp_mpsx_convert(infile, maxn, maxm, optim, xbldef, xbudef, nmobj, nmrhs, nmrng, nmbnd, mpslst, io_manager=None)[source]

ilp_mpsx_convert reads data for a linear or integer programming problem from an external file which is in standard or compatible MPSX input format.

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

https://support.nag.com/numeric/nl/nagdoc_30/flhtml/h/h02buf.html

Parameters
infileint

The unit number (see unit_from_fileobj()) associated with the MPSX data file.

maxnint

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

maxmint

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

optimstr, length 3

Specifies the direction of the optimization. must be set to ‘MIN’ for minimization and to ‘MAX’ for maximization.

xbldeffloat

The default lower bound to be used for the variables in the problem when none is specified in the BOUNDS section of the MPSX data file. For a standard LP or IP problem would normally be set to zero.

xbudeffloat

The default upper bound to be used for the variables in the problem when none is specified in the BOUNDS section of the MPSX data file. For a standard LP or IP problem would normally be set to ‘infinity’ (i.e., ).

nmobjstr, length 8

Either the name of the objective function to be used for the optimization, or blank (in which case the first objective (free) row in the file is used).

nmrhsstr, length 8

Either the name of the RHS set to be used for the optimization, or blank (in which case the first RHS set is used).

nmrngstr, length 8

Either the name of the RANGE set to be used for the optimization, or blank (in which case the first RANGE set (if any) is used).

nmbndstr, length 8

Either the name of the BOUNDS set to be used for the optimization, or blank (in which case the first BOUNDS set (if any) is used).

mpslstbool

If , then a listing of the input data is sent to the file object associated with the advisory I/O unit (see FileObjManager). This can be useful for debugging the MPSX data file.

io_managerFileObjManager, optional

Manager for I/O in this routine.

Returns
nmobjstr, length 8

The name of the objective row as defined in the MPSX data file.

nmrhsstr, length 8

The name of the RHS set read in the MPSX data file.

nmrngstr, length 8

The name of the RANGE set read in the MPSX data file. This is blank if the MPSX data file does not have a RANGE set.

nmbndstr, length 8

The name of the BOUNDS set read in the MPSX data file. This is blank if the MPSX data file does not have a BOUNDS set.

nint

, the actual number of variables in the problem.

mint

, the actual number of general linear constraints in the problem.

afloat, ndarray, shape

, the matrix of general linear constraints.

blfloat, ndarray, shape

, the lower bounds for all the variables and constraints in the following order. The first elements of contain the bounds on the variables and the next elements contain the bounds for the general linear constraints (if any). Note that an ‘infinite’ lower bound is indicated by and an equality constraint by .

bufloat, ndarray, shape

, the upper bounds for all the variables and constraints in the following order. The first elements of contain the bounds on the variables and the next elements contain the bounds for the general linear constraints (if any). Note that an ‘infinite’ upper bound is indicated by and an equality constraint by .

cvecfloat, ndarray, shape

, the coefficients of the objective function. The signs of these coefficients are determined by the problem (either LP or IP) and the direction of the optimization (see above).

xfloat, ndarray, shape

An initial estimate of the solution to the problem. More precisely, if is odd and otherwise, for .

intvarint, ndarray, shape

Indicates which are the integer variables in the problem. More precisely, if is an integer variable, and otherwise, for .

crnamestr, length 8, ndarray, shape

The MPSX names of all the variables and constraints in the problem in the following order. The first elements contain the MPSX names for the variables and the next elements contain the MPSX names for the general linear constraints (if any).

nmprobstr, length 8

The name of the problem as defined in the MPSX data file.

Raises
NagValueError
(errno )

Too many rows. Limit is , but the actual number required is .

(errno )

Too many columns. Limit is , but the actual number required is .

(errno )

No objective function row found.

(errno )

No rows specified in the ROWS section.

(errno )

Illegal constraint type was detected in the ROWS section.

(errno )

Row name with leading blank or non-alphanumeric character .

(errno )

Column name with leading blank or non-alphanumeric character .

(errno )

Illegal bound type .

(errno )

Column name is not defined in the COLUMNS section.

(errno )

The last line must be the ENDATA indicator line.

(errno )

Line is not a comment nor a valid line.

(errno )

Row name is not defined in the ROWS section.

(errno )

No columns specified in the COLUMNS section.

(errno )

On entry, .

Constraint: or .

(errno )

On entry, and .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

Integer marker is not in a correct position.

Notes

In the NAG Library the traditional C interface for this routine uses a different algorithmic base. Please contact NAG if you have any questions about compatibility.

ilp_mpsx_convert reads Linear Programming (LP) or integer programming (IP) problem data from an external file which is prepared in standard or compatible MPSX (see IBM (1971)) input format and then initializes (the number of variables), (the number of general linear constraints), the vectors , and and the matrix for use with opt.lp_solve or ilp_dense(), which are designed to solve problems of the form

ilp_mpsx_convert may be followed by calls to either opt.lp_solve (to solve an LP problem) or ilp_dense() and ilp_info() (to solve an IP problem), possibly followed by a call to ilp_print() (to print the solution using MPSX names).

Note that ilp_mpsx_convert uses an ‘infinite’ bound size of in the definition of and . In other words, any element of greater than or equal to will be regarded as (and similarly any element of less than or equal to will be regarded as ). If this value is deemed to be ‘inappropriate’, you are recommended to reset the value of either the option ‘Infinite Bound Size’ (if an LP problem is being solved) or the argument BIGBND (if an IP problem is being solved) and make any necessary changes to and/or prior to calling opt.lp_solve or ilp_dense() (as appropriate).

The documents for ilp_print() , opt.lp_solve and/or ilp_dense() and ilp_info() should be consulted for further details.

MPSX 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).

The input file must not contain any blank lines. 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-given name

ROWS

data line(s)

COLUMNS

data line(s)

RHS

data line(s)

RANGES (optional)

data line(s)

BOUNDS (optional)

data line(s)

ENDATA

The ‘user-given name’ specifies a name for the problem and must occupy columns 15–22. The name can either be blank or up to a maximum of characters.

A data line follows the same fixed format made up of fields 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

The names and codes consist of ‘alphanumeric’ characters (i.e., a–z, A–Z, , , , asterisk (*), blank (), colon (:), dollar sign ($) or fullstop (.) only) and the names must not contain leading blank characters. Values are read using Fortran format E12.0. 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.

Note that in order to ensure numeric values are interpreted as intended, they should be right-justified in the -character field, with no trailing blanks. This is because in some situations trailing blanks may be interpreted as zeros and this can dramatically affect the interpretation of the value. This is relevant if the value contains an exponent, or if it contains neither an exponent nor an explicit decimal point. For example, the fields

%%%%1.23e-2%
%%%%%%%123%%

may be interpreted as and respectively (where % is used to denote a blank). The actual behaviour is system-dependent.

Comment lines are allowed in the data file. These must have an asterisk (*) in column 1 and any characters in columns 2–80. In any data line, a dollar sign ($) as the first character in Field 3 or 5 indicates that the information from that point through column 80 consists of comments.

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

ROWS data line(s)

These lines specify row (constraint) names and their inequality types (i.e., , or ).

Field 1:

defines the constraint type. It may be in column 2 or column 3.

N

free row, that is no constraint. It may be used to define the objective row.

G

greater than or equal to (i.e., ).

L

less than or equal to (i.e., ).

E

exactly equal to (i.e., ).

Field 2:

defines the row name.

Row type N stands for ‘Not binding’, also known as ‘Free’. It can be used to define the objective row. The objective row is a free row that specifies the vector in the objective function. It is taken to be the first free row, unless some other free row name is specified by the argument (see Parameters). Note that the objective function must be included in the MPSX data file. Thus the maximum number of constraints (; see Parameters) in the problem must be .

COLUMNS data line(s)

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

Field 1:

blank (ignored)

Field 2:

gives the name of the column associated with the elements specified in the following fields.

Field 3:

contains the name of a row.

Field 4:

used in conjunction with Field 3 contains the value of the matrix element.

Field 5:

is optional (may be used like Field 3).

Field 6:

is optional (may be used like Field 4).

Note that only nonzero elements of need to be specified in the COLUMNS section, as any unspecified elements are assumed to be zero.

RHS data line(s)

This section specifies the right-hand side values of the constraint matrix . The lines specify the name of the RHS (right-hand side) vector given to the problem, the numerical values of the elements of the vector are also defined by the data lines and may appear in any order. The data lines have exactly the same format as the COLUMNS data lines, except that the column name is replaced by the RHS name. Note that any unspecified elements are assumed to be zero.

RANGES data line(s) (optional)

Ranges are used for constraints of the form , where and are finite. The range of the constraint is . Either or must be specified in the RHS section and must be defined in this section.

The data lines have exactly the same format as the COLUMNS data lines, except that the column name is replaced by the RANGES name.

BOUNDS data line(s) (optional)

These lines specify limits on the values of the variables ( and in ). If the variable is not specified in the bound set then it is automatically assumed to lie between default lower and upper bounds (usually and ). Like an RHS column which is given a name, the set of variables in one bound set is also given a name.

Field 1:

specifies the type of bound or defines the variable type.

LO

lower bound

UP

upper bound

FX

fixed variable

FR

free variable ( to )

MI

lower bound is

PL

upper bound is . This is the default variable type.

Field 2:

identifies a name for the bound set.

Field 3:

identifies the column name of the variable belonging to this set.

Field 4:

identifies the value of the bound; this has a numerical value only in association with LO, UP, FX in Field 1, otherwise it is blank.

Field 5:

is blank and ignored.

Field 6:

is blank and ignored.

Note that if RANGES and BOUNDS sections are both present, the RANGES section must appear first.

Integer Problems

In IP problems there are two common integer variable types.

  1. –1 integer variables which represent ‘on’ or ‘off’ situations and

  2. General integer variables which are forced to take an integer value, in a specified range, at the optimal integer solution.

Integer variables can be defined in the following compatible and standard MPSX forms.

In the compatible MPSX format, the type of integer variables is defined in Field 1 of the BOUNDS section, that is:

Field 1:

specifies the type of the integer variable.

BV

integer variable (bound value is ).

UI

general integer variable (bound value is in Field 4).

In the standard MPSX format, the integer variables are treated the same as the ‘ordinary’ bounded variables, in the BOUNDS section. Integer markers are, however, introduced in the COLUMNS section to specify the integer variables. The indicator lines for these markers are:

Field 1

Field 2

Field 3

Field 4

Field 5

Field 6

Columns

Contents

INTEGER

‘MARKER’

‘INTORG’

to mark the beginning of the integer variables and

Field 1

Field 2

Field 3

Field 4

Field 5

Field 6

Columns

Contents

INTEGER

‘MARKER’

‘INTEND’

to mark the end. That is, any variables between these markers are treated as integer variables. Note that if the (INTEND) indicator line is not specified in the file then all the variables between the (INTORG) indicator line and the end of the COLUMNS section are assumed to be integer variables. The function accepts both standard and/or compatible MPSX format as a means of specifying integer variables.

References

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