NAG Library Routine Document
E04RDF
1 Purpose
E04RDF reads in a linear semidefinite programming problem (SDP) from a file in sparse SDPA format and returns it in the form which is usable by routines
E04RAF (initialization),
E04REF (linear objective function),
E04RNF (linear matrix constraints),
E04SVF (solver) and
E04RZF (deallocation) from the NAG optimization modelling suite.
2 Specification
SUBROUTINE E04RDF ( 
INFILE, MAXNVAR, MAXNBLK, MAXNNZ, FILELST, NVAR, NBLK, NNZ, CVEC, NNZA, IROWA, ICOLA, A, BLKSIZEA, IFAIL) 
INTEGER 
INFILE, MAXNVAR, MAXNBLK, MAXNNZ, FILELST, NVAR, NBLK, NNZ, NNZA(MAXNVAR+1), IROWA(MAXNNZ), ICOLA(MAXNNZ), BLKSIZEA(MAXNBLK), IFAIL 
REAL (KIND=nag_wp) 
CVEC(MAXNVAR), A(MAXNNZ) 

3 Description
E04RDF is capable of reading linear semidefinite programming problems (SDP) from a text file in sparse SDPA format. The problem is captured and returned in the following form:
where
${A}_{i}$ denotes symmetric matrices and
$c$ is a vector. The expression
$S\u2ab00$ stands for a constraint on the eigenvalues of a symmetric matrix
$S$, namely, all the eigenvalues should be nonnegative, i.e., the matrix
$S$ should be positive semidefinite.
Please note that this form covers even general linear SDP formulations with multiple linear matrix inequalities and a set of standard linear constraints. A set of
${m}_{A}$ linear matrix inequalities
can be equivalently expressed as one matrix inequality
(1)(b) in the following block diagonal form where the matrices
${A}_{i}^{1},{A}_{i}^{2},\dots ,{A}_{i}^{{m}_{A}}$ create the diagonal blocks of
${A}_{i}$:
In addition, notice that if all matrices
${A}_{i}^{k}$ belonging to the same block, say block
$k$, are themselves diagonal matrices (or have dimension
$1\times 1$), the associated matrix inequality
defines actually a standard linear constraint
where
$l$ and columns of the matrix
$B$ are formed by the diagonals of matrices
${A}_{0}^{k}$ and
${A}_{1}^{k},\dots ,{A}_{n}^{k}$, respectively. Precisely,
${l}_{i}={\left({A}_{0}^{k}\right)}_{ii}$ and
${b}_{ij}={\left({A}_{j}^{k}\right)}_{ii}$. See
Section 10.
3.1 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. 
Comments. The file can begin with arbitrarily many lines of comments. Each line of comments must begin with ‘"’ or ‘*’. 
2. 
The first line after the comments contains integer $n$, the number of variables. The rest of this line is ignored. 
3. 
The second line after the comments contains integer ${m}_{A}$, the number of blocks in the block diagonal structure of the matrices. Additional text on this line after ${m}_{A}$ is ignored. 
4. 
The third line after the comments contains a vector of ${m}_{A}$ 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$ by $5$ block in which only the diagonal elements are nonzero. 
5. 
The fourth line after the comments contains an $n$dimensional real vector defining the objective function vector $c$. 
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
where $\mathit{matno}$ is the number $\left(0,\dots ,n\right)$ of the matrix to which this entry belongs and $\mathit{blkno}$ specifies the block number $k=1,2,\dots ,{m}_{A}$ within this matrix. Together, they uniquely identify the block ${A}_{\mathit{matno}}^{\mathit{blkno}}$. Integers $\mathit{i}$ and $\mathit{j}$ are onebased 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, $\mathit{entry}$ should give the real value of the entry in the matrix. Precisely, ${\left({A}_{\mathit{matno}}^{\mathit{blkno}}\right)}_{\mathit{i}\mathit{j}}={\left({A}_{\mathit{matno}}^{\mathit{blkno}}\right)}_{\mathit{j}\mathit{i}}=\mathit{entry}$. 
In the text below and in the file listing (
FILELST) we use the word ‘token’ as a reference to a group of contiguous characters without a space or any other delimeters.
3.2 Recommendation on how best to use E04RDF
(a) 
The input file with the problem needs to be opened for reading by X04ACF (${\mathbf{MODE}}=0$).
In this way we avoid possible limitations of maximal lengths of lines inherited by Fortran I/O (X04ACF uses the formatted stream access mode to bypass the restriction). If the file is opened by other means or standard input is used instead, lines within the file might be truncated which would produce a file format error message. This would most likely happen on the line defining the objective function.
Setting ${\mathbf{FILELST}}=1$ might help with possible file formatting errors. 
(b) 
Unless the dimension of the problem (or its overestimate) is known in advance, call E04RDF initially with ${\mathbf{MAXNVAR}}=0$, ${\mathbf{MAXNBLK}}=0$ and ${\mathbf{MAXNNZ}}=0$. In this case the exact size of the problem is computed and returned in NVAR, NBLK and NNZ. No other data will be stored and none of the arrays CVEC, NNZA, IROWA, ICOLA, A, BLKSIZEA will be referenced.
Then the exact storage can be allocated and the file reopened. When E04RDF is called for the second time, the problem is read in and stored in appropriate arrays. 
(c) 
The example in Section 10 shows a typical sequence of calls to solve the problem read in by E04RDF. First an empty handle needs to be initialized by E04RAF with NVAR variables. This should be followed by calls to E04REF and E04RNF to formulate the objective function and the constraints, respectively. The arguments of both routines use the same naming and storage as in E04RDF so the variables can be passed unchanged; only DIMA in E04RNF is new and should equal to
$\mathrm{SUM}\left({\mathbf{BLKSIZEA}}\left(1:{\mathbf{NBLK}}\right)\right)$ and NNZASUM in E04RNF is the same as NNZ in E04RDF. You may at this point want to modify option settings using E04ZMF. If dual variables (Lagrangian multipliers) are required from the solver, sufficient space needs to be allocated. The size is equal to the sum of the number of elements of dense triangular matrices for each block. For further details, see the argument UA of the solver E04SVF. The solver should be called and then followed, finally, by a call to E04RZF to deallocate memory associated with the problem. 
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 B308 Department of Mathematical and Computing Sciences, Tokyo Institute of Technology.
5 Arguments
 1: $\mathrm{INFILE}$ – INTEGERInput

