GALAHAD LSQP package#
purpose#
The lsqp
package uses an interior-point trust-region method to solve a
given linear or separable convex quadratic program.
The aim is to minimize the separable quadratic objective function
In the special case where \(w = 0\), \(g = 0\) and \(f = 0\), the so-called analytic center of the feasible set will be found, while linear programming, or constrained least distance, problems may be solved by picking \(w = 0\), or \(g = 0\) and \(f = 0\), respectively.
See Section 4 of $GALAHAD/doc/lsqp.pdf for additiional details.
The more-modern package cqp
offers similar functionality, and
is often to be preferred.
terminology#
Any required solution \(x\) necessarily satisfies the primal optimality conditions
method#
Primal-dual interior point methods iterate towards a point that satisfies these optimality conditions by ultimately aiming to satisfy (1a), (2a) and (3), while ensuring that (1b) and (2b) are satisfied as strict inequalities at each stage. Appropriate norms of the amounts by which (1a), (2a) and (3) fail to be satisfied are known as the primal and dual infeasibility, and the violation of complementary slackness, respectively. The fact that (1b) and (2b) are satisfied as strict inequalities gives such methods their other title, namely interior-point methods.
When \(w \neq 0\) or \(g \neq 0\), the method aims at each stage to reduce the overall violation of (1a), (2a) and (3), rather than reducing each of the terms individually. Given an estimate \(v = (x, \; c, \; y, \; y^{l}, \; y^{u}, \; z, \; z^{l}, \; z^{u})\) of the primal-dual variables, a correction \(\Delta v = \Delta (x, \; c, \; y, \; y^{l}, \; y^{u} ,\;z,\;z^{l} ,\;z^{u} )\) is obtained by solving a suitable linear system of Newton equations for the nonlinear systems (1a), (2a) and a parameterized perturbation of (3). An improved estimate \(v + \alpha \Delta v\) is then used, where the step-size \(\alpha\) is chosen as close to 1.0 as possible while ensuring both that (1b) and (2b) continue to hold and that the individual components which make up the complementary slackness (3) do not deviate too significantly from their average value. The parameter that controls the perturbation of (3) is ultimately driven to zero.
The Newton equations are solved by applying the matrix factorization
package SBLS
, but there are options
to factorize the matrix as a whole (the so-called “augmented system”
approach), to perform a block elimination first (the “Schur-complement”
approach), or to let the method itself decide which of the two
previous options is more appropriate.
The “Schur-complement” approach is usually to be preferred when all the
weights are nonzero or when every variable is bounded (at least one side),
but may be inefficient if any of the columns of \(A\) is too dense.
When \(w = 0\) and \(g = 0\), the method aims instead firstly to find an interior primal feasible point, that is to ensure that (1a) is satisfied. One this has been achieved, attention is switched to mninizing the potential function
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.
references#
The basic algorithm is that of
Y. Zhang, ``On the convergence of a class of infeasible interior-point methods for the horizontal linear complementarity problem’’. SIAM J. Optimization 4(1) (1994) 208-227,
with a number of enhancements described by
A. R. Conn, N. I. M. Gould, D. Orban and Ph. L. Toint, ``A primal-dual trust-region algorithm for minimizing a non-convex function subject to general inequality and linear equality constraints’’. Mathematical Programming **87* (1999) 215-249.
matrix 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.
introduction to function calls#
To solve a given problem, functions from the lsqp package must be called in the following order:
lsqp_initialize - provide default control parameters and set up initial data structures
lsqp_read_specfile (optional) - override control values by reading replacement values from a file
lsqp_import - set up problem data structures and fixed values
lsqp_reset_control (optional) - possibly change control parameters if a sequence of problems are being solved
lsqp_solve_qp - solve the quadratic program
lsqp_information (optional) - recover information about the solution and solution process
lsqp_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) or Float64 (double precision).
callable functions#
function lsqp_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 lsqp_control_type) |
status |
is a scalar variable of type Int32 that gives the exit status from the package. Possible values are (currently):
|
function lsqp_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/lsqp/LSQP.template. See also Table 2.1 in the Fortran documentation provided in $GALAHAD/doc/lsqp.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 lsqp_control_type) |
specfile |
is a one-dimensional array of type Vararg{Cchar} that must give the name of the specification file |
function lsqp_import(T, control, data, status, n, m, 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 lsqp_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. |
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 lsqp_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 lsqp_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 lsqp_solve_qp(T, data, status, n, m, w, x0, g, f, a_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, x_stat, c_stat)
Solve the separable convex quadratic program.
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. |
w |
is a one-dimensional array of size n and type T that holds the values of the weights \(w\). |
x0 |
is a one-dimensional array of size n and type T that holds the values of the shifts \(x^0\). |
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 optimal 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. |
c_stat |
is a one-dimensional array of size m and type Int32 that gives the optimal status of the general linear constraints. If c_stat(i) is negative, the constraint value \(a_i^T x\) 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. |
function lsqp_information(T, data, inform, status)
Provides output information.
Parameters:
data |
holds private internal data |
inform |
is a structure containing output information (see lsqp_inform_type) |
status |
is a scalar variable of type Int32 that gives the exit status from the package. Possible values are (currently):
|
function lsqp_terminate(T, data, control, inform)
Deallocate all internal private storage.
Parameters:
data |
holds private internal data |
control |
is a structure containing control information (see lsqp_control_type) |
inform |
is a structure containing output information (see lsqp_inform_type) |
available structures#
lsqp_control_type structure#
struct lsqp_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 indmin::Int32 valmin::Int32 itref_max::Int32 infeas_max::Int32 muzero_fixed::Int32 restore_problem::Int32 indicator_type::Int32 extrapolate::Int32 path_history::Int32 path_derivatives::Int32 fit_order::Int32 sif_file_device::Int32 infinity::T stop_p::T stop_d::T stop_c::T prfeas::T dufeas::T muzero::T reduce_infeas::T potential_unbounded::T pivot_tol::T pivot_tol_for_dependencies::T zero_pivot::T identical_bounds_tol::T mu_min::T indicator_tol_p::T indicator_tol_pd::T indicator_tol_tapia::T cpu_time_limit::T clock_time_limit::T remove_dependencies::Bool treat_zero_bounds_as_general::Bool just_feasible::Bool getdua::Bool puiseux::Bool feasol::Bool balance_initial_complentarity::Bool use_corrector::Bool array_syntax_worse_than_do_loop::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} sbls_control::sbls_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 indmin
an initial guess as to the integer workspace required by SBLS
Int32 valmin
an initial guess as to the real workspace required by SBLS
Int32 itref_max
the maximum number of iterative refinements allowed
Int32 infeas_max
the number of iterations for which the overall infeasibility of the problem is not reduced by at least a factor .reduce_infeas before the problem is flagged as infeasible (see reduce_infeas)
Int32 muzero_fixed
the initial value of the barrier parameter will not be changed for the first muzero_fixed iterations
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 indicator_type
specifies the type of indicator function used. Possible values are
1 primal indicator: constraint active if and only if the distance to nearest bound \(\leq\).indicator_p_tol
2 primal-dual indicator: constraint active if and only if the distance to nearest bound \(\leq\).indicator_tol_pd \* size of corresponding multiplier
3 primal-dual indicator: constraint active if and only if the distance to the nearest bound \(\leq\).indicator_tol_tapia \* distance to same bound at previous iteration
Int32 extrapolate
should extrapolation be used to track the central path? Possible values
0 never
1 after the final major iteration
2 at each major iteration (unused at present)
Int32 path_history
the maximum number of previous path points to use when fitting the data (unused at present)
Int32 path_derivatives
the maximum order of path derivative to use (unused at present)
Int32 fit_order
the order of (Puiseux) series to fit to the path data: $
to fit all data (unused at present)
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 stop_p
the required accuracy for the primal infeasibility
T stop_d
the required accuracy for the dual infeasibility
T stop_c
the required accuracy for the complementarity
T prfeas
initial primal variables will not be closer than prfeas from their bounds
T dufeas
initial dual variables will not be closer than dufeas from their bounds
T muzero
the initial value of the barrier parameter. If muzero is not positive, it will be reset to an appropriate value
T reduce_infeas
if the overall infeasibility of the problem is not reduced by at least a factor reduce_infeas over .infeas_max iterations, the problem is flagged as infeasible (see infeas_max)
T potential_unbounded
if W=0 and the potential function value is smaller than potential_unbounded * number of one-sided bounds, the analytic center will be flagged as unbounded
T pivot_tol
the threshold pivot used by the matrix factorization. See the documentation for SBLS for details
T pivot_tol_for_dependencies
the threshold pivot used by the matrix factorization when attempting to detect linearly dependent constraints. See the documentation for SBLS for details
T zero_pivot
any pivots smaller than zero_pivot in absolute value will be regarded to zero when attempting to detect linearly dependent constraints
T identical_bounds_tol
any pair of constraint bounds (c_l,c_u) or (x_l,x_u) that are closer tha identical_bounds_tol will be reset to the average of their values
T mu_min
start terminal extrapolation when mu reaches mu_min
T indicator_tol_p
if .indicator_type = 1, a constraint/bound will be deemed to be active if and only if the distance to nearest bound $ \(\leq\).indicator_p_tol
T indicator_tol_pd
if .indicator_type = 2, a constraint/bound will be deemed to be active if and only if the distance to nearest bound $ \(\leq\).indicator_tol_pd \* size of corresponding multiplier
T indicator_tol_tapia
if .indicator_type = 3, a constraint/bound will be deemed to be active if and only if the distance to nearest bound $ \(\leq\).indicator_tol_tapia \* distance to same bound at previous iteration
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 remove_dependencies
the equality constraints will be preprocessed to remove any linear dependencies if true
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 just_feasible
if .just_feasible is true, the algorithm will stop as soon as a feasible point is found. Otherwise, the optimal solution to the problem will be found
Bool getdua
if .getdua, is true, advanced initial values are obtained for the dual variables
Bool puiseux
If extrapolation is to be used, decide between Puiseux and Taylor series.
Bool feasol
if .feasol is true, the final solution obtained will be perturbed so tha variables close to their bounds are moved onto these bounds
Bool balance_initial_complentarity
if .balance_initial_complentarity is true, the initial complemetarity is required to be balanced
Bool use_corrector
if .use_corrector, a corrector step will be used
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
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
lsqp_time_type structure#
struct lsqp_time_type{T} total::T preprocess::T find_dependent::T analyse::T factorize::T solve::T clock_total::T clock_preprocess::T clock_find_dependent::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 find_dependent
the CPU time spent detecting linear dependencies
T analyse
the CPU time spent analysing the required matrices prior to factorization
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_find_dependent
the clock time spent detecting linear dependencies
T clock_analyse
the clock time spent analysing the required matrices prior to factorization
T clock_factorize
the clock time spent factorizing the required matrices
T clock_solve
the clock time spent computing the search direction
lsqp_inform_type structure#
struct lsqp_inform_type{T} status::Int32 alloc_status::Int32 bad_alloc::NTuple{81,Cchar} iter::Int32 factorization_status::Int32 factorization_integer::Int64 factorization_real::Int64 nfacts::Int32 nbacts::Int32 obj::T potential::T non_negligible_pivot::T feasible::Bool time::lsqp_time_type{T} fdc_inform::fdc_inform_type{T} sbls_inform::sbls_inform_type{T}
detailed documentation#
inform derived type as a Julia structure
components#
Int32 status
return status. See LSQP_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 iter
the total number of 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 nbacts
the total number of “wasted” function evaluations during the linesearch
T obj
the value of the objective function at the best estimate of the solution determined by LSQP_solve_qp
T potential
the value of the logarithmic potential function sum -log(distance to constraint boundary)
T non_negligible_pivot
the smallest pivot which was not judged to be zero when detecting linear dependent constraints
Bool feasible
is the returned “solution” feasible?
struct lsqp_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
example calls#
This is an example of how to use the package to solve a separable quadratic program; the code is available in $GALAHAD/src/lsqp/Julia/test_lsqp.jl . A variety of supported Hessian and constraint matrix storage formats are shown.
# test_lsqp.jl
# Simple code to test the Julia interface to LSQP
using GALAHAD
using Test
using Printf
using Accessors
function test_lsqp(::Type{T}) where T
# Derived types
data = Ref{Ptr{Cvoid}}()
control = Ref{lsqp_control_type{T}}()
inform = Ref{lsqp_inform_type{T}}()
# Set problem data
n = 3 # dimension
m = 2 # number of general constraints
g = T[0.0, 2.0, 0.0] # linear term in the objective
f = 1.0 # constant term in the objective
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
w = T[1.0, 1.0, 1.0]
x_0 = T[0.0, 0.0, 0.0]
# 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:3
# Initialize LSQP
lsqp_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'
lsqp_import(T, control, data, status, n, m,
"coordinate", A_ne, A_row, A_col, C_NULL)
lsqp_solve_qp(T, data, status, n, m, w, x_0, 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'
lsqp_import(T, control, data, status, n, m,
"sparse_by_rows", A_ne, C_NULL, A_col, A_ptr)
lsqp_solve_qp(T, data, status, n, m, w, x_0, 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'
A_dense_ne = 6 # number of elements of A
A_dense = T[2.0, 1.0, 0.0, 0.0, 1.0, 1.0]
lsqp_import(T, control, data, status, n, m,
"dense", A_dense_ne, C_NULL, C_NULL, C_NULL)
lsqp_solve_qp(T, data, status, n, m, w, x_0, g, f,
A_dense_ne, A_dense, c_l, c_u, x_l, x_u,
x, c, y, z, x_stat, c_stat)
end
lsqp_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: LSQP_solve exit status = %1i\n", st, inform[].status)
end
# @printf("x: ")
# for i = 1:n
# @printf("%f ", x[i])
# @printf("\n")
# @printf("gradient: ")
# for i = 1:n
# @printf("%f ", g[i])
# @printf("\n")
# Delete internal workspace
lsqp_terminate(T, data, control, inform)
end
return 0
end
@testset "LSQP" begin
@test test_lsqp(Float32) == 0
@test test_lsqp(Float64) == 0
end