WCP#
purpose#
The wcp
package uses a primal-dual interior-point method to find a
well-centered point within a polyhedral set.
The aim is to find a point that lies interior to the boundary of the
polyhedron definied by the general linear constraints and simple bounds
See Section 4 of $GALAHAD/doc/wcp.pdf for a brief description of the method employed and other details.
terminolgy#
More specifically, if possible, the package finds a solution to the system of primal optimality equations
method#
The algorithm is iterative, and at each major iteration attempts to find a solution to the perturbed system (1), (2),
Given any solution to (1)–(2) and (10) satisfying (9), the perturbations are reduced (sometimes to zero) so as to ensure that the current solution is feasible for the next perturbed problem. Specifically, the perturbation \((\theta^l_c)_i^{}\) for the constraint \(c_i^{} \geq c^l_i\) is set to zero if \(c_i\) is larger than some given parameter \(\epsilon > 0\). If not, but \(c_i\) is strictly positive, the perturbation will be reduced by a multiplier \(\rho \in (0,1)\). Otherwise, the new perturbation will be set to \(\xi (\theta^l_c)_i^{} + ( 1 - \xi ) ( c_i^l - c_i^{} )\) for some factor \(\xi \in (0,1)\). Identical rules are used to reduce the remaining primal and dual perturbations. The targets \(\mu_c^{l}\), \(\mu_c^{u}\), \(\mu_x^{l}\) and \(\mu_x^{u}\) will also be increased by the factor \(\beta \geq 1\) for those (primal and/or dual) variables with strictly positive perturbations so as to try to accelerate the convergence.
Ultimately the intention is to drive all the perturbations to zero. It can be shown that if the original problem (1)–(4) and (6) has a solution, the perturbations will be zero after a finite number of major iterations. Equally, if there is no interior solution (6), the sets of (primal and dual) variables that are necessarily at (one of) their bounds for all feasible points—we refer to these as implicit equalities—will be identified, as will the possibility that there is no point (interior or otherwise) in the primal and/or dual feasible regions.
Each major iteration requires the solution \(v = (x,c,z^l,z^u,y^l,y^u)\) of the nonlinear system (1), (2) and (7)–(9) for fixed perturbations, using a minor iteration. The minor iteration uses a stabilized (predictor-corrector) Newton method, in which the arc \(v(\alpha) = v + \alpha \dot{v} + \alpha^2 \ddot{v}\), \(\alpha \in [0,1]\), involving the standard Newton step \(\dot{v}\) for the equations (1), (2), (7) and (8), optionally augmented by a corrector \(\ddot{v}\) to account for the nonlinearity in (7) and (8), is truncated so as to ensure that
SBLS
.
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.
In addition, an attempt to identify and remove linearly dependent
equality constraints may be made by factorizing
SBLS
, and examining small pivot blocks.
reference#
The basic algorithm, its convergence analysis and results of numerical experiments are given in
C. Cartis and N. I. M. Gould, Finding a point n the relative interior of a polyhedron. Technical Report TR-2006-016, Rutherford Appleton Laboratory (2006).
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 \(0 \leq i \leq m-1\), \(0 \leq j \leq n-1\). 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 \(0 \leq i \leq m-1\), \(0 \leq j \leq n-1\). 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, \(0 \leq l \leq ne-1\), of \(A\), its row index i, column index j and value \(A_{ij}\), \(0 \leq i \leq m-1\), \(0 \leq j \leq n-1\), 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) holds the total number of entries. The column indices j, \(0 \leq j \leq n-1\), 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, \(0 \leq i \leq m-1\), 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) holds the total number of entries. The row indices i, \(0 \leq i \leq m-1\), 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, \(0 \leq j \leq n-1\), 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.
functions#
- wcp.initialize()#
Set default option values and initialize private data
Returns:
- optionsdict
- dictionary containing default control options:
- errorint
error and warning diagnostics occur on stream error.
- outint
general output occurs on stream out.
- print_levelint
the level of output required is specified by print_level. Possible values are
<=0
gives no output,
1
gives a one-line summary for every iteration.
2
gives a summary of the inner iteration for each iteration.
>=3
gives increasingly verbose (debugging) output.
- print_levelint
the level of output required is specified by print_level.
- start_printint
any printing will start on this iteration.
- stop_printint
any printing will stop on this iteration.
- maxitint
at most maxit inner iterations are allowed.
- initial_pointint
how to choose the initial point. Possible values are
0
the values input in X, shifted to be at least prfeas from their nearest bound, will be used
1
the nearest point to the “bound average” 0.5(X_l+X_u) that satisfies the linear constraints will be used.
- factorint
the factorization to be used. Possible values are
0
automatic
1
Schur-complement factorization
2
augmented-system factorization.
- max_colint
the maximum number of nonzeros in a column of A which is permitted with the Schur-complement factorization.
- indminint
an initial guess as to the integer workspace required by SBLS.
- valminint
an initial guess as to the real workspace required by SBLS.
- itref_maxint
the maximum number of iterative refinements allowed.
- infeas_maxint
the number of iterations for which the overall infeasibility of the problem is not reduced by at least a factor
required_infeas_reduction
before the problem is flagged as infeasible (see required_infeas_reducti.- perturbation_strategyint
the strategy used to reduce relaxed constraint bounds. Possible values are
0
do not perturb the constraints
1
reduce all perturbations by the same amount with linear reduction
2
reduce each perturbation as much as possible with linear reduction
3
reduce all perturbations by the same amount with superlinear reduction
4
reduce each perturbation as much as possible with superlinear reduction.
- restore_problemint
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.
- infinityfloat
any bound larger than infinity in modulus will be regarded as infinite.
- stop_pfloat
the required accuracy for the primal infeasibility.
- stop_dfloat
the required accuracy for the dual infeasibility.
- stop_cfloat
the required accuracy for the complementarity.
- prfeasfloat
initial primal variables will not be closer than prfeas from their bound.
- dufeasfloat
initial dual variables will not be closer than dufeas from their bounds.
- mu_targetfloat
the target value of the barrier parameter. If mu_target is not positive, it will be reset to an appropriate value.
- mu_accept_fractionfloat
the complemtary slackness x_i.z_i will be judged to lie within an acceptable margin around its target value mu as soon as mu_accept_fraction * mu <= x_i.z_i <= ( 1 / mu_accept_fraction ) * mu; the perturbations will be reduced as soon as all of the complemtary slacknesses x_i.z_i lie within acceptable bounds. mu_accept_fraction will be reset to ensure that it lies in the interval (0,1].
- mu_increase_factorfloat
the target value of the barrier parameter will be increased by mu_increase_factor for infeasible constraints every time the perturbations are adjusted.
- required_infeas_reductionfloat
if the overall infeasibility of the problem is not reduced by at least a factor required_infeas_reduction over
infeas_max
iterations, the problem is flagged as infeasible (see infeas_max).- implicit_tolfloat
any primal or dual variable that is less feasible than implicit_tol will be regarded as defining an implicit constraint.
- pivot_tolfloat
the threshold pivot used by the matrix factorization. See the documentation for SBLS for details (obsolete).
- pivot_tol_for_dependenciesfloat
the threshold pivot used by the matrix factorization when attempting to detect linearly dependent constraints. See the documentation for SBLS for details (obsolete).
- zero_pivotfloat
any pivots smaller than zero_pivot in absolute value will be regarded to zero when attempting to detect linearly dependent constraints (obsolete).
- perturb_startfloat
the constraint bounds will initially be relaxed by
perturb_start;
this perturbation will subsequently be reduced to zero. If perturb_start < 0, the amount by which the bounds are relaxed will be computed automatically.- alpha_scalefloat
the test for rank defficiency will be to factorize ( alpha_scale I A^T ) ( A 0 ).
- identical_bounds_tolfloat
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.
- reduce_perturb_factorfloat
the constraint perturbation will be reduced as follows: * - if the variable lies outside a bound, the corresponding perturbation will be reduced to reduce_perturb_factor * current pertubation + ( 1 - reduce_perturb_factor ) * violation * - otherwise, if the variable lies within insufficiently_feasible of its bound the pertubation will be reduced to reduce_perturb_multiplier * current pertubation * - otherwise if will be set to zero.
- reduce_perturb_multiplierfloat
see reduce_perturb_factor.
- insufficiently_feasiblefloat
see reduce_perturb_factor.
- perturbation_smallfloat
if the maximum constraint pertubation is smaller than perturbation_small and the violation is smaller than implicit_tol, the method will deduce that there is a feasible point but no interior.
- cpu_time_limitfloat
the maximum CPU time allowed (-ve means infinite).
- clock_time_limitfloat
the maximum elapsed clock time allowed (-ve means infinite).
- remove_dependenciesbool
the equality constraints will be preprocessed to remove any linear dependencies if True.
- treat_zero_bounds_as_generalbool
any problem bound with the value zero will be treated as if it were a general value if True.
- just_feasiblebool
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.- balance_initial_complementaritybool
if
balance_initial_complementarity
istrue.
the initial complemetarity will be balanced.- use_correctorbool
if
use_corrector,
a corrector step will be used.- space_criticalbool
if
space_critical
is True, every effort will be made to use as little space as possible. This may result in longer computation time.- deallocate_error_fatalbool
if
deallocate_error_fatal
is True, any array/pointer deallocation error will terminate execution. Otherwise, computation will continue.- record_x_statusbool
if
record_x_status
is True, the array inform.X_status will be allocated and the status of the bound constraints will be reported on exit.- record_c_statusbool
if
record_c_status
is True, the array inform.C_status will be allocated and the status of the general constraints will be reported on exit.- prefixstr
all output lines will be prefixed by the string contained in quotes within
prefix
, e.g. ‘word’ (note the qutoes) will result in the prefix word.- fdc_optionsdict
default control options for FDC (see
fdc.initialize
).- sbls_optionsdict
default control options for SBLS (see
sbls.initialize
).
- wcp.load(n, m, A_type, A_ne, A_row, A_col, A_ptr, options=None)#
Import problem data into internal storage prior to solution.
Parameters:
- nint
holds the number of variables.
- mint
holds the number of constraints.
- A_typestring
specifies the unsymmetric storage scheme used for the constraints Jacobian \(A\). It should be one of ‘coordinate’, ‘sparse_by_rows’ or ‘dense’; lower or upper case variants are allowed.
- A_neint
holds the number of entries in \(A\) in the sparse co-ordinate storage scheme. It need not be set for any of the other two schemes.
- A_rowndarray(A_ne)
holds the row indices of \(A\) in the sparse co-ordinate storage scheme. It need not be set for any of the other two schemes, and in this case can be None.
- A_colndarray(A_ne)
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 storage scheme is used, and in this case can be None.
- A_ptrndarray(m+1)
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 None.
- optionsdict, optional
dictionary of control options (see
wcp.initialize
).
- wcp.find_wcp(n, m, a_ne, A_val, c_l, c_u, x_l, x_u, x, y_l, y_u, z_l, z_u, g)#
Find a well-centered point for a given polyhedral set of linear inequalities.
Parameters:
- nint
holds the number of variables.
- mint
holds the number of residuals.
- a_neint
holds the number of entries in the constraint Jacobian \(A\).
- A_valndarray(a_ne)
holds the values of the nonzeros in the constraint Jacobian \(A\) in the same order as specified in the sparsity pattern in
wcp.load
.- c_lndarray(m)
holds the values of the lower bounds \(c_l\) on the constraints The lower bound on any component of \(A x\) that is unbounded from below should be set no larger than minus
options.infinity
.- c_undarray(m)
holds the values of the upper bounds \(c_l\) on the constraints The upper bound on any component of \(A x\) that is unbounded from above should be set no smaller than
options.infinity
.- x_lndarray(n)
holds the values of the lower bounds \(x_l\) on the variables. The lower bound on any component of \(x\) that is unbounded from below should be set no larger than minus
options.infinity
.- x_undarray(n)
holds the values of the upper bounds \(x_l\) on the variables. The upper bound on any component of \(x\) that is unbounded from above should be set no smaller than
options.infinity
.- xndarray(n)
holds the initial estimate of the minimizer \(x\), if known. This is not crucial, and if no suitable value is known, then any value, such as \(x=0\), suffices and will be adjusted accordingly.
- y_lndarray(m)
holds the initial estimate of the Lagrange multipliers \(y_l\) associated with the lower general constraints, \(A x \geq c_l\), if known. This is not crucial, and if no suitable value is known, then any value, such as \(y_l=0\), suffices and will be adjusted accordingly.
- y_undarray(m)
holds the initial estimate of the Lagrange multipliers \(y_u\) associated with the upper general constraints, \(A x \leq c_u\), if known. This is not crucial, and if no suitable value is known, then any value, such as \(y_u=0\), suffices and will be adjusted accordingly.
- z_lndarray(n)
holds the initial estimate of the dual variables \(z_l\) associated with the lower simple bound constraints, \(x \geq x_l\), if known. This is not crucial, and if no suitable value is known, then any value, such as \(z_l=0\), suffices and will be adjusted accordingly.
- z_undarray(n)
holds the initial estimate of the dual variables \(z_u\) associated with the upper simple bound constraints, \(x \leq x_u\), if known. This is not crucial, and if no suitable value is known, then any value, such as \(z_u=0\), suffices and will be adjusted accordingly.
- gndarray(n)
holds an optional dual target vector, if this is required (for experts); normally a vetor of zero suffices.
Returns:
- xndarray(n)
holds the values of the well-centred point \(x\) after a successful call.
- cndarray(m)
holds the values of the residuals \(c(x) = Ax\).
- yndarray(m)
holds the values of the Lagrange multipliers associated with the general linear constraints.
- zndarray(n)
holds the values of the dual variables associated with the simple bound constraints.
- c_statndarray(m)
holds the return status for each constraint. The i-th component will be negative if the value of the \(i\)-th constraint \((Ax)_i\)) lies on its lower bound, positive if it lies on its upper bound, and zero if it lies between bounds.
- x_statndarray(n)
holds the return status for each variable. The i-th component will be negative if the \(i\)-th variable lies on its lower bound, positive if it lies on its upper bound, and zero if it lies between bounds.
- [optional] wcp.information()
Provide optional output information
Returns:
- informdict
- dictionary containing output information:
- statusint
return status. Possible values are:
0
The run was successful.
-1
An allocation error occurred. A message indicating the offending array is written on unit options[‘error’], and the returned allocation status and a string containing the name of the offending array are held in inform[‘alloc_status’] and inform[‘bad_alloc’] respectively.
-2
A deallocation error occurred. A message indicating the offending array is written on unit options[‘error’] and the returned allocation status and a string containing the name of the offending array are held in inform[‘alloc_status’] and inform[‘bad_alloc’] respectively.
-3
The restriction n > 0 or m > 0 or requirement that type contains its relevant string ‘dense’, ‘coordinate’ or ‘sparse_by_rows’ has been violated.
-4
The constraint bounds are inconsistent.
-5
The constraints appear to have no feasible point.
-9
The analysis phase of the factorization failed; the return status from the factorization package is given by inform[‘factor_status’].
-10
The factorization failed; the return status from the factorization package is given by inform[‘factor_status’].
-11
The solution of a set of linear equations using factors from the factorization package failed; the return status from the factorization package is given by inform[‘factor_status’].
-16
The problem is so ill-conditioned that further progress is impossible.
-17
The step is too small to make further impact.
-18
Too many iterations have been performed. This may happen if options[‘maxit’] is too small, but may also be symptomatic of a badly scaled problem.
-19
The CPU time limit has been reached. This may happen if options[‘cpu_time_limit’] is too small, but may also be symptomatic of a badly scaled problem.
- alloc_statusint
the status of the last attempted allocation/deallocation.
- bad_allocstr
the name of the array for which an allocation/deallocation error occurred.
- iterint
the total number of iterations required.
- factorization_statusint
the return status from the factorization.
- factorization_integerlong
the total integer workspace required for the factorization.
- factorization_reallong
the total real workspace required for the factorization.
- nfactsint
the total number of factorizations performed.
- c_implicitint
the number of general constraints that lie on (one) of their bounds for feasible solutions.
- x_implicitint
the number of variables that lie on (one) of their bounds for all feasible solutions.
- y_implicitint
the number of Lagrange multipliers for general constraints that lie on (one) of their bounds for all feasible solutions.
- z_implicitint
the number of dual variables that lie on (one) of their bounds for all feasible solutions.
- objfloat
the value of the objective function at the best estimate of the solution determined by WCP_solve.
- mu_final_target_maxfloat
the largest target value on termination.
- non_negligible_pivotfloat
the smallest pivot which was not judged to be zero when detecting linear dependent constraints.
- feasiblebool
is the returned primal-dual “solution” strictly feasible?
- timedict
- dictionary containing timing information:
- totalfloat
the total CPU time spent in the package.
- preprocessfloat
the CPU time spent preprocessing the problem.
- find_dependentfloat
the CPU time spent detecting linear dependencies.
- analysefloat
the CPU time spent analysing the required matrices prior to factorization.
- factorizefloat
the CPU time spent factorizing the required matrices.
- solvefloat
the CPU time spent computing the search direction.
- clock_totalfloat
the total clock time spent in the package.
- clock_preprocessfloat
the clock time spent preprocessing the problem.
- clock_find_dependentfloat
the clock time spent detecting linear dependencies.
- clock_analysefloat
the clock time spent analysing the required matrices prior to factorization.
- clock_factorizefloat
the clock time spent factorizing the required matrices.
- clock_solvefloat
the clock time spent computing the search direction.
- fdc_informdict
inform parameters for FDC (see
fdc.information
).- sbls_informdict
inform parameters for SBLS (see
sbls.information
).
- wcp.terminate()#
Deallocate all internal private storage.
example code#
from galahad import wcp
import numpy as np
np.set_printoptions(precision=4,suppress=True,floatmode='fixed')
print("\n** python test: wcp")
# set parameters
n = 3
m = 2
infinity = float("inf")
# describe constraints
A_type = 'coordinate'
A_ne = 4
A_row = np.array([0,0,1,1])
A_col = np.array([0,1,1,2])
A_ptr = None
A_val = np.array([2.0,1.0,1.0,1.0])
c_l = np.array([1.0,2.0])
c_u = np.array([2.0,2.0])
x_l = np.array([-1.0,-infinity,-infinity])
x_u = np.array([1.0,infinity,2.0])
# allocate internal data and set default options
options = wcp.initialize()
# set some non-default options
options['print_level'] = 0
#print("options:", options)
# load data (and optionally non-default options)
wcp.load(n, m, A_type, A_ne, A_row, A_col, A_ptr, options)
# provide starting values (not crucial)
x = np.array([0.0,0.0,0.0])
g = np.array([0.0,0.0,0.0])
y_l = np.array([0.0,0.0])
y_u = np.array([0.0,0.0])
z_l = np.array([0.0,0.0,0.0])
z_u = np.array([0.0,0.0,0.0])
# find optimum of lp
print("\n find well-centred point")
x, c, y_l, y_u, z_l, z_u, x_stat, c_stat \
= wcp.find_wcp(n, m, A_ne, A_val, c_l, c_u, x_l, x_u, x, y_l, y_u,
z_l, z_u, g)
print(" x:",x)
print(" c:",c)
print(" y_l:",y_l)
print(" y_u:",y_u)
print(" z_l:",z_l)
print(" z_u:",z_u)
print(" x_stat:",x_stat)
print(" c_stat:",c_stat)
# get information
inform = wcp.information()
print(" strictly feasible:",inform['feasible'])
print('** wcp exit status:', inform['status'])
# deallocate internal data
wcp.terminate()
This example code is available in $GALAHAD/src/wcp/Python/test_wcp.py .