On entry: the unit number associated with the sparse SDPA data file.
Note: that the file needs to be opened in read mode by
X04ACF with
${\mathbf{MODE}}=0$.
Constraint:
${\mathbf{INFILE}}\ge 0$.
 2: $\mathrm{MAXNVAR}$ – INTEGERInput

On entry: the upper limit for the number of variables in the problem. If it is set to zero,
CVEC and
NNZA will not be referenced.
Constraint:
${\mathbf{MAXNVAR}}\ge 0$.
 3: $\mathrm{MAXNBLK}$ – INTEGERInput

On entry: the upper limit for the number of matrix constraints (i.e., the number of diagonal blocks within the matrix). If it is set to zero,
BLKSIZEA will not be referenced.
Constraint:
${\mathbf{MAXNBLK}}\ge 0$.
 4: $\mathrm{MAXNNZ}$ – INTEGERInput

On entry: the upper limit on the sum of nonzeros in all matrices
${A}_{\mathit{i}}^{\mathit{k}}$, for
$\mathit{i}=0,1,\dots ,{\mathbf{NVAR}}$ and
$\mathit{k}=1,2,\dots ,{\mathbf{NBLK}}$. If it is set to zero,
IROWA,
ICOLA and
A will not be referenced.
Constraint:
${\mathbf{MAXNNZ}}\ge 0$.
 5: $\mathrm{FILELST}$ – INTEGERInput

On entry: if
${\mathbf{FILELST}}\ne 0$, a listing of the input data is sent to
the current advisory message unit (as defined by
X04ABF).
This can be useful for debugging the data file.
If ${\mathbf{FILELST}}=0$, no listing is produced.
 6: $\mathrm{NVAR}$ – INTEGEROutput
 7: $\mathrm{NBLK}$ – INTEGEROutput
 8: $\mathrm{NNZ}$ – INTEGEROutput

On exit: the actual number of the variables
$n$, matrix constraints
${m}_{A}$ and number of nonzeros of the problem in the file. This also indicates the exact memory needed in
CVEC,
NNZA,
IROWA,
ICOLA,
A and
BLKSIZEA.
 9: $\mathrm{CVEC}\left({\mathbf{MAXNVAR}}\right)$ – REAL (KIND=nag_wp) arrayOutput

On exit: ${\mathbf{CVEC}}\left(\mathit{i}\right)$, for $\mathit{i}=1,2,\dots ,{\mathbf{NVAR}}$, stores the dense vector $c$ of the linear objective function.
 10: $\mathrm{NNZA}\left({\mathbf{MAXNVAR}}+1\right)$ – INTEGER arrayOutput

