naginterfaces.library.opt.sdp_​read_​sdpa

naginterfaces.library.opt.sdp_read_sdpa(infile, maxnvar, maxnblk, maxnnz, filelst=0, io_manager=None)[source]

sdp_read_sdpa 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 functions handle_init() (initialization), handle_set_linobj() (linear objective function), handle_set_linmatineq() (linear matrix constraints), handle_solve_pennon() (solver) and handle_free() (deallocation) from the NAG optimization modelling suite.

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

https://support.nag.com/numeric/nl/nagdoc_30/flhtml/e04/e04rdf.html

Parameters
infileint

The unit number (see unit_from_fileobj()) associated with the sparse SDPA data file. Note: that the file needs to be opened in read mode.

maxnvarint

The upper limit for the number of variables in the problem. If , and will not be referenced.

maxnblkint

The upper limit for the number of matrix constraints (i.e., the number of diagonal blocks within the matrix). If , will not be referenced.

maxnnzint

The upper limit on the sum of nonzeros in all matrices , for , for . If , , and will not be referenced.

filelstint, optional

If , 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 data file.

If , no listing is produced.

io_managerFileObjManager, optional

Manager for I/O in this routine.

Returns
nvarint

The actual number of the variables , matrix constraints and number of nonzeros of the problem in the file. This also indicates the exact memory needed in , , , , and .

nblkint

The actual number of the variables , matrix constraints and number of nonzeros of the problem in the file. This also indicates the exact memory needed in , , , , and .

nnzint

The actual number of the variables , matrix constraints and number of nonzeros of the problem in the file. This also indicates the exact memory needed in , , , , and .

cvecfloat, ndarray, shape

, for , stores the dense vector of the linear objective function.

nnzaint, ndarray, shape

, for , stores the number of nonzero elements in matrices .

irowaint, ndarray, shape

, and store the nonzeros in the upper triangle of matrices , for , in the coordinate storage, i.e., are one-based row indices, are one-based column indices and are the values of the nonzero elements, for . See Further Comments.

icolaint, ndarray, shape

, and store the nonzeros in the upper triangle of matrices , for , in the coordinate storage, i.e., are one-based row indices, are one-based column indices and are the values of the nonzero elements, for . See Further Comments.

afloat, ndarray, shape

, and store the nonzeros in the upper triangle of matrices , for , in the coordinate storage, i.e., are one-based row indices, are one-based column indices and are the values of the nonzero elements, for . See Further Comments.

blksizeaint, ndarray, shape

, for , stores the sizes of the diagonal blocks in matrices from the top to the bottom.

Raises
NagValueError
(errno )

The token on line at position to was not recognized as a valid integer.

(errno )

The token on line at position to was not recognized as a valid real number.

(errno )

The token on line starting at position was too long and was not recognized.

(errno )

An invalid number of variables was given on line .

The number stated there is and needs to be at least .

(errno )

An invalid number of blocks was given on line .

The number stated there is and needs to be at least .

(errno )

An invalid size of the block number was given on line .

The number stated there is and needs to be nonzero.

(errno )

Not enough data was given on line specifying block sizes.

Expected tokens but found only .

(errno )

Not enough data was given on line specifying the objective function.

Expected tokens but found only .

(errno )

Not enough data was given on line specifying nonzero matrix elements.

Expected tokens but found only .

(errno )

Invalid structural data found on line .

The given matrix number is out of bounds. Its value must be between and (inclusive).

(errno )

Invalid structural data found on line .

The given block number is out of bounds. Its value must be between and (inclusive).

(errno )

Invalid structural data found on line .

The given row index is out of bounds, it must respect the size of the block. Its value must be between and (inclusive).

(errno )

Invalid structural data found on line .

The given column index is out of bounds, it must respect the size of the block. Its value must be between and (inclusive).

(errno )

Invalid structural data found on line .

The specified nonzero element is not in the upper triangle.

The row index is and column index is .

