NAG CL Interface
e04sac (handle_​read_​file)

Settings help

CL Name Style:


1 Purpose

e04sac 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

#include <nag.h>
void  e04sac (void **handle, const char *filename, const char *ftype, Integer pinfo[], NagError *fail)
The function may be called by the names: e04sac or nag_opt_handle_read_file.

3 Description

e04sac 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 function e04ryc. Once the problem is not needed any more, e04rzc should be called to destroy the handle and deallocate the memory held within. See Section 4.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 void ** 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: filename const char * 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 const char * 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 Output
On exit: problem sizes and statistics as given in the table below:
0 Number of variables (nvar).
1 Number of integer variables.
2 Number of binary variables.
10 Number of Lagrange multipliers (dual variables) for the bound constraints and linear constraints (nnzu).
11 Number of Lagrange multipliers (dual variables) for the cone constraints (nnzuc).
12 Number of nonzeros in all Lagrange multipliers for the matrix constraints (nnzua).
20 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.
21 Number of residuals defined in a nonlinear least square problem.
30 Definition of box constraints, 0: not defined, 1: defined.
31 Number of linear constraints.
32 Number of nonlinear constraints.
33 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.
40 Number of cone constraints.
41 Number of matrix inequality constraints.
42 Number of quadratic constraints.
otherwise Reserved for future use.
4299 Reserved for future use.
nvar, nnzu, nnzuc and nnzua define the problem size and are required by other functions such as e04mtc, e04ptc and e04svc in the optimization suite.
5: fail NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

6 Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
NE_BAD_PARAM
On entry, argument value had an illegal value.
NE_DIAG_ELEMENTS
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.
NE_DUPLICATE_ELEMENT
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.
NE_FILE_INCOMPLETE
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.
NE_INT
An invalid number of blocks was given on line value.
The number stated there is value and needs to be at least 1.
An invalid number of variables was given on line value.
The number stated there is value and needs to be at least 1.
NE_INT_ARRAY
An invalid size of the block number value was given on line value.
The number stated there is value and needs to be nonzero.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 7.5 in the Introduction to the NAG Library CL Interface for further information.
NE_INVALID_CS
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).
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).
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.
NE_INVALID_FORMAT
The token on line value at position value to value was not recognized as a valid integer.
The token on line value at position value to value was not recognized as a valid real number.
The token on line value starting at position value was too long and was not recognized.
NE_MPS_BOUNDS
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 -).
NE_MPS_COLUMNS
Column ‘value’ has been defined more than once in the COLUMNS section. Column definitions must be continuous. (See Section 9.1.5).
Unknown column name ‘value’ in value section.
All column names must be specified in the COLUMNS section.
NE_MPS_ENDATA_NOT_FOUND
End of file found before ENDATA indicator line.
NE_MPS_ILL_NCONEVAR
Rotated second-order cone ‘value’ should have at least 3 variables.
Second-order cone ‘value’ should have at least 2 variables.
NE_MPS_ILLEGAL_DATA_LINE
An illegal line was detected in ‘value’ section.
This is neither a comment nor a valid data line.
NE_MPS_ILLEGAL_NUMBER
Field value did not contain a number (see Section 9.1).
NE_MPS_INDICATOR
Both quadratic objective and cone constraints found, not supported.
Incorrect ordering of indicator lines.
BOUNDS indicator line found before COLUMNS indicator line.
Incorrect ordering of indicator lines.
COLUMNS indicator line found before ROWS indicator line.
Incorrect ordering of indicator lines.
CSECTION indicator line found before COLUMNS indicator line.
Incorrect ordering of indicator lines.
OBJNAME indicator line found after ROWS indicator line.
Incorrect ordering of indicator lines.
QUADOBJ indicator line found before BOUNDS indicator line.
Incorrect ordering of indicator lines.
QUADOBJ indicator line found before COLUMNS indicator line.
Incorrect ordering of indicator lines.
RANGES indicator line found before RHS indicator line.
Incorrect ordering of indicator lines.
RHS indicator line found before COLUMNS indicator line.
Indicator line ‘value’ has been found more than once in the MPS file.
Unknown cone type ‘value’.
Unknown indicator line ‘value’.
NE_MPS_INVALID_INTORG_INTEND
Found 'INTEND' marker without previous marker being 'INTORG'.
Found 'INTORG' but not 'INTEND' before the end of the COLUMNS section.
Found 'INTORG' marker within 'INTORG' to 'INTEND' range.
Illegal marker type ‘value’.
Should be either 'INTORG' or 'INTEND'.
NE_MPS_MANDATORY
At least one mandatory section not found in MPS file.
NE_MPS_OBJNAME
The supplied name in OBJNAME of the objective row was not found among the free rows in the ROWS section.
NE_MPS_PRINTABLE
Illegal column name.
Column names must consist of printable characters only.
Illegal cone name.
Cone names must consist of printable characters only.
Illegal row name.
Row names must consist of printable characters only.
NE_MPS_REPEAT_COLUMN
More than one nonzero of A has row name ‘value’ and column name ‘value’ in the COLUMNS section.
NE_MPS_REPEAT_CONE
Cone name ‘value’ has been defined more than once.
NE_MPS_REPEAT_CONEVAR
Column name ‘value’ has been defined more than once in cone constraint.
NE_MPS_REPEAT_ROW
Row name ‘value’ has been defined more than once in the ROWS section.
NE_MPS_ROWS
Unknown inequality key ‘value’ in ROWS section.
Expected ‘N’, ‘G’, ‘L’ or ‘E’.
Unknown row name ‘value’ in value section.
All row names must be specified in the ROWS section.
NE_MPS_ROWS_OR_CONS
Empty ROWS section.
Neither the objective row nor the constraints were defined.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library CL Interface for further information.
NE_NOT_CLOSE_FILE
Cannot close file.
NE_NOT_READ_FILE
The input file seems to be empty. No data was read.
NE_OUT_OF_RANGE
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).
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).
NE_READ_ERROR
Cannot open file value for reading.
Reading from the file caused an unknown error on line value.
NE_STR_UNKNOWN
On entry, ftype=value.
Constraint: ftype=MPS, M, SDPA or S.
NE_WRONG_NUM_TOKENS
Not enough data was given on line value specifying block sizes.
Expected mA tokens but found only value.
Not enough data was given on line value specifying nonzero matrix elements.
Expected value tokens but found only value.
Not enough data was given on line value specifying the objective function.
Expected n tokens but found only value.

7 Accuracy

Not applicable.

8 Parallelism and Performance

Background information to multithreading can be found in the Multithreading documentation.
e04sac is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
e04sac 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 function. 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 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 (fail.code= NE_MPS_ILLEGAL_DATA_LINE; 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 e04sac 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 e04sac. 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 e04sac. 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 function 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 e04ptc.
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 (e04sace.c)

10.2 Program Data

Program Options (e04sace.opt)

10.3 Program Results

Program Results (e04sace.r)