PDF version (NAG web site
, 64bit version, 64bit version)
NAG Toolbox: nag_glopt_nlp_pso (e05sb)
Purpose
nag_glopt_nlp_pso (e05sb) is designed to search for the global minimum or maximum of an arbitrary function, subject to general nonlinear constraints, using Particle Swarm Optimization (PSO). Derivatives are not required, although these may be used by an accompanying local minimization function if desired.
nag_glopt_nlp_pso (e05sb) is essentially identical to
nag_glopt_bnd_pso (e05sa), with an expert interface and various additional parameters added; otherwise most parameters are identical. In particular,
nag_glopt_bnd_pso (e05sa) does not handle general constraints.
Information for users of the NAG Toolbox
nag_glopt_nlp_pso (e05sb) has been designed to be particularly effective on SMP systems, by allowing multiple threads to advance subiterations of the algorithm in a highly asynchronous manner. In doing this, the callback functions supplied to
nag_glopt_nlp_pso (e05sb) are called simultaneously on multiple threads, and therefore must themselves be thread safe. In particular, the arrays
user and
user provided are classified as OpenMP shared memory, and as such it is imperative that any operations performed on these arrays are done in an appropriate manner. Failure to ensure thread safety of the provided callback functions may result in unpredictable behaviour, including the callback functions returning completely wrong solutions to
nag_glopt_nlp_pso (e05sb) – invalidating any solution returned.
Syntax
[
xb,
fb,
cb,
xbest,
fbest,
cbest,
iopts,
opts,
user,
itt,
inform,
ifail] = e05sb(
bl,
bu,
xbest,
fbest,
cbest,
objfun,
confun,
monmod,
iopts,
opts, 'ndim',
ndim, 'ncon',
ncon, 'npar',
npar, 'user',
user)
[
xb,
fb,
cb,
xbest,
fbest,
cbest,
iopts,
opts,
user,
itt,
inform,
ifail] = nag_glopt_nlp_pso(
bl,
bu,
xbest,
fbest,
cbest,
objfun,
confun,
monmod,
iopts,
opts, 'ndim',
ndim, 'ncon',
ncon, 'npar',
npar, 'user',
user)
Before calling
nag_glopt_nlp_pso (e05sb),
nag_glopt_optset (e05zk) must be called with
optstr set to ‘
Initialize = e05sbc’. Optional parameters may also be specified by calling
nag_glopt_optset (e05zk) before the call to
nag_glopt_nlp_pso (e05sb).
Description
nag_glopt_nlp_pso (e05sb) uses a stochastic method based on Particle Swarm Optimization (PSO) to search for the global optimum of a nonlinear function
F$F$, subject to a set of bound constraints on the variables, and optionally a set of general nonlinear constraints. In the PSO algorithm (see
Section [Algorithmic Details]), a set of particles is generated in the search space, and advances each iteration to (hopefully) better positions using a heuristic velocity based upon
inertia,
cognitive memory and
global memory. The inertia is provided by a decreasingly weighted contribution from a particles current velocity, the cognitive memory refers to the best candidate found by an individual particle and the global memory refers to the best candidate found by all the particles. This allows for a global search of the domain in question.
Further, this may be coupled with a selection of local minimization functions, which may be called during the iterations of the heuristic algorithm, the interior phase, to hasten the discovery of locally optimal points, and after the heuristic phase has completed to attempt to refine the final solution, the exterior phase. Different options may be set for the local optimizer in each phase.
Without loss of generality, the problem is assumed to be stated in the following form:
where the objective
F(x)$F\left(\mathbf{x}\right)$ is a scalar function,
c(x)$\mathbf{c}\left(\mathbf{x}\right)$ is a vector of scalar constraint functions,
x$\mathbf{x}$ is a vector in
R^{ndim}${R}^{\mathit{ndim}}$ and the vectors
ℓ ≤ u$\mathbf{\ell}\le \mathbf{u}$ are lower and upper bounds respectively for the
ndim$\mathit{ndim}$ variables and
ncon$\mathit{ncon}$ constraints. Both the objective function and the
ncon$\mathit{ncon}$ constraints may be nonlinear. Continuity of
F$F$, and the functions
c(x)$\mathbf{c}\left(\mathbf{x}\right)$, is not essential. For functions which are smooth and primarily unimodal, faster solutions will almost certainly be achieved by using
Chapter E04 functions directly.
For functions which are smooth and multimodal, gradient dependent local minimization functions may be coupled with nag_glopt_nlp_pso (e05sb).
For multimodal functions for which derivatives cannot be provided, particularly functions with a significant level of noise in their evaluation,
nag_glopt_nlp_pso (e05sb) should be used either alone, or coupled with
nag_opt_uncon_simplex (e04cb).
For heavily constrained problems,
nag_glopt_nlp_pso (e05sb) should either be used alone, or coupled with
nag_opt_nlp1_solve (e04uc) provided the function and the constraints are sufficiently smooth.
The
ndim$\mathit{ndim}$ lower and upper box bounds on the variable
x$\mathbf{x}$ are included to initialize the particle swarm into a finite hypervolume, although their subsequent influence on the algorithm is user determinable (see the option
Boundary in
Section [Optional Parameters]). It is strongly recommended that sensible bounds are provided for all variables and constraints.
nag_glopt_nlp_pso (e05sb) may also be used to maximize the objective function, or to search for a feasible point satisfying the simple bounds and general constraints (see the option
Optimize).
Due to the nature of global optimization, unless a predefined target is provided, there is no definitive way of knowing when to end a computation. As such several stopping heuristics have been implemented into the algorithm. If any of these is achieved,
nag_glopt_nlp_pso (e05sb) will exit with
ifail = 1${\mathbf{ifail}}={\mathbf{1}}$, and the parameter
inform will indicate which criteria was reached. See
inform for more information.
In addition, you may provide your own stopping criteria through
monmod,
objfun and
confun.
nag_glopt_bnd_pso (e05sa) provides a simpler interface, without the inclusion of general nonlinear constraints.
References
Gill P E, Murray W and Wright M H (1981) Practical Optimization Academic Press
Kennedy J and Eberhart R C (1995) Particle Swarm Optimization Proceedings of the 1995 IEEE International Conference on Neural Networks 1942–1948
Koh B, George A D, Haftka R T and Fregly B J (2006) Parallel Asynchronous Particle Swarm Optimization International Journal for Numerical Methods in Engineering 67(4) 578–595
Vaz A I and Vicente L N (2007) A Particle Swarm Pattern Search Method for Bound Constrained Global Optimization Journal of Global Optimization 39(2) 197–219 Kluwer Academic Publishers
Parameters
Note: for descriptions of the symbolic variables, see
Section [Algorithmic Details].
Compulsory Input Parameters
 1:
bl(ndim + ncon${\mathbf{ndim}}+{\mathbf{ncon}}$) – double array
 2:
bu(ndim + ncon${\mathbf{ndim}}+{\mathbf{ncon}}$) – double array
bl${\mathbf{bl}}$ is
ℓ$\mathbf{\ell}$, the array of lower bounds,
bu is
u$\mathbf{u}$, the array of upper bounds. The first
ndim entries in
bl and
bu must contain the lower and upper simple (box) bounds of the variables respectively. These must be provided to initialize the sample population into a finite hypervolume, although their subsequent influence on the algorithm is user determinable (see the option
Boundary in
Section [Optional Parameters]).
The next
ncon entries must contain the lower and upper bounds for any general constraints respectively.
If
bl(i) = bu(i)${\mathbf{bl}}\left(i\right)={\mathbf{bu}}\left(i\right)$ for any
i ∈ {1, … ,ndim}$i\in \{1,\dots ,{\mathbf{ndim}}\}$, variable
i$i$ will remain locked to
bl(i)${\mathbf{bl}}\left(i\right)$ regardless of the
Boundary option selected.
It is strongly advised that you place sensible lower and upper bounds on all variables and constraints, even if your model allows for unbounded variables or constraints.
Constraints:
 bl(i) ≤ bu(i)${\mathbf{bl}}\left(\mathit{i}\right)\le {\mathbf{bu}}\left(\mathit{i}\right)$, for i = 1,2, … ,ndim + ncon$\mathit{i}=1,2,\dots ,{\mathbf{ndim}}+{\mathbf{ncon}}$;
 bl(i) ≠ bu(i)${\mathbf{bl}}\left(i\right)\ne {\mathbf{bu}}\left(i\right)$ for at least one i ∈ {1, … ,ndim}$i\in \{1,\dots ,{\mathbf{ndim}}\}$.
 3:
xbest(ndim,npar) – double array
Note: the
i$i$th component of the best position of the
j$j$th particle,
x̂_{j}(i)${\hat{x}}_{j}\left(i\right)$, is stored in
xbest(i,j)${\mathbf{xbest}}\left(i,j\right)$.
ndim, the first dimension of the array, must satisfy the constraint
ndim ≥ 1${\mathbf{ndim}}\ge 1$.
If using
Start = WARM${\mathbf{Start}}=\mathrm{WARM}$, the initial particle positions,
x̂_{j}^{0}${\hat{\mathbf{x}}}_{j}^{0}$.
 4:
fbest(npar) – double array
npar, the dimension of the array, must satisfy the constraint
npar ≥ 5 × num_threads${\mathbf{npar}}\ge 5\times \mathbf{num\_threads}$, where
num_threads is the value returned by the OpenMP environment variable
OMP_NUM_THREADS, or
num_threads is
1$1$ for a serial version of this function.
If using
Start = WARM${\mathbf{Start}}=\mathrm{WARM}$, objective function values,
f̂_{j}^{0} = F(x̂_{j}^{0})${\hat{f}}_{j}^{0}=F\left({\hat{\mathbf{x}}}_{j}^{0}\right)$, corresponding to the
npar particle locations stored in
xbest.
 5:
cbest(ncon,npar) – double array
Note: the
k$k$th constraint violation of the
j$j$th particle is stored in
cbest(k,j)${\mathbf{cbest}}\left(k,j\right)$.
ncon, the first dimension of the array, must satisfy the constraint
ncon ≥ 0${\mathbf{ncon}}\ge 0$.
If using
Start = WARM${\mathbf{Start}}=\mathrm{WARM}$, the initial constraint violations,
ê_{j}^{0} = e(x̂_{j}^{0})${\hat{\mathbf{e}}}_{j}^{0}=\mathbf{e}\left({\hat{\mathbf{x}}}_{j}^{0}\right)$, corresponding to the
npar particle locations.
 6:
objfun – function handle or string containing name of mfile
objfun must, depending on the value of
mode, calculate the objective function
and/or calculate the gradient of the objective function for a
ndim$\mathit{ndim}$variable vector
x$\mathbf{x}$. Gradients are only required if a local minimizer has been chosen which requires gradients. See the option
Local Minimizer for more information.
[mode, objf, vecout, user] = objfun(mode, ndim, x, objf, vecout, nstate, user)
Input Parameters
 1:
mode – int64int32nag_int scalar
Indicates which functionality is required.
 mode = 0${\mathbf{mode}}=0$
 F(x)$F\left(\mathbf{x}\right)$ should be returned in objf. The value of objf on entry may be used as an upper bound for the calculation. Any expected value of F(x)$F\left(\mathbf{x}\right)$ that is greater than objf may be approximated by this upper bound; that is objf can remain unaltered.
 mode = 1${\mathbf{mode}}=1$
 Local Minimizer = 'e04uc'${\mathbf{Local\; Minimizer}}='\mathrm{e04uc}'$ only
First derivatives can be evaluated and returned in vecout. Any unaltered elements of vecout will be approximated using finite differences.
 mode = 2${\mathbf{mode}}=2$
 Local Minimizer = 'e04uc'${\mathbf{Local\; Minimizer}}='\mathrm{e04uc}'$ only
F(x)$F\left(\mathbf{x}\right)$ must be calculated and returned in objf, and available first derivatives can be evaluated and returned in vecout. Any unaltered elements of vecout will be approximated using finite differences.
 mode = 5${\mathbf{mode}}=5$
 F(x)$F\left(\mathbf{x}\right)$ must be calculated and returned in objf. The value of objf on entry may not be used as an upper bound.
 mode = 6${\mathbf{mode}}=6$
 Local Minimizer = 'e04dg'${\mathbf{Local\; Minimizer}}='\mathrm{e04dg}'$ or 'e04kz'$'\mathrm{e04kz}'$ only
All first derivatives must be evaluated and returned in vecout.
 mode = 7${\mathbf{mode}}=7$
 Local Minimizer = 'e04dg'${\mathbf{Local\; Minimizer}}='\mathrm{e04dg}'$ or 'e04kz'$'\mathrm{e04kz}'$ only
F(x)$F\left(\mathbf{x}\right)$ must be calculated and returned in objf, and all first derivatives must be evaluated and returned in vecout.
 2:
ndim – int64int32nag_int scalar
The number of dimensions.
 3:
x(ndim) – double array
x$\mathbf{x}$, the point at which the objective function and/or its gradient are to be evaluated.
 4:
objf – double scalar
The value of
objf passed to
objfun varies with the parameter
mode.
 mode = 0${\mathbf{mode}}=0$
 objf is an upper bound for the value of F(x)$F\left(\mathbf{x}\right)$, often equal to the best constraint penalised value of F(x)$F\left(\mathbf{x}\right)$ found so far by a given particle if the objective function is strictly positive (see Section [Algorithmic Details]). Only objective function values less than the value of objf on entry will be used further. As such this upper bound may be used to stop further evaluation when this will only increase the objective function value above the upper bound.
 mode = 1${\mathbf{mode}}=1$, 2$2$, 5$5$, 6$6$ or 7$7$
 objf is meaningless on entry.
 5:
vecout(ndim) – double array
If
Local Minimizer = e04uc${\mathbf{Local\; Minimizer}}=\mathrm{e04uc}$ or
e04uc$\mathrm{e04uc}$, the values of
vecout are used internally to indicate whether a finite difference approximation is required. See
nag_opt_nlp1_solve (e04uc).
 6:
