constrainedNlp¶
Solves a general nonlinear programming problem using a sequential equality constrained quadratic programming method.
Synopsis¶
constrainedNlp (fcn, m, meq, ibtype, xlb, xub)
Required Arguments¶
- void
fcn
(n
,x[]
,iact
,result
,ierr
) (Input) User supplied function to evaluate the objective function and constraints at a given point.
- int
n
(Input) - Number of variables.
- float
x[]
(Input) - The point at which the objective function or a constraint is evaluated.
- int
iact
(Input) - Integer indicating whether evaluation of the function is requested or
evaluation of a constraint is requested. If
iact
is zero, then an objective function evaluation is requested. Ifiact
is nonzero then the value ofiact
indicates the index of the constraint to evaluate.iact
=
1 tomeq
for equality constraints andiact
=
meq
+
1 tom
for inequality constraints. - float
result[]
(Output) - If
iact
is zero, thenresult
is the computed objective function at the pointx
. Ifiact
is nonzero, thenresult
is the requested constraint value at the pointx
. - int
ierr
(Output) - An integer. On input
ierr
is set to 0.
If an error or other undesirable condition occurs during evaluation, thenierr
should be set to 1. Settingierr
to 1 will result in the step size being reduced and the step being tried again. (Ifierr
is set to 1 forxguess
, then an error is issued.)
- int
- int
m
(Input) - Total number of constraints.
- int
meq
(Input) - Number of equality constraints.
- int
ibtype
(Input) - Scalar indicating the types of bounds on variables.
ibtype |
Action |
---|---|
0 | User will supply all the bounds. |
1 | All variables are nonnegative. |
2 | All variables are nonpositive. |
3 | User supplies only the bounds on first variable, all other variables will have the same bounds. |
- float
xlb[]
(Input, Output, or Input/Output) Array with
n
components containing the lower bounds on the variables. (Input, ifibtype
= 0; output, ifibtype
= 1 or 2; Input/Output, ifibtype
= 3)If there is no lower bound on a variable, then the corresponding
xlb
value should be set tomachine(8)
.- float
xub[]
(Input, Output, or Input/Output) Array with
n
components containing the upper bounds on the variables. (Input, ifibtype
= 0; output, ifibtype
1 or 2; Input/Output, ifibtype
= 3)If there is no upper bound on a variable, then the corresponding
xub
value should be set tomachine(7)
.
Return Value¶
The solution x of the nonlinear programming problem. If no solution can be
computed, then None
is returned.
Optional Arguments¶
gradient
, voidgrad
(n
,x[]
,iact
,result[])
(Input)User-supplied function to evaluate the gradients at a given point where
Arguments
- int
n
(Input) - Number of variables.
- float
x[]
(Input) - The point at which the gradient of the objective function or gradient of a constraint is evaluated
- int
iact
(Input) - Integer indicating whether evaluation of the function gradient is
requested or evaluation of a constraint gradient is requested. If
iact
is zero, then an objective function gradient evaluation is requested. Ifiact
is nonzero then the value ofiact
indicates the index of the constraint gradient to evaluate.iact
=
1 tomeq
for equality constraints andiact
=meq+
1 tom
for inequality constraints. - float
result[]
(Output) - If
iact
is zero, thenresult
is the computed gradient of the objective function at the pointx
. Ifiact
is nonzero, thenresult
is the computed gradient of the requested constraint value at the pointx
.
- int
t_print
, int (Input)Parameter indicating the desired output level. (Input)
t_print
Action 0 No output printed. 1 One line of intermediate results is printed in each iteration. 2 Lines of intermediate results summarizing the most important data for each step are printed. 3 Lines of detailed intermediate results showing all primal and dual variables, the relevant values from the working set, progress in the backtracking and etc are printed 4 Lines of detailed intermediate results showing all primal and dual variables, the relevant values from the working set, progress in the backtracking, the gradients in the working set, the quasi-Newton updated and etc are printed. Default:
t_print
= 0.xguess
, float[]
(Input)Array of length
n
containing an initial guess of the solution.Default:
xguess
=X
, (with the smallest value of \(\|x\|_2\)) that satisfies the bounds.itmax
, int (Input)Maximum number of iterations allowed.
Default:
itmax
= 200.tau0
, float (Input)A universal bound describing how much the unscaled penalty-term may deviate from zero.
constrainedNlp
assumes that within the region described by\[\sum_{i=1}^{M_e} \left|g_i(x)\right| - \sum_{i=M_e+1}^{M} \min \left(0, g_i\left(x\right)\right) \leq \mathit{tau}0\]all functions may be evaluated safely. The initial guess, however, may violate these requirements. In that case an initial feasibility improvement phase is run by
constrainedNlp
until such a point is found. A smalltau0
diminishes the efficiency ofconstrainedNlp
, because the iterates then will follow the boundary of the feasible set closely. Conversely, a largetau0
may degrade the reliability of the code.Default
tau0
= 1.0.del0
, float (Input)In the initial phase of minimization a constraint is considered binding if
\[\frac{g_i(x)}{\max \left(1, \left\|\nabla g_i(x)\right\|\right)} \leq \mathit{del}0 \phantom{...} i = M_{\mathrm{e}} + 1, \ldots, M\]Good values are between .01 and 1.0. If
del0
is chosen too small then identification of the correct set of binding constraints may be delayed. Contrary, ifdel0
is too large, then the method will often escape to the full regularized SQP method, using individual slack variables for any active constraint, which is quite costly. For well-scaled problemsdel0
=1.0 is reasonable.Default:
del0
= .5*tau0
smallw
, float (Input)Scalar containing the error allowed in the multipliers. For example, a negative multiplier of an inequality constraint is accepted (as zero) if its absolute value is less than
smallw
.Default:
smallw
= exp(2*log(eps
/3)) whereeps
is the machine precision.delmin
, float (Input)Scalar which defines allowable constraint violations of the final accepted result. Constraints are satisfied if \(|g_i(x)|\) ≤
delmin
for equality constraints, and \(g_i(x)\) ≥ (‑delmin
) for equality constraints.Default:
delmin = min
(.1*del0
,max
(epsdif
,max
(1.e-6*del0
,smallw
))scfmax
, float (Input)Scalar containing the bound for the internal automatic scaling of the objective function. (Input)
Default:
scfmax
= 1.0e4obj
(Output)- Scalar containing the value of the objective function at the computed solution.
lagrangeMultipliers
(Output)- An array containing the Lagrange multiplier estimates of the constraints.
constraintResiduals
(Output)- An array containing the constraints residuals.
Note: The following optional arguments are valid only if
gradient is not supplied. |
difftype
, int (Input)Type of numerical differentiation to be used.
Default:
difftype
= 1
difftype |
Action |
---|---|
1 | Use a forward difference quotient with discretization stepsize \(0.1(\text{epsfcn})^{1/2}\) componentwise relative. |
2 | Use the symmetric difference quotient with discretization stepsize \(0.1(\text{epsfcn})^{1/3}\) componentwise relative. |
3 | Use the sixth order approximation computing a Richardson extrapolation of three symmetric difference quotient values. This uses a discretization stepsize \(0.01(\text{epsfcn})^{1/7}\). |
xscale
, float[]
(Input)Vector of length
n
setting the internal scaling of the variables. The initial value given and the objective function and gradient evaluations however are always in the original unscaled variables. The first internal variable is obtained by dividing valuesx[i]
byxscale[i]
. In the absence of other information, set all entries to 1.0.Default:
xscale[]
= 1.0.epsdif
(Input)Relative precision in gradients.
Default:
epsdif
= ɛ where ɛ is the machine precision.epsfcn
, float (Input)Relative precision of the function evaluation routine.
Default:
epsfcn
= ɛ where ɛ is the machine precisiontaubnd
, float (Input)Amount by which bounds may be violated during numerical differentiation. Bounds are violated by
taubnd
(at most) only if a variable is on a bound and finite differences are taken for gradient evaluations.Default:
taubnd
= 1.0
Description¶
The function constrainedNlp
provides an interface to a licensed version
of subroutine DONLP2
, a code developed by Peter Spellucci (1998). It
uses a sequential equality constrained quadratic programming method with an
active set technique, and an alternative usage of a fully regularized mixed
constrained subproblem in case of nonregular constraints (i.e. linear
dependent gradients in the “working sets”). It uses a slightly modified
version of the Pantoja-Mayne update for the Hessian of the Lagrangian,
variable dual scaling and an improved Armjijo-type stepsize algorithm.
Bounds on the variables are treated in a gradient-projection like fashion.
Details may be found in the following two papers:
P. Spellucci: An SQP method for general nonlinear programs using only equality constrained subproblems. Math. Prog. 82, (1998), 413-448.
P. Spellucci: A new technique for inconsistent problems in the SQP method. Math. Meth. of Oper. Res. 47, (1998), 355-500. (published by Physica Verlag, Heidelberg, Germany).
The problem is stated as follows:
Although default values are provided for optional input arguments, it may be
necessary to adjust these values for some problems. Through the use of
optional arguments, constrainedNlp
allows for several parameters of the
algorithm to be adjusted to account for specific characteristics of
problems. The DONLP2
Users Guide provides detailed descriptions of these
parameters as well as strategies for maximizing the perfomance of the
algorithm. The DONLP2 Users Guide is available in the “help”
subdirectory of the main IMSL product installation directory. In addition,
the following are a number of guidelines to consider when using
constrainedNlp
.
- A good initial starting point is very problem specific and should be
provided by the calling program whenever possible. See optional argument
xguess
. - Gradient approximation methods can have an effect on the success of
constrainedNlp
. Selecting a higher order approximation method may be necessary for some problems. See optional argumentdifftype
. - If a two sided constraint \(l_i\leq g_i(x)\leq u_i\)
is transformed into two constraints \(g _{2i}(x)\geq 0\) and
\(g_{2i+1}(x)\geq 0\), then choose
\(del0<1/2(u_i-l_i)/\max\{1,\|∇g_i(x)\|\}\), or at least try to provide
an estimate for that value. This will increase the efficiency of the
algorithm. See optional argument
del0
. - The parameter
ierr
provided in the interface to the user supplied functionfcn
can be very useful in cases when evaluation is requested at a point that is not possible or reasonable. For example, if evaluation at the requested point would result in a floating point exception, then settingierr
to1
and returning without performing the evaluation will avoid the exception.constrainedNlp
will then reduce the stepsize and try the step again. Note, ifierr
is set to1
for the initial guess, then an error is issued.
On some platforms, constrainedNlp
can evaluate the user-supplied
functions fcn
and grad
in parallel. This is done only if the
function ompOptions is called to flag user-defined
functions as thread-safe. A function is thread-safe if there are no
dependencies between calls. Such dependencies are usually the result of
writing to global or static variables.
Example¶
The problem
is solved.
from numpy import *
from pyimsl.math.constrainedNlp import constrainedNlp
from pyimsl.math.writeMatrix import writeMatrix
# Himmelblau problem 1
def fcn(n, x, iact, result, ierr):
tmp1 = x[0] - 2.0e0
tmp2 = x[1] - 1.0e0
if iact == 0:
result[0] = tmp1 * tmp1 + tmp2 * tmp2
elif iact == 1:
result[0] = x[0] - 2.0e0 * x[1] + 1.0e0
elif iact == 2:
result[0] = -(x[0] * x[0]) / 4.0e0 - x[1] * x[1] + 1.0e0
ierr = 0
m = 2
me = 1
n = 2
ibtype = 0
inf = 1e300000
xlb = [-inf, -inf]
xub = [inf, inf]
x = constrainedNlp(fcn, m, me, ibtype, xlb, xub)
writeMatrix("The solution is ", x)
Output¶
The solution is
1 2
0.8229 0.9114
Fatal Errors¶
IMSL_STOP_USER_FCN |
Request from user supplied function to stop algorithm. User flag = “#”. |