GALAHAD BLLSB package#
purpose#
The bllsb
package uses a primal-dual interior-point crossover method
to solve a bound-constrained linear least-squares problem,
The aim is to minimize the (regularized) least-squares objective function
See Section 4 of $GALAHAD/doc/bllsb.pdf for additional details.
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 (2a) and (3), while ensuring that (1) and (2b) are satisfied as strict inequalities at each stage. Appropriate norms of the amounts by which (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 (1) and (2b) are satisfied as strict inequalities gives such methods their other title, namely interior-point methods.
The method aims at each stage to reduce the overall violation of (2a) and (3), rather than reducing each of the terms individually. Given an estimate \(v = (x, \; z, \; z^{l}, \; z^{u})\) of the primal-dual variables, a correction \(\Delta v = \Delta (x, \;z,, \;z^{l} ,\;z^{u} )\) is obtained by solving a suitable linear system of Newton equations for the nonlinear systems (2a) and a parameterized ``residual trajectory’’ perturbation of (3); residual trajectories proposed by Zhang (1994) and Zhao and Sun (1999) are possibilities. 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 (1) 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.
If the algorithm believes that it is close to the solution, it may take a speculative ``pounce’’, based on an estimate of the ultimate active set, to avoid further costly iterations. If the pounce is unsuccessful, the iteration continues, and further pounces may be attempted later.
The Newton equations are solved by applying the matrix factorization
package SLS
.
references#
The basic algorithm is a generalisation of those 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,
and
with many enhancements described by
N. I. M. Gould, D. Orban and D. P. Robinson, ``Trajectory-following methods for large-scale degenerate convex quadratic programming’’, Mathematical Programming Computation 5(2) (2013) 113-142
and tailored for a regularized linear least-squares objective.
matrix storage#
The unsymmetric \(o\) by \(n\) matrix \(A_o\) may be presented and stored in a variety of convenient input formats.
Dense storage format: The matrix \(A_o\) 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 Ao_val will hold the value \(A_{ij}\) for \(1 \leq i \leq o\), \(1 \leq j \leq n\). The string Ao_type = ‘dense’ should be specified.
Dense by columns storage format: The matrix \(A_o\) 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 \(o \ast j + i\) of the storage array Ao_val will hold the value \(A_{ij}\) for \(1 \leq i \leq o\), \(1 \leq j \leq n\). The string Ao_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_o\), its row index i, column index j and value \(A_{ij}\), \(1 \leq i \leq o\), \(1 \leq j \leq n\), are stored as the \(l\)-th components of the integer arrays Ao_row and Ao_col and real array Ao_val, respectively, while the number of nonzeros is recorded as Ao_ne = \(ne\). The string Ao_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_o\) the i-th component of the integer array Ao_ptr holds the position of the first entry in this row, while Ao_ptr(o+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 = Ao_ptr(i), \(\ldots\), Ao_ptr(i+1)-1, \(1 \leq i \leq o\), of the integer array Ao_col, and real array Ao_val, respectively. For sparse matrices, this scheme almost always requires less storage than its predecessor. The string Ao_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_o\) the j-th component of the integer array Ao_ptr holds the position of the first entry in this column, while Ao_ptr(n+1) holds the total number of entries plus one. The row indices i, \(1 \leq i \leq o\), and values \(A_{ij}\) of the nonzero entries in the j-th columnsare stored in components l = Ao_ptr(j), \(\ldots\), Ao_ptr(j+1)-1, \(1 \leq j \leq n\), of the integer array Ao_row, and real array Ao_val, respectively. As before, for sparse matrices, this scheme almost always requires less storage than the co-ordinate format. The string Ao_type = ‘sparse_by_columns’ should be specified.
introduction to function calls#
To solve a given problem, functions from the bllsb package must be called in the following order:
bllsb_initialize - provide default control parameters and set up initial data structures
bllsb_read_specfile (optional) - override control values by reading replacement values from a file
bllsb_import - set up problem data structures and fixed values
bllsb_reset_control (optional) - possibly change control parameters if a sequence of problems are being solved
bllsb_solve_blls - solve the bound-constrained (regularized) linear least-squares problem
bllsb_information (optional) - recover information about the solution and solution process
bllsb_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 bllsb_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 bllsb_control_type) |
status |
is a scalar variable of type Int32 that gives the exit status from the package. Possible values are (currently):
|
function bllsb_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/bllsb/BLLSB.template. See also Table 2.1 in the Fortran documentation provided in $GALAHAD/doc/bllsb.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 bllsb_control_type) |
specfile |
is a one-dimensional array of type Vararg{Cchar} that must give the name of the specification file |
function bllsb_import(T, control, data, status, n, o, Ao_type, Ao_ne, Ao_row, Ao_col, Ao_ptr_ne, Ao_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 bllsb_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. |
o |
is a scalar variable of type Int32 that holds the number of residuals. |
Ao_type |
is a one-dimensional array of type Vararg{Cchar} that specifies the unsymmetric storage scheme used for the objective design matrix, \(A_o\). It should be one of ‘coordinate’, ‘sparse_by_rows’, ‘sparse_by_columns’, ‘dense’ or ‘dense_by_columns’; lower or upper case variants are allowed. |
Ao_ne |
is a scalar variable of type Int32 that holds the number of entries in \(A_o\) in the sparse co-ordinate storage scheme. It need not be set for any of the other schemes. |
Ao_row |
is a one-dimensional array of size Ao_ne and type Int32 that holds the row indices of \(A_o\) in the sparse co-ordinate and sparse column-wise storage schemes. It need not be set for any of the other schemes, and in this case can be C_NULL. |
Ao_col |
is a one-dimensional array of size Ao_ne and type Int32 that holds the column indices of \(A_o\) in the sparse co-ordinate and the sparse row-wise storage schemes. It need not be set for any of the other schemes, and in this case can be C_NULL. |
Ao_ptr_ne |
is a scalar variable of type Int32 that holds the length of the pointer array if sparse row or column storage scheme is used for \(A_o\). For the sparse row scheme, Ao_ptr_ne should be at least o+1, while for the sparse column scheme, it should be at least n+1, It need not be set when the other schemes are used. |
Ao_ptr |
is a one-dimensional array of size n+1 and type Int32 that holds the starting position of each row of \(A_o\), as well as the total number of entries, in the sparse row-wise storage scheme. By contrast, it is a one-dimensional array of size n+1 and type Int32 that holds the starting position of each column of \(A_o\), as well as the total number of entries, in the sparse column-wise storage scheme. It need not be set when the other schemes are used, and in this case can be C_NULL. |
function bllsb_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 bllsb_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 bllsb_solve_blls(T, data, status, n, o, Ao_ne, Ao_val, b, sigma, x_l, x_u, x, r, z, x_stat, w)
Solve the linearly-constrained regularized linear least-squares problem.
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 |
o |
is a scalar variable of type Int32 that holds the number of residulas. |
Ao_ne |
is a scalar variable of type Int32 that holds the number of entries in the objectve design matrix \(A_o\). |
Ao_val |
is a one-dimensional array of size Ao_ne and type T that holds the values of the entries of the design matrix \(A_o\) in any of the available storage schemes. |
b |
is a one-dimensional array of size o and type T that holds the observations \(b\). The j-th component of |
sigma |
is a scalar of type T that holds the non-negative regularization weight \(\sigma \geq 0\). |
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 |
r |
is a one-dimensional array of size o and type T that holds the residual \(r(x) = A_o x - b\). The i-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. |
w |
is a one-dimensional array of size o and type T that holds the values \(w\) of strictly-positive observation weights. The i-th component of w, i = 0, … , o-1, contains \(w_i\). If the weights are all one, w can be set to C_NULL. |
function bllsb_information(T, data, inform, status)
Provides output information
Parameters:
data |
holds private internal data |
inform |
is a structure containing output information (see bllsb_inform_type) |
status |
is a scalar variable of type Int32 that gives the exit status from the package. Possible values are (currently):
|
function bllsb_terminate(T, data, control, inform)
Deallocate all internal private storage
Parameters:
data |
holds private internal data |
control |
is a structure containing control information (see bllsb_control_type) |
inform |
is a structure containing output information (see bllsb_inform_type) |
available structures#
bllsb_control_type structure#
struct bllsb_control_type{T} f_indexing::Bool error::Int32 out::Int32 print_level::Int32 start_print::Int32 stop_print::Int32 maxit::Int32 infeas_max::Int32 muzero_fixed::Int32 restore_problem::Int32 indicator_type::Int32 arc::Int32 series_order::Int32 sif_file_device::Int32 qplib_file_device::Int32 infinity::T stop_abs_p::T stop_rel_p::T stop_abs_d::T stop_rel_d::T stop_abs_c::T stop_rel_c::T prfeas::T dufeas::T muzero::T tau::T gamma_c::T gamma_f::T reduce_infeas::T identical_bounds_tol::T mu_pounce::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 treat_separable_as_general::Bool just_feasible::Bool getdua::Bool puiseux::Bool every_order::Bool feasol::Bool balance_initial_complentarity::Bool crossover::Bool reduced_pounce_system::Bool space_critical::Bool deallocate_error_fatal::Bool generate_sif_file::Bool generate_qplib_file::Bool sif_file_name::NTuple{31,Cchar} qplib_file_name::NTuple{31,Cchar} prefix::NTuple{31,Cchar} fdc_control::fdc_control_type{T} sls_control::sls_control_type{T} sls_pounce_control::sls_control_type{T} fit_control::fit_control_type roots_control::roots_control_type{T} cro_control::cro_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
\(\leq\) 0 gives no output,
= 1 gives a one-line summary for every iteration,
= 2 gives a summary of the inner iteration for each iteration,
\(\geq\) 3 gives increasingly verbose (debugging) output
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 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: a constraint is active if and only if the distance to its nearest bound \(\leq\).indicator_p_tol
2 primal-dual indicator: a constraint is active if and only if the distance to its nearest bound \(\leq\).indicator_tol_pd \* size of corresponding multiplier
3 primal-dual indicator: a constraint is active if and only if the distance to its nearest bound \(\leq\).indicator_tol_tapia \* distance to same bound at previous iteration
Int32 arc
which residual trajectory should be used to aim from the current iterate to the solution. Possible values are
1 the Zhang linear residual trajectory
2 the Zhao-Sun quadratic residual trajectory
3 the Zhang arc ultimately switching to the Zhao-Sun residual trajectory
4 the mixed linear-quadratic residual trajectory
5 the Zhang arc ultimately switching to the mixed linear-quadratic residual trajectory
Int32 series_order
the order of (Taylor/Puiseux) series to fit to the path data
Int32 sif_file_device
specifies the unit number to write generated SIF file describing the current problem
Int32 qplib_file_device
specifies the unit number to write generated QPLIB file describing the current problem
T infinity
any bound larger than infinity in modulus will be regarded as infinite
T stop_abs_p
the required absolute and relative accuracies for the primal infeasibility
T stop_rel_p
see stop_abs_p
T stop_abs_d
the required absolute and relative accuracies for the dual infeasibility
T stop_rel_d
see stop_abs_d
T stop_abs_c
the required absolute and relative accuracies for the complementarity
T stop_rel_c
see stop_abs_c
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 tau
the weight attached to primal-dual infeasibility compared to complementa when assessing step acceptance
T gamma_c
individual complementarities will not be allowed to be smaller than gamma_c times the average value
T gamma_f
the average complementarity will not be allowed to be smaller than gamma_f times the primal/dual infeasibility
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 identical_bounds_tol
any pair of constraint bounds \((c_l,c_u)\) or \((x_l,x_u)\) that are closer than .identical_bounds_tol will be reset to the average of their values
T mu_pounce
start terminal extrapolation when mu reaches mu_pounce
T indicator_tol_p
if .indicator_type = 1, a constraint/bound will be deemed to be active if and only if the distance to its 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 its 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 its 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 treat_separable_as_general
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 just_feasible
if .treat_separable_as_general, is true, any separability in the problem structure will be ignored
Bool getdua
if .getdua, is true, advanced initial values are obtained for the dual variables
Bool puiseux
decide between Puiseux and Taylor series approximations to the arc
Bool every_order
try every order of series up to series_order?
Bool feasol
if .feasol is true, the final solution obtained will be perturbed so that 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 crossover
if .crossover is true, cross over the solution to one defined by linearly-independent constraints if possible
Bool reduced_pounce_system
if .reduced_pounce_system is true, eliminate fixed variables when solving the linear system required by the attempted pounce to the solution
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
Bool generate_qplib_file
if .generate_qplib_file is .true. if a QPLIB 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} qplib_file_name
name of generated QPLIB 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 sls_control_type sls_control
control parameters for SLS
struct sls_control_type sls_pounce_control
control parameters for SLS pounce
struct fit_control_type fit_control
control parameters for FIT
struct roots_control_type roots_control
control parameters for ROOTS
struct cro_control_type cro_control
control parameters for CRO
bllsb_time_type structure#
struct bllsb_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
bllsb_inform_type structure#
struct bllsb_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 threads::Int32 obj::T primal_infeasibility::T dual_infeasibility::T complementary_slackness::T non_negligible_pivot::T feasible::Bool checkpointsIter::NTuple{16,Int32} checkpointsTime::NTuple{16,T} time::bllsb_time_type{T} fdc_inform::fdc_inform_type{T} sls_inform::sls_inform_type{T} sls_pounce_inform::sls_inform_type{T} fit_inform::fit_inform_type roots_inform::roots_inform_type cro_inform::cro_inform_type{T} rpd_inform::rpd_inform_type
detailed documentation#
inform derived type as a Julia structure
components#
Int32 status
return status. See BLLSB_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
Int32 threads
the number of threads used
T obj
the value of the objective function at the best estimate of the solution determined by BLLSB_solve
T primal_infeasibility
the value of the primal infeasibility
T dual_infeasibility
the value of the dual infeasibility
T complementary_slackness
the value of the complementary slackness
T init_primal_infeasibility
these values at the initial point (needed bg GALAHAD_CBLLSB)
T init_dual_infeasibility
see init_primal_infeasibility
T init_complementary_slackness
see init_primal_infeasibility
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?
Int32 checkpointsIter[16]
checkpoints(i) records the iteration at which the criticality measures first fall below \(10^{-i-1}\), i = 0, …, 15 (-1 means not achieved)
T checkpointsTime[16]
see checkpointsIter
struct bllsb_time_type time
timings (see above)
struct fdc_inform_type fdc_inform
inform parameters for FDC
struct sls_inform_type sls_inform
inform parameters for SLS
struct sls_inform_type sls_pounce_inform
inform parameters for SLS pounce
struct fit_inform_type fit_inform
return information from FIT
struct roots_inform_type roots_inform
return information from ROOTS
struct cro_inform_type cro_inform
inform parameters for CRO
struct rpd_inform_type rpd_inform
inform parameters for RPD
example calls#
This is an example of how to use the package to solve a given linearly-constrained regularized linear least-squares problem; the code is available in $GALAHAD/src/bllsb/Julia/test_bllsb.jl . A variety of supported design matrix storage formats are shown.
# test_bllsb.jl
# Simple code to test the Julia interface to BLLSB
using GALAHAD
using Test
using Printf
using Accessors
function test_bllsb(::Type{T}) where T
# Derived types
data = Ref{Ptr{Cvoid}}()
control = Ref{bllsb_control_type{T}}()
inform = Ref{bllsb_inform_type{T}}()
# Set problem data
n = 3 # dimension
o = 4 # number of observations
sigma = 1.0 # regularization weight
b = T[2.0, 2.0, 3.0, 1.0] # observations
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, 2.0] # weights
# Set output storage
r = zeros(T, o) # residual values
x_stat = zeros(Cint, n) # variable status
st = ""
status = Ref{Cint}()
@printf(" Fortran sparse matrix indexing\n\n")
@printf(" basic tests of bllsb storage formats\n\n")
for d in 1:5
# Initialize BLLSB
bllsb_initialize(T, data, control, status)
# Set user-defined control options
@reset control[].f_indexing = true # Fortran sparse matrix indexing
@reset control[].symmetric_linear_solver = galahad_linear_solver("potr")
@reset control[].fdc_control.symmetric_linear_solver = galahad_linear_solver("potr")
@reset control[].fdc_control.use_sls = true
# 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 = "CO"
Ao_ne = 7 # objective Jacobian elements
Ao_row = Cint[1, 1, 2, 2, 3, 3, 4] # row indices
Ao_col = Cint[1, 2, 2, 3, 1, 3, 2] # column indices
Ao_val = T[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] # vals
bllsb_import(T, control, data, status, n, o,
"coordinate", Ao_ne, Ao_row, Ao_col, 0, C_NULL)
bllsb_solve_blls(T, data, status, n, o, Ao_ne, Ao_val, b,
sigma, x_l, x_u, x, r, z, x_stat, w)
end
# sparse by rows
if d == 2
st = "SR"
Ao_ne = 7 # objective Jacobian elements
Ao_col = Cint[1, 2, 2, 3, 1, 3, 2] # column indices
Ao_ptr_ne = o + 1 # number of row pointers
Ao_ptr = Cint[1, 3, 5, 7, 8] # row pointers
Ao_val = T[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] # vals
bllsb_import(T, control, data, status, n, o,
"sparse_by_rows", Ao_ne, C_NULL, Ao_col,
Ao_ptr_ne, Ao_ptr)
bllsb_solve_blls(T, data, status, n, o, Ao_ne, Ao_val, b,
sigma, x_l, x_u, x, r, z, x_stat, w)
end
# sparse by columns
if d == 3
st = "SC"
Ao_ne = 7 # objective Jacobian elements
Ao_row = Cint[1, 3, 1, 2, 4, 2, 3] # row indices
Ao_ptr_ne = n + 1 # number of column pointers
Ao_ptr = Cint[1, 3, 6, 8] # column pointers
Ao_val = T[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] # vals
bllsb_import(T, control, data, status, n, o,
"sparse_by_columns", Ao_ne, Ao_row, C_NULL,
Ao_ptr_ne, Ao_ptr)
bllsb_solve_blls(T, data, status, n, o, Ao_ne, Ao_val, b,
sigma, x_l, x_u, x, r, z, x_stat, w)
end
if d == 4 # dense by rows
st = "DR"
Ao_ne = 12 # objective Jacobian elements
Ao_dense = T[1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0]
bllsb_import(T, control, data, status, n, o,
"dense", Ao_ne, C_NULL, C_NULL, 0, C_NULL)
bllsb_solve_blls(T, data, status, n, o, Ao_ne, Ao_dense, b,
sigma, x_l, x_u, x, r, z, x_stat, w)
end
if d == 5 # dense by cols
st = "DC"
Ao_ne = 12 # objective Jacobian elements
Ao_dense = T[1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0]
bllsb_import(T, control, data, status, n, o,
"dense_by_columns", Ao_ne, C_NULL, C_NULL, 0, C_NULL)
bllsb_solve_blls(T, data, status, n, o, Ao_ne, Ao_dense, b,
sigma, x_l, x_u, x, r, z, x_stat, w)
end
bllsb_information(T, data, inform, status)
if inform[].status == 0
@printf("%s:%6i iterations. Optimal objective value = %5.2f status = %1i\n", st,
inform[].iter, inform[].obj, inform[].status)
else
@printf("%s: BLLSB_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
bllsb_terminate(T, data, control, inform)
end
return 0
end
@testset "BLLSB" begin
@test test_bllsb(Float32) == 0
@test test_bllsb(Float64) == 0
end