nstate – int64int32nag_int scalar
nstate indicates various stages of initialization throughout the function. This allows for permanent global parameters to be initialized the least number of times. For example, you may initialize a random number generator seed.
 nstate = 3${\mathbf{nstate}}=3$
 SMP users only. objfun is called for the first time in a parallel region on a new thread other than the master thread. You may use this opportunity to set up any threaddependent information in user and user.
 nstate = 2${\mathbf{nstate}}=2$
 objfun is called for the very first time. You may save computational time if certain data must be read or calculated only once.
 nstate = 1${\mathbf{nstate}}=1$
 objfun is called for the first time by a NAG local minimization function. You may save computational time if certain data required for the local minimizer need only be calculated at the initial point of the local minimization.
 nstate = 0${\mathbf{nstate}}=0$
 Used in all other cases.
 7:
user – Any MATLAB object
objfun is called from
nag_glopt_nlp_pso (e05sb) with the object supplied to
nag_glopt_nlp_pso (e05sb).
Output Parameters
 1:
mode – int64int32nag_int scalar
If the value of
mode is set to be negative, then
nag_glopt_nlp_pso (e05sb) will exit as soon as possible with
ifail = 3${\mathbf{ifail}}={\mathbf{3}}$ and
inform = mode${\mathbf{inform}}={\mathbf{mode}}$.
 2:
objf – double scalar
The value of
objf returned varies with the parameter
mode.
 mode = 0${\mathbf{mode}}=0$
 objf must be the value of F(x)$F\left(\mathbf{x}\right)$. Only values of F(x)$F\left(\mathbf{x}\right)$ strictly less than objf on entry need be accurate.
 mode = 1${\mathbf{mode}}=1$ or 6$6$
 Need not be set.
 mode = 2${\mathbf{mode}}=2$, 5$5$ or 7$7$
 F(x)$F\left(\mathbf{x}\right)$ must be calculated and returned in objf. The entry value of objf may not be used as an upper bound.
 3:
vecout(ndim) – double array
The required values of
vecout returned to the calling function depend on the value of
mode.
 mode = 0${\mathbf{mode}}=0$ or 5$5$
 The value of vecout need not be set.
 mode = 1${\mathbf{mode}}=1$ or 2$2$
 vecout can contain components of the gradient of the objective function (∂F)/(∂x_{i})$\frac{\partial F}{\partial {x}_{i}}$ for some i = 1,2, … ndim$i=1,2,\dots {\mathbf{ndim}}$, or acceptable approximations. Any unaltered elements of vecout will be approximated using finite differences.
 mode = 6${\mathbf{mode}}=6$ or 7$7$
 vecout must contain the gradient of the objective function (∂F)/(∂x_{i})$\frac{\partial F}{\partial {x}_{i}}$ for all i = 1,2, … ndim$i=1,2,\dots {\mathbf{ndim}}$. Approximation of the gradient is strongly discouraged, and no finite difference approximations will be performed internally (see nag_opt_uncon_conjgrd_comp (e04dg) and nag_opt_bounds_mod_deriv_easy (e04kz)).
 4:
user – Any MATLAB object
 7:
confun – function handle or string containing name of mfile
confun must calculate any constraints other than the box constraints. If no constraints are required,
confun may be string
'e05szm'. For information on how a NAG local minimizer will use
confun see the documentation for
(e04uc).
[mode, c, cjac, user] = confun(mode, ncon, ndim, ldcj, needc, x, cjac, nstate, user)
Input Parameters
 1:
mode – int64int32nag_int scalar
Indicates which values must be assigned during each call of
confun. Only the following values need be assigned, for each value of
k ∈ {1, … ,ncon}$k\in \{1,\dots ,{\mathbf{ncon}}\}$ such that
needc(k) > 0${\mathbf{needc}}\left(k\right)>0$:
 mode = 0${\mathbf{mode}}=0$
 the constraint values c_{k}(x)${c}_{k}\left(\mathbf{x}\right)$.
 mode = 1${\mathbf{mode}}=1$
 rows of the constraint jacobian,
( ∂ c_{k})/(∂x_{i})(x)$\frac{\partial {c}_{k}}{\partial {x}_{\mathit{i}}}\left(\mathbf{x}\right)$, for i = 1,2, … ,ndim$\mathit{i}=1,2,\dots ,{\mathbf{ndim}}$.
 mode = 2${\mathbf{mode}}=2$
 the constraint values c_{k}(x)${c}_{k}\left(\mathbf{x}\right)$ and the corresponding rows of the constraint jacobian,
( ∂ c_{k})/(∂x_{i})(x)$\frac{\partial {c}_{k}}{\partial {x}_{\mathit{i}}}\left(\mathbf{x}\right)$, for i = 1,2, … ,ndim$\mathit{i}=1,2,\dots ,{\mathbf{ndim}}$.
 2:
ncon – int64int32nag_int scalar
The number of constraints, not including box bounds.
 3:
ndim – int64int32nag_int scalar
The number of variables.
 4:
ldcj – int64int32nag_int scalar
The first dimension of the array
cjac as declared in the (sub)program from which
nag_glopt_nlp_pso (e05sb) is called.
 5:
needc(ncon) – int64int32nag_int array
The indices of the elements of
c and/or
cjac that must be evaluated by
confun. If
needc(k) > 0${\mathbf{needc}}\left(k\right)>0$, the
k$k$th element of
c, corresponding to the values of the
k$k$th constraint, and/or the available elements of the
k$k$th row of
cjac, corresponding to the derivatives of the
k$k$th constraint, must be evaluated at
x$\mathbf{x}$ (see parameter
mode).
 6:
x(ndim) – double array
x$\mathbf{x}$, the vector of variables at which the constraint functions and/or the available elements of the constraint Jacobian are to be evaluated.
 7:
cjac(ldcj,ndim) – double array
Note: the derivative of the
k$k$th constraint with respect to the
i$i$th component,
(∂c_{k})/(∂x_{i})$\frac{\partial {c}_{k}}{\partial {x}_{\mathrm{i}}}$, is stored in
cjac(k,i)${\mathbf{cjac}}\left(k,i\right)$.
The elements of
cjac are set to special values which enable
nag_glopt_nlp_pso (e05sb) to detect whether they are changed by
confun.
 8:
nstate – int64int32nag_int scalar
nstate indicates various stages of initialization throughout the function. This allows for permanent global parameters to be initialized a minimum number of times. For example, you may initialize a random number generator seed. Note that unless the option
Optimize = CONSTRAINTS${\mathbf{Optimize}}=\mathrm{CONSTRAINTS}$ has been set,
objfun will be called before
confun.
 nstate = 3${\mathbf{nstate}}=3$
 SMP users only. objfun is called for the first time in a parallel region on a new thread other than the master thread. You may use this opportunity to set up any threaddependent information in user and user.
 nstate = 2${\mathbf{nstate}}=2$
 confun is called for the very first time. This parameter setting allows you to save computational time if certain data must be read or calculated only once.
 nstate = 1${\mathbf{nstate}}=1$
 confun is called for the first time during a NAG local minimization function. This parameter setting allows you to save computational time if certain data required for the local minimizer need only be calculated at the initial point of the local minimization.
 nstate = 0${\mathbf{nstate}}=0$
 Used in all other cases.
 9:
user – Any MATLAB object
confun is called from
nag_glopt_nlp_pso (e05sb) with the object supplied to
nag_glopt_nlp_pso (e05sb).
Output Parameters
 1:
mode – int64int32nag_int scalar
May be set to a negative value if you wish to terminate the solution to the current problem. In this case
nag_glopt_nlp_pso (e05sb) will terminate with
ifail = 3${\mathbf{ifail}}={\mathbf{3}}$ and
inform = mode${\mathbf{inform}}={\mathbf{mode}}$ as soon as possible.
 2:
c(ncon) – double array
If
needc(k) > 0${\mathbf{needc}}\left(k\right)>0$ and
mode = 0${\mathbf{mode}}=0$ or
2$2$,
c(k)${\mathbf{c}}\left(k\right)$ must contain the value of
c_{k}(x)${c}_{k}\left(\mathbf{x}\right)$. The remaining elements of
c, corresponding to the nonpositive elements of
needc, need not be set.
 3:
cjac(ldcj,ndim) – double array
Note: the derivative of the
k$k$th constraint with respect to the
i$i$th component,
(∂c_{k})/(∂x_{i})$\frac{\partial {c}_{k}}{\partial {x}_{\mathrm{i}}}$, is stored in
cjac(k,i)${\mathbf{cjac}}\left(k,i\right)$.
If
needc(k) > 0${\mathbf{needc}}\left(k\right)>0$ and
mode = 1${\mathbf{mode}}=1$ or
2$2$, the elements of
cjac corresponding to the
k$k$th row of the constraint jacobian should contain the available elements of the vector
∇c_{k}$\nabla {c}_{k}$ given by
where
(∂c_{k})/(∂x_{i}) $\frac{\partial {c}_{k}}{\partial {x}_{i}}$ is the partial derivative of the
k$k$th constraint with respect to the
i$i$th variable, evaluated at the point
x$\mathbf{x}$; elements of
cjac that remain unaltered will be approximated internally using finite differences. The remaining rows of
cjac, corresponding to nonpositive elements of
needc, need not be set.
It must be emphasized that unassigned elements of
cjac are not treated as constant; they are estimated by finite differences, at nontrivial expense. An interval for each element of
x$\mathbf{x}$ is computed automatically at the start of the optimization. The automatic procedure can usually identify constant elements of
cjac, which are then computed once only by finite differences.
 4:
user – Any MATLAB object
confun should be tested separately before being used in conjunction with
nag_glopt_nlp_pso (e05sb).
 8:
monmod – function handle or string containing name of mfile
A userspecified monitoring and modification function.
monmod is called once every complete iteration after a finalization check. It may be used to modify the particle locations that will be evaluated at the next iteration. This permits the incorporation of algorithmic modifications such as including additional advection heuristics and genetic mutations.
monmod is only called during the main loop of the algorithm, and as such will be unaware of any further improvement from the final local minimization. If no monitoring and/or modification is required,
monmod may be string
'e05sym' .
[x, user, inform] = monmod(ndim, ncon, npar, x, xb, fb, cb, xbest, fbest, cbest, itt, user, inform)
Input Parameters
 1:
ndim – int64int32nag_int scalar
The number of dimensions.
 2:
ncon – int64int32nag_int scalar
The number of constraints.
 3:
npar – int64int32nag_int scalar
The number of particles.
 4:
x(ndim,npar) – double array
Note: the
i$i$th component of the
j$j$th particle,
x_{j}(i)${x}_{j}\left(i\right)$, is stored in
x(i,j)${\mathbf{x}}\left(i,j\right)$.
The
npar particle locations,
x_{j}${\mathbf{x}}_{j}$, which will currently be used during the next iteration unless altered in
monmod.
 5:
xb(ndim) – double array
The location, x̃$\stackrel{~}{\mathbf{x}}$, of the best solution yet found.
 6:
fb – double scalar
The objective value, f̃ = F(x̃)$\stackrel{~}{f}=F\left(\stackrel{~}{\mathbf{x}}\right)$, of the best solution yet found.
 7:
cb(ncon) – double array
The constraint violations, ẽ = e(x̃)$\stackrel{~}{\mathbf{e}}=\mathbf{e}\left(\stackrel{~}{\mathbf{x}}\right)$, of the best solution yet found.
 8:
xbest(ndim,npar) – double array
Note: the
i$i$th component of the position of the
j$j$th particle's cognitive memory,
x̂_{j}(i)${\hat{x}}_{j}\left(i\right)$, is stored in
xbest(i,j)${\mathbf{xbest}}\left(i,j\right)$.
The locations currently in the cognitive memory,
x̂_{j}${\hat{\mathbf{x}}}_{\mathit{j}}$, for
j = 1,2, … ,npar$\mathit{j}=1,2,\dots ,{\mathbf{npar}}$ (see
Section [Algorithmic Details]).
 9:
fbest(npar) – double array
The objective values currently in the cognitive memory,
F(x̂_{j})$F\left({\hat{\mathbf{x}}}_{\mathit{j}}\right)$, for
j = 1,2, … ,npar$\mathit{j}=1,2,\dots ,{\mathbf{npar}}$.
 10:
cbest(ncon,npar) – double array
Note: the
k$k$th constraint violation of the
j$j$th particle's cognitive memory is stored in
cbest(k,j)${\mathbf{cbest}}\left(k,j\right)$.
The constraint violations currently in the cognitive memory,
ê = e(x̂_{j})$\hat{\mathbf{e}}=\mathbf{e}\left({\hat{\mathbf{x}}}_{\mathit{j}}\right)$, for
j = 1,2, … ,npar$\mathit{j}=1,2,\dots ,{\mathbf{npar}}$, evaluated at
x̂_{j}${\hat{\mathbf{x}}}_{j}$.
 11:
itt(7$7$) – int64int32nag_int array
Iteration and function evaluation counters (see description of
itt below).
 12:
user – Any MATLAB object
monmod is called from
nag_glopt_nlp_pso (e05sb) with the object supplied to
nag_glopt_nlp_pso (e05sb).
 13:
inform – int64int32nag_int scalar
inform = thread_num${\mathbf{inform}}=\mathbf{thread\_num}$, where
thread_num is the value returned by a call of the OpenMP function
OMP_GET_THREAD_NUM(). If running in serial this will always be zero.
Output Parameters
 1:
x(ndim,npar) – double array
Note: the
i$i$th component of the
j$j$th particle,
x_{j}(i)${x}_{j}\left(i\right)$, is stored in
x(i,j)${\mathbf{x}}\left(i,j\right)$.
The particle locations to be used during the next iteration.
 2:
user – Any MATLAB object
 3:
inform – int64int32nag_int scalar
Setting
inform < 0${\mathbf{inform}}<0$ will cause near immediate exit from
nag_glopt_nlp_pso (e05sb). This value will be returned as
inform with
ifail = 3${\mathbf{ifail}}={\mathbf{3}}$. You need not set
inform unless you wish to force an exit.
 9:
iopts( : $:$) – int64int32nag_int array
Optional parameter array as generated and possibly modified by calls to
nag_glopt_optset (e05zk). The contents of
iopts must not be modified directly between calls to
nag_glopt_nlp_pso (e05sb),
nag_glopt_optset (e05zk) or
nag_glopt_optget (e05zl).
Note: the contents of
iopts must not have been altered between calls to
nag_glopt_optset (e05zk),
nag_glopt_optget (e05zl),
nag_glopt_nlp_pso (e05sb) and the selected problem solving routine.
 10:
opts( : $:$) – double array
Optional parameter array as generated and possibly modified by calls to
nag_glopt_optset (e05zk). The contents of
opts must not be modified directly between calls to
nag_glopt_nlp_pso (e05sb),
nag_glopt_optset (e05zk) or
nag_glopt_optget (e05zl).
Note: the contents of
opts must not have been altered between calls to
nag_glopt_optset (e05zk),
nag_glopt_optget (e05zl),
nag_glopt_nlp_pso (e05sb) and the selected problem solving routine.
Optional Input Parameters
 1:
ndim – int64int32nag_int scalar
Default:
The dimension of the arrays
bl,
bu and the first dimension of the array
xbest. (An error is raised if these dimensions are not equal.)
ndim$\mathit{ndim}$, the number of dimensions.
Constraint:
ndim ≥ 1${\mathbf{ndim}}\ge 1$.
 2:
ncon – int64int32nag_int scalar
Default:
The first dimension of the array
cbest.
ncon$\mathit{ncon}$, the number of constraints, not including box constraints.
Constraint:
ncon ≥ 0${\mathbf{ncon}}\ge 0$.
 3:
npar – int64int32nag_int scalar
Default:
The dimension of the array
fbest and the second dimension of the arrays
xbest,
cbest. (An error is raised if these dimensions are not equal.)
npar$\mathit{npar}$, the number of particles to be used in the swarm. Assuming all particles remain within constraints, each complete iteration will perform at least
npar function evaluations. Otherwise, significantly fewer objective function evaluations may be performed.
Default:
npar = 10 × ndim${\mathbf{npar}}=10\times {\mathbf{ndim}}$
Constraint:
npar ≥ 5 × num_threads${\mathbf{npar}}\ge 5\times \mathbf{num\_threads}$, where
num_threads is the value returned by the OpenMP environment variable
OMP_NUM_THREADS, or
num_threads is
1$1$ for a serial version of this function.
 4:
user – Any MATLAB object
user is not used by
nag_glopt_nlp_pso (e05sb), but is passed to
objfun,
confun and
monmod. Note that for large objects it may be more efficient to use a global variable which is accessible from the mfiles than to use
user.
Input Parameters Omitted from the MATLAB Interface
 iuser ruser
Output Parameters
 1:
xb(ndim) – double array
The location of the best solution found, x̃$\stackrel{~}{\mathbf{x}}$, in R^{ndim}${R}^{\mathit{ndim}}$.
 2:
fb – double scalar
The objective value of the best solution, f̃ = F(x̃)$\stackrel{~}{f}=F\left(\stackrel{~}{\mathbf{x}}\right)$.
 3:
cb(ncon) – double array
The constraint violations of the best solution found,
ẽ = e(x̃)$\stackrel{~}{\mathbf{e}}=\mathbf{e}\left(\stackrel{~}{\mathbf{x}}\right)$. These may have been deemed to be acceptable given the tolerance and scaling of the constraints. See
Sections [Algorithmic Details] and
[Optional Parameters].
 4:
xbest(ndim,npar) – double array
Note: the
i$i$th component of the best position of the
j$j$th particle,
x̂_{j}(i)${\hat{x}}_{j}\left(i\right)$, is stored in
xbest(i,j)${\mathbf{xbest}}\left(i,j\right)$.
The best positions found,
x̂_{j}${\hat{\mathbf{x}}}_{j}$, by the
npar particles in the swarm.
 5:
fbest(npar) – double array
Objective function values,
f̂_{j} = F(x̂_{j})${\hat{f}}_{j}=F\left({\hat{\mathbf{x}}}_{j}\right)$, corresponding to the locations returned in
xbest.
 6:
cbest(ncon,npar) – double array
Note: the
k$k$th constraint violation of the
j$j$th particle is stored in
cbest(k,j)${\mathbf{cbest}}\left(k,j\right)$.
The final constraint violations,
ê_{j}${\hat{\mathbf{e}}}_{j}$, corresponding to the locations returned in
xbest.
 7:
iopts( : $:$) – int64int32nag_int array
Communication array, used to store information between calls to nag_glopt_nlp_pso (e05sb).
Note: the contents of
iopts must not have been altered between calls to
nag_glopt_optset (e05zk),
nag_glopt_optget (e05zl),
nag_glopt_nlp_pso (e05sb) and the selected problem solving routine.
 8:
opts( : $:$) – double array
Communication array, used to store information between calls to nag_glopt_nlp_pso (e05sb).
Note: the contents of
opts must not have been altered between calls to
nag_glopt_optset (e05zk),
nag_glopt_optget (e05zl),
nag_glopt_nlp_pso (e05sb) and the selected problem solving routine.
 9:
user – Any MATLAB object
 10:
itt(7$7$) – int64int32nag_int array
Integer iteration counters for
nag_glopt_nlp_pso (e05sb).
 itt(1)${\mathbf{itt}}\left(1\right)$
 Number of complete iterations.
 itt(2)${\mathbf{itt}}\left(2\right)$
 Number of complete iterations without improvement to the current optimum.
 itt(3)${\mathbf{itt}}\left(3\right)$
 Number of particles converged to the current optimum.
 itt(4)${\mathbf{itt}}\left(4\right)$
 Number of improvements to the optimum.
 itt(5)${\mathbf{itt}}\left(5\right)$
 Number of function evaluations performed.
 itt(6)${\mathbf{itt}}\left(6\right)$
 Number of particles reset.
 itt(7)${\mathbf{itt}}\left(7\right)$
 Number of violated constraints at completion. Note this is always calculated using the L^{1}${L}^{1}$ norm and a nonzero result does not necessarily mean that the algorithm did not find a suitably constrained point with respect to the single norm used.
 11:
inform – int64int32nag_int scalar
Indicates which finalization criterion was reached. The possible values of
inform are:
inform  Meaning 
< 0$<0$  Exit from a usersupplied subroutine. 
0  nag_glopt_nlp_pso (e05sb) has detected an error and terminated. 
1  The provided objective target has been achieved. (Target Objective Value). 
2  The standard deviation of the location of all the particles is below the set threshold (Swarm Standard Deviation). If the solution returned is not satisfactory, you may try setting a smaller value of Swarm Standard Deviation, or try adjusting the options governing the repulsive phase (Repulsion Initialize, Repulsion Finalize). 
3  The total number of particles converged (Maximum Particles Converged) to the current global optimum has reached the set limit. This is the number of particles which have moved to a distance less than Distance Tolerance from the optimum with regard to the L^{2}${L}^{2}$ norm. If the solution is not satisfactory, you may consider lowering the Distance Tolerance. However, this may hinder the global search capability of the algorithm. 
4  The maximum number of iterations without improvement (Maximum Iterations Static) has been reached, and the required number of particles (Maximum Iterations Static Particles) have converged to the current optimum. Increasing either of these options will allow the algorithm to continue searching for longer. Alternatively if the solution is not satisfactory, restarting the application several times with Repeatability = OFF${\mathbf{Repeatability}}=\mathrm{OFF}$ may lead to an improved solution. 
5  The maximum number of iterations (Maximum Iterations Completed) has been reached. If the number of iterations since improvement is small, then a better solution may be found by increasing this limit, or by using the option Local Minimizer with corresponding exterior options. Otherwise if the solution is not satisfactory, you may try rerunning the application several times with Repeatability = OFF${\mathbf{Repeatability}}=\mathrm{OFF}$ and a lower iteration limit, or adjusting the options governing the repulsive phase (Repulsion Initialize, Repulsion Finalize). 
6  The maximum allowed number of function evaluations (Maximum Function Evaluations) has been reached. As with inform = 5${\mathbf{inform}}=5$, increasing this limit if the number of iterations without improvement is small, or decreasing this limit and running the algorithm multiple times with Repeatability = OFF${\mathbf{Repeatability}}=\mathrm{OFF}$, may provide a superior result. 
7  A feasible point has been found. The objective has not been minimized, although it has been evaluated at the final solutions given in xb and xbest (Optimize = CONSTRAINTS${\mathbf{Optimize}}=\mathrm{CONSTRAINTS}$). 
If you wish to continue from the final position gained from a previous simulation with adjusted options, you may set the option
Start = WARM${\mathbf{Start}}=\mathrm{WARM}$, and pass back in the returned arrays
xbest,
fbest, and
cbest. You should either record the returned values of
xb,
fb and
cb for comparison, as these will not be reused by the algorithm, or include them in
xbest,
fbest and
cbest respectively by overwriting the entries corresponding to one particle with the relevant information.
 12:
ifail – int64int32nag_int scalar
ifail = 0${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see
[Error Indicators and Warnings]).
For this reason, the value
− 1 or 1$1\text{ or}1$ is recommended. If the output of error messages is undesirable, then the value
1$1$ is recommended; otherwise, the recommended value is
− 1$1$.
When the value − 1 or 1$\mathbf{1}\text{ or}1$ is used it is essential to test the value of ifail on exit.nag_glopt_nlp_pso (e05sb) returns
ifail = 0${\mathbf{ifail}}={\mathbf{0}}$ if and only if a finalization criterion has been reached which can guarantee success. This may only happen if:
These finalization criteria are not active using default option settings, and must be explicitly set using
nag_glopt_optset (e05zk) if required.
nag_glopt_nlp_pso (e05sb) will return
ifail = 1${\mathbf{ifail}}={\mathbf{1}}$ if no error has been detected, and a finalization criterion has been achieved which cannot guarantee success. This does not indicate that the function has failed, merely that the returned solution cannot be guaranteed to be the true global optimum.
The value of
inform should be examined to determine which finalization criterion was reached.
Other positive values of
ifail indicate that either an error or a warning has been triggered. See
Sections [Error Indicators and Warnings],
[Accuracy] and
[Algorithmic Details] for more information.
Error Indicators and Warnings
Note: nag_glopt_nlp_pso (e05sb) may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the function:
Cases prefixed with W are classified as warnings and
do not generate an error of type NAG:error_n. See nag_issue_warnings.
 W ifail = 1${\mathbf{ifail}}=1$

A finalization criterion was reached that cannot guarantee success.
 ifail = 2${\mathbf{ifail}}=2$

If the option
Target Warning has been activated, this indicates that the
Target Objective Value has been achieved to specified tolerances at a sufficiently constrained point, either during the initialization phase, or during the first two iterations of the algorithm. While this is not necessarily an error, it may occur if:
(i) 
The target was achieved at the first point sampled by the function. This will be the mean of the lower and upper bounds. 
(ii) 
The target may have been achieved at a randomly generated sample point. This will always be a possibility provided that the domain under investigation contains a point with a target objective value. 
(iii) 
If the Local Minimizer has been set, then a sample point may have been inside the basin of attraction of a satisfactory point. If this occurs repeatedly when the function is called, it may imply that the objective is largely unimodal, and that it may be more efficient to use the function selected as the Local Minimizer directly. 
Assuming that
objfun is correct, you may wish to set a better
Target Objective Value, or a stricter
Target Objective Tolerance.
 W ifail = 3${\mathbf{ifail}}=3$

User requested exit during call to
confun.
User requested exit during call to
confun.
User requested exit during call to
confun.
User requested exit during call to
monmod.
User requested exit during call to
monmod.
User requested exit during call to
objfun.
User requested exit during call to
objfun.
User requested exit during call to
objfun.
User requested exit during call to
objfun.
User requested exit during call to
objfun.
User requested exit during call to
objfun.
 W ifail = 4${\mathbf{ifail}}=4$

Unable to locate strictly feasible point.
 ifail = 11${\mathbf{ifail}}=11$

Constraint:
ndim ≥ 1${\mathbf{ndim}}\ge 1$.
 ifail = 12${\mathbf{ifail}}=12$

Constraint:
npar ≥ 5 × num_threads${\mathbf{npar}}\ge 5\times \mathbf{num\_threads}$, where
num_threads is the value returned by the OpenMP environment variable
OMP_NUM_THREADS, or
num_threads is
1$1$ for a serial version of this function.
 ifail = 13${\mathbf{ifail}}=13$

Constraint:
ncon ≥ 0${\mathbf{ncon}}\ge 0$.
 ifail = 14${\mathbf{ifail}}=14$

Constraint:
bu(i) ≥ bl(i)${\mathbf{bu}}\left(i\right)\ge {\mathbf{bl}}\left(i\right)$ for all
i$i$.
Constraint:
bu(i) ≥ bl(i)${\mathbf{bu}}\left(i\right)\ge {\mathbf{bl}}\left(i\right)$ for all
i$i$.
On entry,
bl(i) = bu(i)${\mathbf{bl}}\left(i\right)={\mathbf{bu}}\left(i\right)$ for all box bounds
i$i$.
Constraint:
bu(i) > bl(i)${\mathbf{bu}}\left(i\right)>{\mathbf{bl}}\left(i\right)$ for at least one box bound
i$i$.
 ifail = 17${\mathbf{ifail}}=17$

nag_glopt_nlp_pso (e05sb) has been called with
ncon > 0${\mathbf{ncon}}>0$ and the dummy constraint function
nag_glopt_nlp_pso_dummy_confun (e05szm). Only use
nag_glopt_nlp_pso_dummy_confun (e05szm) with
ncon = 0${\mathbf{ncon}}=0$.
 ifail = 18${\mathbf{ifail}}=18$

The option
Optimize = CONSTRAINTS${\mathbf{Optimize}}=\mathrm{CONSTRAINTS}$ is active, however
ncon = 0${\mathbf{ncon}}=0$.
 ifail = 19${\mathbf{ifail}}=19$

Error _$\_$ occurred whilst adjusting to exterior local minimizer options.
Error _$\_$ occurred whilst adjusting to interior local minimizer options.
 ifail = 21${\mathbf{ifail}}=21$

Either the option arrays have not been initialized for nag_glopt_nlp_pso (e05sb), or they have become corrupted.
Either the option arrays have not been initialized for nag_glopt_nlp_pso (e05sb), or they have become corrupted.
Either the option arrays have not been initialized for nag_glopt_nlp_pso (e05sb), or they have become corrupted.
Either the option arrays have not been initialized for nag_glopt_nlp_pso (e05sb), or they have become corrupted.
Either the option arrays have not been initialized for nag_glopt_nlp_pso (e05sb), or they have become corrupted.
 ifail = 32${\mathbf{ifail}}=32$