On exit: ${\mathbf{NNZA}}\left(\mathit{i}+1\right)$, for $\mathit{i}=0,1,\dots ,{\mathbf{NVAR}}$, stores the number of nonzero elements in matrices ${A}_{i}$.
 11: $\mathrm{IROWA}\left({\mathbf{MAXNNZ}}\right)$ – INTEGER arrayOutput
 12: $\mathrm{ICOLA}\left({\mathbf{MAXNNZ}}\right)$ – INTEGER arrayOutput
 13: $\mathrm{A}\left({\mathbf{MAXNNZ}}\right)$ – REAL (KIND=nag_wp) arrayOutput

On exit:
IROWA,
ICOLA and
A store the nonzeros in the upper triangle of matrices
${A}_{\mathit{i}}$, for
$\mathit{i}=0,1,\dots ,{\mathbf{NVAR}}$, in the coordinate storage, i.e.,
${\mathbf{IROWA}}\left(\mathit{j}\right)$ are onebased row indices,
${\mathbf{ICOLA}}\left(\mathit{j}\right)$ are onebased column indices and
${\mathbf{A}}\left(\mathit{j}\right)$ are the values of the nonzero elements, for
$\mathit{j}=1,2,\dots ,{\mathbf{NNZ}}$. See
Section 9.
 14: $\mathrm{BLKSIZEA}\left({\mathbf{MAXNBLK}}\right)$ – INTEGER arrayOutput

On exit: ${\mathbf{BLKSIZEA}}\left(\mathit{k}\right)$, for $\mathit{k}=1,2,\dots ,{\mathbf{NBLK}}$, stores the sizes of the diagonal blocks in matrices ${A}_{i}$ from the top to the bottom.
 15: $\mathrm{IFAIL}$ – INTEGERInput/Output

On entry:
IFAIL must be set to
$0$,
$1\text{ or}1$. If you are unfamiliar with this argument you should refer to
Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
$1\text{ or}1$ is recommended. If the output of error messages is undesirable, then the value
$1$ is recommended. Otherwise, because for this routine the values of the output arguments may be useful even if
${\mathbf{IFAIL}}\ne {\mathbf{0}}$ on exit, the recommended value is
$1$.
When the value $\mathbf{1}\text{ or}1$ is used it is essential to test the value of IFAIL on exit.
On exit:
${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see
Section 6).
6 Error Indicators and Warnings
If on entry
${\mathbf{IFAIL}}=0$ or
$1$, explanatory error messages are output on the current error message unit (as defined by
X04AAF).
Note: E04RDF may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the routine:
 ${\mathbf{IFAIL}}=1$

At least one of
MAXNVAR,
MAXNBLK or
MAXNNZ is too small. Suggested values are returned in
NVAR,
NBLK and
NNZ, respectively.
 ${\mathbf{IFAIL}}=2$

The token on line $\u2329\mathit{\text{value}}\u232a$ at position $\u2329\mathit{\text{value}}\u232a$ to $\u2329\mathit{\text{value}}\u232a$ was not recognized as a valid integer.
 ${\mathbf{IFAIL}}=3$

The token on line $\u2329\mathit{\text{value}}\u232a$ at position $\u2329\mathit{\text{value}}\u232a$ to $\u2329\mathit{\text{value}}\u232a$ was not recognized as a valid real number.
 ${\mathbf{IFAIL}}=4$

The token on line $\u2329\mathit{\text{value}}\u232a$ starting at position $\u2329\mathit{\text{value}}\u232a$ was too long and was not recognized.
 ${\mathbf{IFAIL}}=5$

An invalid number of variables was given on line $\u2329\mathit{\text{value}}\u232a$.
The number stated there is $\u2329\mathit{\text{value}}\u232a$ and needs to be at least $1$.
 ${\mathbf{IFAIL}}=6$

An invalid number of blocks was given on line $\u2329\mathit{\text{value}}\u232a$.
The number stated there is $\u2329\mathit{\text{value}}\u232a$ and needs to be at least $1$.
 ${\mathbf{IFAIL}}=7$

An invalid size of the block number $\u2329\mathit{\text{value}}\u232a$ was given on line $\u2329\mathit{\text{value}}\u232a$.
The number stated there is $\u2329\mathit{\text{value}}\u232a$ and needs to be nonzero.
 ${\mathbf{IFAIL}}=8$

Not enough data was given on line $\u2329\mathit{\text{value}}\u232a$ specifying block sizes.
Expected
${m}_{A}$ tokens but found only $\u2329\mathit{\text{value}}\u232a$.
 ${\mathbf{IFAIL}}=9$

Not enough data was given on line $\u2329\mathit{\text{value}}\u232a$ specifying the objective function.
Expected $n$ tokens but found only $\u2329\mathit{\text{value}}\u232a$.
 ${\mathbf{IFAIL}}=10$

