GALAHAD EQP package#
purpose#
The eqp
package uses an iterative method to solve a
given equality-constrained quadratic program.
The aim is to minimize the quadratic objective function
See Section 4 of $GALAHAD/doc/eqp.pdf for additional details.
terminology#
Any required solution
In the shifted-least-distance case,
method#
A solution to the problem is found in two phases.
In the first, a point
SBLS
provides a number of possibilities. In order to ensure that the
minimizer obtained is finite, an additional, precautionary trust-region
constraint GLTR
is used to solve
this additionally-constrained problem.
references#
The preconditioning aspcets are described in detail in
H. S. Dollar, N. I. M. Gould and A. J. Wathen. ``On implicit-factorization constraint preconditioners’’. In Large Scale Nonlinear Optimization (G. Di Pillo and M. Roma, eds.) Springer Series on Nonconvex Optimization and Its Applications, Vol. 83, Springer Verlag (2006) 61–82
and
H. S. Dollar, N. I. M. Gould, W. H. A. Schilders and A. J. Wathen ``On iterative methods and implicit-factorization preconditioners for regularized saddle-point systems’’. SIAM Journal on Matrix Analysis and Applications 28(1) (2006) 170–189,
while the constrained conjugate-gradient method is discussed in
N. I. M. Gould, S. Lucidi, M. Roma and Ph. L. Toint, ``Solving the trust-region subproblem using the Lanczos method’’. SIAM Journal on Optimization 9(2) (1999), 504–525.
matrix storage#
unsymmetric 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
symmetric storage#
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 eqp package must be called in the following order:
eqp_initialize - provide default control parameters and set up initial data structures
eqp_read_specfile (optional) - override control values by reading replacement values from a file
eqp_import - set up problem data structures and fixed values
eqp_reset_control (optional) - possibly change control parameters if a sequence of problems are being solved
solve the problem by calling one of
eqp_solve_qp - solve the quadratic program
eqp_solve_sldqp - solve the shifted least-distance problem
eqp_resolve_qp (optional) - resolve the problem with the same Hessian and Jacobian, but different
, and/oreqp_information (optional) - recover information about the solution and solution process
eqp_terminate - deallocate data structures
See the examples section for illustrations of use.
parametric real type T and integer type INT#
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). The symbol INT refers to a parametric integer type that may be Int32 (32-bit integer) or Int64 (64-bit integer).
callable functions#
function eqp_initialize(T, INT, 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 eqp_control_type) |
status |
is a scalar variable of type INT that gives the exit status from the package. Possible values are (currently):
|
function eqp_read_specfile(T, INT, 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/eqp/EQP.template. See also Table 2.1 in the Fortran documentation provided in $GALAHAD/doc/eqp.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 eqp_control_type) |
specfile |
is a one-dimensional array of type Vararg{Cchar} that must give the name of the specification file |
function eqp_import(T, INT, 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 eqp_control_type) |
data |
holds private internal data |
status |
is a scalar variable of type INT that gives the exit status from the package. Possible values are:
|
n |
is a scalar variable of type INT that holds the number of variables. |
m |
is a scalar variable of type INT 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_ne |
is a scalar variable of type INT 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 INT that holds the row indices of the lower triangular part of |
H_col |
is a one-dimensional array of size H_ne and type INT that holds the column indices of the lower triangular part of |
H_ptr |
is a one-dimensional array of size n+1 and type INT that holds the starting position of each row of the lower triangular part of |
A_type |
is a one-dimensional array of type Vararg{Cchar} that specifies the unsymmetric storage scheme used for the constraint Jacobian, |
A_ne |
is a scalar variable of type INT that holds the number of entries in |
A_row |
is a one-dimensional array of size A_ne and type INT that holds the row indices of |
A_col |
is a one-dimensional array of size A_ne and type INT that holds the column indices of |
A_ptr |
is a one-dimensional array of size n+1 and type INT that holds the starting position of each row of |
function eqp_reset_control(T, INT, 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 eqp_control_type) |
data |
holds private internal data |
status |
is a scalar variable of type INT that gives the exit status from the package. Possible values are:
|
function eqp_solve_qp(T, INT, data, status, n, m, h_ne, H_val, g, f, a_ne, A_val, c, x, y)
Solve the quadratic program when the Hessian
Parameters:
data |
holds private internal data |
status |
is a scalar variable of type INT that gives the entry and exit status from the package. Possible exit values are:
|
n |
is a scalar variable of type INT that holds the number of variables |
m |
is a scalar variable of type INT that holds the number of general linear constraints. |
h_ne |
is a scalar variable of type INT 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 T 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 T that holds the linear term |
f |
is a scalar of type T that holds the constant term |
a_ne |
is a scalar variable of type INT that holds the number of entries in the constraint Jacobian matrix |
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 |
c |
is a one-dimensional array of size m and type T that holds the linear term |
x |
is a one-dimensional array of size n and type T that holds the values |
y |
is a one-dimensional array of size n and type T that holds the values |
function eqp_solve_sldqp(T, INT, data, status, n, m, w, x0, g, f, a_ne, A_val, c, x, y)
Solve the shifted least-distance quadratic program
Parameters:
data |
holds private internal data |
status |
is a scalar variable of type INT that gives the entry and exit status from the package. Possible exit values are:
|
n |
is a scalar variable of type INT that holds the number of variables |
m |
is a scalar variable of type INT that holds the number of general linear constraints. |
w |
is a one-dimensional array of size n and type T that holds the values of the weights |
x0 |
is a one-dimensional array of size n and type T that holds the values of the shifts |
g |
is a one-dimensional array of size n and type T that holds the linear term |
f |
is a scalar of type T that holds the constant term |
a_ne |
is a scalar variable of type INT that holds the number of entries in the constraint Jacobian matrix |
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 |
c |
is a one-dimensional array of size m and type T that holds the linear term |
x |
is a one-dimensional array of size n and type T that holds the values |
y |
is a one-dimensional array of size n and type T that holds the values |
function eqp_resolve_qp(T, INT, data, status, n, m, g, f, c, x, y)
Resolve the quadratic program or shifted least-distance quadratic program when some or all of the data
Parameters:
data |
holds private internal data |
status |
is a scalar variable of type INT that gives the entry and exit status from the package. Possible exit values are:
|
n |
is a scalar variable of type INT that holds the number of variables |
m |
is a scalar variable of type INT that holds the number of general linear constraints. |
g |
is a one-dimensional array of size n and type T that holds the linear term |
f |
is a scalar of type T that holds the constant term |
c |
is a one-dimensional array of size m and type T that holds the linear term |
x |
is a one-dimensional array of size n and type T that holds the values |
y |
is a one-dimensional array of size n and type T that holds the values |
function eqp_information(T, INT, data, inform, status)
Provides output information
Parameters:
data |
holds private internal data |
inform |
is a structure containing output information (see eqp_inform_type) |
status |
is a scalar variable of type INT that gives the exit status from the package. Possible values are (currently):
|
function eqp_terminate(T, INT, data, control, inform)
Deallocate all internal private storage
Parameters:
data |
holds private internal data |
control |
is a structure containing control information (see eqp_control_type) |
inform |
is a structure containing output information (see eqp_inform_type) |
available structures#
eqp_control_type structure#
struct eqp_control_type{T,INT} f_indexing::Bool error::INT out::INT print_level::INT factorization::INT max_col::INT indmin::INT valmin::INT len_ulsmin::INT itref_max::INT cg_maxit::INT preconditioner::INT semi_bandwidth::INT new_a::INT new_h::INT sif_file_device::INT pivot_tol::T pivot_tol_for_basis::T zero_pivot::T inner_fraction_opt::T radius::T min_diagonal::T max_infeasibility_relative::T max_infeasibility_absolute::T inner_stop_relative::T inner_stop_absolute::T inner_stop_inter::T find_basis_by_transpose::Bool remove_dependencies::Bool space_critical::Bool deallocate_error_fatal::Bool generate_sif_file::Bool sif_file_name::NTuple{31,Cchar} prefix::NTuple{31,Cchar} fdc_control::fdc_control_type{T,INT} sbls_control::sbls_control_type{T,INT} gltr_control::gltr_control_type{T,INT}
detailed documentation#
control derived type as a Julia structure
components#
Bool f_indexing
use C or Fortran sparse matrix indexing
INT error
error and warning diagnostics occur on stream error
INT out
general output occurs on stream out
INT print_level
the level of output required is specified by print_level
INT factorization
the factorization to be used. Possible values are /li 0 automatic /li 1 Schur-complement factorization /li 2 augmented-system factorization (OBSOLETE)
INT max_col
the maximum number of nonzeros in a column of A which is permitted with the Schur-complement factorization (OBSOLETE)
INT indmin
an initial guess as to the integer workspace required by SBLS (OBSOLETE)
INT valmin
an initial guess as to the real workspace required by SBLS (OBSOLETE)
INT len_ulsmin
an initial guess as to the workspace required by ULS (OBSOLETE)
INT itref_max
the maximum number of iterative refinements allowed (OBSOLETE)
INT 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
INT preconditioner
the preconditioner to be used for the CG. 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 (OBSOLETE)
5 optionally supplied diagonal, G = D
INT semi_bandwidth
the semi-bandwidth of a band preconditioner, if appropriate (OBSOLETE)
INT new_a
how much has A changed since last problem solved: 0 = not changed, 1 = values changed, 2 = structure changed
INT new_h
how much has H changed since last problem solved: 0 = not changed, 1 = values changed, 2 = structure changed
INT sif_file_device
specifies the unit number to write generated SIF file describing the current problem
T pivot_tol
the threshold pivot used by the matrix factorization. See the documentation for SBLS for details (OBSOLETE)
T pivot_tol_for_basis
the threshold pivot used by the matrix factorization when finding the ba See the documentation for ULS for details (OBSOLETE)
T zero_pivot
any pivots smaller than zero_pivot in absolute value will be regarded to zero when attempting to detect linearly dependent constraints (OBSOLETE)
T inner_fraction_opt
the computed solution which gives at least inner_fraction_opt times the optimal value will be found (OBSOLETE)
T radius
an upper bound on the permitted step (-ve will be reset to an appropriat large value by eqp_solve)
T min_diagonal
diagonal preconditioners will have diagonals no smaller than min_diagonal (OBSOLETE)
T max_infeasibility_relative
if the constraints are believed to be rank defficient and the residual at a “typical” feasible point is larger than max( max_infeasibility_relative * norm A, max_infeasibility_absolute ) the problem will be marked as infeasible
T max_infeasibility_absolute
see max_infeasibility_relative
T inner_stop_relative
the computed solution is considered as an acceptable approximation to th minimizer of the problem if the gradient of the objective 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 inner_stop_inter
see inner_stop_relative
Bool find_basis_by_transpose
if .find_basis_by_transpose is true, implicit factorization precondition will be based on a basis of A found by examining A’s transpose (OBSOLETE)
Bool remove_dependencies
if .remove_dependencies is true, the equality constraints will be preprocessed to remove any linear dependencies
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
NTuple{31,Cchar} sif_file_name
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’
struct fdc_control_type fdc_control
control parameters for FDC
struct sbls_control_type sbls_control
control parameters for SBLS
struct gltr_control_type gltr_control
control parameters for GLTR
eqp_time_type structure#
struct eqp_time_type{T} total::T find_dependent::T factorize::T solve::T solve_inter::T clock_total::T clock_find_dependent::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 find_dependent
the CPU time spent detecting linear dependencies
T factorize
the CPU time spent factorizing the required matrices
T solve
the CPU time spent computing the search direction
T solve_inter
see solve
T clock_total
the total clock time spent in the package
T clock_find_dependent
the clock time spent detecting linear dependencies
T clock_factorize
the clock time spent factorizing the required matrices
T clock_solve
the clock time spent computing the search direction
eqp_inform_type structure#
struct eqp_inform_type{T,INT} status::INT alloc_status::INT bad_alloc::NTuple{81,Cchar} cg_iter::INT cg_iter_inter::INT factorization_integer::Int64 factorization_real::Int64 obj::T time::eqp_time_type{T} fdc_inform::fdc_inform_type{T,INT} sbls_inform::sbls_inform_type{T,INT} gltr_inform::gltr_inform_type{T,INT}
detailed documentation#
inform derived type as a Julia structure
components#
INT status
return status. See EQP_solve for details
INT 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
INT cg_iter
the total number of conjugate gradient iterations required
INT cg_iter_inter
see cg_iter
Int64 factorization_integer
the total integer workspace required for the factorization
Int64 factorization_real
the total real workspace required for the factorization
T obj
the value of the objective function at the best estimate of the solution determined by QPB_solve
struct eqp_time_type time
timings (see above)
struct fdc_inform_type fdc_inform
inform parameters for FDC
struct sbls_inform_type sbls_inform
inform parameters for SBLS
struct gltr_inform_type gltr_inform
return information from GLTR
example calls#
This is an example of how to use the package to solve an equality-constrained quadratic program; the code is available in $GALAHAD/src/eqp/Julia/test_eqp.jl . A variety of supported Hessian and constraint matrix storage formats are shown.
# test_eqp.jl
# Simple code to test the Julia interface to EQP
using GALAHAD
using Test
using Printf
using Accessors
using Quadmath
function test_eqp(::Type{T}, ::Type{INT}) where {T,INT}
# Derived types
data = Ref{Ptr{Cvoid}}()
control = Ref{eqp_control_type{T,INT}}()
inform = Ref{eqp_inform_type{T,INT}}()
# Set problem data
n = INT(3) # dimension
m = INT(2) # number of general constraints
H_ne = INT(3) # Hesssian elements
H_row = INT[1, 2, 3] # row indices, NB lower triangle
H_col = INT[1, 2, 3] # column indices, NB lower triangle
H_ptr = INT[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
A_ne = INT(4) # Jacobian elements
A_row = INT[1, 1, 2, 2] # row indices
A_col = INT[1, 2, 2, 3] # column indices
A_ptr = INT[1, 3, 5] # row pointers
A_val = T[2.0, 1.0, 1.0, 1.0] # values
c = T[3.0, 0.0] # rhs of the constraints
# Set output storage
x_stat = zeros(INT, n) # variable status
c_stat = zeros(INT, m) # constraint status
st = ' '
status = Ref{INT}()
@printf(" Fortran sparse matrix indexing\n\n")
@printf(" basic tests of qp storage formats\n\n")
for d in 1:6
# Initialize EQP
eqp_initialize(T, INT, data, control, status)
# Set user-defined control options
@reset control[].fdc_control.use_sls = true
@reset control[].fdc_control.symmetric_linear_solver = galahad_linear_solver("sytr")
@reset control[].sbls_control.symmetric_linear_solver = galahad_linear_solver("sytr")
@reset control[].sbls_control.definite_linear_solver = galahad_linear_solver("sytr")
# 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'
eqp_import(T, INT, control, data, status, n, m,
"coordinate", H_ne, H_row, H_col, C_NULL,
"coordinate", A_ne, A_row, A_col, C_NULL)
eqp_solve_qp(T, INT, data, status, n, m, H_ne, H_val, g, f,
A_ne, A_val, c, x, y)
end
# sparse by rows
if d == 2
st = 'R'
eqp_import(T, INT, 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)
eqp_solve_qp(T, INT, data, status, n, m, H_ne, H_val, g, f,
A_ne, A_val, c, x, y)
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]
eqp_import(T, INT, control, data, status, n, m,
"dense", H_ne, C_NULL, C_NULL, C_NULL,
"dense", A_ne, C_NULL, C_NULL, C_NULL)
eqp_solve_qp(T, INT, data, status, n, m, H_dense_ne, H_dense, g, f,
A_dense_ne, A_dense, c, x, y)
end
# diagonal
if d == 4
st = 'L'
eqp_import(T, INT, 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)
eqp_solve_qp(T, INT, data, status, n, m, H_ne, H_val, g, f,
A_ne, A_val, c, x, y)
end
# scaled identity
if d == 5
st = 'S'
eqp_import(T, INT, 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)
eqp_solve_qp(T, INT, data, status, n, m, H_ne, H_val, g, f,
A_ne, A_val, c, x, y)
end
# identity
if d == 6
st = 'I'
eqp_import(T, INT, 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)
eqp_solve_qp(T, INT, data, status, n, m, H_ne, H_val, g, f,
A_ne, A_val, c, x, y)
end
# zero
if d == 7
st = 'Z'
eqp_import(T, INT, 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)
eqp_solve_qp(T, INT, data, status, n, m, H_ne, H_val, g, f,
A_ne, A_val, c, x, y)
end
eqp_information(T, INT, data, inform, status)
if inform[].status == 0
@printf("%c:%6i cg iterations. Optimal objective value = %5.2f status = %1i\n",
st, inform[].cg_iter, inform[].obj, inform[].status)
else
@printf("%c: EQP_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
eqp_terminate(T, INT, data, control, inform)
end
# test shifted least-distance interface
for d in 1:1
# Initialize EQP
eqp_initialize(T, INT, data, control, status)
@reset control[].fdc_control.use_sls = true
@reset control[].fdc_control.symmetric_linear_solver = galahad_linear_solver("sytr")
@reset control[].sbls_control.symmetric_linear_solver = galahad_linear_solver("sytr")
@reset control[].sbls_control.definite_linear_solver = galahad_linear_solver("sytr")
# 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]
# Set shifted least-distance data
w = T[1.0, 1.0, 1.0]
x_0 = T[0.0, 0.0, 0.0]
# sparse co-ordinate storage
if d == 1
st = 'W'
eqp_import(T, INT, control, data, status, n, m,
"shifted_least_distance", H_ne, C_NULL, C_NULL, C_NULL,
"coordinate", A_ne, A_row, A_col, C_NULL)
eqp_solve_sldqp(T, INT, data, status, n, m, w, x_0, g, f,
A_ne, A_val, c, x, y)
end
eqp_information(T, INT, data, inform, status)
if inform[].status == 0
@printf("%c:%6i cg iterations. Optimal objective value = %5.2f status = %1i\n",
st, inform[].cg_iter, inform[].obj, inform[].status)
else
@printf("%c: EQP_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
eqp_terminate(T, INT, data, control, inform)
end
return 0
end
for (T, INT, libgalahad) in ((Float32 , Int32, GALAHAD.libgalahad_single ),
(Float32 , Int64, GALAHAD.libgalahad_single_64 ),
(Float64 , Int32, GALAHAD.libgalahad_double ),
(Float64 , Int64, GALAHAD.libgalahad_double_64 ),
(Float128, Int32, GALAHAD.libgalahad_quadruple ),
(Float128, Int64, GALAHAD.libgalahad_quadruple_64))
if isfile(libgalahad)
@testset "EQP -- $T -- $INT" begin
@test test_eqp(T, INT) == 0
end
end
end