(errno )

Invalid structural data found on line .

The specified element belongs to a diagonal block but is not diagonal.

The row index is and column index is .

(errno )

An entry in the constraints with , , row index and column index was defined more than once. All entries need to be unique.

(errno )

A premature end of the input stream. The part defining the number of variables was not found.

(errno )

A premature end of the input stream. The part defining the number of blocks was not found.

(errno )

A premature end of the input stream. The part defining the dimensions of the blocks was not found.

(errno )

A premature end of the input stream. The part defining the objective function was not found.

(errno )

A premature end of the input stream. The part defining the nonzero entries was not found.

(errno )

The input stream seems to be empty. No data was read.

(errno )

Reading from the stream caused an unknown error on line .

(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: .

Warns
NagAlgorithmicWarning
(errno )

At least one of , or is too small.

should be at least , was .

should be at least , was .

should be at least , was .

Notes

sdp_read_sdpa 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 denotes symmetric matrices and is a vector. The expression stands for a constraint on the eigenvalues of a symmetric matrix , namely, all the eigenvalues should be non-negative, i.e., the matrix 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 linear matrix inequalities

can be equivalently expressed as one matrix inequality (3)(b) in the following block diagonal form where the matrices create the diagonal blocks of :

In addition, notice that if all matrices belonging to the same block, say block , are themselves diagonal matrices (or have dimension ), the associated matrix inequality

actually defines a standard linear constraint

where and columns of the matrix are formed by the diagonals of matrices and , respectively. Precisely, and .

Alternatively, handle_read_file() may be used to read the data file directly into a handle of the NAG optimization modelling suite.

Sparse SDPA file format

The problem data is written in an ASCII input file in the 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 an arbitrary number of lines of comment. Each line of comment must begin with ‘’’ or ‘*’.

  2. The first line after the comments contains integer , the number of variables. The rest of this line is ignored.

  3. The second line after the comments contains integer , the number of blocks in the block diagonal structure of the matrices. Additional text on this line after is ignored.

  4. The third line after the comments contains a vector of 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 ‘’ indicates a block in which only the diagonal elements are nonzero.

  5. The fourth line after the comments contains an -dimensional real vector defining the objective function vector .

  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 is the number of the matrix to which this entry belongs and specifies the block number within this matrix. Together, they uniquely identify the block . Integers and 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, should give the real value of the entry in the matrix. Precisely, .

In the text below and in the file listing () we use the word ‘token’ as a reference to a group of contiguous characters without a space or any other delimeters.

Recommendation on how best to use sdp_read_sdpa

  1. The input file with the problem needs to be opened for reading by the FileObjManager method unit_from_fileobj() (). In this way we avoid possible limitations of maximal lengths of lines inherited by Fortran I/O (the FileObjManager method unit_from_fileobj() 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 might help with possible file formatting errors.

  2. Unless the dimension of the problem (or its overestimate) is known in advance, initially call sdp_read_sdpa with , and . In this case, the exact size of the problem is computed and returned in , and . No other data will be stored and the arrays , , , , , will not be referenced. Then the exact storage can be allocated and the file reopened. When sdp_read_sdpa is called for the second time, the problem is read in and stored in appropriate arrays.

  3. A typical sequence of calls to solve the problem read in by sdp_read_sdpa might be as follows. First, an empty handle needs to be initialized by handle_init() with variables. This should be followed by calls to handle_set_linobj() and handle_set_linmatineq() to formulate the objective function and the constraints, respectively. The arguments of both functions use the same naming and storage as in sdp_read_sdpa so the variables can be passed unchanged; only in handle_set_linmatineq() is new and should be equal to . in handle_set_linmatineq() is the same as in sdp_read_sdpa. You may at this point want to modify option settings using handle_opt_set(). 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 in the solver handle_solve_pennon(). The solver should be called and then followed, finally, by a call to handle_free() to deallocate memory associated with the problem.

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.