NAG FL Interface
e04saf (handle_​read_​file)

Settings help

FL Name Style:


FL Specification Language:


1 Purpose

e04saf initializes a data structure for the NAG optimization modelling suite from a data file for problems such as, Linear Programming (LP), Quadratic Programming (QP), Second-order Cone Programming (SOCP), or linear Semidefinite Programming (SDP).

2 Specification

Fortran Interface
Subroutine e04saf ( handle, file, ftype, pinfo, ifail)
Integer, Intent (Inout) :: ifail
Integer, Intent (Out) :: pinfo(100)
Character (*), Intent (In) :: file, ftype
Type (c_ptr), Intent (Out) :: handle
C Header Interface
#include <nag.h>
void  e04saf_ (void **handle, const char *file, const char *ftype, Integer pinfo[], Integer *ifail, const Charlen length_file, const Charlen length_ftype)
The routine may be called by the names e04saf or nagf_opt_handle_read_file.

3 Description

e04saf reads a file in one of the supported file formats and stores the data in a new handle. The supported formats are MPS and its derivatives (for LP, QP, SOCP) and sparse SDPA for linear semidefinite programming problems. See Section 9 for more details on the supported file formats. It might be useful to refer to the file format you use to fully understand the possible error messages. Once the file is successfuly processed, the problem can be solved by a compatible solver from the suite or queried via the printing routine e04ryf. Once the problem is not needed any more, e04rzf should be called to destroy the handle and deallocate the memory held within. See Section 3.1 in the E04 Chapter Introduction for more details about the NAG optimization modelling suite. Also see Section 2.2 in the E04 Chapter Introduction for more details on the standard formulations of the optimization problems (e.g., LP, QP, SOCP and SDP) for better understanding on the notations used in this document.

4 References

Borchers B (1999) SDPLIB 1.2, A Library of semidefinite programming test problems Optimization Methods and Software 11(1) 683–690 http://euler.nmt.edu/~brian/sdplib/
Fujisawa K, Kojima M and Nakata K (1998) SDPA (Semidefinite Programming Algorithm) User's Manual Technical Report B-308 Department of Mathematical and Computing Sciences, Tokyo Institute of Technology.
IBM (1971) MPSX – Mathematical programming system Program Number 5734 XM4 IBM Trade Corporation, New York

5 Arguments

1: handle Type (c_ptr) Output
Note: handle does not need to be set on input.
On exit: holds a handle to the internal data structure. It must not be changed between calls to the NAG optimization modelling suite.
2: file Character(*) Input
On entry: the name of the file to be opened.
Constraint: must contain a valid filename for the computer system being used.
3: ftype Character(*) Input
On entry: the expected file format of the input file. ftype is case insensitive.
ftype='MPS' or 'M'
The input file is in MPS format.
ftype='SDPA' or 'S'
The input file is in SDPA format.
Constraint: ftype='MPS', 'M', 'SDPA' or 'S'.
4: pinfo(100) Integer array Output
On exit: problem sizes and statistics as given in the table below:
1 Number of variables (nvar).
2 Number of integer variables.
3 Number of binary variables.
11 Number of Lagrange multipliers (dual variables) for the bound constraints and linear constraints (nnzu).
12 Number of Lagrange multipliers (dual variables) for the cone constraints (nnzuc).
13 Number of nonzeros in all Lagrange multipliers for the matrix constraints (nnzua).
21 Flag indicating the objective function type, 0: no objective, 1: linear objective, 2: quadratic without linear term, 3: quadratic with linear term, 4: general nonlinear, 5: nonlinear least square with dense Jacobian, 6: nonlinear least square with sparse Jacobian.
22 Number of residuals defined in a nonlinear least square problem.
31 Definition of box constraints, 0: not defined, 1: defined.
32 Number of linear constraints.
33 Number of nonlinear constraints.
34 Definition of Hessian for nonlinear objective and constraints, 0: not defined, -1: defined as Lagrangian, 1: defined as individual Hessians of the objective and the constraints.
41 Number of cone constraints.
42 Number of matrix inequality constraints.
43 Number of quadratic constraints.
otherwise Reserved for future use.
nvar, nnzu, nnzuc and nnzua define the problem size and are required by other routines such as e04mtf, e04ptf and e04svf in the optimization suite.
5: ifail Integer Input/Output
On entry: ifail must be set to 0, −1 or 1 to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of 0 causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of −1 means that an error message is printed while a value of 1 means that it is not.
If halting is not appropriate, the value −1 or 1 is recommended. If message printing is undesirable, then the value 1 is recommended. Otherwise, the value 0 is recommended. When the value -1 or 1 is used it is essential to test the value of ifail on exit.
On exit: ifail=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6 Error Indicators and Warnings

