GALAHAD QPA package#
purpose#
The qpa
package uses a working-set method to solve
non-convex quadratic programs in various guises.
The first is the l\({}_1\) quadratic programming problem
that aims to minimize
The package may also be used to solve the standard quadratic programming problem whose aim is to minimize \(q(x)\) subject to the general linear constraints and simple bounds
Similarly, the package is capable of solving the bound-constrained l\({}_1\) quadratic programming problem whose intention is to minimize \(q(x) + \rho_g v_g(x),\) subject to the above simple bound constraints by automatically adjusting \(\rho_b\) in \(f(x;\rho_g,\rho_b)\).
If the matrix \(H\) is positive semi-definite, a global solution is found. However, if \(H\) is indefinite, the procedure may find a (weak second-order) critical point that is not the global solution to the given problem.
See Section 4 of $GALAHAD/doc/qpa.pdf for additional details.
N.B. In many cases, the alternative quadratic programming package qpb
is faster, and thus to be preferred.
terminolgy#
Any required solution \(x\) for the standard quadratic programming problem necessarily satisfies the primal optimality conditions
method#
At the \(k\)-th iteration of the method, an improvement to the value of the merit function \(m(x, \rho_g, \rho_b ) = q(x) + \rho_g v_g(x) + \rho_b v_b(x)\) at \(x = x^{(k)}\) is sought. This is achieved by first computing a search direction \(s^{(k)}\), and then setting \(x^{(k+1)} = x^{(k)} + \alpha^{(k)} s^{(k)}\), where the stepsize \(\alpha^{(k)}\) is chosen as the first local minimizer of \(\phi ( \alpha ) = m( x^{(k)} + \alpha s^{(k)} , \rho_g, \rho_b )\) as \(\alpha\) incesases from zero. The stepsize calculation is straightforward, and exploits the fact that \(\phi ( \alpha )\) is a piecewise quadratic function of \(\alpha\).
The search direction is defined by a subset of the “active” terms in \(v(x)\), i.e., those for which \(a_i^T x = c_i^l\) or \(c_i^u\) (for \(i=1,\ldots,m\)) or \(x_j = x_j^l\) or \(x_j^u\) (for (\(j=1,\ldots,n\)). The “working” set \(W^{(k)}\) is chosen from the active terms, and is such that its members have linearly independent gradients. The search direction \(s^{(k)}\) is chosen as an approximate solution of the equality-constrained quadratic program
Preconditioning of the conjugate gradient iteration requires the solution of one or more linear systems of the form
SLS
. This
reference matrix may be factorized as a whole (the so-called “augmented
system” approach), or by performing a block elimination first (the
“Schur-complement” approach). The latter is usually to be preferred when
a (non-singular) diagonal preconditioner is used, but may be inefficient
if any of the columns of \(A^{(l)}\) is too dense. Subsequent iterations
within the current major iteration obtain solutions to (3) via the
factors of \(K^{(l)}\) and an appropriate (dense) Schur complement,
obtained from the package SCU
. The major iteration terminates once
the space required to hold the factors of the (growing) Schur complement
exceeds a given threshold.
The working set changes by (a) adding an active term encountered during the determination of the stepsize, or (b) the removal of a term if \(s = 0\) solves (1)–(2). The decision on which to remove in the latter case is based upon the expected decrease upon the removal of an individual term, and this information is available from the magnitude and sign of the components of the auxiliary vector \(u\) computed in (3). At optimality, the components of \(u\) for \(a_i\) terms will all lie between \(0\) and \(\rho_g\) — and those for the other terms between \(0\) and \(\rho_b\) — and any violation of this rule indicates further progress is possible. The components of \(u\) corresonding to the terms involving \(a_i^T x\) are sometimes known as Lagrange multipliers (or generalized gradients) and denoted by \(y\), while those for the remaining \(x_j\) terms are dual variables and denoted by \(z\).
To solve the standard quadratic programming problem, a sequence of \(\ell_1\)-quadratic programs are solved, each with a larger value of \(\rho_g\) and/or \(\rho_b\) than its predecessor. The required solution has been found once the infeasibilities \(v_g(x)\) and \(v_b(x)\) have been reduced to zero at the solution of the \(\ell_1\)-problem for the given \(\rho_g\) and \(\rho_b\).
In order to make the solution as efficient as possible, the variables
and constraints are reordered internally by the package QPP
prior
to solution. In particular, fixed variables and free (unbounded on
both sides) constraints are temporarily removed.
reference#
The method is described in detail in
N. I. M. Gould and Ph. L. Toint ``An iterative working-set method for large-scale non-convex quadratic programming’’. Applied Numerical Mathematics 43(1–2) (2002) 109–128.
matrix storage#
unsymmetric storage#
The unsymmetric \(m\) by \(n\) matrix \(A\) may be presented and stored in a variety of convenient input formats.
Dense storage format: The matrix \(A\) is stored as a compact dense matrix by rows, that is, the values of the entries of each row in turn are stored in order within an appropriate real one-dimensional array. In this case, component \(n \ast i + j\) of the storage array A_val will hold the value \(A_{ij}\) for \(1 \leq i \leq m\), \(1 \leq j \leq n\). The string A_type = ‘dense’ should be specified.
Dense by columns storage format: The matrix \(A\) is stored as a compact dense matrix by columns, that is, the values of the entries of each column in turn are stored in order within an appropriate real one-dimensional array. In this case, component \(m \ast j + i\) of the storage array A_val will hold the value \(A_{ij}\) for \(1 \leq i \leq m\), \(1 \leq j \leq n\). The string A_type = ‘dense_by_columns’ should be specified.
Sparse co-ordinate storage format: Only the nonzero entries of the matrices are stored. For the \(l\)-th entry, \(1 \leq l \leq ne\), of \(A\), its row index i, column index j and value \(A_{ij}\), \(1 \leq i \leq m\), \(1 \leq j \leq n\), are stored as the \(l\)-th components of the integer arrays A_row and A_col and real array A_val, respectively, while the number of nonzeros is recorded as A_ne = \(ne\). The string A_type = ‘coordinate’should be specified.
Sparse row-wise storage format: Again only the nonzero entries are stored, but this time they are ordered so that those in row i appear directly before those in row i+1. For the i-th row of \(A\) the i-th component of the integer array A_ptr holds the position of the first entry in this row, while A_ptr(m+1) holds the total number of entries plus one. The column indices j, \(1 \leq j \leq n\), and values \(A_{ij}\) of the nonzero entries in the i-th row are stored in components l = A_ptr(i), \(\ldots\), A_ptr(i+1)-1, \(1 \leq i \leq m\), of the integer array A_col, and real array A_val, respectively. For sparse matrices, this scheme almost always requires less storage than its predecessor. The string A_type = ‘sparse_by_rows’ should be specified.
Sparse column-wise storage format: Once again only the nonzero entries are stored, but this time they are ordered so that those in column j appear directly before those in column j+1. For the j-th column of \(A\) the j-th component of the integer array A_ptr holds the position of the first entry in this column, while A_ptr(n+1) holds the total number of entries plus one. The row indices i, \(1 \leq i \leq m\), and values \(A_{ij}\) of the nonzero entries in the j-th columnsare stored in components l = A_ptr(j), \(\ldots\), A_ptr(j+1)-1, \(1 \leq j \leq n\), of the integer array A_row, and real array A_val, respectively. As before, for sparse matrices, this scheme almost always requires less storage than the co-ordinate format. The string A_type = ‘sparse_by_columns’ should be specified.
symmetric storage#
The symmetric \(n\) by \(n\) matrix \(H\) may also be presented and stored in a variety of formats. But crucially symmetry is exploited by only storing values from the lower triangular part (i.e, those entries that lie on or below the leading diagonal).
Dense storage format: The matrix \(H\) is stored as a compact dense matrix by rows, that is, the values of the entries of each row in turn are stored in order within an appropriate real one-dimensional array. Since \(H\) is symmetric, only the lower triangular part (that is the part \(H_{ij}\) for \(1 \leq j \leq i \leq n\)) need be held. In this case the lower triangle should be stored by rows, that is component \((i-1) * i / 2 + j\) of the storage array H_val will hold the value \(H_{ij}\) (and, by symmetry, \(H_{ji}\)) for \(1 \leq j \leq i \leq n\). The string H_type = ‘dense’ should be specified.
Sparse co-ordinate storage format: Only the nonzero entries of the matrices are stored. For the \(l\)-th entry, \(1 \leq l \leq ne\), of \(H\), its row index i, column index j and value \(H_{ij}\), \(1 \leq j \leq i \leq n\), are stored as the \(l\)-th components of the integer arrays H_row and H_col and real array H_val, respectively, while the number of nonzeros is recorded as H_ne = \(ne\). Note that only the entries in the lower triangle should be stored. The string H_type = ‘coordinate’ should be specified.
Sparse row-wise storage format: Again only the nonzero entries are stored, but this time they are ordered so that those in row i appear directly before those in row i+1. For the i-th row of \(H\) the i-th component of the integer array H_ptr holds the position of the first entry in this row, while H_ptr(n+1) holds the total number of entries plus one. The column indices j, \(1 \leq j \leq i\), and values \(H_{ij}\) of the entries in the i-th row are stored in components l = H_ptr(i), …, H_ptr(i+1)-1 of the integer array H_col, and real array H_val, respectively. Note that as before only the entries in the lower triangle should be stored. For sparse matrices, this scheme almost always requires less storage than its predecessor. The string H_type = ‘sparse_by_rows’ should be specified.
Diagonal storage format: If \(H\) is diagonal (i.e., \(H_{ij} = 0\) for all \(1 \leq i \neq j \leq n\)) only the diagonals entries \(H_{ii}\), \(1 \leq i \leq n\) need be stored, and the first n components of the array H_val may be used for the purpose. The string H_type = ‘diagonal’ should be specified.
Multiples of the identity storage format: If \(H\) is a multiple of the identity matrix, (i.e., \(H = \alpha I\) where \(I\) is the n by n identity matrix and \(\alpha\) is a scalar), it suffices to store \(\alpha\) as the first component of H_val. The string H_type = ‘scaled_identity’ should be specified.
The identity matrix format: If \(H\) is the identity matrix, no values need be stored. The string H_type = ‘identity’ should be specified.
The zero matrix format: The same is true if \(H\) is the zero matrix, but now the string H_type = ‘zero’ or ‘none’ should be specified.
introduction to function calls#
To solve a given problem, functions from the qpa package must be called in the following order:
qpa_initialize - provide default control parameters and set up initial data structures
qpa_read_specfile (optional) - override control values by reading replacement values from a file
qpa_import - set up problem data structures and fixed values
qpa_reset_control (optional) - possibly change control parameters if a sequence of problems are being solved
solve the problem by calling one of
qpa_solve_qp - solve the quadratic program (2)-(4)
qpa_solve_l1qp - solve the l1 quadratic program (1)
qpa_solve_bcl1qp - solve the bound constrained l1 quadratic program (4)-(5)
qpa_information (optional) - recover information about the solution and solution process
qpa_terminate - deallocate data structures
See the examples section for illustrations of use.
parametric real type T#
Below, the symbol T refers to a parametric real type that may be Float32 (single precision), Float64 (double precision) or, if supported, Float128 (quadruple precision).
callable functions#
function qpa_initialize(T, data, control, status)
Set default control values and initialize private data
Parameters:
data |
holds private internal data |
control |
is a structure containing control information (see qpa_control_type) |
status |
is a scalar variable of type Int32 that gives the exit status from the package. Possible values are (currently):
|
function qpa_read_specfile(T, control, specfile)
Read the content of a specification file, and assign values associated with given keywords to the corresponding control parameters. An in-depth discussion of specification files is available, and a detailed list of keywords with associated default values is provided in $GALAHAD/src/qpa/QPA.template. See also Table 2.1 in the Fortran documentation provided in $GALAHAD/doc/qpa.pdf for a list of how these keywords relate to the components of the control structure.
Parameters:
control |
is a structure containing control information (see qpa_control_type) |
specfile |
is a one-dimensional array of type Vararg{Cchar} that must give the name of the specification file |
function qpa_import(T, control, data, status, n, m, H_type, H_ne, H_row, H_col, H_ptr, A_type, A_ne, A_row, A_col, A_ptr)
Import problem data into internal storage prior to solution.
Parameters:
control |
is a structure whose members provide control parameters for the remaining procedures (see qpa_control_type) |
data |
holds private internal data |
status |
is a scalar variable of type Int32 that gives the exit status from the package. Possible values are:
|
n |
is a scalar variable of type Int32 that holds the number of variables. |
m |
is a scalar variable of type Int32 that holds the number of general linear constraints. |
H_type |
is a one-dimensional array of type Vararg{Cchar} that specifies the symmetric storage scheme used for the Hessian, \(H\). It should be one of ‘coordinate’, ‘sparse_by_rows’, ‘dense’, ‘diagonal’, ‘scaled_identity’, ‘identity’, ‘zero’ or ‘none’, the latter pair if \(H=0\); lower or upper case variants are allowed. |
H_ne |
is a scalar variable of type Int32 that holds the number of entries in the lower triangular part of \(H\) in the sparse co-ordinate storage scheme. It need not be set for any of the other schemes. |
H_row |
is a one-dimensional array of size H_ne and type Int32 that holds the row indices of the lower triangular part of \(H\) in the sparse co-ordinate storage scheme. It need not be set for any of the other three schemes, and in this case can be C_NULL. |
H_col |
is a one-dimensional array of size H_ne and type Int32 that holds the column indices of the lower triangular part of \(H\) in either the sparse co-ordinate, or the sparse row-wise storage scheme. It need not be set when the dense, diagonal or (scaled) identity storage schemes are used, and in this case can be C_NULL. |
H_ptr |
is a one-dimensional array of size n+1 and type Int32 that holds the starting position of each row of the lower triangular part of \(H\), as well as the total number of entries, in the sparse row-wise storage scheme. It need not be set when the other schemes are used, and in this case can be C_NULL. |
A_type |
is a one-dimensional array of type Vararg{Cchar} that specifies the unsymmetric storage scheme used for the constraint Jacobian, \(A\). It should be one of ‘coordinate’, ‘sparse_by_rows’ or ‘dense; lower or upper case variants are allowed. |
A_ne |
is a scalar variable of type Int32 that holds the number of entries in \(A\) in the sparse co-ordinate storage scheme. It need not be set for any of the other schemes. |
A_row |
is a one-dimensional array of size A_ne and type Int32 that holds the row indices of \(A\) in the sparse co-ordinate storage scheme. It need not be set for any of the other schemes, and in this case can be C_NULL. |
A_col |
is a one-dimensional array of size A_ne and type Int32 that holds the column indices of \(A\) in either the sparse co-ordinate, or the sparse row-wise storage scheme. It need not be set when the dense or diagonal storage schemes are used, and in this case can be C_NULL. |
A_ptr |
is a one-dimensional array of size n+1 and type Int32 that holds the starting position of each row of \(A\), as well as the total number of entries, in the sparse row-wise storage scheme. It need not be set when the other schemes are used, and in this case can be C_NULL. |
function qpa_reset_control(T, control, data, status)
Reset control parameters after import if required.
Parameters:
control |
is a structure whose members provide control parameters for the remaining procedures (see qpa_control_type) |
data |
holds private internal data |
status |
is a scalar variable of type Int32 that gives the exit status from the package. Possible values are:
|
function qpa_solve_qp(T, data, status, n, m, h_ne, H_val, g, f, a_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, x_stat, c_stat)
Solve the quadratic program (2)-(4).
Parameters:
data |
holds private internal data |
status |
is a scalar variable of type Int32 that gives the entry and exit status from the package. Possible exit values are:
|
n |
is a scalar variable of type Int32 that holds the number of variables |
m |
is a scalar variable of type Int32 that holds the number of general linear constraints. |
h_ne |
is a scalar variable of type Int32 that holds the number of entries in the lower triangular part of the Hessian matrix \(H\). |
H_val |
is a one-dimensional array of size h_ne and type T that holds the values of the entries of the lower triangular part of the Hessian matrix \(H\) in any of the available storage schemes. |
g |
is a one-dimensional array of size n and type T that holds the linear term \(g\) of the objective function. The j-th component of |
f |
is a scalar of type T that holds the constant term \(f\) of the objective function. |
a_ne |
is a scalar variable of type Int32 that holds the number of entries in the constraint Jacobian matrix \(A\). |
A_val |
is a one-dimensional array of size a_ne and type T that holds the values of the entries of the constraint Jacobian matrix \(A\) in any of the available storage schemes. |
c_l |
is a one-dimensional array of size m and type T that holds the lower bounds \(c^l\) on the constraints \(A x\). The i-th component of |
c_u |
is a one-dimensional array of size m and type T that holds the upper bounds \(c^l\) on the constraints \(A x\). The i-th component of |
x_l |
is a one-dimensional array of size n and type T that holds the lower bounds \(x^l\) on the variables \(x\). The j-th component of |
x_u |
is a one-dimensional array of size n and type T that holds the upper bounds \(x^l\) on the variables \(x\). The j-th component of |
x |
is a one-dimensional array of size n and type T that holds the values \(x\) of the optimization variables. The j-th component of |
c |
is a one-dimensional array of size m and type T that holds the residual \(c(x)\). The i-th component of |
y |
is a one-dimensional array of size n and type T that holds the values \(y\) of the Lagrange multipliers for the general linear constraints. The j-th component of |
z |
is a one-dimensional array of size n and type T that holds the values \(z\) of the dual variables. The j-th component of |
x_stat |
is a one-dimensional array of size n and type Int32 that gives the current status of the problem variables. If x_stat(j) is negative, the variable \(x_j\) most likely lies on its lower bound, if it is positive, it lies on its upper bound, and if it is zero, it lies between its bounds. On entry, if control.cold_start = 0, x_stat should be set as above to provide a guide to the initial working set. |
c_stat |
is a one-dimensional array of size m and type Int32 that gives the current status of the general linear constraints. If c_stat(i) is negative, the constraint value \(a_i^Tx\) most likely lies on its lower bound, if it is positive, it lies on its upper bound, and if it is zero, it lies between its bounds. On entry, if control.cold_start = 0, c_stat should be set as above to provide a guide to the initial working set. |
function qpa_solve_l1qp(T, data, status, n, m, h_ne, H_val, g, f, rho_g, rho_b, a_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, x_stat, c_stat)
Solve the l_1 quadratic program (1).
Parameters:
data |
holds private internal data |
status |
is a scalar variable of type Int32 that gives the entry and exit status from the package. Possible exit values are:
|
n |
is a scalar variable of type Int32 that holds the number of variables |
m |
is a scalar variable of type Int32 that holds the number of general linear constraints. |
h_ne |
is a scalar variable of type Int32 that holds the number of entries in the lower triangular part of the Hessian matrix \(H\). |
H_val |
is a one-dimensional array of size h_ne and type T that holds the values of the entries of the lower triangular part of the Hessian matrix \(H\) in any of the available storage schemes. |
g |
is a one-dimensional array of size n and type T that holds the linear term \(g\) of the objective function. The j-th component of |
f |
is a scalar of type T that holds the constant term \(f\) of the objective function. |
rho_g |
is a scalar of type T that holds the parameter \(\rho_g\) associated with the linear constraints. |
rho_b |
is a scalar of type T that holds the parameter \(\rho_b\) associated with the simple bound constraints. |
a_ne |
is a scalar variable of type Int32 that holds the number of entries in the constraint Jacobian matrix \(A\). |
A_val |
is a one-dimensional array of size a_ne and type T that holds the values of the entries of the constraint Jacobian matrix \(A\) in any of the available storage schemes. |
c_l |
is a one-dimensional array of size m and type T that holds the lower bounds \(c^l\) on the constraints \(A x\). The i-th component of |
c_u |
is a one-dimensional array of size m and type T that holds the upper bounds \(c^l\) on the constraints \(A x\). The i-th component of |
x_l |
is a one-dimensional array of size n and type T that holds the lower bounds \(x^l\) on the variables \(x\). The j-th component of |
x_u |
is a one-dimensional array of size n and type T that holds the upper bounds \(x^l\) on the variables \(x\). The j-th component of |
x |
is a one-dimensional array of size n and type T that holds the values \(x\) of the optimization variables. The j-th component of |
c |
is a one-dimensional array of size m and type T that holds the residual \(c(x)\). The i-th component of |
y |
is a one-dimensional array of size n and type T that holds the values \(y\) of the Lagrange multipliers for the general linear constraints. The j-th component of |
z |
is a one-dimensional array of size n and type T that holds the values \(z\) of the dual variables. The j-th component of |
x_stat |
is a one-dimensional array of size n and type Int32 that gives the current status of the problem variables. If x_stat(j) is negative, the variable \(x_j\) most likely lies on its lower bound, if it is positive, it lies on its upper bound, and if it is zero, it lies between its bounds. On entry, if control.cold_start = 0, x_stat should be set as above to provide a guide to the initial working set. |
c_stat |
is a one-dimensional array of size m and type Int32 that gives the current status of the general linear constraints. If c_stat(i) is negative, the constraint value \(a_i^Tx\) most likely lies on its lower bound, if it is positive, it lies on its upper bound, and if it is zero, it lies between its bounds. On entry, if control.cold_start = 0, c_stat should be set as above to provide a guide to the initial working set. |
function qpa_solve_bcl1qp(T, data, status, n, m, h_ne, H_val, g, f, rho_g, a_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, x_stat, c_stat)
Solve the bound-constrained l_1 quadratic program (4)-(5)
Parameters:
data |
holds private internal data |
status |
is a scalar variable of type Int32 that gives the entry and exit status from the package. Possible exit values are:
|
n |
is a scalar variable of type Int32 that holds the number of variables |
m |
is a scalar variable of type Int32 that holds the number of general linear constraints. |
h_ne |
is a scalar variable of type Int32 that holds the number of entries in the lower triangular part of the Hessian matrix \(H\). |
H_val |
is a one-dimensional array of size h_ne and type T that holds the values of the entries of the lower triangular part of the Hessian matrix \(H\) in any of the available storage schemes. |
g |
is a one-dimensional array of size n and type T that holds the linear term \(g\) of the objective function. The j-th component of |
f |
is a scalar of type T that holds the constant term \(f\) of the objective function. |
rho_g |
is a scalar of type T that holds the parameter \(\rho_g\) associated with the linear constraints. |
a_ne |
is a scalar variable of type Int32 that holds the number of entries in the constraint Jacobian matrix \(A\). |
A_val |
is a one-dimensional array of size a_ne and type T that holds the values of the entries of the constraint Jacobian matrix \(A\) in any of the available storage schemes. |
c_l |
is a one-dimensional array of size m and type T that holds the lower bounds \(c^l\) on the constraints \(A x\). The i-th component of |
c_u |
is a one-dimensional array of size m and type T that holds the upper bounds \(c^l\) on the constraints \(A x\). The i-th component of |
x_l |
is a one-dimensional array of size n and type T that holds the lower bounds \(x^l\) on the variables \(x\). The j-th component of |
x_u |
is a one-dimensional array of size n and type T that holds the upper bounds \(x^l\) on the variables \(x\). The j-th component of |
x |
is a one-dimensional array of size n and type T that holds the values \(x\) of the optimization variables. The j-th component of |
c |
is a one-dimensional array of size m and type T that holds the residual \(c(x)\). The i-th component of |
y |
is a one-dimensional array of size n and type T that holds the values \(y\) of the Lagrange multipliers for the general linear constraints. The j-th component of |
z |
is a one-dimensional array of size n and type T that holds the values \(z\) of the dual variables. The j-th component of |
x_stat |
is a one-dimensional array of size n and type Int32 that gives the current status of the problem variables. If x_stat(j) is negative, the variable \(x_j\) most likely lies on its lower bound, if it is positive, it lies on its upper bound, and if it is zero, it lies between its bounds. On entry, if control.cold_start = 0, x_stat should be set as above to provide a guide to the initial working set. |
c_stat |
is a one-dimensional array of size m and type Int32 that gives the current status of the general linear constraints. If c_stat(i) is negative, the constraint value \(a_i^Tx\) most likely lies on its lower bound, if it is positive, it lies on its upper bound, and if it is zero, it lies between its bounds. On entry, if control.cold_start = 0, c_stat should be set as above to provide a guide to the initial working set. |
function qpa_information(T, data, inform, status)
Provides output information
Parameters:
data |
holds private internal data |
inform |
is a structure containing output information (see qpa_inform_type) |
status |
is a scalar variable of type Int32 that gives the exit status from the package. Possible values are (currently):
|
function qpa_terminate(T, data, control, inform)
Deallocate all internal private storage
Parameters:
data |
holds private internal data |
control |
is a structure containing control information (see qpa_control_type) |
inform |
is a structure containing output information (see qpa_inform_type) |
available structures#
qpa_control_type structure#
struct qpa_control_type{T} f_indexing::Bool error::Int32 out::Int32 print_level::Int32 start_print::Int32 stop_print::Int32 maxit::Int32 factor::Int32 max_col::Int32 max_sc::Int32 indmin::Int32 valmin::Int32 itref_max::Int32 infeas_check_interval::Int32 cg_maxit::Int32 precon::Int32 nsemib::Int32 full_max_fill::Int32 deletion_strategy::Int32 restore_problem::Int32 monitor_residuals::Int32 cold_start::Int32 sif_file_device::Int32 infinity::T feas_tol::T obj_unbounded::T increase_rho_g_factor::T infeas_g_improved_by_factor::T increase_rho_b_factor::T infeas_b_improved_by_factor::T pivot_tol::T pivot_tol_for_dependencies::T zero_pivot::T inner_stop_relative::T inner_stop_absolute::T multiplier_tol::T cpu_time_limit::T clock_time_limit::T treat_zero_bounds_as_general::Bool solve_qp::Bool solve_within_bounds::Bool randomize::Bool array_syntax_worse_than_do_loop::Bool space_critical::Bool deallocate_error_fatal::Bool generate_sif_file::Bool symmetric_linear_solver::NTuple{31,Cchar} sif_file_name::NTuple{31,Cchar} prefix::NTuple{31,Cchar} each_interval::Bool sls_control::sls_control_type{T}
detailed documentation#
control derived type as a Julia structure
components#
Bool f_indexing
use C or Fortran sparse matrix indexing
Int32 error
error and warning diagnostics occur on stream error
Int32 out
general output occurs on stream out
Int32 print_level
the level of output required is specified by print_level
Int32 start_print
any printing will start on this iteration
Int32 stop_print
any printing will stop on this iteration
Int32 maxit
at most maxit inner iterations are allowed
Int32 factor
the factorization to be used. Possible values are 0 automatic 1 Schur-complement factorization 2 augmented-system factorization
Int32 max_col
the maximum number of nonzeros in a column of A which is permitted with the Schur-complement factorization
Int32 max_sc
the maximum permitted size of the Schur complement before a refactorization is performed
Int32 indmin
an initial guess as to the integer workspace required by SLS (OBSOLETE)
Int32 valmin
an initial guess as to the real workspace required by SLS (OBSOLETE)
Int32 itref_max
the maximum number of iterative refinements allowed (OBSOLETE)
Int32 infeas_check_interval
the infeasibility will be checked for improvement every infeas_check_interval iterations (see infeas_g_improved_by_factor and infeas_b_improved_by_factor below)
Int32 cg_maxit
the maximum number of CG iterations allowed. If cg_maxit < 0, this number will be reset to the dimension of the system + 1
Int32 precon
the preconditioner to be used for the CG is defined by precon. Possible values are 0 automatic 1 no preconditioner, i.e, the identity within full factorization 2 full factorization 3 band within full factorization 4 diagonal using the barrier terms within full factorization
Int32 nsemib
the semi-bandwidth of a band preconditioner, if appropriate
Int32 full_max_fill
if the ratio of the number of nonzeros in the factors of the reference matrix to the number of nonzeros in the matrix itself exceeds full_max_fill, and the preconditioner is being selected automatically (precon = 0), a banded approximation will be used instead
Int32 deletion_strategy
the constraint deletion strategy to be used. Possible values are:
0 most violated of all 1 LIFO (last in, first out) k LIFO(k) most violated of the last k in LIFO
Int32 restore_problem
indicate whether and how much of the input problem should be restored on output. Possible values are 0 nothing restored 1 scalar and vector parameters 2 all parameters
Int32 monitor_residuals
the frequency at which residuals will be monitored
Int32 cold_start
indicates whether a cold or warm start should be made. Possible values are
0 warm start - the values set in C_stat and B_stat indicate which constraints will be included in the initial working set. 1 cold start from the value set in X; constraints active at X will determine the initial working set. 2 cold start with no active constraints 3 cold start with only equality constraints active 4 cold start with as many active constraints as possible
Int32 sif_file_device
specifies the unit number to write generated SIF file describing the current problem
T infinity
any bound larger than infinity in modulus will be regarded as infinite
T feas_tol
any constraint violated by less than feas_tol will be considered to be satisfied
T obj_unbounded
if the objective function value is smaller than obj_unbounded, it will be flagged as unbounded from below.
T increase_rho_g_factor
if the problem is currently infeasible and solve_qp (see below) is .TRUE. the current penalty parameter for the general constraints will be increased by increase_rho_g_factor when needed
T infeas_g_improved_by_factor
if the infeasibility of the general constraints has not dropped by a fac of infeas_g_improved_by_factor over the previous infeas_check_interval iterations, the current corresponding penalty parameter will be increase
T increase_rho_b_factor
if the problem is currently infeasible and solve_qp or solve_within_boun (see below) is .TRUE., the current penalty parameter for the simple boun constraints will be increased by increase_rho_b_factor when needed
T infeas_b_improved_by_factor
if the infeasibility of the simple bounds has not dropped by a factor of infeas_b_improved_by_factor over the previous infeas_check_interval iterations, the current corresponding penalty parameter will be increase
T pivot_tol
the threshold pivot used by the matrix factorization. See the documentation for SLS for details (OBSOLE
T pivot_tol_for_dependencies
the threshold pivot used by the matrix factorization when attempting to detect linearly dependent constraints.
T zero_pivot
any pivots smaller than zero_pivot in absolute value will be regarded to zero when attempting to detect linearly dependent constraints (OBSOLE
T inner_stop_relative
the search direction is considered as an acceptable approximation to the minimizer of the model if the gradient of the model in the preconditioning(inverse) norm is less than max( inner_stop_relative * initial preconditioning(inverse) gradient norm, inner_stop_absolute )
T inner_stop_absolute
see inner_stop_relative
T multiplier_tol
any dual variable or Lagrange multiplier which is less than multiplier_t outside its optimal interval will be regarded as being acceptable when checking for optimality
T cpu_time_limit
the maximum CPU time allowed (-ve means infinite)
T clock_time_limit
the maximum elapsed clock time allowed (-ve means infinite)
Bool treat_zero_bounds_as_general
any problem bound with the value zero will be treated as if it were a general value if true
Bool solve_qp
if solve_qp is .TRUE., the value of prob.rho_g and prob.rho_b will be increased as many times as are needed to ensure that the output solution is feasible, and thus aims to solve the quadratic program (2)-(4)
Bool solve_within_bounds
if solve_within_bounds is .TRUE., the value of prob.rho_b will be increased as many times as are needed to ensure that the output solution is feasible with respect to the simple bounds, and thus aims to solve the bound-constrained quadratic program (4)-(5)
Bool randomize
if randomize is .TRUE., the constraint bounds will be perturbed by small random quantities during the first stage of the solution process. Any randomization will ultimately be removed. Randomization helps when solving degenerate problems
Bool array_syntax_worse_than_do_loop
if .array_syntax_worse_than_do_loop is true, f77-style do loops will be used rather than f90-style array syntax for vector operations (OBSOLETE)
Bool space_critical
if .space_critical true, every effort will be made to use as little space as possible. This may result in longer computation time
Bool deallocate_error_fatal
if .deallocate_error_fatal is true, any array/pointer deallocation error will terminate execution. Otherwise, computation will continue
Bool generate_sif_file
if .generate_sif_file is .true. if a SIF file describing the current problem is to be generated
char symmetric_linear_solver[31]
indefinite linear equation solver
NTuple{31,Cchar} sif_file_name
definite linear equation solver
name of generated SIF file containing input problem
NTuple{31,Cchar} prefix
all output lines will be prefixed by .prefix(2:LEN(TRIM(.prefix))-1) where .prefix contains the required string enclosed in quotes, e.g. “string” or ‘string’
Bool each_interval
component specifically for parametric problems (not used at present)
struct sls_control_type sls_control
control parameters for SLS
qpa_time_type structure#
struct qpa_time_type{T} total::T preprocess::T analyse::T factorize::T solve::T clock_total::T clock_preprocess::T clock_analyse::T clock_factorize::T clock_solve::T
detailed documentation#
time derived type as a Julia structure
components#
T total
the total CPU time spent in the package
T preprocess
the CPU time spent preprocessing the problem
T analyse
the CPU time spent analysing the required matrices prior to factorizatio
T factorize
the CPU time spent factorizing the required matrices
T solve
the CPU time spent computing the search direction
T clock_total
the total clock time spent in the package
T clock_preprocess
the clock time spent preprocessing the problem
T clock_analyse
the clock time spent analysing the required matrices prior to factorizat
T clock_factorize
the clock time spent factorizing the required matrices
T clock_solve
the clock time spent computing the search direction
qpa_inform_type structure#
struct qpa_inform_type{T} status::Int32 alloc_status::Int32 bad_alloc::NTuple{81,Cchar} major_iter::Int32 iter::Int32 cg_iter::Int32 factorization_status::Int32 factorization_integer::Int64 factorization_real::Int64 nfacts::Int32 nmods::Int32 num_g_infeas::Int32 num_b_infeas::Int32 obj::T infeas_g::T infeas_b::T merit::T time::qpa_time_type{T} sls_inform::sls_inform_type{T}
detailed documentation#
inform derived type as a Julia structure
components#
Int32 status
return status. See QPA_solve for details
Int32 alloc_status
the status of the last attempted allocation/deallocation
NTuple{81,Cchar} bad_alloc
the name of the array for which an allocation/deallocation error occurred
Int32 major_iter
the total number of major iterations required
Int32 iter
the total number of iterations required
Int32 cg_iter
the total number of conjugate gradient iterations required
Int32 factorization_status
the return status from the factorization
Int64 factorization_integer
the total integer workspace required for the factorization
Int64 factorization_real
the total real workspace required for the factorization
Int32 nfacts
the total number of factorizations performed
Int32 nmods
the total number of factorizations which were modified to ensure that th matrix was an appropriate preconditioner
Int32 num_g_infeas
the number of infeasible general constraints
Int32 num_b_infeas
the number of infeasible simple-bound constraints
T obj
the value of the objective function at the best estimate of the solution determined by QPA_solve
T infeas_g
the 1-norm of the infeasibility of the general constraints
T infeas_b
the 1-norm of the infeasibility of the simple-bound constraints
T merit
the merit function value = obj + rho_g * infeas_g + rho_b * infeas_b
struct qpa_time_type time
timings (see above)
struct sls_inform_type sls_inform
inform parameters for SLS
example calls#
This is an example of how to use the package to solve a quadratic program; the code is available in $GALAHAD/src/qpa/Julia/test_qpa.jl . A variety of supported Hessian and constraint matrix storage formats are shown.
# test_qpa.jl
# Simple code to test the Julia interface to QPA
using GALAHAD
using Test
using Printf
using Accessors
using Quadmath
function test_qpa(::Type{T}) where T
# Derived types
data = Ref{Ptr{Cvoid}}()
control = Ref{qpa_control_type{T}}()
inform = Ref{qpa_inform_type{T}}()
# Set problem data
n = 3 # dimension
m = 2 # number of general constraints
H_ne = 3 # Hesssian elements
H_row = Cint[1, 2, 3] # row indices, NB lower triangle
H_col = Cint[1, 2, 3] # column indices, NB lower triangle
H_ptr = Cint[1, 2, 3, 4] # row pointers
H_val = T[1.0, 1.0, 1.0] # values
g = T[0.0, 2.0, 0.0] # linear term in the objective
f = one(T) # constant term in the objective
rho_g = T(0.1) # penalty paramter for general constraints
rho_b = T(0.1) # penalty paramter for simple bound constraints
A_ne = 4 # Jacobian elements
A_row = Cint[1, 1, 2, 2] # row indices
A_col = Cint[1, 2, 2, 3] # column indices
A_ptr = Cint[1, 3, 5] # row pointers
A_val = T[2.0, 1.0, 1.0, 1.0] # values
c_l = T[1.0, 2.0] # constraint lower bound
c_u = T[2.0, 2.0] # constraint upper bound
x_l = T[-1.0, -Inf, -Inf] # variable lower bound
x_u = T[1.0, Inf, 2.0] # variable upper bound
# Set output storage
c = zeros(T, m) # constraint values
x_stat = zeros(Cint, n) # variable status
c_stat = zeros(Cint, m) # constraint status
st = ' '
status = Ref{Cint}()
@printf(" Fortran sparse matrix indexing\n\n")
@printf(" basic tests of qp storage formats\n\n")
for d in 1:7
# Initialize QPA
qpa_initialize(T, data, control, status)
# Set user-defined control options
@reset control[].f_indexing = true # Fortran sparse matrix indexing
# Start from 0
x = T[0.0, 0.0, 0.0]
y = T[0.0, 0.0]
z = T[0.0, 0.0, 0.0]
# sparse co-ordinate storage
if d == 1
st = 'C'
qpa_import(T, control, data, status, n, m,
"coordinate", H_ne, H_row, H_col, C_NULL,
"coordinate", A_ne, A_row, A_col, C_NULL)
qpa_solve_qp(T, data, status, n, m, H_ne, H_val, g, f,
A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z,
x_stat, c_stat)
end
# sparse by rows
if d == 2
st = 'R'
qpa_import(T, control, data, status, n, m,
"sparse_by_rows", H_ne, C_NULL, H_col, H_ptr,
"sparse_by_rows", A_ne, C_NULL, A_col, A_ptr)
qpa_solve_qp(T, data, status, n, m, H_ne, H_val, g, f,
A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z,
x_stat, c_stat)
end
# dense
if d == 3
st = 'D'
H_dense_ne = 6 # number of elements of H
A_dense_ne = 6 # number of elements of A
H_dense = T[1.0, 0.0, 1.0, 0.0, 0.0, 1.0]
A_dense = T[2.0, 1.0, 0.0, 0.0, 1.0, 1.0]
qpa_import(T, control, data, status, n, m,
"dense", H_ne, C_NULL, C_NULL, C_NULL,
"dense", A_ne, C_NULL, C_NULL, C_NULL)
qpa_solve_qp(T, data, status, n, m, H_dense_ne, H_dense, g, f,
A_dense_ne, A_dense, c_l, c_u, x_l, x_u,
x, c, y, z, x_stat, c_stat)
end
# diagonal
if d == 4
st = 'L'
qpa_import(T, control, data, status, n, m,
"diagonal", H_ne, C_NULL, C_NULL, C_NULL,
"sparse_by_rows", A_ne, C_NULL, A_col, A_ptr)
qpa_solve_qp(T, data, status, n, m, H_ne, H_val, g, f,
A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z,
x_stat, c_stat)
end
# scaled identity
if d == 5
st = 'S'
qpa_import(T, control, data, status, n, m,
"scaled_identity", H_ne, C_NULL, C_NULL, C_NULL,
"sparse_by_rows", A_ne, C_NULL, A_col, A_ptr)
qpa_solve_qp(T, data, status, n, m, H_ne, H_val, g, f,
A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z,
x_stat, c_stat)
end
# identity
if d == 6
st = 'I'
qpa_import(T, control, data, status, n, m,
"identity", H_ne, C_NULL, C_NULL, C_NULL,
"sparse_by_rows", A_ne, C_NULL, A_col, A_ptr)
qpa_solve_qp(T, data, status, n, m, H_ne, H_val, g, f,
A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z,
x_stat, c_stat)
end
# zero
if d == 7
st = 'Z'
qpa_import(T, control, data, status, n, m,
"zero", H_ne, C_NULL, C_NULL, C_NULL,
"sparse_by_rows", A_ne, C_NULL, A_col, A_ptr)
qpa_solve_qp(T, data, status, n, m, H_ne, H_val, g, f,
A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z,
x_stat, c_stat)
end
qpa_information(T, data, inform, status)
if inform[].status == 0
@printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n",
st, inform[].iter, inform[].obj, inform[].status)
else
@printf("%c: QPA_solve exit status = %1i\n", st, inform[].status)
end
# @printf("x: ")
# for i = 1:n
# @printf("%f ", x[i])
# end
# @printf("\n")
# @printf("gradient: ")
# for i = 1:n
# @printf("%f ", g[i])
# end
# @printf("\n")
# Delete internal workspace
qpa_terminate(T, data, control, inform)
end
@printf("\n basic tests of l_1 qp storage formats\n\n")
qpa_initialize(T, data, control, status)
# Set user-defined control options
@reset control[].f_indexing = true # Fortran sparse matrix indexing
# Start from 0
x = T[0.0, 0.0, 0.0]
y = T[0.0, 0.0]
z = T[0.0, 0.0, 0.0]
# solve the l_1qp problem
qpa_import(T, control, data, status, n, m,
"coordinate", H_ne, H_row, H_col, C_NULL,
"coordinate", A_ne, A_row, A_col, C_NULL)
qpa_solve_l1qp(T, data, status, n, m, H_ne, H_val, g, f, rho_g, rho_b,
A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z,
x_stat, c_stat)
qpa_information(T, data, inform, status)
if inform[].status == 0
@printf("%s %6i iterations. Optimal objective value = %5.2f status = %1i\n",
"l1qp ", inform[].iter, inform[].obj, inform[].status)
else
@printf("%c: QPA_solve exit status = %1i\n", st, inform[].status)
end
# Start from 0
for i in 1:n
x[i] = 0.0
z[i] = 0.0
end
for i in 1:m
y[i] = 0.0
end
# solve the bound constrained l_1qp problem
qpa_import(T, control, data, status, n, m,
"coordinate", H_ne, H_row, H_col, C_NULL,
"coordinate", A_ne, A_row, A_col, C_NULL)
qpa_solve_bcl1qp(T, data, status, n, m, H_ne, H_val, g, f, rho_g,
A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z,
x_stat, c_stat)
qpa_information(T, data, inform, status)
if inform[].status == 0
@printf("%s %6i iterations. Optimal objective value = %5.2f status = %1i\n",
"bcl1qp", inform[].iter, inform[].obj, inform[].status)
else
@printf("%c: QPA_solve exit status = %1i\n", st, inform[].status)
end
# Delete internal workspace
qpa_terminate(T, data, control, inform)
return 0
end
@testset "QPA" begin
@test test_qpa(Float32) == 0
@test test_qpa(Float64) == 0
@test test_qpa(Float128) == 0
end