Derivative checks indicate possible errors in the supplied derivatives.
Gradient checks may be disabled by setting
Verify Gradients = OFF${\mathbf{Verify\; Gradients}}=\mathrm{OFF}$.
Derivative checks indicate possible errors in the supplied derivatives.
Gradient checks may be disabled by setting
Verify Gradients = OFF${\mathbf{Verify\; Gradients}}=\mathrm{OFF}$.
Derivative checks indicate possible errors in the supplied derivatives.
Gradient checks may be disabled by setting
Verify Gradients = OFF${\mathbf{Verify\; Gradients}}=\mathrm{OFF}$.
 ifail = − 999${\mathbf{ifail}}=999$

Dynamic memory allocation failed.
Accuracy
If
ifail = 0${\mathbf{ifail}}={\mathbf{0}}$ (or
ifail = 2${\mathbf{ifail}}={\mathbf{2}}$) or
ifail = 1${\mathbf{ifail}}={\mathbf{1}}$ on exit, a criterion will have been reached depending on user selected options. As with all global optimization software, the solution achieved may not be the true global optimum. Various options allow for either greater search diversity or faster convergence to a (local) optimum (See
Sections [Algorithmic Details] and
[Optional Parameters]).
Provided the objective function and constraints are sufficiently well behaved, if a local minimizer is used in conjunction with nag_glopt_nlp_pso (e05sb), then it is more likely that the final result will at least be in the near vicinity of a local optimum, and due to the global search characteristics of the particle swarm, this solution should be superior to many other local optima.
Caution should be used in accelerating the rate of convergence, as with faster convergence, less of the domain will remain searchable by the swarm, making it increasingly difficult for the algorithm to detect the basins of attraction of superior local optima. Using the options
Repulsion Initialize and
Repulsion Finalize described in
Section [Optional Parameters] will help to overcome this, by causing the swarm to diverge away from the current optimum once no more local improvement is likely.
On successful exit with guaranteed success,
ifail = 0${\mathbf{ifail}}={\mathbf{0}}$ (or
ifail = 2${\mathbf{ifail}}={\mathbf{2}}$). This may happen if a
Target Objective Value is assigned and is reached by the algorithm at a satisfactorily constrained point. It will also occur if a constrained point is found when
Optimize = CONSTRAINTS${\mathbf{Optimize}}=\mathrm{CONSTRAINTS}$ is set.
On successful exit without guaranteed success,
ifail = 1${\mathbf{ifail}}={\mathbf{1}}$ is returned. This will happen if another finalization criterion is achieved without the detection of an error.
In both cases, the value of
inform provides further information as to the cause of the exit.
Further Comments
The memory used by
nag_glopt_nlp_pso (e05sb) is relatively static throughout. Indeed, most of the memory required is used to store the current particle locations, the cognitive particle memories, the particle velocities and the particle weights. As such,
nag_glopt_nlp_pso (e05sb) may be used in problems with high dimension number (
ndim > 100${\mathbf{ndim}}>100$) without the concern of computational resource exhaustion, although the probability of successfully locating the global optimum will decrease dramatically with the increase in dimensionality.
Due to the stochastic nature of the algorithm, the result will vary over multiple runs. This is particularly true if parameters and options are chosen to accelerate convergence at the expense of the global search. However, the option
Repeatability = ON${\mathbf{Repeatability}}=\mathrm{ON}$ may be set to initialize the internal random number generator using a preset seed, which will result in identical solutions being obtained.
Example
Open in the MATLAB editor:
nag_glopt_nlp_pso_example
function nag_glopt_nlp_pso_example
npar = int64(20);
bl = [500; 500; 1e6; 1; 0.9];
bu = [ 500; 500; 10; 5e5; 0.9];
x_target_u = [420.9687463599820; 420.9687463599820];
x_target_c = [394.1470221120988; 433.48214189947606];
f_target_u = 837.9657745448674;
f_target_c = 731.70709230672696;
c_target_u = [0; 31644.05623568455; 0.07574889943398055];
c_target_c = [0; 0; 0];
xbest = zeros(2, 20);
fbest = zeros(20, 1);
cbest = zeros(3, 20);;
iopts = zeros(100, 1, 'int64');
opts = zeros(100, 1);
[iopts, opts, ifail] = ...
nag_glopt_optset('Initialize = nag_glopt_nlp_pso', iopts, opts);
[iopts, opts, ifail] = nag_glopt_optset('SMP Callback Thread Safe = no', iopts, opts);
fprintf('\nDefault Option Queries:\n\n');
[ivalue, rvalue, cvalue, optype, ifail] = ...
nag_glopt_optget('Constraint Norm', iopts, opts);
fprintf('Constraint Norm : %s\n', cvalue);
[ivalue, rvalue, cvalue, optype, ifail] = ...
nag_glopt_optget('Maximum Iterations Completed', iopts, opts);
fprintf('Maximum Iterations Completed : %d (%s)\n', ivalue, strtrim(cvalue));
[ivalue, rvalue, cvalue, optype, ifail] = ...
nag_glopt_optget('Distance Tolerance', iopts, opts);
fprintf('Distance Tolerance : %15.4e\n', rvalue);
fprintf('\n1. Solution without using coupled local minimizer.\n');
[iopts, opts, ifail] = nag_glopt_optset('Repeatability = On', iopts, opts);
opstr = sprintf('Distance Tolerance = %32.16e', rvalue*0.1);
[iopts, opts, ifail] = nag_glopt_optset(opstr, iopts, opts);
[iopts, opts, ifail] = nag_glopt_optset('Constraint Tolerance = 1.0e4', iopts, opts);
[iopts, opts, ifail] = nag_glopt_optset('Constraint Norm = Euclidean', iopts, opts);
opstr = sprintf('Target Objective Value = %32.16e', f_target_c);
[iopts, opts, ifail] = nag_glopt_optset(opstr, iopts, opts);
[iopts, opts, ifail] = nag_glopt_optset('Target Objective Tolerance = 1.0e4', iopts, opts);
[xb, fb, cb, xbest, fbest, cbest, iopts, opts, user, itt, inform, ifail] = ...
nag_glopt_nlp_pso(bl, bu, xbest, fbest, cbest, @objfun, @confun, ...
'nag_glopt_nlp_pso_dummy_monmod', iopts, opts);
switch ifail
case {0,1}
display_result(x_target_u, x_target_c, f_target_u, f_target_c, ...
c_target_u, c_target_c, xb, fb, cb, itt, inform);
case 3
display_result(x_target_u, x_target_c, f_target_u, f_target_c, ...
c_target_u, c_target_c, xb, fb, cb, itt, inform);
otherwise
end
fprintf('\n2. Solution using coupled local minimizer nag_opt_nlp1_solve.\n');
[iopts, opts, ifail] = ...
nag_glopt_optset('Local Minimizer = nag_opt_nlp1_solve', iopts, opts);
[iopts, opts, ifail] = ...
nag_glopt_optset('Local Interior Major Iterations = 5', iopts, opts);
[iopts, opts, ifail] = ...
nag_glopt_optset('Local Interior Minor Iterations = 3', iopts, opts);
[iopts, opts, ifail] = ...
nag_glopt_optset('Local Exterior Major Iterations = 30', iopts, opts);
[iopts, opts, ifail] = ...
nag_glopt_optset('Local Exterior Minor Iterations = 15', iopts, opts);
[ivalue, rvalue, cvalue, optype, ifail] = ...
nag_glopt_optget('Distance Tolerance', iopts, opts);
opstr = sprintf('Distance Tolerance = %32.16e', rvalue*10);
[iopts, opts, ifail] = nag_glopt_optset(opstr, iopts, opts);
opstr = sprintf('Local Interior Tolerance = %32.16e', rvalue);
[iopts, opts, ifail] = nag_glopt_optset(opstr, iopts, opts);
opstr = sprintf('Local exterior Tolerance = %32.16e', rvalue*1e4);
[iopts, opts, ifail] = nag_glopt_optset(opstr, iopts, opts);
[xb, fb, cb, xbest, fbest, cbest, iopts, opts, user, itt, inform, ifail] = ...
nag_glopt_nlp_pso(bl, bu, xbest, fbest, cbest, @objfun, @confun, ...
'nag_glopt_nlp_pso_dummy_monmod', iopts, opts);
switch ifail
case {0,1}
display_result(x_target_u, x_target_c, f_target_u, f_target_c, ...
c_target_u, c_target_c, xb, fb, cb, itt, inform);
case 3
display_result(x_target_u, x_target_c, f_target_u, f_target_c, ...
c_target_u, c_target_c, xb, fb, cb, itt, inform);
otherwise
end
function [mode, c, cjac, user] = confun(mode, ncon, ndim, ldcj, needc, x, cjac, nstate, user)
c = zeros(ncon, 1);
if (nstate == 1)
cjac(1, 1) = 3;
cjac(1, 2) = 2;
end
if mode==0  mode==2
for k = 1:double(ncon)
if (needc(k)>0)
switch k
case (1)
c(k) = 3.0*x(1)  2.0*x(2);
case (2)
c(k) = x(1)^2  x(2)^2 + 3.0*x(1)*x(2);
case (3)
c(k) = cos((x(1)/200.0)^2+(x(2)/100.0));
otherwise
c(k) = 0;
end
end
end
end
if mode==1  mode==2
for k = 1:double(ncon)
switch k
case (1)
case (2)
cjac(k,1) = 2.0*x(1) + 3.0*x(2);
cjac(k,2) = 2.0*x(2) + 3.0*x(1) ;
otherwise
end
end
end
moe = 0;
function [mode, objf, vecout, user] = objfun(mode, ndim, x, objf, vecout, nstate, user)
switch nstate
case (2)
case (1)
case (0)
otherwise
mode = int64(1);
error('*** Error detected in objfun');
end
evalobjf = false;
evalobjg = false;
switch mode
case {0,5}
evalobjf = true;
case {1,6}
evalobjg = true;
case {2,7}
evalobjf = true;
evalobjg = true;
otherwise
mode = int64(1);
error('*** Illegal value of mode (%d) in objfun', mode);
end
if evalobjf
objf = sum(x(1:double(ndim)).*sin(sqrt(abs(x(1:double(ndim))))));
end
if evalobjg
vecout = sqrt(abs(x));
for i=1:double(ndim)
vecout(i) = sin(vecout(i)) + 0.5*vecout(i)*cos(vecout(i));
end
end
function [] = display_result(x_target_u, x_target_c, f_target_u, ...
f_target_c, c_target_u, c_target_c, ...
xb, fb, cb, itt, inform)
fprintf('\nAlgorithm Statistics\n\n');
fprintf('Total complete iterations : %d\n', itt(1));
fprintf('Complete iterations since improvement : %d\n', itt(2));
fprintf('Total particles converged to xb : %d\n', itt(3));
fprintf('Total improvements to global optimum : %d\n', itt(4));
fprintf('Total function evaluations : %d\n', itt(5));
fprintf('Total particles reinitialized : %d\n', itt(6));
fprintf('Total constraints violated : %d\n\n', itt(7));
switch inform
case 0
fprintf('Solution Status : An error was detected by nag_glopt_bnd_pso_easy\n');
case 1
fprintf('Solution Status : Target value achieved\n');
case 2
fprintf('Solution Status : Minimum swarm standard deviation obtained\n');
case 3
fprintf('Solution Status : Sufficient particles converged\n');
case 4
fprintf('Solution Status : No improvement in preset iteration limit\n');
case 5
fprintf('Solution Status : Maximum complete iterations attained\n');
case 6
fprintf('Solution Status : Maximum function evaluations exceeded\n');
case 7
fprintf('Solution Status : Constrained point located\n');
otherwise
fprintf('User termination case: %d\n', inform);
end
fprintf('\n Known unconstrained objective minimum : %9.3f\n', f_target_u);
fprintf(' Best Known constrained objective minimum : %9.3f\n', f_target_c);
fprintf(' Achieved objective value : %9.3f\n\n', fb);
title = 'Comparison between known and achieved optima.';
clabs = {'x_target_u'; 'x_target_c'; 'xb '};
[ifail] = ...
nag_file_print_matrix_real_gen_comp('G', 'N', [x_target_u, x_target_c, xb], 'f11.2', title, ...
'I', clabs, 'C', clabs, int64(80), int64(0));
fprintf('\n');
title = 'Comparison between scaled constraint violations.';
clabs = {'c_target_u'; 'c_target_c'; 'cb '};
c_scale = [2490; 750000; 0.1];
c_arr = [c_target_u./c_scale, c_target_c./c_scale, cb./c_scale];
[ifail] = nag_file_print_matrix_real_gen_comp('G', 'N', c_arr, 'f11.5', title, ...
'I', clabs, 'C', clabs, int64(80), int64(0));
fprintf('\n');
Default Option Queries:
Constraint Norm : L1
Maximum Iterations Completed : 1000 (DEFAULT)
Distance Tolerance : 1.0000e04
1. Solution without using coupled local minimizer.
Algorithm Statistics

Total complete iterations : 277
Complete iterations since improvement : 1
Total particles converged to xb : 0
Total improvements to global optimum : 117
Total function evaluations : 4222
Total particles reinitialized : 0
Total constraints violated : 0
Solution Status : Target value achieved
Known unconstrained objective minimum : 837.966
Best Known constrained objective minimum : 731.707
Achieved objective value : 731.708
Comparison between known and achieved optima.
x_target_u x_target_c xb
1 420.97 394.15 394.17
2 420.97 433.48 433.53
Comparison between scaled constraint violations.
c_target_u c_target_c cb
1 0.00000 0.00000 0.00000
2 0.04219 0.00000 0.00000
3 0.75749 0.00000 0.00002
2. Solution using coupled local minimizer nag_opt_nlp1_solve.
Algorithm Statistics