Not enough data was given on line $\u2329\mathit{\text{value}}\u232a$ specifying nonzero matrix elements.
Expected $\u2329\mathit{\text{value}}\u232a$ tokens but found only $\u2329\mathit{\text{value}}\u232a$.
 ${\mathbf{IFAIL}}=11$

Invalid structural data found on line $\u2329\mathit{\text{value}}\u232a$.
The given matrix number is out of bounds. Its value $\u2329\mathit{\text{value}}\u232a$ must be between
$0$ and $n$ (inclusive).
 ${\mathbf{IFAIL}}=12$

Invalid structural data found on line $\u2329\mathit{\text{value}}\u232a$.
The given block number is out of bounds. Its value $\u2329\mathit{\text{value}}\u232a$ must be between
$1$ and ${m}_{A}$ (inclusive).
 ${\mathbf{IFAIL}}=13$

Invalid structural data found on line $\u2329\mathit{\text{value}}\u232a$.
The given row index is out of bounds, it must respect the size of the block. Its value $\u2329\mathit{\text{value}}\u232a$ must be between $\u2329\mathit{\text{value}}\u232a$ and $\u2329\mathit{\text{value}}\u232a$ (inclusive).
 ${\mathbf{IFAIL}}=14$

Invalid structural data found on line $\u2329\mathit{\text{value}}\u232a$.
The given column index is out of bounds, it must respect the size of the block. Its value $\u2329\mathit{\text{value}}\u232a$ must be between $\u2329\mathit{\text{value}}\u232a$ and $\u2329\mathit{\text{value}}\u232a$ (inclusive).
 ${\mathbf{IFAIL}}=15$

Invalid structural data found on line $\u2329\mathit{\text{value}}\u232a$.
The specified nonzero element is not in the upper triangle.
The row index is $\u2329\mathit{\text{value}}\u232a$ and column index is $\u2329\mathit{\text{value}}\u232a$.
 ${\mathbf{IFAIL}}=16$

Invalid structural data found on line $\u2329\mathit{\text{value}}\u232a$.
The specified element belongs to a diagonal block but is not diagonal.
The row index is $\u2329\mathit{\text{value}}\u232a$ and column index is $\u2329\mathit{\text{value}}\u232a$.
 ${\mathbf{IFAIL}}=17$

An entry in the constraints with $\mathit{matno}=\u2329\mathit{\text{value}}\u232a$, $\mathit{blkno}=\u2329\mathit{\text{value}}\u232a$, row index $\u2329\mathit{\text{value}}\u232a$ and column index $\u2329\mathit{\text{value}}\u232a$ was defined more than once. All entries need to be unique.
 ${\mathbf{IFAIL}}=18$

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.
 ${\mathbf{IFAIL}}=19$

The input stream seems to be empty. No data was read.
This might indicate a problem with opening the file, check that
X04ACF was used correctly.
 ${\mathbf{IFAIL}}=20$

Reading from the stream caused an unknown error on line $\u2329\mathit{\text{value}}\u232a$.
 ${\mathbf{IFAIL}}=21$

On entry, ${\mathbf{INFILE}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{INFILE}}\ge 0$.
On entry, ${\mathbf{MAXNBLK}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{MAXNBLK}}\ge 0$.
On entry, ${\mathbf{MAXNNZ}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{MAXNNZ}}\ge 0$.
On entry, ${\mathbf{MAXNVAR}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{MAXNVAR}}\ge 0$.
 ${\mathbf{IFAIL}}=99$
An unexpected error has been triggered by this routine. Please
contact
NAG.
See
Section 3.9 in How to Use the NAG Library and its Documentation for further information.
 ${\mathbf{IFAIL}}=399$
Your licence key may have expired or may not have been installed correctly.
See
Section 3.8 in How to Use the NAG Library and its Documentation for further information.
 ${\mathbf{IFAIL}}=999$
Dynamic memory allocation failed.
See
Section 3.7 in How to Use the NAG Library and its Documentation for further information.
7 Accuracy
Not applicable.
8 Parallelism and Performance
E04RDF is not threaded in any implementation.
The following artificial example demonstrates how the elements of
${A}_{i}$ matrices are organized within arrays
NNZA,
IROWA,
ICOLA and
A. For simplicity let us assume that
${\mathbf{NBLK}}=1$,
${\mathbf{BLKSIZEA}}\left(1\right)=3$ and
${\mathbf{NVAR}}=4$. Please note that the values of the elements were chosen to ease readability rather than to define a valid problem.
Let the matrix constraint
(1)(b) be defined by
All matrices
${A}_{i}$ have to be symmetric and therefore only the elements in the upper triangles are stored. The table below shows how the arrays would be populated.
IROWA 
$\begin{array}{ccc}\phantom{0}1\phantom{\mathrm{.}}\hfill & \phantom{0}2\phantom{\mathrm{.}}\hfill & \phantom{0}3\phantom{\mathrm{.}}\hfill \end{array}$ 
$\begin{array}{cccc}\phantom{0}1\phantom{\mathrm{.}}& \phantom{0}2\phantom{\mathrm{.}}& \phantom{0}2\phantom{\mathrm{.}}& \phantom{0}3\phantom{\mathrm{.}}\end{array}$ 