If on entry ifail=0 or −1, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
ifail=1
On entry, ftype=value.
Constraint: ftype='MPS', 'M', 'SDPA' or 'S'.
ifail=2
Cannot open file value for reading.
ifail=3
Cannot close file.
ifail=4
The input file seems to be empty. No data was read.
ifail=5
Reading from the file caused an unknown error on line value.
ifail=50
The token on line value at position value to value was not recognized as a valid integer.
ifail=51
The token on line value at position value to value was not recognized as a valid real number.
ifail=52
The token on line value starting at position value was too long and was not recognized.
ifail=53
An invalid number of variables was given on line value.
The number stated there is value and needs to be at least 1.
ifail=54
An invalid number of blocks was given on line value.
The number stated there is value and needs to be at least 1.
ifail=55
An invalid size of the block number value was given on line value.
The number stated there is value and needs to be nonzero.
ifail=56
Not enough data was given on line value specifying block sizes.
Expected mA tokens but found only value.
ifail=57
Not enough data was given on line value specifying the objective function.
Expected n tokens but found only value.
ifail=58
Not enough data was given on line value specifying nonzero matrix elements.
Expected value tokens but found only value.
ifail=59
Invalid structural data found on line value.
The given matrix number is out of bounds. Its value value must be between 0 and n (inclusive).
ifail=60
Invalid structural data found on line value.
The given block number is out of bounds. Its value value must be between 1 and mA (inclusive).
ifail=61
Invalid structural data found on line value.
The given row index is out of bounds, it must respect the size of the block. Its value value must be between value and value (inclusive).
ifail=62
Invalid structural data found on line value.
The given column index is out of bounds, it must respect the size of the block. Its value value must be between value and value (inclusive).
ifail=63
Invalid structural data found on line value.
The specified nonzero element is not in the upper triangle.
The row index is value and column index is value.
ifail=64
Invalid structural data found on line value.
The specified element belongs to a diagonal block but is not diagonal.
The row index is value and column index is value.
ifail=65
An entry in the constraints with matno=value, blkno=value, row index value and column index value was defined more than once. All entries need to be unique.
ifail=66
A premature end of the input stream. The part defining the dimensions of the blocks was not found.
A premature end of the input stream. The part defining the nonzero entries was not found.
A premature end of the input stream. The part defining the number of blocks was not found.
A premature end of the input stream. The part defining the number of variables was not found.
A premature end of the input stream. The part defining the objective function was not found.
ifail=100
Incorrect ordering of indicator lines.
OBJNAME indicator line found after ROWS indicator line.
ifail=101
Incorrect ordering of indicator lines.
COLUMNS indicator line found before ROWS indicator line.
ifail=102
Incorrect ordering of indicator lines.
RHS indicator line found before COLUMNS indicator line.
ifail=103
Incorrect ordering of indicator lines.
RANGES indicator line found before RHS indicator line.
ifail=104
Incorrect ordering of indicator lines.
BOUNDS indicator line found before COLUMNS indicator line.
ifail=105
Incorrect ordering of indicator lines.
QUADOBJ indicator line found before BOUNDS indicator line.
ifail=106
Incorrect ordering of indicator lines.
QUADOBJ indicator line found before COLUMNS indicator line.
ifail=107
Incorrect ordering of indicator lines.
CSECTION indicator line found before COLUMNS indicator line.
ifail=108
Unknown indicator line ‘value’.
ifail=109
Indicator line ‘value’ has been found more than once in the MPS file.
ifail=110
End of file found before ENDATA indicator line.
ifail=111
At least one mandatory section not found in MPS file.
ifail=112
An illegal line was detected in ‘value’ section.
This is neither a comment nor a valid data line.
ifail=113
Unknown inequality key ‘value’ in ROWS section.
Expected ‘N’, ‘G’, ‘L’ or ‘E’.
ifail=114
Empty ROWS section.
Neither the objective row nor the constraints were defined.
ifail=115
The supplied name in OBJNAME of the objective row was not found among the free rows in the ROWS section.
ifail=116
Illegal row name.
Row names must consist of printable characters only.
ifail=117
Illegal column name.
Column names must consist of printable characters only.
ifail=118
Row name ‘value’ has been defined more than once in the ROWS section.
ifail=119
Column ‘value’ has been defined more than once in the COLUMNS section. Column definitions must be continuous. (See Section 9.1.5).
ifail=120
Found 'INTORG' marker within 'INTORG' to 'INTEND' range.
ifail=121
Found 'INTEND' marker without previous marker being 'INTORG'.
ifail=122
Found 'INTORG' but not 'INTEND' before the end of the COLUMNS section.
ifail=123
Illegal marker type ‘value’.
Should be either 'INTORG' or 'INTEND'.
ifail=124
Unknown row name ‘value’ in value section.
All row names must be specified in the ROWS section.
ifail=125
Unknown column name ‘value’ in value section.
All column names must be specified in the COLUMNS section.
ifail=126
Inconsistent bounds for column ‘value’.
Inconsistent bounds for row ‘value’.
Unknown bound type ‘value’ in BOUNDS section.
Inconsistent bounds are reported when the lower bound is greater than or equal to 1.0E+20 or the upper bound is less than or equal to -1.0E+20, or when the lower bound is greater than the upper bound. Any upper bound greater than or equal to 1.0E+20 will be regarded as + (and similarly any lower bound less than or equal to -1.0E+20 will be regarded as -).
ifail=127
More than one nonzero of A has row name ‘value’ and column name ‘value’ in the COLUMNS section.
ifail=128
Field value did not contain a number (see Section 9.1).
ifail=129
Both quadratic objective and cone constraints found, not supported.
ifail=130
Rotated second-order cone ‘value’ should have at least 3 variables.
Second-order cone ‘value’ should have at least 2 variables.
ifail=131
Unknown cone type ‘value’.
ifail=132
Illegal cone name.
Cone names must consist of printable characters only.
ifail=133
Cone name ‘value’ has been defined more than once.
ifail=134
Column name ‘value’ has been defined more than once in cone constraint.
ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
ifail=-399
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
ifail=-999
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