Total complete iterations : 4
Complete iterations since improvement : 1
Total particles converged to xb : 0
Total improvements to global optimum : 7
Total function evaluations : 151
Total particles reinitialized : 0
Total constraints violated : 0
Solution Status : Target value achieved
Known unconstrained objective minimum : 837.966
Best Known constrained objective minimum : 731.707
Achieved objective value : 731.706
Comparison between known and achieved optima.
x_target_u x_target_c xb
1 420.97 394.15 394.15
2 420.97 433.48 433.49
Comparison between scaled constraint violations.
c_target_u c_target_c cb
1 0.00000 0.00000 0.00000
2 0.04219 0.00000 0.00000
3 0.75749 0.00000 0.00000
Open in the MATLAB editor:
e05sb_example
function e05sb_example
npar = int64(20);
bl = [500; 500; 1e6; 1; 0.9];
bu = [ 500; 500; 10; 5e5; 0.9];
x_target_u = [420.9687463599820; 420.9687463599820];
x_target_c = [394.1470221120988; 433.48214189947606];
f_target_u = 837.9657745448674;
f_target_c = 731.70709230672696;
c_target_u = [0; 31644.05623568455; 0.07574889943398055];
c_target_c = [0; 0; 0];
xbest = zeros(2, 20);
fbest = zeros(20, 1);
cbest = zeros(3, 20);;
iopts = zeros(100, 1, 'int64');
opts = zeros(100, 1);
[iopts, opts, ifail] = e05zk('Initialize = e05sb', iopts, opts);
fprintf('\nDefault Option Queries:\n\n');
[ivalue, rvalue, cvalue, optype, ifail] = ...
e05zl('Constraint Norm', iopts, opts);
fprintf('Constraint Norm : %s\n', cvalue);
[ivalue, rvalue, cvalue, optype, ifail] = ...
e05zl('Maximum Iterations Completed', iopts, opts);
fprintf('Maximum Iterations Completed : %d (%s)\n', ivalue, strtrim(cvalue));
[ivalue, rvalue, cvalue, optype, ifail] = ...
e05zl('Distance Tolerance', iopts, opts);
fprintf('Distance Tolerance : %15.4e\n', rvalue);
fprintf('\n1. Solution without using coupled local minimizer.\n');
[iopts, opts, ifail] = e05zk('Repeatability = On', iopts, opts);
opstr = sprintf('Distance Tolerance = %32.16e', rvalue*0.1);
[iopts, opts, ifail] = e05zk(opstr, iopts, opts);
[iopts, opts, ifail] = e05zk('Constraint Tolerance = 1.0e4', iopts, opts);
[iopts, opts, ifail] = e05zk('Constraint Norm = Euclidean', iopts, opts);
opstr = sprintf('Target Objective Value = %32.16e', f_target_c);
[iopts, opts, ifail] = e05zk(opstr, iopts, opts);
[iopts, opts, ifail] = e05zk('Target Objective Tolerance = 1.0e4', iopts, opts);
[xb, fb, cb, xbest, fbest, cbest, iopts, opts, user, itt, inform, ifail] = ...
e05sb(bl, bu, xbest, fbest, cbest, @objfun, @confun, ...
'e05sym', iopts, opts);
switch ifail
case {0,1}
display_result(x_target_u, x_target_c, f_target_u, f_target_c, ...
c_target_u, c_target_c, xb, fb, cb, itt, inform);
case 3
display_result(x_target_u, x_target_c, f_target_u, f_target_c, ...
c_target_u, c_target_c, xb, fb, cb, itt, inform);
otherwise
end
fprintf('\n2. Solution using coupled local minimizer e04uc.\n');
[iopts, opts, ifail] = e05zk('Local Minimizer = e04uc', iopts, opts);
[iopts, opts, ifail] = e05zk('Local Interior Major Iterations = 5', iopts, opts);
[iopts, opts, ifail] = e05zk('Local Interior Minor Iterations = 3', iopts, opts);
[iopts, opts, ifail] = e05zk('Local Exterior Major Iterations = 30', iopts, opts);
[iopts, opts, ifail] = e05zk('Local Exterior Minor Iterations = 15', iopts, opts);
[ivalue, rvalue, cvalue, optype, ifail] = ...
e05zl('Distance Tolerance', iopts, opts);
opstr = sprintf('Distance Tolerance = %32.16e', rvalue*10);
[iopts, opts, ifail] = e05zk(opstr, iopts, opts);
opstr = sprintf('Local Interior Tolerance = %32.16e', rvalue);
[iopts, opts, ifail] = e05zk(opstr, iopts, opts);
opstr = sprintf('Local exterior Tolerance = %32.16e', rvalue*1e4);
[iopts, opts, ifail] = e05zk(opstr, iopts, opts);
[xb, fb, cb, xbest, fbest, cbest, iopts, opts, user, itt, inform, ifail] = ...
e05sb(bl, bu, xbest, fbest, cbest, @objfun, @confun, ...
'e05sym', iopts, opts);
switch ifail
case {0,1}
display_result(x_target_u, x_target_c, f_target_u, f_target_c, ...
c_target_u, c_target_c, xb, fb, cb, itt, inform);
case 3
display_result(x_target_u, x_target_c, f_target_u, f_target_c, ...
c_target_u, c_target_c, xb, fb, cb, itt, inform);
otherwise
end
function [mode, c, cjac, user] = confun(mode, ncon, ndim, ldcj, needc, x, cjac, nstate, user)
c = zeros(ncon, 1);
if (nstate == 1)
cjac(1, 1) = 3;
cjac(1, 2) = 2;
end
if mode==0  mode==2
for k = 1:double(ncon)
if (needc(k)>0)
switch k
case (1)
c(k) = 3.0*x(1)  2.0*x(2);
case (2)
c(k) = x(1)^2  x(2)^2 + 3.0*x(1)*x(2);
case (3)
c(k) = cos((x(1)/200.0)^2+(x(2)/100.0));
otherwise
c(k) = 0;
end
end
end
end
if mode==1  mode==2
for k = 1:double(ncon)
switch k
case (1)
case (2)
cjac(k,1) = 2.0*x(1) + 3*x(2);
cjac(k,2) = 2.0*x(2) + 3*x(1);
otherwise
end
end
end
function [mode, objf, vecout, user] = objfun(mode, ndim, x, objf, vecout, nstate, user)
switch nstate
case (2)
case (1)
case (0)
otherwise
mode = int64(1);
error('*** Error detected in objfun');
end
evalobjf = false;
evalobjg = false;
switch mode
case {0,5}
evalobjf = true;
case {1,6}
evalobjg = true;
case {2,7}
evalobjf = true;
evalobjg = true;
otherwise
mode = int64(1);
error('*** Illegal value of mode (%d) in objfun', mode);
end
if evalobjf
objf = sum(x(1:double(ndim)).*sin(sqrt(abs(x(1:double(ndim))))));
end
if evalobjg
vecout = sqrt(abs(x));
for i=1:double(ndim)
vecout(i) = sin(vecout(i)) + 0.5*vecout(i)*cos(vecout(i));
end
end
function [] = display_result(x_target_u, x_target_c, f_target_u, ...
f_target_c, c_target_u, c_target_c, ...
xb, fb, cb, itt, inform)
fprintf('\nAlgorithm Statistics\n\n');
fprintf('Total complete iterations : %d\n', itt(1));
fprintf('Complete iterations since improvement : %d\n', itt(2));
fprintf('Total particles converged to xb : %d\n', itt(3));
fprintf('Total improvements to global optimum : %d\n', itt(4));
fprintf('Total function evaluations : %d\n', itt(5));
fprintf('Total particles reinitialized : %d\n', itt(6));
fprintf('Total constraints violated : %d\n\n', itt(7));
switch inform
case 0
fprintf('Solution Status : An error was detected by e05sa\n');
case 1
fprintf('Solution Status : Target value achieved\n');
case 2
fprintf('Solution Status : Minimum swarm standard deviation obtained\n');
case 3
fprintf('Solution Status : Sufficient particles converged\n');
case 4
fprintf('Solution Status : No improvement in preset iteration limit\n');
case 5
fprintf('Solution Status : Maximum complete iterations attained\n');
case 6
fprintf('Solution Status : Maximum function evaluations exceeded\n');
case 7
fprintf('Solution Status : Constrained point located\n');
otherwise
fprintf('User termination case: %d\n', inform);
end
fprintf('\n Known unconstrained objective minimum : %9.3f\n', f_target_u);
fprintf(' Best Known constrained objective minimum : %9.3f\n', f_target_c);
fprintf(' Achieved objective value : %9.3f\n\n', fb);
title = 'Comparison between known and achieved optima.';
clabs = {'x_target_u'; 'x_target_c'; 'xb '};
[ifail] = x04cb('G', 'N', [x_target_u, x_target_c, xb], 'f11.2', title, ...
'I', clabs, 'C', clabs, int64(80), int64(0));
fprintf('\n');
title = 'Comparison between scaled constraint violations.';
clabs = {'c_target_u'; 'c_target_c'; 'cb '};
c_scale = [2490; 750000; 0.1];
c_arr = [c_target_u./c_scale, c_target_c./c_scale, cb./c_scale];
[ifail] = x04cb('G', 'N', c_arr, 'f11.5', title, ...
'I', clabs, 'C', clabs, int64(80), int64(0));
fprintf('\n');
Default Option Queries:
Constraint Norm : L1
Maximum Iterations Completed : 1000 (DEFAULT)
Distance Tolerance : 1.0000e04
1. Solution without using coupled local minimizer.
Algorithm Statistics

Total complete iterations : 277
Complete iterations since improvement : 1
Total particles converged to xb : 0
Total improvements to global optimum : 117
Total function evaluations : 4222
Total particles reinitialized : 0
Total constraints violated : 0
Solution Status : Target value achieved
Known unconstrained objective minimum : 837.966
Best Known constrained objective minimum : 731.707
Achieved objective value : 731.708
Comparison between known and achieved optima.
x_target_u x_target_c xb
1 420.97 394.15 394.17
2 420.97 433.48 433.53
Comparison between scaled constraint violations.
c_target_u c_target_c cb
1 0.00000 0.00000 0.00000
2 0.04219 0.00000 0.00000
3 0.75749 0.00000 0.00002
2. Solution using coupled local minimizer e04uc.
Algorithm Statistics