$\begin{array}{cc}\phantom{0}2\phantom{\mathrm{.}}& \phantom{0}3\phantom{\mathrm{.}}\end{array}$ 
$\begin{array}{ccc}\phantom{0}1\phantom{\mathrm{.}}& \phantom{0}2\phantom{\mathrm{.}}& \phantom{0}3\phantom{\mathrm{.}}\end{array}$ 
ICOLA 
$\begin{array}{ccc}\phantom{0}2\phantom{\mathrm{.}}& \phantom{0}3\phantom{\mathrm{.}}& \phantom{0}3\phantom{\mathrm{.}}\end{array}$ 
$\begin{array}{cccc}\phantom{0}1\phantom{\mathrm{.}}& \phantom{0}2\phantom{\mathrm{.}}& \phantom{0}3\phantom{\mathrm{.}}& \phantom{0}3\phantom{\mathrm{.}}\end{array}$ 

$\begin{array}{cc}\phantom{0}2\phantom{\mathrm{.}}& \phantom{0}3\phantom{\mathrm{.}}\end{array}$ 
$\begin{array}{ccc}\phantom{0}1\phantom{\mathrm{.}}& \phantom{0}1\phantom{\mathrm{.}}& \phantom{0}1\phantom{\mathrm{.}}\end{array}$ 
A 
$\underbrace{\begin{array}{ccc}0.1& 0.2& 0.3\end{array}}$ 
$\underbrace{\begin{array}{cccc}1.1& 1.2& 1.3& 1.4\end{array}}$ 
$\underbrace{\phantom{000.0}}$ 
$\underbrace{\begin{array}{cc}3.1& 3.2\end{array}}$ 
$\underbrace{\begin{array}{ccc}4.1& 4.2& 4.3\end{array}}$ 

${A}_{0}$ 
${A}_{1}$ 
${A}_{2}$ 
${A}_{3}$ 
${A}_{4}$ 
NNZA 
$3$ 
$4$ 
$0$ 
$2$ 
$3$ 
See also
Section 3 in E04RNF which accepts the same format.
10 Example
The following example comes from
Fujisawa et al. (1998).
Imagine that we want to store the following problem in a file in the SDPA format.
There are two variables (
$n=2$) in the problem. One linear matrix constraint and one block of linear constraints can be formed as
(1) with two diagonal blocks (
${m}_{A}=2$). Both blocks have dimension
$2$ but the first one (defining linear constraints) is only diagonal, thus the sizes will be stated as
$\begin{array}{cc}2& 2\end{array}$.
The problem can be rewritten as
where
 $c={\left(\begin{array}{cc}10& 20\end{array}\right)}^{\mathrm{T}}$,

${A}_{0}=\left(\begin{array}{cccc}1& 0& 0& 0\\ 0& 1.5& 0& 0\\ 0& 0& 3& 0\\ 0& 0& 0& 4\end{array}\right)$,

${A}_{1}=\left(\begin{array}{cccc}1& 0& 0& 0\\ 0& 1& 0& 0\\ 0& 0& 0& 0\\ 0& 0& 0& 0\end{array}\right)$,

${A}_{2}=\left(\begin{array}{cccc}0& 0& 0& 0\\ 0& 1& 0& 0\\ 0& 0& 5& 2\\ 0& 0& 2& 6\end{array}\right)$.
The optimal solution is ${x}^{*}={\left(\begin{array}{cc}1.0& 1.0\end{array}\right)}^{\mathrm{T}}$ with the objective function value $30.0$. The optimal Lagrangian multipliers (dual variables) are $10.0$, $0.0$ and $\left(\begin{array}{cc}20/7\text{,}& 20/7\\ 20/7\text{,}& 20/7\end{array}\right)$.
See also
Section 10 in E04RAF for links to further examples in the suite.
10.1 Program Text
Program Text (e04rdfe.f90)
10.2 Program Data
Program Options (e04rdfe.opt)
10.3 Program Results
Program Results (e04rdfe.r)