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
The package may also be used to solve the
standard quadratic programming problem
whose aim is to minimize
Similarly, the package is capable of solving the
bound-constrained l
If the matrix
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
method#
At the
The search direction is defined by a subset of the “active” terms in
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 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
To solve the standard quadratic programming problem, a sequence of
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#
The unsymmetric
Dense storage format:
The matrix
Dense by columns storage format:
The matrix
Sparse co-ordinate storage format:
Only the nonzero entries of the matrices are stored.
For the
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
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
The symmetric
Dense storage format:
The matrix
Sparse co-ordinate storage format:
Only the nonzero entries of the matrices are stored.
For the
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
Diagonal storage format:
If
Multiples of the identity storage format:
If
The identity matrix format:
If
The zero matrix format:
The same is true if
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.
callable functions#
overview of functions provided#
// typedefs typedef float spc_; typedef double rpc_; typedef int ipc_; // structs struct qpa_control_type; struct qpa_inform_type; struct qpa_time_type; // function calls void qpa_initialize(void **data, struct qpa_control_type* control, ipc_ *status); void qpa_read_specfile(struct qpa_control_type* control, const char specfile[]); void qpa_import( struct qpa_control_type* control, void **data, ipc_ *status, ipc_ n, ipc_ m, const char H_type[], ipc_ H_ne, const ipc_ H_row[], const ipc_ H_col[], const ipc_ H_ptr[], const char A_type[], ipc_ A_ne, const ipc_ A_row[], const ipc_ A_col[], const ipc_ A_ptr[] ); void qpa_reset_control( struct qpa_control_type* control, void **data, ipc_ *status ); void qpa_solve_qp( void **data, ipc_ *status, ipc_ n, ipc_ m, ipc_ h_ne, const rpc_ H_val[], const rpc_ g[], const rpc_ f, ipc_ a_ne, const rpc_ A_val[], const rpc_ c_l[], const rpc_ c_u[], const rpc_ x_l[], const rpc_ x_u[], rpc_ x[], rpc_ c[], rpc_ y[], rpc_ z[], ipc_ x_stat[], ipc_ c_stat[] ); void qpa_solve_l1qp( void **data, ipc_ *status, ipc_ n, ipc_ m, ipc_ h_ne, const rpc_ H_val[], const rpc_ g[], const rpc_ f, const rpc_ rho_g, const rpc_ rho_b, ipc_ a_ne, const rpc_ A_val[], const rpc_ c_l[], const rpc_ c_u[], const rpc_ x_l[], const rpc_ x_u[], rpc_ x[], rpc_ c[], rpc_ y[], rpc_ z[], ipc_ x_stat[], ipc_ c_stat[] ); void qpa_solve_bcl1qp( void **data, ipc_ *status, ipc_ n, ipc_ m, ipc_ h_ne, const rpc_ H_val[], const rpc_ g[], const rpc_ f, const rpc_ rho_g, ipc_ a_ne, const rpc_ A_val[], const rpc_ c_l[], const rpc_ c_u[], const rpc_ x_l[], const rpc_ x_u[], rpc_ x[], rpc_ c[], rpc_ y[], rpc_ z[], ipc_ x_stat[], ipc_ c_stat[] ); void qpa_information(void **data, struct qpa_inform_type* inform, ipc_ *status); void qpa_terminate( void **data, struct qpa_control_type* control, struct qpa_inform_type* inform );
typedefs#
typedef float spc_
spc_
is real single precision
typedef double rpc_
rpc_
is the real working precision used, but may be changed to float
by
defining the preprocessor variable REAL_32
or (if supported) to
__real128
using the variable REAL_128
.
typedef int ipc_
ipc_
is the default integer word length used, but may be changed to
int64_t
by defining the preprocessor variable INTEGER_64
.
function calls#
void qpa_initialize(void **data, struct qpa_control_type* control, ipc_ *status)
Set default control values and initialize private data
Parameters:
data |
holds private internal data |
control |
is a struct containing control information (see qpa_control_type) |
status |
is a scalar variable of type ipc_, that gives the exit status from the package. Possible values are (currently):
|
void qpa_read_specfile(struct qpa_control_type* control, const char 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 struct containing control information (see qpa_control_type) |
specfile |
is a character string containing the name of the specification file |
void qpa_import( struct qpa_control_type* control, void **data, ipc_ *status, ipc_ n, ipc_ m, const char H_type[], ipc_ H_ne, const ipc_ H_row[], const ipc_ H_col[], const ipc_ H_ptr[], const char A_type[], ipc_ A_ne, const ipc_ A_row[], const ipc_ A_col[], const ipc_ A_ptr[] )
Import problem data into internal storage prior to solution.
Parameters:
control |
is a struct whose members provide control paramters for the remaining prcedures (see qpa_control_type) |
data |
holds private internal data |
status |
is a scalar variable of type ipc_, that gives the exit status from the package. Possible values are:
|
n |
is a scalar variable of type ipc_, that holds the number of variables. |
m |
is a scalar variable of type ipc_, that holds the number of general linear constraints. |
H_type |
is a one-dimensional array of type char that specifies the symmetric storage scheme used for the Hessian, |
H_ne |
is a scalar variable of type ipc_, that holds the number of entries in the lower triangular part of |
H_row |
is a one-dimensional array of size H_ne and type ipc_, that holds the row indices of the lower triangular part of |
H_col |
is a one-dimensional array of size H_ne and type ipc_, that holds the column indices of the lower triangular part of |
H_ptr |
is a one-dimensional array of size n+1 and type ipc_, that holds the starting position of each row of the lower triangular part of |
A_type |
is a one-dimensional array of type char that specifies the unsymmetric storage scheme used for the constraint Jacobian, |
A_ne |
is a scalar variable of type ipc_, that holds the number of entries in |
A_row |
is a one-dimensional array of size A_ne and type ipc_, that holds the row indices of |
A_col |
is a one-dimensional array of size A_ne and type ipc_, that holds the column indices of |
A_ptr |
is a one-dimensional array of size n+1 and type ipc_, that holds the starting position of each row of |
void qpa_reset_control( struct qpa_control_type* control, void **data, ipc_ *status )
Reset control parameters after import if required.
Parameters:
control |
is a struct whose members provide control paramters for the remaining prcedures (see qpa_control_type) |
data |
holds private internal data |
status |
is a scalar variable of type ipc_, that gives the exit status from the package. Possible values are:
|
void qpa_solve_qp( void **data, ipc_ *status, ipc_ n, ipc_ m, ipc_ h_ne, const rpc_ H_val[], const rpc_ g[], const rpc_ f, ipc_ a_ne, const rpc_ A_val[], const rpc_ c_l[], const rpc_ c_u[], const rpc_ x_l[], const rpc_ x_u[], rpc_ x[], rpc_ c[], rpc_ y[], rpc_ z[], ipc_ x_stat[], ipc_ c_stat[] )
Solve the quadratic program (2)-(4).
Parameters:
data |
holds private internal data |
status |
is a scalar variable of type ipc_, that gives the entry and exit status from the package. Possible exit values are:
|
n |
is a scalar variable of type ipc_, that holds the number of variables |
m |
is a scalar variable of type ipc_, that holds the number of general linear constraints. |
h_ne |
is a scalar variable of type ipc_, that holds the number of entries in the lower triangular part of the Hessian matrix |
H_val |
is a one-dimensional array of size h_ne and type rpc_, that holds the values of the entries of the lower triangular part of the Hessian matrix |
g |
is a one-dimensional array of size n and type rpc_, that holds the linear term |
f |
is a scalar of type rpc_, that holds the constant term |
a_ne |
is a scalar variable of type ipc_, that holds the number of entries in the constraint Jacobian matrix |
A_val |
is a one-dimensional array of size a_ne and type rpc_, that holds the values of the entries of the constraint Jacobian matrix |
c_l |
is a one-dimensional array of size m and type rpc_, that holds the lower bounds |
c_u |
is a one-dimensional array of size m and type rpc_, that holds the upper bounds |
x_l |
is a one-dimensional array of size n and type rpc_, that holds the lower bounds |
x_u |
is a one-dimensional array of size n and type rpc_, that holds the upper bounds |
x |
is a one-dimensional array of size n and type rpc_, that holds the values |
c |
is a one-dimensional array of size m and type rpc_, that holds the residual |
y |
is a one-dimensional array of size n and type rpc_, that holds the values |
z |
is a one-dimensional array of size n and type rpc_, that holds the values |
x_stat |
is a one-dimensional array of size n and type ipc_, that gives the current status of the problem variables. If x_stat(j) is negative, the variable |
c_stat |
is a one-dimensional array of size m and type ipc_, that gives the current status of the general linear constraints. If c_stat(i) is negative, the constraint value |
void qpa_solve_l1qp( void **data, ipc_ *status, ipc_ n, ipc_ m, ipc_ h_ne, const rpc_ H_val[], const rpc_ g[], const rpc_ f, const rpc_ rho_g, const rpc_ rho_b, ipc_ a_ne, const rpc_ A_val[], const rpc_ c_l[], const rpc_ c_u[], const rpc_ x_l[], const rpc_ x_u[], rpc_ x[], rpc_ c[], rpc_ y[], rpc_ z[], ipc_ x_stat[], ipc_ c_stat[] )
Solve the l_1 quadratic program (1).
Parameters:
data |
holds private internal data |
status |
is a scalar variable of type ipc_, that gives the entry and exit status from the package. Possible exit values are:
|
n |
is a scalar variable of type ipc_, that holds the number of variables |
m |
is a scalar variable of type ipc_, that holds the number of general linear constraints. |
h_ne |
is a scalar variable of type ipc_, that holds the number of entries in the lower triangular part of the Hessian matrix |
H_val |
is a one-dimensional array of size h_ne and type rpc_, that holds the values of the entries of the lower triangular part of the Hessian matrix |
g |
is a one-dimensional array of size n and type rpc_, that holds the linear term |
f |
is a scalar of type rpc_, that holds the constant term |
rho_g |
is a scalar of type rpc_, that holds the parameter |
rho_b |
is a scalar of type rpc_, that holds the parameter |
a_ne |
is a scalar variable of type ipc_, that holds the number of entries in the constraint Jacobian matrix |
A_val |
is a one-dimensional array of size a_ne and type rpc_, that holds the values of the entries of the constraint Jacobian matrix |
c_l |
is a one-dimensional array of size m and type rpc_, that holds the lower bounds |
c_u |
is a one-dimensional array of size m and type rpc_, that holds the upper bounds |
x_l |
is a one-dimensional array of size n and type rpc_, that holds the lower bounds |
x_u |
is a one-dimensional array of size n and type rpc_, that holds the upper bounds |
x |
is a one-dimensional array of size n and type rpc_, that holds the values |
c |
is a one-dimensional array of size m and type rpc_, that holds the residual |
y |
is a one-dimensional array of size n and type rpc_, that holds the values |
z |
is a one-dimensional array of size n and type rpc_, that holds the values |
x_stat |
is a one-dimensional array of size n and type ipc_, that gives the current status of the problem variables. If x_stat(j) is negative, the variable |
c_stat |
is a one-dimensional array of size m and type ipc_, that gives the current status of the general linear constraints. If c_stat(i) is negative, the constraint value |
void qpa_solve_bcl1qp( void **data, ipc_ *status, ipc_ n, ipc_ m, ipc_ h_ne, const rpc_ H_val[], const rpc_ g[], const rpc_ f, const rpc_ rho_g, ipc_ a_ne, const rpc_ A_val[], const rpc_ c_l[], const rpc_ c_u[], const rpc_ x_l[], const rpc_ x_u[], rpc_ x[], rpc_ c[], rpc_ y[], rpc_ z[], ipc_ x_stat[], ipc_ 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 ipc_, that gives the entry and exit status from the package. Possible exit values are:
|
n |
is a scalar variable of type ipc_, that holds the number of variables |
m |
is a scalar variable of type ipc_, that holds the number of general linear constraints. |
h_ne |
is a scalar variable of type ipc_, that holds the number of entries in the lower triangular part of the Hessian matrix |
H_val |
is a one-dimensional array of size h_ne and type rpc_, that holds the values of the entries of the lower triangular part of the Hessian matrix |
g |
is a one-dimensional array of size n and type rpc_, that holds the linear term |
f |
is a scalar of type rpc_, that holds the constant term |
rho_g |
is a scalar of type rpc_, that holds the parameter |
a_ne |
is a scalar variable of type ipc_, that holds the number of entries in the constraint Jacobian matrix |
A_val |
is a one-dimensional array of size a_ne and type rpc_, that holds the values of the entries of the constraint Jacobian matrix |
c_l |
is a one-dimensional array of size m and type rpc_, that holds the lower bounds |
c_u |
is a one-dimensional array of size m and type rpc_, that holds the upper bounds |
x_l |
is a one-dimensional array of size n and type rpc_, that holds the lower bounds |
x_u |
is a one-dimensional array of size n and type rpc_, that holds the upper bounds |
x |
is a one-dimensional array of size n and type rpc_, that holds the values |
c |
is a one-dimensional array of size m and type rpc_, that holds the residual |
y |
is a one-dimensional array of size n and type rpc_, that holds the values |
z |
is a one-dimensional array of size n and type rpc_, that holds the values |
x_stat |
is a one-dimensional array of size n and type ipc_, that gives the current status of the problem variables. If x_stat(j) is negative, the variable |
c_stat |
is a one-dimensional array of size m and type ipc_, that gives the current status of the general linear constraints. If c_stat(i) is negative, the constraint value |
void qpa_information(void **data, struct qpa_inform_type* inform, ipc_ *status)
Provides output information
Parameters:
data |
holds private internal data |
inform |
is a struct containing output information (see qpa_inform_type) |
status |
is a scalar variable of type ipc_, that gives the exit status from the package. Possible values are (currently):
|
void qpa_terminate( void **data, struct qpa_control_type* control, struct qpa_inform_type* inform )
Deallocate all internal private storage
Parameters:
data |
holds private internal data |
control |
is a struct containing control information (see qpa_control_type) |
inform |
is a struct containing output information (see qpa_inform_type) |
available structures#
qpa_control_type structure#
#include <galahad_qpa.h> struct qpa_control_type { // components bool f_indexing; ipc_ error; ipc_ out; ipc_ print_level; ipc_ start_print; ipc_ stop_print; ipc_ maxit; ipc_ factor; ipc_ max_col; ipc_ max_sc; ipc_ indmin; ipc_ valmin; ipc_ itref_max; ipc_ infeas_check_interval; ipc_ cg_maxit; ipc_ precon; ipc_ nsemib; ipc_ full_max_fill; ipc_ deletion_strategy; ipc_ restore_problem; ipc_ monitor_residuals; ipc_ cold_start; ipc_ sif_file_device; rpc_ infinity; rpc_ feas_tol; rpc_ obj_unbounded; rpc_ increase_rho_g_factor; rpc_ infeas_g_improved_by_factor; rpc_ increase_rho_b_factor; rpc_ infeas_b_improved_by_factor; rpc_ pivot_tol; rpc_ pivot_tol_for_dependencies; rpc_ zero_pivot; rpc_ inner_stop_relative; rpc_ inner_stop_absolute; rpc_ multiplier_tol; rpc_ cpu_time_limit; rpc_ clock_time_limit; bool 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; char symmetric_linear_solver[31]; char sif_file_name[31]; char prefix[31]; bool each_interval; struct sls_control_type sls_control; };
detailed documentation#
control derived type as a C struct
components#
bool f_indexing
use C or Fortran sparse matrix indexing
ipc_ error
error and warning diagnostics occur on stream error
ipc_ out
general output occurs on stream out
ipc_ print_level
the level of output required is specified by print_level
ipc_ start_print
any printing will start on this iteration
ipc_ stop_print
any printing will stop on this iteration
ipc_ maxit
at most maxit inner iterations are allowed
ipc_ factor
the factorization to be used. Possible values are 0 automatic 1 Schur-complement factorization 2 augmented-system factorization
ipc_ max_col
the maximum number of nonzeros in a column of A which is permitted with the Schur-complement factorization
ipc_ max_sc
the maximum permitted size of the Schur complement before a refactorization is performed
ipc_ indmin
an initial guess as to the integer workspace required by SLS (OBSOLETE)
ipc_ valmin
an initial guess as to the real workspace required by SLS (OBSOLETE)
ipc_ itref_max
the maximum number of iterative refinements allowed (OBSOLETE)
ipc_ 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)
ipc_ 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
ipc_ 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
ipc_ nsemib
the semi-bandwidth of a band preconditioner, if appropriate
ipc_ 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
ipc_ 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
ipc_ 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
ipc_ monitor_residuals
the frequency at which residuals will be monitored
ipc_ 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
ipc_ sif_file_device
specifies the unit number to write generated SIF file describing the current problem
rpc_ infinity
any bound larger than infinity in modulus will be regarded as infinite
rpc_ feas_tol
any constraint violated by less than feas_tol will be considered to be satisfied
rpc_ obj_unbounded
if the objective function value is smaller than obj_unbounded, it will be flagged as unbounded from below.
rpc_ 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
rpc_ 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
rpc_ 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
rpc_ 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
rpc_ pivot_tol
the threshold pivot used by the matrix factorization. See the documentation for SLS for details (OBSOLE
rpc_ pivot_tol_for_dependencies
the threshold pivot used by the matrix factorization when attempting to detect linearly dependent constraints.
rpc_ zero_pivot
any pivots smaller than zero_pivot in absolute value will be regarded to zero when attempting to detect linearly dependent constraints (OBSOLE
rpc_ 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 )
rpc_ inner_stop_absolute
see inner_stop_relative
rpc_ 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
rpc_ cpu_time_limit
the maximum CPU time allowed (-ve means infinite)
rpc_ 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]
the name of the symmetric-indefinite linear equation solver used. Possible choices are currently: ‘sils’, ‘ma27’, ‘ma57’, ‘ma77’, ‘ma86’, ‘ma97’, ‘ssids’, ‘mumps’, ‘pardiso’, ‘mkl_pardiso’, ‘pastix’, ‘wsmp’, and ‘sytr’, although only ‘sytr’ and, for OMP 4.0-compliant compilers, ‘ssids’ are installed by default; others are easily installed (see README.external). More details of the capabilities of each solver are provided in the documentation for galahad_sls.
char sif_file_name[31]
definite linear equation solver
name of generated SIF file containing input problem
char prefix[31]
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#
#include <galahad_qpa.h> struct qpa_time_type { // components rpc_ total; rpc_ preprocess; rpc_ analyse; rpc_ factorize; rpc_ solve; rpc_ clock_total; rpc_ clock_preprocess; rpc_ clock_analyse; rpc_ clock_factorize; rpc_ clock_solve; };
detailed documentation#
time derived type as a C struct
components#
rpc_ total
the total CPU time spent in the package
rpc_ preprocess
the CPU time spent preprocessing the problem
rpc_ analyse
the CPU time spent analysing the required matrices prior to factorizatio
rpc_ factorize
the CPU time spent factorizing the required matrices
rpc_ solve
the CPU time spent computing the search direction
rpc_ clock_total
the total clock time spent in the package
rpc_ clock_preprocess
the clock time spent preprocessing the problem
rpc_ clock_analyse
the clock time spent analysing the required matrices prior to factorizat
rpc_ clock_factorize
the clock time spent factorizing the required matrices
rpc_ clock_solve
the clock time spent computing the search direction
qpa_inform_type structure#
#include <galahad_qpa.h> struct qpa_inform_type { // components ipc_ status; ipc_ alloc_status; char bad_alloc[81]; ipc_ major_iter; ipc_ iter; ipc_ cg_iter; ipc_ factorization_status; int64_t factorization_integer; int64_t factorization_real; ipc_ nfacts; ipc_ nmods; ipc_ num_g_infeas; ipc_ num_b_infeas; rpc_ obj; rpc_ infeas_g; rpc_ infeas_b; rpc_ merit; struct qpa_time_type time; struct sls_inform_type sls_inform; };
detailed documentation#
inform derived type as a C struct
components#
ipc_ status
return status. See QPA_solve for details
ipc_ alloc_status
the status of the last attempted allocation/deallocation
char bad_alloc[81]
the name of the array for which an allocation/deallocation error occurred
ipc_ major_iter
the total number of major iterations required
ipc_ iter
the total number of iterations required
ipc_ cg_iter
the total number of conjugate gradient iterations required
ipc_ factorization_status
the return status from the factorization
int64_t factorization_integer
the total integer workspace required for the factorization
int64_t factorization_real
the total real workspace required for the factorization
ipc_ nfacts
the total number of factorizations performed
ipc_ nmods
the total number of factorizations which were modified to ensure that th matrix was an appropriate preconditioner
ipc_ num_g_infeas
the number of infeasible general constraints
ipc_ num_b_infeas
the number of infeasible simple-bound constraints
rpc_ obj
the value of the objective function at the best estimate of the solution determined by QPA_solve
rpc_ infeas_g
the 1-norm of the infeasibility of the general constraints
rpc_ infeas_b
the 1-norm of the infeasibility of the simple-bound constraints
rpc_ 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/C/qpat.c . A variety of supported Hessian and constraint matrix storage formats are shown.
Notice that C-style indexing is used, and that this is flagged by setting
control.f_indexing
to false
. The floating-point type rpc_
is set in galahad_precision.h
to double
by default, but to float
if the preprocessor variable SINGLE
is defined. Similarly, the integer
type ipc_
from galahad_precision.h
is set to int
by default,
but to int64_t
if the preprocessor variable INTEGER_64
is defined.
/* qpat.c */
/* Full test for the QPA C interface using C sparse matrix indexing */
#include <stdio.h>
#include <math.h>
#include <string.h>
#include "galahad_precision.h"
#include "galahad_cfunctions.h"
#include "galahad_qpa.h"
#ifdef REAL_128
#include <quadmath.h>
#endif
int main(void) {
// Derived types
void *data;
struct qpa_control_type control;
struct qpa_inform_type inform;
// Set problem data
ipc_ n = 3; // dimension
ipc_ m = 2; // number of general constraints
ipc_ H_ne = 3; // Hesssian elements
ipc_ H_row[] = {0, 1, 2 }; // row indices, NB lower triangle
ipc_ H_col[] = {0, 1, 2}; // column indices, NB lower triangle
ipc_ H_ptr[] = {0, 1, 2, 3}; // row pointers
rpc_ H_val[] = {1.0, 1.0, 1.0 }; // values
rpc_ g[] = {0.0, 2.0, 0.0}; // linear term in the objective
rpc_ f = 1.0; // constant term in the objective
rpc_ rho_g = 0.1; // penalty paramter for general constraints
rpc_ rho_b = 0.1; // penalty paramter for simple bound constraints
ipc_ A_ne = 4; // Jacobian elements
ipc_ A_row[] = {0, 0, 1, 1}; // row indices
ipc_ A_col[] = {0, 1, 1, 2}; // column indices
ipc_ A_ptr[] = {0, 2, 4}; // row pointers
rpc_ A_val[] = {2.0, 1.0, 1.0, 1.0 }; // values
rpc_ c_l[] = {1.0, 2.0}; // constraint lower bound
rpc_ c_u[] = {2.0, 2.0}; // constraint upper bound
rpc_ x_l[] = {-1.0, - INFINITY, - INFINITY}; // variable lower bound
rpc_ x_u[] = {1.0, INFINITY, 2.0}; // variable upper bound
// Set output storage
rpc_ c[m]; // constraint values
ipc_ x_stat[n]; // variable status
ipc_ c_stat[m]; // constraint status
char st = ' ';
ipc_ status;
printf(" C sparse matrix indexing\n\n");
printf(" basic tests of qp storage formats\n\n");
for( ipc_ d=1; d <= 7; d++){
// Initialize QPA
qpa_initialize( &data, &control, &status );
strcpy(control.symmetric_linear_solver, "sytr ") ;
// Set user-defined control options
control.f_indexing = false; // C sparse matrix indexing
// Start from 0
rpc_ x[] = {0.0,0.0,0.0};
rpc_ y[] = {0.0,0.0};
rpc_ z[] = {0.0,0.0,0.0};
switch(d){
case 1: // sparse co-ordinate storage
st = 'C';
qpa_import( &control, &data, &status, n, m,
"coordinate", H_ne, H_row, H_col, NULL,
"coordinate", A_ne, A_row, A_col, NULL );
qpa_solve_qp( &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 );
break;
printf(" case %1" i_ipc_ " break\n",d);
case 2: // sparse by rows
st = 'R';
qpa_import( &control, &data, &status, n, m,
"sparse_by_rows", H_ne, NULL, H_col, H_ptr,
"sparse_by_rows", A_ne, NULL, A_col, A_ptr );
qpa_solve_qp( &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 );
break;
case 3: // dense
st = 'D';
ipc_ H_dense_ne = 6; // number of elements of H
ipc_ A_dense_ne = 6; // number of elements of A
rpc_ H_dense[] = {1.0, 0.0, 1.0, 0.0, 0.0, 1.0};
rpc_ A_dense[] = {2.0, 1.0, 0.0, 0.0, 1.0, 1.0};
qpa_import( &control, &data, &status, n, m,
"dense", H_ne, NULL, NULL, NULL,
"dense", A_ne, NULL, NULL, NULL );
qpa_solve_qp( &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 );
break;
case 4: // diagonal
st = 'L';
qpa_import( &control, &data, &status, n, m,
"diagonal", H_ne, NULL, NULL, NULL,
"sparse_by_rows", A_ne, NULL, A_col, A_ptr );
qpa_solve_qp( &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 );
break;
case 5: // scaled identity
st = 'S';
qpa_import( &control, &data, &status, n, m,
"scaled_identity", H_ne, NULL, NULL, NULL,
"sparse_by_rows", A_ne, NULL, A_col, A_ptr );
qpa_solve_qp( &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 );
break;
case 6: // identity
st = 'I';
qpa_import( &control, &data, &status, n, m,
"identity", H_ne, NULL, NULL, NULL,
"sparse_by_rows", A_ne, NULL, A_col, A_ptr );
qpa_solve_qp( &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 );
break;
case 7: // zero
st = 'Z';
qpa_import( &control, &data, &status, n, m,
"zero", H_ne, NULL, NULL, NULL,
"sparse_by_rows", A_ne, NULL, A_col, A_ptr );
qpa_solve_qp( &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 );
break;
}
qpa_information( &data, &inform, &status );
if(inform.status == 0){
#ifdef REAL_128
// interim replacement for quad output: $GALAHAD/include/galahad_pquad_f.h
#include "galahad_pquad_f.h"
#else
printf("%c:%6" i_ipc_ " iterations. Optimal objective "
"value = %.2f status = %1" i_ipc_ "\n",
st, inform.iter, inform.obj, inform.status);
#endif
}else{
printf("%c: QPA_solve exit status = %1" i_ipc_ "\n",
st, inform.status);
}
//printf("x: ");
//for( ipc_ i = 0; i < n; i++) printf("%f ", x[i]);
//printf("\n");
//printf("gradient: ");
//for( ipc_ i = 0; i < n; i++) printf("%f ", g[i]);
//printf("\n");
// Delete internal workspace
qpa_terminate( &data, &control, &inform );
}
printf("\n basic tests of l_1 qp storage formats\n\n");
qpa_initialize( &data, &control, &status );
strcpy(control.symmetric_linear_solver, "sytr ") ;
// Set user-defined control options
control.f_indexing = false; // C sparse matrix indexing
// Start from 0
rpc_ x[] = {0.0,0.0,0.0};
rpc_ y[] = {0.0,0.0};
rpc_ z[] = {0.0,0.0,0.0};
// solve the l_1qp problem
qpa_import( &control, &data, &status, n, m,
"coordinate", H_ne, H_row, H_col, NULL,
"coordinate", A_ne, A_row, A_col, NULL );
qpa_solve_l1qp( &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( &data, &inform, &status );
if(inform.status == 0){
#ifdef REAL_128
// interim replacement for quad output: $GALAHAD/include/galahad_pquad_f.h
#include "galahad_pquad_f.h"
#else
printf("%c:%6" i_ipc_ " iterations. Optimal objective "
"value = %.2f status = %1" i_ipc_ "\n",
st, inform.iter, inform.obj, inform.status);
#endif
}else{
printf("%c: QPA_solve exit status = %1" i_ipc_ "\n", st, inform.status);
}
// Start from 0
for( ipc_ i=0; i <= n-1; i++) x[i] = 0.0;
for( ipc_ i=0; i <= m-1; i++) y[i] = 0.0;
for( ipc_ i=0; i <= n-1; i++) z[i] = 0.0;
// solve the bound constrained l_1qp problem
qpa_import( &control, &data, &status, n, m,
"coordinate", H_ne, H_row, H_col, NULL,
"coordinate", A_ne, A_row, A_col, NULL );
qpa_solve_bcl1qp( &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( &data, &inform, &status );
if(inform.status == 0){
#ifdef REAL_128
// interim replacement for quad output: $GALAHAD/include/galahad_pquad_f.h
#include "galahad_pquad_f.h"
#else
printf("%c:%6" i_ipc_ " iterations. Optimal objective "
"value = %.2f status = %1" i_ipc_ "\n",
st, inform.iter, inform.obj, inform.status);
#endif
}else{
printf("%c: QPA_solve exit status = %1" i_ipc_ "\n", st, inform.status);
}
// Delete internal workspace
qpa_terminate( &data, &control, &inform );
}
This is the same example, but now fortran-style indexing is used; the code is available in $GALAHAD/src/qpa/C/qpatf.c .
/* qpatf.c */
/* Full test for the QPA C interface using Fortran sparse matrix indexing */
#include <stdio.h>
#include <math.h>
#include <string.h>
#include "galahad_precision.h"
#include "galahad_cfunctions.h"
#include "galahad_qpa.h"
#ifdef REAL_128
#include <quadmath.h>
#endif
int main(void) {
// Derived types
void *data;
struct qpa_control_type control;
struct qpa_inform_type inform;
// Set problem data
ipc_ n = 3; // dimension
ipc_ m = 2; // number of general constraints
ipc_ H_ne = 3; // Hesssian elements
ipc_ H_row[] = {1, 2, 3 }; // row indices, NB lower triangle
ipc_ H_col[] = {1, 2, 3}; // column indices, NB lower triangle
ipc_ H_ptr[] = {1, 2, 3, 4}; // row pointers
rpc_ H_val[] = {1.0, 1.0, 1.0 }; // values
rpc_ g[] = {0.0, 2.0, 0.0}; // linear term in the objective
rpc_ f = 1.0; // constant term in the objective
rpc_ rho_g = 0.1; // penalty paramter for general constraints
rpc_ rho_b = 0.1; // penalty paramter for simple bound constraints
ipc_ A_ne = 4; // Jacobian elements
ipc_ A_row[] = {1, 1, 2, 2}; // row indices
ipc_ A_col[] = {1, 2, 2, 3}; // column indices
ipc_ A_ptr[] = {1, 3, 5}; // row pointers
rpc_ A_val[] = {2.0, 1.0, 1.0, 1.0 }; // values
rpc_ c_l[] = {1.0, 2.0}; // constraint lower bound
rpc_ c_u[] = {2.0, 2.0}; // constraint upper bound
rpc_ x_l[] = {-1.0, - INFINITY, - INFINITY}; // variable lower bound
rpc_ x_u[] = {1.0, INFINITY, 2.0}; // variable upper bound
// Set output storage
rpc_ c[m]; // constraint values
ipc_ x_stat[n]; // variable status
ipc_ c_stat[m]; // constraint status
char st = ' ';
ipc_ status;
printf(" Fortran sparse matrix indexing\n\n");
printf(" basic tests of qp storage formats\n\n");
for( ipc_ d=1; d <= 7; d++){
// Initialize QPA
qpa_initialize( &data, &control, &status );
strcpy(control.symmetric_linear_solver, "sytr ") ;
// Set user-defined control options
control.f_indexing = true; // Fortran sparse matrix indexing
// Start from 0
rpc_ x[] = {0.0,0.0,0.0};
rpc_ y[] = {0.0,0.0};
rpc_ z[] = {0.0,0.0,0.0};
switch(d){
case 1: // sparse co-ordinate storage
st = 'C';
qpa_import( &control, &data, &status, n, m,
"coordinate", H_ne, H_row, H_col, NULL,
"coordinate", A_ne, A_row, A_col, NULL );
qpa_solve_qp( &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 );
break;
printf(" case %1" i_ipc_ " break\n",d);
case 2: // sparse by rows
st = 'R';
qpa_import( &control, &data, &status, n, m,
"sparse_by_rows", H_ne, NULL, H_col, H_ptr,
"sparse_by_rows", A_ne, NULL, A_col, A_ptr );
qpa_solve_qp( &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 );
break;
case 3: // dense
st = 'D';
ipc_ H_dense_ne = 6; // number of elements of H
ipc_ A_dense_ne = 6; // number of elements of A
rpc_ H_dense[] = {1.0, 0.0, 1.0, 0.0, 0.0, 1.0};
rpc_ A_dense[] = {2.0, 1.0, 0.0, 0.0, 1.0, 1.0};
qpa_import( &control, &data, &status, n, m,
"dense", H_ne, NULL, NULL, NULL,
"dense", A_ne, NULL, NULL, NULL );
qpa_solve_qp( &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 );
break;
case 4: // diagonal
st = 'L';
qpa_import( &control, &data, &status, n, m,
"diagonal", H_ne, NULL, NULL, NULL,
"sparse_by_rows", A_ne, NULL, A_col, A_ptr );
qpa_solve_qp( &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 );
break;
case 5: // scaled identity
st = 'S';
qpa_import( &control, &data, &status, n, m,
"scaled_identity", H_ne, NULL, NULL, NULL,
"sparse_by_rows", A_ne, NULL, A_col, A_ptr );
qpa_solve_qp( &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 );
break;
case 6: // identity
st = 'I';
qpa_import( &control, &data, &status, n, m,
"identity", H_ne, NULL, NULL, NULL,
"sparse_by_rows", A_ne, NULL, A_col, A_ptr );
qpa_solve_qp( &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 );
break;
case 7: // zero
st = 'Z';
qpa_import( &control, &data, &status, n, m,
"zero", H_ne, NULL, NULL, NULL,
"sparse_by_rows", A_ne, NULL, A_col, A_ptr );
qpa_solve_qp( &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 );
break;
}
qpa_information( &data, &inform, &status );
if(inform.status == 0){
#ifdef REAL_128
// interim replacement for quad output: $GALAHAD/include/galahad_pquad_f.h
#include "galahad_pquad_f.h"
#else
printf("%c:%6" i_ipc_ " iterations. Optimal objective "
"value = %.2f status = %1" i_ipc_ "\n",
st, inform.iter, inform.obj, inform.status);
#endif
}else{
printf("%c: QPA_solve exit status = %1" i_ipc_ "\n",
st, inform.status);
}
//printf("x: ");
//for( ipc_ i = 0; i < n; i++) printf("%f ", x[i]);
//printf("\n");
//printf("gradient: ");
//for( ipc_ i = 0; i < n; i++) printf("%f ", g[i]);
//printf("\n");
// Delete internal workspace
qpa_terminate( &data, &control, &inform );
}
printf("\n basic tests of l_1 qp storage formats\n\n");
qpa_initialize( &data, &control, &status );
strcpy(control.symmetric_linear_solver, "sytr ") ;
// Set user-defined control options
control.f_indexing = true; // Fortran sparse matrix indexing
// Start from 0
rpc_ x[] = {0.0,0.0,0.0};
rpc_ y[] = {0.0,0.0};
rpc_ z[] = {0.0,0.0,0.0};
// solve the l_1qp problem
qpa_import( &control, &data, &status, n, m,
"coordinate", H_ne, H_row, H_col, NULL,
"coordinate", A_ne, A_row, A_col, NULL );
qpa_solve_l1qp( &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( &data, &inform, &status );
if(inform.status == 0){
#ifdef REAL_128
// interim replacement for quad output: $GALAHAD/include/galahad_pquad_f.h
#include "galahad_pquad_f.h"
#else
printf("%c:%6" i_ipc_ " iterations. Optimal objective "
"value = %.2f status = %1" i_ipc_ "\n",
st, inform.iter, inform.obj, inform.status);
#endif
}else{
printf("%c: QPA_solve exit status = %1" i_ipc_ "\n", st, inform.status);
}
// Start from 0
for( ipc_ i=0; i <= n-1; i++) x[i] = 0.0;
for( ipc_ i=0; i <= m-1; i++) y[i] = 0.0;
for( ipc_ i=0; i <= n-1; i++) z[i] = 0.0;
// solve the bound constrained l_1qp problem
qpa_import( &control, &data, &status, n, m,
"coordinate", H_ne, H_row, H_col, NULL,
"coordinate", A_ne, A_row, A_col, NULL );
qpa_solve_bcl1qp( &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( &data, &inform, &status );
if(inform.status == 0){
#ifdef REAL_128
// interim replacement for quad output: $GALAHAD/include/galahad_pquad_f.h
#include "galahad_pquad_f.h"
#else
printf("%c:%6" i_ipc_ " iterations. Optimal objective "
"value = %.2f status = %1" i_ipc_ "\n",
st, inform.iter, inform.obj, inform.status);
#endif
}else{
printf("%c: QPA_solve exit status = %1" i_ipc_ "\n", st, inform.status);
}
// Delete internal workspace
qpa_terminate( &data, &control, &inform );
}