Total complete iterations : 4
Complete iterations since improvement : 1
Total particles converged to xb : 0
Total improvements to global optimum : 7
Total function evaluations : 151
Total particles reinitialized : 0
Total constraints violated : 0
Solution Status : Target value achieved
Known unconstrained objective minimum : 837.966
Best Known constrained objective minimum : 731.707
Achieved objective value : 731.706
Comparison between known and achieved optima.
x_target_u x_target_c xb
1 420.97 394.15 394.15
2 420.97 433.48 433.49
Comparison between scaled constraint violations.
c_target_u c_target_c cb
1 0.00000 0.00000 0.00000
2 0.04219 0.00000 0.00000
3 0.75749 0.00000 0.00000
Algorithmic Details
The following pseudocode describes the algorithm used with the repulsion mechanism.
vj
=
R
∈
U( − Vmax,Vmax)
end for
x̃
=
(1/2)
(ℓbox + ubox)
f̃
=
F
(x̃)
ẽ
=
e
(x̃)
Ic
=
Is
=
0
SWARM
while (not finalized),
Ic
=
Ic
+
1
for
j
=
1
,
np
xj
=
BOUNDARY(xj,ℓbox,ubox)
fj
=
F
(xj)
ej
=
e
(xj)
if
(fj / fscale + φ(wj)‖ej‖ < f̂j / fscale + φ(wj)‖êj‖)
f̂j
=
fj
,
x̂j
=
xj
if
((‖ej‖ < ‖ẽ‖) or (‖ej‖ ≈ ‖ẽ‖ and fj < f̃))
f̃
=
fj
,
x̃
=
xj
end for
if
(new(f̃))
LOCMIN(x̃,f̃,ẽ,Oi)
,
Is = 0
[see note on repulsion below for code insertion]
else
Is
=
Is
+
1
for
j
=
1
,
np
vj
=
wj
vj
+
Cs
D1
(x̂j − xj)
+
Cg
D2
(x̃ − xj)
xj
=
xj
+
vj
if
(‖xj − x̃‖ < dtol)
reset
xj,
vj,
wj;
x̂j
=
xj
else
update (wj)
end for
if (target achieved or termination criterion satisfied)
finalized = true
monmod
(xj)
end
LOCMIN(x̃,f̃,ẽ,Oe)
$$\begin{array}{ll}\text{INITIALIZE}& \text{for}j=1\text{,}{n}_{p}\\ & \phantom{\rule{2em}{0ex}}{\mathbf{x}}_{j}=\mathbf{R}\in U({\mathbf{\ell}}_{\mathrm{box}},{\mathbf{u}}_{\mathrm{box}})\\ & \phantom{\rule{2em}{0ex}}{\hat{\mathbf{x}}}_{j}=\{\begin{array}{ll}\mathbf{R}\in U({\mathbf{\ell}}_{\mathrm{box}},{\mathbf{u}}_{\mathrm{box}})& {\mathbf{Start}}=\mathrm{COLD}\\ {\hat{\mathbf{x}}}_{j}^{0}& {\mathbf{Start}}=\mathrm{WARM}\end{array}\\ & \phantom{\rule{2em}{0ex}}{\mathbf{v}}_{j}=\mathbf{R}\in U({\mathbf{V}}_{\mathrm{max}},{\mathbf{V}}_{\mathrm{max}})\\ & \phantom{\rule{2em}{0ex}}{\hat{f}}_{j}=\{\begin{array}{ll}F\left({\hat{\mathbf{x}}}_{j}\right)& {\mathbf{Start}}=\mathrm{COLD}\\ {\hat{f}}_{j}^{0}& {\mathbf{Start}}=\mathrm{WARM}\end{array}\\ & \phantom{\rule{2em}{0ex}}{\hat{\mathbf{e}}}_{j}=\{\begin{array}{ll}\mathbf{e}\left({\hat{\mathbf{x}}}_{j}\right)& {\mathbf{Start}}=\mathrm{COLD}\\ {\hat{\mathbf{e}}}_{j}^{0}& {\mathbf{Start}}=\mathrm{WARM}\end{array}\\ & \phantom{\rule{2em}{0ex}}{w}_{j}=\{\begin{array}{ll}{W}_{\mathrm{max}}& {\mathbf{Weight\; Initialize}}=\mathrm{MAXIMUM}\\ {W}_{\mathrm{ini}}& {\mathbf{Weight\; Initialize}}=\mathrm{INITIAL}\\ R\in U({W}_{\mathrm{min}},{W}_{\mathrm{max}})& {\mathbf{Weight\; Initialize}}=\mathrm{RANDOMIZED}\end{array}\\ & \text{end for}\\ & \stackrel{~}{\mathbf{x}}=\frac{1}{2}({\mathbf{\ell}}_{\mathrm{box}}+{\mathbf{u}}_{\mathrm{box}})\\ & \stackrel{~}{f}=F\left(\stackrel{~}{\mathbf{x}}\right)\\ & \stackrel{~}{\mathbf{e}}=\mathbf{e}\left(\stackrel{~}{\mathbf{x}}\right)\\ & {I}_{c}={I}_{s}=0\\ \\ \text{SWARM}& \text{while (not finalized),}\\ & \phantom{\rule{2em}{0ex}}{I}_{c}={I}_{c}+1\\ & \phantom{\rule{2em}{0ex}}\text{for}j=1,{n}_{p}\\ & \phantom{\rule{4em}{0ex}}{\mathbf{x}}_{j}=\mathrm{BOUNDARY}({\mathbf{x}}_{j},{\mathbf{\ell}}_{\mathrm{box}},{\mathbf{u}}_{\mathrm{box}})\\ & \phantom{\rule{4em}{0ex}}{f}_{j}=F\left({\mathbf{x}}_{j}\right)\\ & \phantom{\rule{4em}{0ex}}{\mathbf{e}}_{j}=\mathbf{e}\left({\mathbf{x}}_{j}\right)\\ & \phantom{\rule{4em}{0ex}}\text{if}({f}_{j}/{f}_{\mathrm{scale}}+\varphi \left({w}_{j}\right)\Vert {\mathbf{e}}_{j}\Vert <{\hat{f}}_{j}/{f}_{\mathrm{scale}}+\varphi \left({w}_{j}\right)\Vert {\hat{\mathbf{e}}}_{j}\Vert )\\ & \phantom{\rule{6em}{0ex}}{\hat{f}}_{j}={f}_{j}\text{,}{\hat{\mathbf{x}}}_{j}={\mathbf{x}}_{j}\\ & \phantom{\rule{4em}{0ex}}\text{if}\left((\Vert {\mathbf{e}}_{j}\Vert <\Vert \stackrel{~}{\mathbf{e}}\Vert )\text{ or}(\Vert {\mathbf{e}}_{j}\Vert \approx \Vert \stackrel{~}{\mathbf{e}}\Vert \text{ and}{f}_{j}<\stackrel{~}{f})\right)\\ & \phantom{\rule{6em}{0ex}}\stackrel{~}{f}={f}_{j}\text{,}\stackrel{~}{\mathbf{x}}={\mathbf{x}}_{j}\\ & \phantom{\rule{2em}{0ex}}\text{end for}\\ & \phantom{\rule{2em}{0ex}}\text{if}\left(\mathrm{new}\left(\stackrel{~}{f}\right)\right)\\ & \phantom{\rule{4em}{0ex}}\mathrm{LOCMIN}(\stackrel{~}{\mathbf{x}},\stackrel{~}{f},\stackrel{~}{\mathbf{e}},{O}_{i})\text{,}{I}_{s}=0\\ & \phantom{\rule{2em}{0ex}}\text{[see note on repulsion below for code insertion]}\\ & \phantom{\rule{2em}{0ex}}\text{else}\\ & \phantom{\rule{4em}{0ex}}{I}_{s}={I}_{s}+1\\ & \phantom{\rule{2em}{0ex}}\text{for}j=1,{n}_{p}\\ & \phantom{\rule{4em}{0ex}}{\mathbf{v}}_{j}={w}_{j}{\mathbf{v}}_{j}+{C}_{s}{\mathbf{D}}_{1}({\hat{\mathbf{x}}}_{j}{\mathbf{x}}_{j})+{C}_{g}{\mathbf{D}}_{2}(\stackrel{~}{\mathbf{x}}{\mathbf{x}}_{j})\\ & \phantom{\rule{4em}{0ex}}{\mathbf{x}}_{j}={\mathbf{x}}_{j}+{\mathbf{v}}_{j}\\ & \phantom{\rule{4em}{0ex}}\text{if}(\Vert {\mathbf{x}}_{j}\stackrel{~}{\mathbf{x}}\Vert <\mathit{dtol})\\ & \phantom{\rule{6em}{0ex}}\text{reset}{\mathbf{x}}_{j}\text{,}{\mathbf{v}}_{j}\text{,}{w}_{j}\text{;}{\hat{\mathbf{x}}}_{j}={\mathbf{x}}_{j}\\ & \phantom{\rule{4em}{0ex}}\text{else}\\ & \phantom{\rule{6em}{0ex}}\text{update}\left({w}_{j}\right)\\ & \phantom{\rule{2em}{0ex}}\text{end for}\\ & \phantom{\rule{2em}{0ex}}\text{if (target achieved or termination criterion satisfied)}\\ & \phantom{\rule{4em}{0ex}}\text{finalized}=\text{true}\\ & \phantom{\rule{2em}{0ex}}{\mathbf{monmod}}\left({\mathbf{x}}_{j}\right)\\ & \text{end}\\ & \mathrm{LOCMIN}(\stackrel{~}{\mathbf{x}},\stackrel{~}{f},\stackrel{~}{\mathbf{e}},{O}_{e})\end{array}$$
The definition of terms used in the above pseudocode are as follows.
n_{p}${n}_{p}$ 
the number of particles, npar 
ℓ_{box}${\mathbf{\ell}}_{\mathrm{box}}$ 
array of ndim lower box bounds 
u_{box}${\mathbf{u}}_{\mathrm{box}}$ 
array of ndim upper box bounds 
x_{j}${\mathbf{x}}_{j}$ 
position of particle j$j$ 
x̂_{j}${\hat{\mathbf{x}}}_{j}$ 
best position found by particle j$j$ 
x̃$\stackrel{~}{\mathbf{x}}$ 
best position found by any particle 
f_{j}${f}_{j}$ 
F(x_{j})$F\left({\mathbf{x}}_{j}\right)$ 
f̂_{j}${\hat{f}}_{j}$ 
F(x̂_{j})$F\left({\hat{\mathbf{x}}}_{j}\right)$, best value found by particle j$j$ 
f̃$\stackrel{~}{f}$ 
F(x̃)$F\left(\stackrel{~}{\mathbf{x}}\right)$, best value found by any particle 
e_{k}(x)${e}_{k}\left(\mathbf{x}\right)$ 
k$k$th (scaled) constraint violation at x$\mathbf{x}$, evaluated as min (c_{k}(x) − l_{ndim + k},0.0) + max (c_{k}(x) − u_{ndim + k},0.0)$\mathrm{min}\phantom{\rule{0.125em}{0ex}}({c}_{k}\left(\mathbf{x}\right){l}_{{\mathbf{ndim}}+k},0.0)+\mathrm{max}\phantom{\rule{0.125em}{0ex}}({c}_{k}\left(\mathbf{x}\right){u}_{{\mathbf{ndim}}+k},0.0)$; this may be scaled by the maximum k$k$th constraint found thus far 
e(x)$\mathbf{e}\left(\mathbf{x}\right)$ 
the array of ncon constraint violations, e_{k}(x)${e}_{\mathit{k}}\left(\mathbf{x}\right)$, for k = 1,2, … ,ncon$\mathit{k}=1,2,\dots ,{\mathbf{ncon}}$, at a point x$\mathbf{x}$ 
e_{j}${\mathbf{e}}_{j}$ 
e(x_{j})$\mathbf{e}\left({\mathbf{x}}_{j}\right)$, the array of constraint violations evaluated at x_{j}${\mathbf{x}}_{j}$ 
ê_{j}${\hat{\mathbf{e}}}_{j}$ 
e(x̂_{j})$\mathbf{e}\left({\hat{\mathbf{x}}}_{j}\right)$, the array of constraint violations evaluated at x̂_{j}${\hat{\mathbf{x}}}_{j}$ 
ẽ$\stackrel{~}{\mathbf{e}}$ 
e(x̃)$\mathbf{e}\left(\stackrel{~}{\mathbf{x}}\right)$, the array of constraint violations evaluated at x̃$\stackrel{~}{\mathbf{x}}$ 
v_{j}${\mathbf{v}}_{j}$ 
velocity of particle j$j$ 
w_{j}${w}_{j}$ 
weight on v_{j}${\mathbf{v}}_{j}$ for velocity update, decreasing according to Weight Decrease 
V_{max}${\mathbf{V}}_{\mathrm{max}}$ 
maximum absolute velocity, dependent upon Maximum Variable Velocity 
I_{c}${I}_{c}$ 
swarm iteration counter 
I_{s}${I}_{s}$ 
iterations since x̃$\stackrel{~}{\mathbf{x}}$ was updated 
f_{scale}${f}_{\mathrm{scale}}$ 
objective function scaling defined by the options Constraint Scaling, Objective Scaling and Objective Scale. 
D_{1}${\mathbf{D}}_{1}$,D_{2}${\mathbf{D}}_{2}$ 
diagonal matrices with random elements in range (0,1)$(0,1)$ 
C_{s}${C}_{s}$ 
the cognitive advance coefficient which weights velocity towards x̂_{j}${\hat{\mathbf{x}}}_{j}$, adjusted using Advance Cognitive 
C_{g}${C}_{g}$ 
the global advance coefficient which weights velocity towards x̃$\stackrel{~}{\mathbf{x}}$, adjusted using Advance Global 
dtol$\mathit{dtol}$ 
the Distance Tolerance for resetting a converged particle 
R ∈ U(ℓ_{box},u_{box})$\mathbf{R}\in U({\mathbf{\ell}}_{\mathrm{box}},{\mathbf{u}}_{\mathrm{box}})$ 
an array of random numbers whose i$i$th element is drawn from a uniform distribution in the range (ℓ_{box}_{i},u_{box}_{i})$({{\mathbf{\ell}}_{\mathrm{box}}}_{\mathit{i}},{{\mathbf{u}}_{\mathrm{box}}}_{\mathit{i}})$, for i = 1,2, … ,ndim$\mathit{i}=1,2,\dots ,{\mathbf{ndim}}$ 
O_{i}${O}_{i}$ 
local optimizer interior options 
O_{e}${O}_{e}$ 
local optimizer exterior options 
φ(w_{j})$\varphi \left({w}_{j}\right)$ 
a function of w_{j}${w}_{j}$ designed to increasingly weight towards minimizing constraint violations as w_{j}${w}_{j}$ decreases 
LOCMIN(x,f,e,O)$\mathrm{LOCMIN}(\mathbf{x},f,\mathbf{e},O)$ 
apply local optimizer using the set of options O$O$ using the solution (x,f,e)$(\mathbf{x},f,\mathbf{e})$ as the starting point, if used (not default) 
monmod 
monitor progress and possibly modify x_{j}${\mathbf{x}}_{j}$ 
BOUNDARY 
apply required behaviour for x_{j}${\mathbf{x}}_{j}$ outside bounding box, (see Boundary) 
new (f̃$\stackrel{~}{f}$) 
true if x̃$\stackrel{~}{\mathbf{x}}$, c̃$\stackrel{~}{\mathbf{c}}$, f̃$\stackrel{~}{f}$ were updated at this iteration 
Additionally a repulsion phase can be introduced by changing from the default values of options
Repulsion Finalize (
r_{f}${r}_{f}$),
Repulsion Initialize (
r_{i}${r}_{i}$) and
Repulsion Particles (
r_{p}${r}_{p}$). If the number of static particles is denoted
n_{s}${n}_{s}$ then the following can be inserted after the new(
f̃$\stackrel{~}{f}$) check in the pseudocode above.
Optional Parameters
This section can be skipped if you wish to use the default values for all optional parameters, otherwise, the following is a list of the optional parameters available and a full description of each optional parameter is provided in
Section [Description of the optional parameters].
Description of the Optional Parameters
For each option, we give a summary line, a description of the optional parameter and details of constraints.
The summary line contains:
 the keywords;
 a parameter value,
where the letters a$a$, i and r$i\text{ and}r$ denote options that take character, integer and real values respectively;
 the default value, where the symbol ε$\epsilon $ is a generic notation for machine precision (see nag_machine_precision (x02aj)), and Imax$\mathit{Imax}$ represents the largest representable integer value (see nag_machine_integer_max (x02bb)).
All options accept the value ‘DEFAULT’ in order to return single options to their default states.
Keywords and character values are case insensitive, however they must be separated by at least one space.
For
nag_glopt_nlp_pso (e05sb) the maximum length of the parameter
cvalue used by
nag_glopt_optget (e05zl) is
15$15$.
Advance Cognitive r$r$Default = 2.0$\text{}=2.0$The cognitive advance coefficient, C_{s}${C}_{s}$. When larger than the global advance coefficient, this will cause particles to be attracted toward their previous best positions. Setting r = 0.0$r=0.0$ will cause nag_glopt_nlp_pso (e05sb) to act predominantly as a local optimizer. Setting r > 2.0$r>2.0$ may cause the swarm to diverge, and is generally inadvisable. At least one of the global and cognitive coefficients must be nonzero.
Advance Global r$r$Default = 2.0$\text{}=2.0$The global advance coefficient, C_{g}${C}_{g}$. When larger than the cognitive coefficient this will encourage convergence toward the best solution yet found. Values r ∈ (0,1)$r\in (0,1)$ will inhibit particles overshooting the optimum. Values r ∈ [1,2)$r\in [1,2)$ cause particles to fly over the optimum some of the time. Larger values can prohibit convergence. Setting r = 0.0$r=0.0$ will remove any attraction to the current optimum, effectively generating a Monte–Carlo multistart optimization algorithm. At least one of the global and cognitive coefficients must be nonzero.
Boundary a$a$Default = FLOATING$\text{}=\text{FLOATING}$Determines the behaviour if particles leave the domain described by the box bounds. This only affects the general PSO algorithm, and will not pass down to any NAG local minimizers chosen.
This option is only effective in those dimensions for which
bl(i) ≠ bu(i)${\mathbf{bl}}\left(i\right)\ne {\mathbf{bu}}\left(i\right)$,
i = 1,2, … ,ndim$i=1,2,\dots ,{\mathbf{ndim}}$.
 IGNORE
 The box bounds are ignored. The objective function is still evaluated at the new particle position.
 RESET
 The particle is reinitialized inside the domain. x̂_{j}${\hat{\mathbf{x}}}_{j}$, f̂_{j}${\hat{f}}_{j}$ and ê_{j}${\hat{\mathbf{e}}}_{j}$ are not affected.
 FLOATING
 The particle position remains the same, however the objective function will not be evaluated at the next iteration. The particle will probably be advected back into the domain at the next advance due to attraction by the cognitive and global memory.
 HYPERSPHERICAL
 The box bounds are wrapped around an ndim$\mathit{ndim}$dimensional hypersphere. As such a particle leaving through a lower bound will immediately reenter through the corresponding upper bound and vice versa. The standard distance between particles is also modified accordingly.
 FIXED
 The particle rests on the boundary, with the corresponding dimensional velocity set to 0.0$0.0$.
Constraint Norm a$a$Default = L1$\text{}=\mathrm{L1}$Determines with respect to which norm the constraint residuals should be constructed. These are automatically scaled with respect to
ncon as stated. For the set of (scaled) violations
e$\mathbf{e}$, these may be,
 L1
 The L^{1}${L}^{1}$ norm will be used, ‖e‖_{1} = 1/(ncon)∑_{1}^{ncon}e_{k}${\Vert \mathbf{e}\Vert}_{1}=\frac{1}{{\mathbf{ncon}}}{\displaystyle \sum _{1}^{{\mathbf{ncon}}}}\left{e}_{k}\right$
 L2
 The L^{2}${L}^{2}$ norm will be used, ‖e‖_{2} = 1/(ncon)sqrt(∑_{1}^{ncon}e_{k}^{2})${\Vert \mathbf{e}\Vert}_{2}=\frac{1}{{\mathbf{ncon}}}\sqrt{{\displaystyle \sum _{1}^{{\mathbf{ncon}}}}{e}_{k}^{2}}$
 L2SQ
 The square of the L^{2}${L}^{2}$ norm will be used, ‖e‖_{22} = 1/(ncon)∑_{1}^{ncon}e_{k}^{2}${\Vert \mathbf{e}\Vert}_{{2}^{2}}=\frac{1}{{\mathbf{ncon}}}{\displaystyle \sum _{1}^{{\mathbf{ncon}}}}{e}_{k}^{2}$
 LMAX
 The L^{∞}${L}^{\infty}$ norm will be used, ‖e‖_{∞} = max_{0 < k ≤ ncon} (e_{k})${\Vert \mathbf{e}\Vert}_{\infty}={\displaystyle \underset{0<k\le {\mathbf{ncon}}}{\mathrm{max}}}\phantom{\rule{0.25em}{0ex}}\left(\left{e}_{k}\right\right)$
Constraint Scale Maximum r$r$Default = 1.0e6$\text{}=\text{1.0e6}$Internally, each constraint violation is scaled with respect to the maximum violation yet achieved for that constraint. This option acts as a ceiling for this scale.
Constraint:
r > 1.0$r>1.0$.
Constraint Scaling a$a$Default = INITIAL$\text{}=\mathrm{INITIAL}$Determines whether to scale the constraints and objective function when constructing the penalty function.
 OFF
 Neither the constraint violations nor the objective will be scaled automatically. This should only be used if the constraints and objective are similarly scaled everywhere throughout the domain.
 INITIAL
 The maximum of the initial cognitive memories, f̂_{j}${\hat{f}}_{j}$ and ê_{j}${\hat{\mathbf{e}}}_{j}$, will be used to scale the objective function and constraint violations respectively.
 ADAPTIVE
 Initially, the maximum of the initial cognitive memories, f̂_{j}${\hat{f}}_{j}$ and ê_{j}${\hat{\mathbf{e}}}_{j}$, will be used to scale the objective function and constraint violations respectively. If a significant change is detected in the behaviour of the constraints or the objective, these will be rescaled with respect to the current state of the cognitive memory.
Constraint Superiority r$r$Default = 0.01$\text{}=0.01$The minimum scaled improvement in the constraint violation for a location to be immediately superior to that in memory, regardless of the objective value.
Constraint:
r > 0.0$r>0.0$.
Constraint Tolerance r$r$Default = 10^{4}$\text{}={10}^{4}$The maximum scaled violation of the constraints for which a sample particle is considered comparable to the current global optimum. Should this not be exceeded, then the current global optimum will be updated if the value of the objective function of the sample particle is superior.
Constraint Warning a$a$Default = ON$\text{}=\mathrm{ON}$Activates or deactivates the error exit associated with the inability to completely satisfy all constraints,
ifail = 4${\mathbf{ifail}}={\mathbf{4}}$. It is advisable to deactivate this option if
ifail = 0${\mathbf{ifail}}={\mathbf{0}}$ on entry and the satisfaction of all constraints is not program critical.
 OFF
 No error will be returned.
 ON
 An error will be returned if any constraints are sufficiently violated at the end of the simulation.
Distance Scaling a$a$Default = ON$\text{}=\mathrm{ON}$Determines whether distances should be scaled by box widths.
 ON
 When a distance is calculated between x$\mathbf{x}$ and y$\mathbf{y}$, a scaled L^{2}${L}^{2}$ norm is used.
 OFF
 Distances are calculated as the standard L^{2}${L}^{2}$ norm without any rescaling.
Distance Tolerance r$r$Default = 10^{4}$\text{}={10}^{4}$This is the distance, dtol$\mathit{dtol}$ between particles and the global optimum which must be reached for the particle to be considered converged, i.e., that any subsequent movement of such a particle cannot significantly alter the global optimum. Once achieved the particle is reset into the box bounds to continue searching.
Constraint:
r > 0.0$r>0.0$.
Function Precision r$r$Default = ε^{0.9}$\text{}={\epsilon}^{0.9}$The parameter defines ε_{r}${\epsilon}_{r}$, which is intended to be a measure of the accuracy with which the problem function F(x)$F\left(\mathbf{x}\right)$ can be computed. If r < ε$r<\epsilon $ or r ≥ 1$r\ge 1$, the default value is used.
The value of
ε_{r}${\epsilon}_{r}$ should reflect the relative precision of
1 + F(x)$1+\leftF\left(\mathbf{x}\right)\right$; i.e.,
ε_{r}${\epsilon}_{r}$ acts as a relative precision when
F$\leftF\right$ is large, and as an absolute precision when
F$\leftF\right$ is small. For example, if
F(x)$F\left(\mathbf{x}\right)$ is typically of order
1000$1000$ and the first six significant digits are known to be correct, an appropriate value for
ε_{r}${\epsilon}_{r}$ would be
10^{ − 6}${10}^{6}$. In contrast, if
F(x)$F\left(\mathbf{x}\right)$ is typically of order
10^{ − 4}${10}^{4}$ and the first six significant digits are known to be correct, an appropriate value for
ε_{r}${\epsilon}_{r}$ would be
10^{ − 10}${10}^{10}$. The choice of
ε_{r}${\epsilon}_{r}$ can be quite complicated for badly scaled problems; see Chapter 8 of
Gill et al. (1981) for a discussion of scaling techniques. The default value is appropriate for most simple functions that are computed with full accuracy. However when the accuracy of the computed function values is known to be significantly worse than full precision, the value of
ε_{r}${\epsilon}_{r}$ should be large enough so that no attempt will be made to distinguish between function values that differ by less than the error inherent in the calculation.
Local Boundary Restriction r$r$Default = 0.5$\text{}=0.5$Contracts the box boundaries used by a box constrained local minimizer to,
[β_{l},β_{u}]$[{\beta}_{l},{\beta}_{u}]$, containing the start point
x$x$, where
Smaller values of
r$r$ thereby restrict the size of the domain exposed to the local minimizer, possibly reducing the amount of work done by the local minimizer.
Constraint:
0.0 ≤ r ≤ 1.0$0.0\le r\le 1.0$.
Local Interior Iterations i_{1}${i}_{1}$Local Interior Major Iterations i_{1}${i}_{1}$Local Exterior Iterations i_{2}${i}_{2}$Local Exterior Major Iterations i_{2}${i}_{2}$The maximum number of iterations or function evaluations the chosen local minimizer will perform inside (outside) the main loop if applicable. For the NAG minimizers these correspond to:
Unless set, these are functions of the parameters passed to nag_glopt_nlp_pso (e05sb).
Setting
i = 0$i=0$ will disable the local minimizer in the corresponding algorithmic region. For example, setting
Local Interior Iterations = 0${\mathbf{Local\; Interior\; Iterations}}=0$ and
Local Exterior Iterations = 30${\mathbf{Local\; Exterior\; Iterations}}=30$ will cause the algorithm to perform no local minimizations inside the main loop of the algorithm, and a local minimization with upto
30$30$ iterations after the main loop has been exited.
Note: currently
nag_opt_bounds_quasi_func_easy (e04jy) or
nag_opt_bounds_mod_deriv_easy (e04kz) are restricted to using
400 × ndim$400\times {\mathbf{ndim}}$ and
50 × ndim$50\times {\mathbf{ndim}}$ as function evaluation limits respectively. This applies to both local minimizations inside and outside the main loop. They may still be deactivated in either phase by setting
i = 0$i=0$, and may subsequently be reactivated in either phase by setting
i > 0$i>0$.
Constraint:
i_{1} ≥ 0${i}_{1}\ge 0$, i_{2} ≥ 0${i}_{2}\ge 0$.
Local Interior Tolerance r_{1}${r}_{1}$Default = 10^{4}$\text{}={10}^{4}$Local Exterior Tolerance r_{2}${r}_{2}$Default = 10^{4}$\text{}={10}^{4}$This is the tolerance provided to a local minimizer in the interior (exterior) of the main loop of the algorithm.
Constraint:
r_{1} > 0.0${r}_{1}>0.0$, r_{2} > 0.0${r}_{2}>0.0$.
Local Interior Minor Iterations i_{1}${i}_{1}$Local Exterior Minor Iterations i_{2}${i}_{2}$Where applicable, the secondary number of iterations the chosen local minimizer will use inside (outside) the main loop. Currently the relevant default values are:
Minimizer 
Parameter/option 
Default Interior 
Default Exterior 
nag_opt_nlp1_solve (e04uc) 
Minor Iteration Limit 
max (10,2 × ndim)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}(10,2\times {\mathbf{ndim}})$ 
max (30,3 × ndim)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}(30,3\times {\mathbf{ndim}})$ 
Constraint:
i_{1} ≥ 0${i}_{1}\ge 0$, i_{2} ≥ 0${i}_{2}\ge 0$.
Local Minimizer a$a$Default = OFF$\text{}=\mathrm{OFF}$Allows for a choice of
Chapter E04 functions to be used as a coupled, dedicated local minimizer.
 OFF
 No local minimization will be performed in either the INTERIOR or EXTERIOR sections of the algorithm.
 nag_opt_uncon_simplex (e04cb)
 Use nag_opt_uncon_simplex (e04cb) as the local minimizer. This does not require the calculation of derivatives.
On a call to
objfun during a local minimization,
mode = 5${\mathbf{mode}}=5$.
 nag_opt_bounds_mod_deriv_easy (e04kz)
 Use nag_opt_bounds_mod_deriv_easy (e04kz) as the local minimizer. This requires the calculation of derivatives in objfun, as indicated by mode.
The box bounds forwarded to this function from
nag_glopt_nlp_pso (e05sb) will have been acted upon by
Local Boundary Restriction. As such, the domain exposed may be greatly smaller than that provided to
nag_glopt_nlp_pso (e05sb).
Accurate derivatives must be provided to this function, and will not be approximated internally. Each iteration of this local minimizer also requires the calculation of both the objective function and its derivative. Hence on a call to
objfun during a local minimization,
mode = 7${\mathbf{mode}}=7$.
 nag_opt_bounds_quasi_func_easy (e04jy)
 Use nag_opt_bounds_quasi_func_easy (e04jy) as the local minimizer. This does not require the calculation of derivatives.
On a call to
objfun during a local minimization,
mode = 5${\mathbf{mode}}=5$.
The box bounds forwarded to this function from
nag_glopt_nlp_pso (e05sb) will have been acted upon by
Local Boundary Restriction. As such, the domain exposed may be greatly smaller than that provided to
nag_glopt_nlp_pso (e05sb).
 nag_opt_uncon_conjgrd_comp (e04dg)
(e04dg)
 Use (e04dg) as the local minimizer.
Accurate derivatives must be provided, and will not be approximated internally. Additionally, each call to
objfun during a local minimization will require either the objective to be evaluated alone, or both the objective and its gradient to be evaluated. Hence on a call to
objfun,
mode = 5${\mathbf{mode}}=5$ or
7$7$.
 nag_opt_nlp1_solve (e04uc)
(e04uc)
 Use (e04uc) as the local minimizer.
This operates such that any derivatives of either the objective function or the constraint Jacobian, which you cannot supply, will be approximated internally using finite differences.
Either, the objective, objective gradient, or both may be requested during a local minimization, and as such on a call to
objfun,
mode = 1${\mathbf{mode}}=1$,
2$2$ or
5$5$.
The box bounds forwarded to this function from
nag_glopt_nlp_pso (e05sb) will have been acted upon by
Local Boundary Restriction. As such, the domain exposed may be greatly smaller than that provided to
nag_glopt_nlp_pso (e05sb).
Maximum Function Evaluations i$i$Default = Imax$=\mathit{Imax}$The maximum number of evaluations of the objective function. When reached this will return
ifail = 1${\mathbf{ifail}}={\mathbf{1}}$ and
inform = 6${\mathbf{inform}}=6$.
Constraint:
i > 0$i>0$.
Maximum Iterations Completed i$i$Default = 1000 × ndim$\text{}=1000\times {\mathbf{ndim}}$The maximum number of complete iterations that may be performed. Once exceeded
nag_glopt_nlp_pso (e05sb) will exit with
ifail = 1${\mathbf{ifail}}={\mathbf{1}}$ and
inform = 5${\mathbf{inform}}=5$.
Unless set, this adapts to the parameters passed to nag_glopt_nlp_pso (e05sb).
Constraint:
i ≥ 1$i\ge 1$.
Maximum Iterations Static i$i$Default = 100$\text{}=100$The maximum number of iterations without any improvement to the current global optimum. If exceeded
nag_glopt_nlp_pso (e05sb) will exit with
ifail = 1${\mathbf{ifail}}={\mathbf{1}}$ and
inform = 4${\mathbf{inform}}=4$. This exit will be hindered by setting
Maximum Iterations Static Particles to larger values.
Constraint:
i ≥ 1$i\ge 1$.
Maximum Iterations Static Particles i$i$Default = 0$\text{}=0$The minimum number of particles that must have converged to the current optimum before the function may exit due to
Maximum Iterations Static with
ifail = 1${\mathbf{ifail}}={\mathbf{1}}$ and
inform = 4${\mathbf{inform}}=4$.
Constraint:
i ≥ 0$i\ge 0$.
Maximum Particles Converged i$i$Default = Imax$=\mathit{Imax}$The maximum number of particles that may converge to the current optimum. When achieved,
nag_glopt_nlp_pso (e05sb) will exit with
ifail = 1${\mathbf{ifail}}={\mathbf{1}}$ and
inform = 3${\mathbf{inform}}=3$. This exit will be hindered by setting ‘
Repulsion’ options, as these cause the swarm to reexpand.
Constraint:
i > 0$i>0$.
Maximum Particles Reset i$i$Default = Imax$=\mathit{Imax}$The maximum number of particles that may be reset after converging to the current optimum. Once achieved no further particles will be reset, and any particles within
Distance Tolerance of the global optimum will continue to evolve as normal.
Constraint:
i > 0$i>0$.
Maximum Variable Velocity r$r$Default = 0.25$\text{}=0.25$Along any dimension j$j$, the absolute velocity is bounded above by v_{j} ≤ r × (u_{j} − ℓ_{j}) = V_{max}$\left{\mathbf{v}}_{j}\right\le r\times ({\mathbf{u}}_{j}{\mathbf{\ell}}_{j})={\mathbf{V}}_{\mathrm{max}}$. Very low values will greatly increase convergence time. There is no upper limit, although larger values will allow more particles to be advected out of the box bounds, and values greater than 4.0$4.0$ may cause significant and potentially unrecoverable swarm divergence.
Constraint:
r > 0.0$r>0.0$.
Objective Scale r$r$Default = 1.0$\text{}=1.0$The initial scale for the objective function. This will remain fixed if
Objective Scaling = USER${\mathbf{Objective\; Scaling}}=\mathrm{USER}$ is selected.
Objective Scaling a$a$Default = MAXIMUM$\text{}=\mathrm{MAXIMUM}$The method of (re)scaling applied to the objective function when the function detects a significant difference between the scale and the global and cognitive memory (
f̃$\stackrel{~}{f}$ and
f̂_{j}${\hat{f}}_{j}$). This only has an effect when
ncon > 0${\mathbf{ncon}}>0$ and
Constraint Scaling is active.
 MAXIMUM
 The objective is rescaled with respect to the maximum absolute value of the objective in the cognitive and global memory.
 MEAN
 The objective is rescaled with respect to the mean absolute value of the objective in the cognitive and global memory.
 USER
 The scale remains fixed at the value set using Objective Scale.
Optimize a$a$Default = MINIMIZE$\text{}=\mathrm{MINIMIZE}$Determines whether to maximize or minimize the objective function, or ignore the objective and search for a constrained point.
 MINIMIZE
 The objective function will be minimized.
 MAXIMIZE
 The objective function will be maximized. This is accomplished by minimizing the negative of the objective.
 CONSTRAINTS
 The objective function will be ignored, and the algorithm will attempt to find a feasible point given the provided constraints. The objective function will be evaluated at the best point found with regards to constraint violations, and the final positions returned in xbest. The objective will be calculated at the best point found in terms of constraints only. Should a constrained point be found, nag_glopt_nlp_pso (e05sb) will exit with ifail = 0${\mathbf{ifail}}={\mathbf{0}}$ and inform = 6${\mathbf{inform}}=6$.
Constraint:
if
Optimize = CONSTRAINTS${\mathbf{Optimize}}=\mathrm{CONSTRAINTS}$,
ncon > 0${\mathbf{ncon}}>0$ is required.
Repeatability a$a$Default = OFF$\text{}=\mathrm{OFF}$Allows for the same random number generator seed to be used for every call to
nag_glopt_nlp_pso (e05sb).
Repeatability = OFF${\mathbf{Repeatability}}=\mathrm{OFF}$ is recommended in general.
 OFF
 The internal generation of random numbers will be nonrepeatable.
 ON
 The same seed will be used.
Repulsion Finalize i$i$Default = Imax$=\mathit{Imax}$The number of iterations performed in a repulsive phase before recontraction. This allows a rediversified swarm to contract back toward the current optimum, allowing for a finer search of the near optimum space.
Constraint:
i ≥ 2$i\ge 2$.
Repulsion Initialize i$i$Default = Imax$=\mathit{Imax}$The number of iterations without any improvement to the global optimum before the algorithm begins a repulsive phase. This phase allows the particle swarm to reexpand away from the current optimum, allowing more of the domain to be investigated. The repulsive phase is automatically ended if a superior optimum is found.
Constraint:
i ≥ 2$i\ge 2$.
Repulsion Particles i$i$Default = 0$\text{}=0$The number of particles required to have converged to the current optimum before any repulsive phase may be initialized. This will prevent repulsion before a satisfactory search of the near optimum area has been performed, which may happen for large dimensional problems.
Constraint:
i ≥ 0$i\ge 0$.
Start a$a$Default = COLD$\text{}=\mathrm{COLD}$Used to affect the initialization of the function.
 COLD
 The random number generators and all initialization data will be generated internally. The variables xbest, fbest and cbest need not be set.
 WARM
 You must supply the initial best location, function and constraint violation values xbest, fbest and cbest. This option is recommended if you already have a data set you wish to improve upon.
Swarm Standard Deviation r$r$Default = 0.1$\text{}=0.1$The target standard deviation of the particle distances from the current optimum. Once the standard deviation is below this level,
nag_glopt_nlp_pso (e05sb) will exit with
ifail = 1${\mathbf{ifail}}={\mathbf{1}}$ and
inform = 2${\mathbf{inform}}=2$. This criterion will be penalized by the use of ‘
Repulsion’ options, as these cause the swarm to reexpand, increasing the standard deviation of the particle distances from the best point.
In SMP parallel implementations of
nag_glopt_nlp_pso (e05sb), the standard deviation will be calculated based only on the particles local to the particular thread that checks for finalization. Considerably fewer particles may be used in this calculation than when the algorithm is run in serial. It is therefore recommended that you provide a smaller value of
Swarm Standard Deviation when running in parallel than when running in serial.
Constraint:
r ≥ 0.0$r\ge 0.0$.
Target Objective a$a$Default = OFF$\text{}=\mathrm{OFF}$Target Objective Value r$r$Default = 0.0$\text{}=0.0$Activate or deactivate the use of a target value as a finalization criterion. If active, then once the supplied target value for the objective function is found (beyond the first iteration if
Target Warning is active)
nag_glopt_nlp_pso (e05sb) will exit with
ifail = 0${\mathbf{ifail}}={\mathbf{0}}$ and
inform = 1${\mathbf{inform}}=1$. Other than checking for feasibility only (
Optimize = CONSTRAINTS${\mathbf{Optimize}}=\mathrm{CONSTRAINTS}$), this is the only finalization criterion that guarantees that the algorithm has been successful. If the target value was achieved at the initialization phase or first iteration and
Target Warning is active,
nag_glopt_nlp_pso (e05sb) will exit with
ifail = 2${\mathbf{ifail}}={\mathbf{2}}$. This option may take any real value
r$r$, or the character ON/OFF as well as DEFAULT. If this option is queried using
nag_glopt_optget (e05zl), the current value of
r$r$ will be returned in
rvalue, and
cvalue will indicate whether this option is ON or OFF. The behaviour of the option is as follows:
 r$r$
 Once a point is found with an objective value within the Target Objective Tolerance of r$r$, nag_glopt_nlp_pso (e05sb) will exit successfully with ifail = 0${\mathbf{ifail}}={\mathbf{0}}$ and inform = 1${\mathbf{inform}}=1$.
 OFF
 The current value of r$r$ will remain stored, however it will not be used as a finalization criterion.
 ON
 The current value of r$r$ stored will be used as a finalization criterion.
 DEFAULT
 The stored value of r$r$ will be reset to its default value (0.0$0.0$), and this finalization criterion will be deactivated.
Target Objective Safeguard r$r$Default = 10.0ε$\text{}=10.0\epsilon $If you have given a target objective value to reach in
objval$\mathit{objval}$ (the value of the optional parameter
Target Objective Value),
objsfg$\mathit{objsfg}$ sets your desired safeguarded termination tolerance, for when
objval$\mathit{objval}$ is close to zero.
Constraint:
objsfg ≥ 2ε$\mathit{objsfg}\ge 2\epsilon $.
Target Objective Tolerance r$r$Default = 0.0$\text{}=0.0$The optional tolerance to a userspecified target value.
Constraint:
r ≥ 0.0$r\ge 0.0$.
Target Warning a$a$Default = OFF$\text{}=\mathrm{OFF}$Activates or deactivates the error exit associated with the target value being achieved before entry into the main loop of the algorithm,
ifail = 2${\mathbf{ifail}}={\mathbf{2}}$.
 OFF
 No error will be returned, and the function will exit normally.
 ON
 An error will be returned if the target objective is reached prematurely, and the function will exit with ifail = 2${\mathbf{ifail}}={\mathbf{2}}$.
Verify Gradients a$a$Default = ON$\text{}=\mathrm{ON}$Adjusts the level of gradient checking performed when gradients are required. Gradient checks are only performed on the first call to the chosen local minimizer if it requires gradients. There is no guarantee that the gradient check will be correct, as the finite differences used in the gradient check are themselves subject to inaccuracies.
 OFF
 No gradient checking will be performed.
 ON
 A cheap gradient check will be performed on both the gradients corresponding to the objective through objfun and those provided via the constraint Jacobian through confun.
 OBJECTIVE
 A more expensive gradient check will be performed on the gradients corresponding to the objective objfun. The gradients of the constraints will not be checked.
 CONSTRAINTS
 A more expensive check will be performed on the elements of cjac provided via confun. The objective gradient will not be checked.
 FULL
 A more expensive check will be performed on both the gradient of the objective and the constraint Jacobian.
Weight Decrease a$a$Default = INTEREST$\text{}=\mathrm{INTEREST}$Determines how particle weights decrease.
 OFF
 Weights do not decrease.
 INTEREST
 Weights decrease through compound interest as w_{IT + 1} = w_{IT}(1 − W_{val})${w}_{\mathit{IT}+1}={w}_{\mathit{IT}}(1{W}_{\mathit{val}})$, where W_{val}${W}_{\mathit{val}}$ is the Weight Value and IT$\mathit{IT}$ is the current number of iterations.
 LINEAR
 Weights decrease linearly following w_{IT + 1} = w_{IT} − IT × (W_{max} − W_{min}) / IT_{max}${w}_{\mathit{IT}+1}={w}_{\mathit{IT}}\mathit{IT}\times ({W}_{\mathit{max}}{W}_{\mathit{min}})/{\mathit{IT}}_{\mathit{max}}$, where IT$\mathit{IT}$ is the iteration number and IT_{max}${\mathit{IT}}_{\mathit{max}}$ is the maximum number of iterations as set by Maximum Iterations Completed.
Weight Initial r$r$Default = W_{max}$\text{}={W}_{\mathit{max}}$The initial value of any particle's inertial weight,
W_{ini}${W}_{\mathit{ini}}$, or the minimum possible initial value if initial weights are randomized. When set, this will override
Weight Initialize = RANDOMIZED${\mathbf{Weight\; Initialize}}=\mathrm{RANDOMIZED}$ or
MAXIMUM$\mathrm{MAXIMUM}$, and as such these must be set afterwards if so desired.
Constraint:
W_{min} ≤ r ≤ W_{max}${W}_{\mathit{min}}\le r\le {W}_{\mathit{max}}$.
Weight Initialize a$a$Default = MAXIMUM$\text{}=\mathrm{MAXIMUM}$Determines how the initial weights are distributed.
 INITIAL
 All weights are initialized at the initial weight, W_{ini}${W}_{\mathit{ini}}$, if set. If Weight Initial has not been set, this will be the maximum weight, W_{max}${W}_{\mathit{max}}$.
 MAXIMUM
 All weights are initialized at the maximum weight, W_{max}${W}_{\mathit{max}}$.
 RANDOMIZED
 Weights are uniformly distributed in (W_{min},W_{max})$({W}_{\mathit{min}},{W}_{\mathit{max}})$ or (W_{ini},W_{max})$({W}_{\mathit{ini}},{W}_{\mathit{max}})$ if Weight Initial has been set.
Weight Maximum r$r$Default = 1.0$\text{}=1.0$The maximum particle weight, W_{max}${W}_{\mathit{max}}$.
Constraint:
1.0 ≥ r ≥ W_{min}$1.0\ge r\ge {W}_{\mathit{min}}$ (If W_{ini}${W}_{\mathit{ini}}$ has been set then 1.0 ≥ r ≥ W_{ini}$1.0\ge r\ge {W}_{\mathit{ini}}$.)
Weight Minimum r$r$Default = 0.1$\text{}=0.1$The minimum achievable weight of any particle, W_{min}${W}_{\mathit{min}}$. Once achieved, no further weight reduction is possible.
Constraint:
0.0 ≤ r ≤ W_{max}$0.0\le r\le {W}_{\mathit{max}}$ (If W_{ini}${W}_{\mathit{ini}}$ has been set then 0.0 ≤ r ≤ W_{ini}$0.0\le r\le {W}_{\mathit{ini}}$.)
Weight Reset a$a$Default = MAXIMUM$\text{}=\mathrm{MAXIMUM}$Determines how particle weights are reinitialized.
 INITIAL
 Weights are reinitialized at the initial weight if set. If Weight Initial has not been set, this will be the maximum weight.
 MAXIMUM
 Weights are reinitialized at the maximum weight.
 RANDOMIZED
 Weights are uniformly distributed in (W_{min},W_{max})$({W}_{\mathit{min}},{W}_{\mathit{max}})$ or (W_{ini},W_{max})$({W}_{\mathit{ini}},{W}_{\mathit{max}})$ if Weight Initial has been set.
Weight Value r$r$Default = 0.01$\text{}=0.01$The constant
W_{val}${W}_{\mathit{val}}$ used with
Weight Decrease = INTEREST${\mathbf{Weight\; Decrease}}=\mathrm{INTEREST}$.
Constraint:
0.0 ≤ r ≤ (1/3)$0.0\le r\le \frac{1}{3}$.
PDF version (NAG web site
, 64bit version, 64bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013