7 Accuracy

Not applicable.

8 Parallelism and Performance

Background information to multithreading can be found in the Multithreading documentation.
e04saf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
e04saf makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

9 Further Comments

9.1 MPS input format

The input file of data may only contain two types of lines:
  1. 1.Indicator lines (specifying the type of data which is to follow).
  2. 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)
CSECTION user-supplied name parameter cone type (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 23 512 1522 2536 4047 5061
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 12. This allows values to be entered in several equivalent forms. For example, 1.2345678, 1.2345678E+0, 123.45678E−2 and 12345678E−07 all represent the same number. It is safest to include an explicit decimal point.
Lines with an asterisk (*) in column 1 will be considered comment lines and will be ignored by the routine.
Columns outside the six fields must be blank, except for columns 72–80, whose contents are ignored by the routine. A non-blank character outside the predefined six fields and columns 72–80 is considered to be a major error (ifail=112; see Section 6), unless it is part of a comment.

9.1.1 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 3 but may be blank.
Field Required Description
3 No Name of the problem

9.1.2 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
2 No Sense of the objective function
Field 2 may contain either MIN, MAX, MINIMIZE or MAXIMIZE.

9.1.3 OBJNAME Section (optional)

The data line in this section can be used to specify the name of a free row (see Section 9.1.4) 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.
Field Required Description
2 No Row name to be used as the objective function
Field 2 must contain a valid row name.

9.1.4 ROWS Section

The data lines in this section specify unique row (constraint) names and their inequality types (i.e., unconstrained, =, or ).
Field Required Description
1 Yes Inequality key
2 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 2 or 3.
Inequality
Key

Description

l

u
N Free row -
G Greater than or equal to finite
L Less than or equal to - finite
E Equal to finite l
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 c in the linear objective term cTx. If there is more than one free row, the first free row is chosen, unless another free row name is specified by OBJNAME (see Section 9.1.3). Note that c 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.

9.1.5 COLUMNS Section

Data lines in this section specify the names to be assigned to the variables (columns) in the general linear constraint matrix A, and define, in terms of column vectors, the actual values of the corresponding matrix elements.
Field Required Description
2 Yes Column name
3 Yes Row name
4 Yes Value
5 No Row name
6 No Value
Each data line in the COLUMNS section defines the nonzero elements of A or c. Any elements of A or c that are undefined are assumed to be zero. Nonzero elements of A must be grouped by column, that is to say that all of the nonzero elements in the jth column of A must be specified before those in the j+1th column, for j=1,2,,n-1. Rows may appear in any order within the column.
9.1.5.1 Integer Markers
For backward compatibility e04saf 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
2 No Marker ID
3 Yes Marker tag
5 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 8 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 e04saf. 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.

9.1.6 RHS Section

This section specifies the right-hand side values (if any) of the general linear constraint matrix A.
Field Required Description
2 Yes RHS name
3 Yes Row name
4 Yes Value
5 No Row name
6 No Value
The MPS file may contain several RHS sets distinguished by RHS name. However only 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 e04saf. An RHS given to the objective function is dealt with differently by different MPS readers, therefore, it is safer not to 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.

9.1.7 RANGES Section (optional)

Ranges are used to modify the interpretation of constraints defined in the ROWS section (see Section 9.1.4) to the form lAxu, where both l and u are finite. The range of the constraint is r=u-l.
Field Required Description
2 Yes Range name
3 Yes Row name
4 Yes Value
5 No Row name
6 No Value
The range of each constraint implies an upper and lower bound dependent on the inequality key of each constraint, on the RHS b of the constraint (as defined in the RHS section), and on the range r.
Inequality
Key

Sign of r

l

u
E + b b+r
E - b+r b
G +/- b b+|r|
L +/- b-|r| b
N +/- - +
Only the first range set will be used.

9.1.8 BOUNDS Section (optional)

These lines specify limits on the values of the variables (the quantities l and u in lxu). If a variable is not specified in the bound set then it is automatically assumed to lie between 0 and +.
Field Required Description
1 Yes Bound type identifier
2 Yes Bound name
3 Yes Column name
4 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 k 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

l

u
Integer
Variable?
UP unchanged k No
LO k unchanged No
FX k k No
FR - No
MI - unchanged No
PL unchanged No
BV 0 1 Yes
UI unchanged k Yes
LI k unchanged Yes
Only the first bound set will be used.

9.1.9 QUADOBJ Section (optional)

The QUADOBJ section defines nonzero elements of the upper or lower triangle of the Hessian matrix H.
Field Required Description
2 Yes Column name (HColumn Index)
3 Yes Column name (HRow Index)
4 Yes Value
5 No Column name (HRow Index)
6 No Value
Each data line in the QUADOBJ section defines one (or optionally two) nonzero elements Hij of the matrix H. Each element Hij is given as a triplet of row index i, column index j and a value. The column names (as defined in the COLUMNS section) are used to link the names of the variables and the indices i and j.
It is only necessary to define either the upper or lower triangle of the H 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.

9.1.10 CSECTION Section (optional)

Data lines in this section specify the cone constraint that has the following form in Second-order Cone Programming (SOCP).
xGi Kmi,i=1,,r,  
where xGi is a subvector of decision variables x indexed by Gi, Kmi is either quadratic cone or rotated quadratic cone of dimension mi. This section may appear multiple times in the file to define various cone constraints i=1,,r.
The CSECTION has data on the same line as the indicator to store the name, parameter and type of the cone. Cone name is compulsory and must be in Field 3. The possible cone type key is either QUAD for quadratic cone or RQUAD for rotated quadratic cone. The parameter of cone is not used in all cases.
Field Required Description
3 Yes Name of the cone
4 No Parameter of the cone
5 Yes Cone type
The data lines in this section specify variable names in the cone. Note that we require at least 2 variables for quadratic cone and 3 variables for rotated quadratic cone.
Field Required Description
2 Yes A valid variable name

9.2 Sparse SDPA file format

The problem data is written in an ASCII input file in a SDPA sparse format which was first introduced in Fujisawa et al. (1998). In the description below we follow closely the specification from Borchers (1999).
The format is line oriented. If more elements are required on the line they need to be separated by a space, a tab, or any of the special characters ‘,’, ‘(’, ‘)’, ‘{’, or ‘}’. The file consists of six sections:
  1. 1.Comments. The file can begin with arbitrarily many lines of comments. Each line of comments must begin with ‘"’ or ‘*’.
  2. 2.The first line after the comments contains integer n, the number of variables. The rest of this line is ignored.
  3. 3.The second line after the comments contains integer mA, the number of blocks in the block diagonal structure of the matrices. Additional text on this line after mA is ignored.
  4. 4.The third line after the comments contains a vector of mA integers that give the sizes of the individual blocks. Negative numbers may be used to indicate that a block is actually a diagonal submatrix. Thus a block size of ‘-5’ indicates a 5×5 block in which only the diagonal elements are nonzero.
  5. 5.The fourth line after the comments contains an n-dimensional real vector defining the objective function vector c.
  6. 6.The remaining lines of the file contain nonzero entries in the constraint matrices, with one entry per line. The format for each line is
    matno blkno i j entry  
    where matno is the number (0,,n) of the matrix to which this entry belongs and blkno specifies the block number k=1,2,,mA within this matrix. Together, they uniquely identify the block A matno blkno . Integers i and j are one-based indices which specify a location of the entry within the block. Note that since all matrices are assumed to be symmetric, only entries in the upper triangle of a matrix should be supplied. Finally, entry should give the real value of the entry in the matrix. Precisely, ( A matno blkno ) i j = ( A matno blkno ) j i = entry .
For SDPA format we use the word ‘token’ as a reference to a group of contiguous characters without a space or any other delimeters.

9.3 Internal Changes

Internal changes have been made to this routine as follows:
For details of all known issues which have been reported for the NAG Library please refer to the Known Issues.

10 Example

This example demonstrates how to load data of an SOCP problem from an MPS file and solve it using SOCP solver e04ptf.
The data file stores the following SOCP problem
minimize 10.0x1 + 20.0x2 + x3  
subject to the bounds
-2.0 x1 2.0 -2.0 x2 2.0  
the general linear constraints
-0.1x1 - 0.1x2 + x3 1.5 1.0 -0.06x1 + x2 + x3  
and the cone constraint
(x3,x1,x2) K q 3 .  
The optimal solution (to five significant figures) is
x*=(-1.2682,-4.0843,1.3323)T,  
and the objective function value is -19.518.

10.1 Program Text

Program Text (e04safe.f90)

10.2 Program Data

Program Options (e04safe.opt)

10.3 Program Results

Program Results (e04safe.r)