Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_mip_sqp (h02da)

## Purpose

nag_mip_sqp (h02da) solves general nonlinear programming problems with integer constraints on some of the variables.

## Syntax

[ax, x, c, cjac, objgrd, objmip, user, ifail] = h02da(ncnln, a, d, bl, bu, varcon, x, confun, objfun, iopts, opts, 'n', n, 'nclin', nclin, 'maxit', maxit, 'acc', acc, 'user', user)
[ax, x, c, cjac, objgrd, objmip, user, ifail] = nag_mip_sqp(ncnln, a, d, bl, bu, varcon, x, confun, objfun, iopts, opts, 'n', n, 'nclin', nclin, 'maxit', maxit, 'acc', acc, 'user', user)
Before calling nag_mip_sqp (h02da), nag_mip_optset (h02zk) must be called with optstr set to ‘’. Optional parameters may also be specified by calling nag_mip_optset (h02zk) before the call to nag_mip_sqp (h02da).

## Description

nag_mip_sqp (h02da) solves mixed integer nonlinear programming problems using a modified sequential quadratic programming method. The problem is assumed to be stated in the following general form:
 $minimize x∈ Rnc,Zni fx subject to cjx=0, j=1,2,…,me cjx≥0, j=me+1,me+2,…,m l≤xi≤u, i=1,2,…,n$
with ${n}_{c}$ continuous variables and ${n}_{i}$ binary and integer variables in a total of $n$ variables; ${m}_{e}$ equality constraints in a total of $m$ constraint functions.
Partial derivatives of $f\left(x\right)$ and $c\left(x\right)$ are not required for the ${n}_{i}$ integer variables. Gradients with respect to integer variables are approximated by difference formulae.
No assumptions are made regarding $f\left(x\right)$ except that it is twice continuously differentiable with respect to continuous elements of $x$. It is not assumed that integer variables are relaxable. In other words, problem functions are evaluated only at integer points.
The method seeks to minimize the exact penalty function:
 $Pσx = fx +σ gx ∞$
where $\sigma$ is adapted by the algorithm and $g\left(x\right)$ is given by:
 $gx = cjx, j=1,2,…,me = mincjx,0, j=me+1,me+2,…,m.$
Successive quadratic approximations are applied under the assumption that integer variables have a smooth influence on the model functions, that is function values do not change drastically when incrementing or decrementing an integer value. In practice this requires integer variables to be ordinal not categorical. The algorithm is stabilised by a trust region method including Yuan's second order corrections, see Yuan and Sun (2006). The Hessian of the Lagrangian function is approximated by BFGS (see The Quasi-Newton Update in nag_opt_nlp1_solve (e04uc)) updates subject to the continuous and integer variables.
The mixed-integer quadratic programming subproblems of the SQP-trust region method are solved by a branch and cut method with continuous subproblem solutions obtained by the primal-dual method of Goldfarb and Idnani, see Powell (1983). Different strategies are available for selecting a branching variable:
• Maximal fractional branching. Select an integer variable from the relaxed subproblem solution with largest distance from next integer value
• Minimal fractional branching. Select an integer variable from the relaxed subproblem solution with smallest distance from next integer value
and a node from where branching, that is the generation of two new subproblems, begins:
• Best of two. The optimal objective function values of the two child nodes are compared and the node with a lower value is chosen
• Best of all. Select an integer variable from the relaxed subproblem solution with the smallest distance from the next integer value
• Depth first. Select a child node whenever possible.
This implementation is based on the algorithm MISQP as described in Exler et al. (2013).
Linear constraints may optionally be supplied by a matrix $A$ and vector $d$ rather than the constraint functions $c\left(x\right)$ such that
 $Ax=d or ​ Ax≥d .$
Partial derivatives with respect to $x$ of these constraint functions are not requested by nag_mip_sqp (h02da).

## References

Exler O, Lehmann T and Schittkowski K (2013) A comparative study of SQP-type algorithms for nonlinear and nonconvex mixed-integer optimization Mathematical Programming Computation 4 383–412
Mann A (1986) GAMS/MINOS: Three examples Department of Operations Research Technical Report Stanford University
Powell M J D (1983) On the quadratic programming algorithm of Goldfarb and Idnani Report DAMTP 1983/Na 19 University of Cambridge, Cambridge
Yuan Y-x and Sun W (2006) Optimization Theory and Methods Springer–Verlag

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{ncnln}$int64int32nag_int scalar
${n}_{N}$, the number of constraints supplied by $c\left(x\right)$.
Constraint: ${\mathbf{ncnln}}\ge 0$.
2:     $\mathrm{a}\left(\mathit{lda},:\right)$ – double array
The first dimension of the array a must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{nclin}}\right)$.
The second dimension of the array a must be at least ${\mathbf{n}}$ if ${\mathbf{nclin}}>0$.
The $\mathit{i}$th row of a must contain the coefficients of the $\mathit{i}$th general linear constraint, for $\mathit{i}=1,2,\dots ,{n}_{l}$. Any equality constraints must be specified first.
If ${\mathbf{nclin}}=0$, the array a is not referenced.
3:     $\mathrm{d}\left({\mathbf{nclin}}\right)$ – double array
${d}_{i}$, the constant for the $i$th linear constraint.
If ${\mathbf{nclin}}=0$, the array d is not referenced.
4:     $\mathrm{bl}\left({\mathbf{n}}\right)$ – double array
5:     $\mathrm{bu}\left({\mathbf{n}}\right)$ – double array
${\mathbf{bl}}$ must contain the lower bounds, ${l}_{i}$, and ${\mathbf{bu}}$ the upper bounds, ${u}_{i}$, for the variables; bounds on integer variables are rounded, bounds on binary variables need not be supplied.
Constraint: ${\mathbf{bl}}\left(\mathit{i}\right)\le {\mathbf{bu}}\left(\mathit{i}\right)$, for $\mathit{i}=1,2,\dots ,{\mathbf{n}}$.
6:     $\mathrm{varcon}\left({\mathbf{n}}+{\mathbf{nclin}}+{\mathbf{ncnln}}\right)$int64int32nag_int array
varcon indicates the nature of each variable and constraint in the problem. The first $n$ elements of the array must describe the nature of the variables, the next ${n}_{L}$ elements the nature of the general linear constraints (if any) and the next ${n}_{N}$ elements the general constraints (if any).
${\mathbf{varcon}}\left(j\right)=0$
A continuous variable.
${\mathbf{varcon}}\left(j\right)=1$
A binary variable.
${\mathbf{varcon}}\left(j\right)=2$
An integer variable.
${\mathbf{varcon}}\left(j\right)=3$
An equality constraint.
${\mathbf{varcon}}\left(j\right)=4$
An inequality constraint.
Constraints:
• ${\mathbf{varcon}}\left(\mathit{j}\right)=0$, $1$ or $2$, for $\mathit{j}=1,2,\dots ,{\mathbf{n}}$;
• ${\mathbf{varcon}}\left(\mathit{j}\right)=3$ or $4$, for $\mathit{j}={\mathbf{n}}+1,\dots ,{\mathbf{n}}+{\mathbf{nclin}}+{\mathbf{ncnln}}$;
• At least one variable must be either binary or integer;
• Any equality constraints must precede any inequality constraints.
7:     $\mathrm{x}\left({\mathbf{n}}\right)$ – double array
An initial estimate of the solution, which need not be feasible. Values corresponding to integer variables are rounded; if an initial value less than half is supplied for a binary variable the value zero is used, otherwise the value one is used.
8:     $\mathrm{confun}$ – function handle or string containing name of m-file
confun must calculate the constraint functions supplied by $c\left(x\right)$ and their Jacobian at $x$. If all constraints are supplied by $A$ and $d$ (i.e., ${\mathbf{ncnln}}=0$), confun will never be called by nag_mip_sqp (h02da) and confun may be the string nag_mip_sqp_dummy_confun (h02ddm). (nag_mip_sqp_dummy_confun (h02ddm) is included in the NAG Toolbox.) If ${\mathbf{ncnln}}>0$, the first call to confun will occur after the first call to objfun.
[mode, c, cjac, user] = confun(mode, ncnln, n, varcon, x, cjac, nstate, user)

Input Parameters

1:     $\mathrm{mode}$int64int32nag_int scalar
Indicates which values must be assigned during each call of objfun. Only the following values need be assigned:
${\mathbf{mode}}=0$
Elements of c containing continuous variables.
${\mathbf{mode}}=1$
Elements of cjac containing continuous variables.
2:     $\mathrm{ncnln}$int64int32nag_int scalar
The dimension of the array c and the first dimension of the array cjac. the number of constraints supplied by $c\left(x\right)$, ${n}_{N}$.
3:     $\mathrm{n}$int64int32nag_int scalar
The second dimension of the array cjac. $n$, the total number of variables, ${n}_{c}+{n}_{i}$.
4:     $\mathrm{varcon}\left({\mathbf{n}}+\mathit{nclin}+{\mathbf{ncnln}}\right)$int64int32nag_int array
The array varcon as supplied to nag_mip_sqp (h02da).
5:     $\mathrm{x}\left({\mathbf{n}}\right)$ – double array
The vector of variables at which the objective function and/or all continuous elements of its gradient are to be evaluated.
6:     $\mathrm{cjac}\left({\mathbf{ncnln}},{\mathbf{n}}\right)$ – double array
Note: the derivative of the $i$th constraint with respect to the $j$th variable, $\frac{\partial {c}_{i}}{\partial {x}_{j}}$, is stored in ${\mathbf{cjac}}\left(i,j\right)$.
Continuous elements of cjac are set to the value of NaN.
7:     $\mathrm{nstate}$int64int32nag_int scalar
If ${\mathbf{nstate}}=1$, nag_mip_sqp (h02da) is calling confun for the first time. This argument setting allows you to save computation time if certain data must be read or calculated only once.
8:     $\mathrm{user}$ – Any MATLAB object
confun is called from nag_mip_sqp (h02da) with the object supplied to nag_mip_sqp (h02da).

Output Parameters

1:     $\mathrm{mode}$int64int32nag_int scalar
May be set to a negative value if you wish to terminate the solution to the current problem, and in this case nag_mip_sqp (h02da) will terminate with ifail set to mode.
2:     $\mathrm{c}\left(\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{ncnln}}\right)\right)$ – double array
Must contain ncnln constraint values, with the value of the $j$th constraint ${c}_{j}\left(x\right)$ in ${\mathbf{c}}\left(j\right)$.
3:     $\mathrm{cjac}\left({\mathbf{ncnln}},{\mathbf{n}}\right)$ – double array
Note: the derivative of the $i$th constraint with respect to the $j$th variable, $\frac{\partial {c}_{i}}{\partial {x}_{j}}$, is stored in ${\mathbf{cjac}}\left(i,j\right)$.
The $i$th row of cjac must contain elements of $\frac{\partial {c}_{i}}{\partial {x}_{j}}$ for each continuous variable ${x}_{j}$.
4:     $\mathrm{user}$ – Any MATLAB object
9:     $\mathrm{objfun}$ – function handle or string containing name of m-file
objfun must calculate the objective function $f\left(x\right)$ and its gradient for a specified $n$-element vector $x$.
[mode, objmip, objgrd, user] = objfun(mode, n, varcon, x, objgrd, nstate, user)

Input Parameters

1:     $\mathrm{mode}$int64int32nag_int scalar
Indicates which values must be assigned during each call of objfun. Only the following values need be assigned:
${\mathbf{mode}}=0$
The objective function value, objmip.
${\mathbf{mode}}=1$
The continuous elements of objgrd.
2:     $\mathrm{n}$int64int32nag_int scalar
$n$, the total number of variables, ${n}_{c}+{n}_{i}$.
3:     $\mathrm{varcon}\left({\mathbf{n}}+\mathit{nclin}+\mathit{ncnln}\right)$int64int32nag_int array
The array varcon as supplied to nag_mip_sqp (h02da).
4:     $\mathrm{x}\left({\mathbf{n}}\right)$ – double array
The vector of variables at which the objective function and/or all continuous elements of its gradient are to be evaluated.
5:     $\mathrm{objgrd}\left({\mathbf{n}}\right)$ – double array
Continuous elements of objgrd are set to the value of NaN.
6:     $\mathrm{nstate}$int64int32nag_int scalar
If ${\mathbf{nstate}}=1$, nag_mip_sqp (h02da) is calling objfun for the first time. This argument setting allows you to save computation time if certain data must be read or calculated only once.
7:     $\mathrm{user}$ – Any MATLAB object
objfun is called from nag_mip_sqp (h02da) with the object supplied to nag_mip_sqp (h02da).

Output Parameters

1:     $\mathrm{mode}$int64int32nag_int scalar
May be set to a negative value if you wish to terminate the solution to the current problem, and in this case nag_mip_sqp (h02da) will terminate with ifail set to mode.
2:     $\mathrm{objmip}$ – double scalar
Must be set to the objective function value, $f$, if ${\mathbf{mode}}=0$; otherwise objmip is not referenced.
3:     $\mathrm{objgrd}\left({\mathbf{n}}\right)$ – double array
Must contain the gradient vector of the objective function if ${\mathbf{mode}}=1$, with ${\mathbf{objgrd}}\left(j\right)$ containing the partial derivative of $f$ with respect to continuous variable ${x}_{j}$; otherwise objgrd is not referenced.
4:     $\mathrm{user}$ – Any MATLAB object
10:   $\mathrm{iopts}\left(:\right)$int64int32nag_int array
Note: the dimension of this array is dictated by the requirements of associated functions that must have been previously called. This array must be the same array passed as argument iopts in the previous call to nag_mip_optset (h02zk).
11:   $\mathrm{opts}\left(:\right)$ – double array
Note: the dimension of this array is dictated by the requirements of associated functions that must have been previously called. This array must be the same array passed as argument opts in the previous call to nag_mip_optset (h02zk).
The real option array as returned by nag_mip_optset (h02zk).

### Optional Input Parameters

1:     $\mathrm{n}$int64int32nag_int scalar
Default: the dimension of the arrays bl, bu, x and the second dimension of the array a. (An error is raised if these dimensions are not equal.)
$n$, the total number of variables, ${n}_{c}+{n}_{i}$.
Constraint: ${\mathbf{n}}>0$.
2:     $\mathrm{nclin}$int64int32nag_int scalar
Default: the dimension of the array d and the first dimension of the array a. (An error is raised if these dimensions are not equal.)
${n}_{l}$, the number of general linear constraints defined by $A$ and $d$.
Constraint: ${\mathbf{nclin}}\ge 0$.
3:     $\mathrm{maxit}$int64int32nag_int scalar
Default: $500$
The maximum number of iterations within which to find a solution. If maxit is less than or equal to zero, the suggested value below is used.
4:     $\mathrm{acc}$ – double scalar
Default: $1.0e-4$
The requested accuracy for determining feasible points during iterations and for halting the method when the predicted improvement in objective function is less than acc. If acc is less than or equal to $\epsilon$ ($\epsilon$ being the machine precision as given by nag_machine_precision (x02aj)), the below suggested value is used.
5:     $\mathrm{user}$ – Any MATLAB object
user is not used by nag_mip_sqp (h02da), but is passed to confun and objfun. Note that for large objects it may be more efficient to use a global variable which is accessible from the m-files than to use user.

### Output Parameters

1:     $\mathrm{ax}\left(\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{nclin}}\right)\right)$ – double array
The final values of the linear constraints $Ax$.
If ${\mathbf{nclin}}=0$, ax is not referenced.
2:     $\mathrm{x}\left({\mathbf{n}}\right)$ – double array
The final estimate of the solution.
3:     $\mathrm{c}\left(\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{ncnln}}\right)\right)$ – double array
If ${\mathbf{ncnln}}>0$, ${\mathbf{c}}\left(\mathit{j}\right)$ contains the value of the $\mathit{j}$th constraint function ${c}_{\mathit{j}}\left(x\right)$ at the final iterate, for $\mathit{j}=1,2,\dots ,{\mathbf{ncnln}}$.
If ${\mathbf{ncnln}}=0$, the array c is not referenced.
4:     $\mathrm{cjac}\left(\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{ncnln}}\right),{\mathbf{n}}\right)$ – double array
Note: the derivative of the $i$th constraint with respect to the $j$th variable, $\frac{\partial {c}_{i}}{\partial {x}_{j}}$, is stored in ${\mathbf{cjac}}\left(i,j\right)$.
If ${\mathbf{ncnln}}>0$, cjac contains the Jacobian matrix of the constraint functions at the final iterate, i.e., ${\mathbf{cjac}}\left(\mathit{i},\mathit{j}\right)$ contains the partial derivative of the $\mathit{i}$th constraint function with respect to the $\mathit{j}$th variable, for $\mathit{i}=1,2,\dots ,{\mathbf{ncnln}}$ and $\mathit{j}=1,2,\dots ,{\mathbf{n}}$. (See the discussion of argument cjac under confun.)
If ${\mathbf{ncnln}}=0$, the array cjac is not referenced.
5:     $\mathrm{objgrd}\left({\mathbf{n}}\right)$ – double array
The objective function gradient at the solution.
6:     $\mathrm{objmip}$ – double scalar
With ${\mathbf{ifail}}={\mathbf{0}}$, objmip contains the value of the objective function for the MINLP solution.
7:     $\mathrm{user}$ – Any MATLAB object
8:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{ifail}}={\mathbf{0}}$ unless the function detects an error (see Error Indicators and Warnings).

## Error Indicators and Warnings

Errors or warnings detected by the function:
${\mathbf{ifail}}=1$
Constraint: ${\mathbf{n}}>0$.
${\mathbf{ifail}}=2$
Constraint: ${\mathbf{nclin}}\ge 0$.
${\mathbf{ifail}}=3$
Constraint: ${\mathbf{ncnln}}\ge 0$.
${\mathbf{ifail}}=4$
Constraint: $\mathit{lda}\ge {\mathbf{nclin}}$.
${\mathbf{ifail}}=5$
Constraint: ${\mathbf{bl}}\left(\mathit{i}\right)\le {\mathbf{bu}}\left(\mathit{i}\right)$, for $\mathit{i}=1,2,\dots ,{\mathbf{n}}$.
${\mathbf{ifail}}=6$
Constraint: ${\mathbf{varcon}}\left(\mathit{i}\right)=0$, $1$ or $2$, for $\mathit{i}=1,2,\dots ,{\mathbf{n}}$.
${\mathbf{ifail}}=7$
Constraint: ${\mathbf{varcon}}\left(\mathit{i}\right)=3$ or $4$, for $\mathit{i}={\mathbf{n}}+1,\dots ,{\mathbf{n}}+{\mathbf{nclin}}+{\mathbf{ncnln}}$.
${\mathbf{ifail}}=8$
The supplied objfun returned a NaN value.
${\mathbf{ifail}}=9$
The supplied confun returned a NaN value.
${\mathbf{ifail}}=10$
On entry, the optional parameter arrays iopts and opts have either not been initialized or been corrupted.
${\mathbf{ifail}}=11$
On entry, there are no binary or integer variables.
${\mathbf{ifail}}=12$
On entry, linear equality constraints do not precede linear inequality constraints.
${\mathbf{ifail}}=13$
On entry, nonlinear equality constraints do not precede nonlinear inequality constraints.
${\mathbf{ifail}}=81$
One or more objective gradients appear to be incorrect.
${\mathbf{ifail}}=91$
One or more constraint gradients appear to be incorrect.
${\mathbf{ifail}}=1001$
On entry. Exceeded the maximum number of iterations.
${\mathbf{ifail}}=1002$
More than the maximum number of feasible steps without improvement in the objective function.
${\mathbf{ifail}}=1003$
Penalty parameter tends to infinity in an underlying mixed-integer quadratic program; the problem may be infeasible.
${\mathbf{ifail}}=1004$
Termination at an infeasible iterate; if the problem is feasible, try a different starting value.
${\mathbf{ifail}}=1005$
Termination with zero integer trust region for integer variables; try a different starting value.
${\mathbf{ifail}}=1008$
The optimization failed due to numerical difficulties. Set optional parameter ${\mathbf{Print Level}}=3$ for more information.
${\mathbf{ifail}}<0$
The optimization halted because you set mode negative in objfun or mode negative in confun, to $_$.
${\mathbf{ifail}}=-99$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

Not applicable.

None.

## Example

Select a portfolio of at most $p$ assets from $n$ available with expected return $\rho$, is fully invested and that minimizes
 $xTΣx subject to rTx = ρ ∑ i=1 n xi = 1 xi ≤ yi ∑ i=1 n yi ≤ p xi ≥ 0 yi = 0 or 1$
where
• $x$ is a vector of proportions of selected assets
• $y$ is an indicator variable that describes if an asset is in or out
• $r$ is a vector of mean returns
• $\Sigma$ is the covariance matrix of returns.
This example is taken from Mann (1986) with
 $r = 89127 Σ = 43-10 3610 -11100 0000 p = 3 ρ = 10.$
Linear constraints are supplied through both $A$ and $d$, and confun.
```function h02da_example

diary h02da_example.r
fprintf('h02da example results\n\n');

% Problem size
n = int64(8);
nclin = int64(5);
ncnln = int64(2);

varcon = zeros(n+nclin+ncnln, 1, 'int64');

% Set variable types: continuous then binary
varcon(1:4) = int64([0;0;0;0]);
varcon(5:8) = int64([1;1;1;1]);

bl = zeros(n,1);
bu = zeros(n,1);

% Set bounds of continuous variables
bl(1:4) = 0;
bu(1:4) = 1000;

% Set linear constraints
varcon(n+1)         = 3; % equality
varcon(n+2:n+nclin) = 4; % inequality

% Set Ax=d then Ax>=d
a = zeros(nclin,n);
a(1,1:4) = 1;
a(2,[1,5]) = [-1,1];
a(3,[2,6]) = [-1,1];
a(4,[3,7]) = [-1,1];
a(5,[4,8]) = [-1,1];

d = zeros(nclin,1);
d(1) = 1;

% Set constraints supplied by confun, equality first
varcon(n+nclin+1) = 3;
varcon(n+nclin+2) = 4;

iopts = zeros(200, 1, 'int64');
opts = zeros(100, 1);

% Initialize options
[iopts, opts, ifail] = h02zk( ...
'Initialize = h02da', iopts, opts);

% Optimisation parameters
maxit =  int64(500);
acc = 1e-6;

x = zeros(n,1);
% Initial estimate (binary variables need not be given)
x(1:4) = 1;

% Portfolio parameters
user.p = 3;
user.rho = 10;

% Call the solver
[ax, x, c, cjac, objgrd, objmip, user, ifail] = ...
h02da( ...
ncnln, a, d, bl, bu, varcon, x, @confun, @objfun, iopts, opts, ...
'user', user);

% Query the accuracy of the mixed integer QP solver
[ivalue, accqp, cvalue, optype, ifail] = ...
h02zl('QP Accuracy', iopts, opts);

% Results
[ifail] = x04ca('G', ' ', x, 'Final estimate');
fprintf('\nMixed integer QP Accuracy: %g', accqp);
fprintf('\nOptimised value: %g\n\n', objmip);

diary off

function [mode, c, cjac, user] = ...
confun(mode, ncnln, n, varcon, x, cjac, nstate, user)
c = zeros(ncnln, 1);

if (mode == 0)
% Constraints
% Mean return at least rho:
c(1) = 8*x(1) + 9*x(2) + 12*x(3) + 7*x(4) - user.rho;

% Maximum of p assets in portfolio:
c(2) = user.p - x(5) - x(6) - x(7) - x(8);
else
% Jacobian
cjac(1,1:4) = [8,9,12,7];

% c(2) does not include continuous variables which requires
% that their derivatives are zero
cjac(2,1:4) = 0;
end

function [mode, objmip, objgrd, user] = ...
objfun(mode, n, varcon, x, objgrd, nstate, user)
objmip = 0;

if (mode == 0)
% Objective value
objmip = x(1)*(4*x(1)+3*x(2)-x(3)) + ...
x(2)*(3*x(1)+6*x(2)+x(3)) + ...
x(3)*(x(2)-x(1)+10*x(3));
else
% Objective gradients for continuous variables
objgrd(1) = 8*x(1) +  6*x(2) -  2*x(3);
objgrd(2) = 6*x(1) + 12*x(2) +  2*x(3);
objgrd(3) = 2*(x(2)-x(1)) + 20*x(3);
objgrd(4) = 0;
end
```
```h02da example results

Final estimate
1
1   0.3750
2   0.0000
3   0.5250
4   0.1000
5   1.0000
6   0.0000
7   1.0000
8   1.0000

Mixed integer QP Accuracy: 1e-10
Optimised value: 2.925

```

## 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 Description of the s.

### 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$, $i$ and $r$ denote options that take character, integer and real values respectively.
All options accept the value $\mathrm{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.
nag_mip_optset (h02zk) can be called to supply options, one call being necessary for each optional parameter. For example,
```Call H02ZKF('Check Gradients = Yes', iopts, liopts, opts, lopts, ifail)
```
nag_mip_optset (h02zk) should be consulted for a full description of the method of supplying optional parameters.
For nag_mip_sqp (h02da) the maximum length of the argument cvalue used by nag_mip_optget (h02zl) is $12$.
Branch Bound Steps  $i$
Default$\text{}=500$
Maximum number of branch-and-bound steps for solving the mixed integer quadratic problems.
Constraint: ${\mathbf{Branch Bound Steps}}>1$.
Branching Rule  $a$
Default$\text{}=\mathrm{Maximum}$
Branching rule for branch and bound search.
${\mathbf{Branching Rule}}=\mathrm{Maximum}$
Maximum fractional branching.
${\mathbf{Branching Rule}}=\mathrm{Minimum}$
Minimum fractional branching.
Check Gradients  $a$
Default$\text{}=\mathrm{No}$
Perform an internal check of supplied objective and constraint gradients. It is advisable to set ${\mathbf{Check Gradients}}=\mathrm{Yes}$ during code development to avoid difficulties associated with incorrect user-supplied gradients.
Continuous Trust Radius  $r$
Default$\text{}=10.0$
Initial continuous trust region radius, ${\Delta }_{0}^{c}$; the initial trial step $d\in {R}^{{n}_{c}}$ for the SQP approximation must satisfy ${‖d‖}_{\infty }\le {\Delta }_{0}^{c}$.
Constraint: ${\mathbf{Continuous Trust Radius}}>0.0$.
Descent  $r$
Default$\text{}=0.05$
Initial descent parameter, $\delta$, larger values of $\delta$ allow penalty parameter $\sigma$ to increase faster which can lead to faster convergence.
Constraint: $0.0<{\mathbf{Descent}}<1.0$.
Descent Factor  $r$
Default$\text{}=0.1$
Factor for decreasing the internal descent parameter, $\delta$, between iterations.
Constraint: $0.0<{\mathbf{Descent Factor}}<1.0$.
Feasible Steps  $i$
Default$\text{}=10$
Maximum number of feasible steps without improvements, where feasibility is measured by ${‖g\left(x\right)‖}_{\infty }\le \sqrt{{\mathbf{acc}}}$.
Constraint: ${\mathbf{Feasible Steps}}>1$.
Improved Bounds  $a$
Default$\text{}=\mathrm{No}$
Calculate improved bounds in case of ‘Best of all’ node selection strategy.
Integer Trust Radius  $r$
Default$\text{}=10.0$
Initial integer trust region radius, ${\Delta }_{0}^{i}$; the initial trial step $e\in {R}^{{n}_{i}}$ for the SQP approximation must satisfy ${‖e‖}_{\infty }\le {\Delta }_{0}^{i}$.
Constraint: ${\mathbf{Integer Trust Radius}}\ge 1.0$.
Maximum Restarts  $i$
Default$\text{}=2$
Maximum number of restarts that allow the mixed integer SQP algorithm to return to a better solution. Setting a value higher than the default might lead to better results at the expense of function evaluations.
Constraint: $0<{\mathbf{Maximum Restarts}}\le 15$.
Minor Print Level  $i$
Default$\text{}=0$
Print level of the subproblem solver. Active only if ${\mathbf{Print Level}}\ne 0$.
Constraint: $0<{\mathbf{Minor Print Level}}<4$.
Modify Hessian  $a$
Default$\text{}=\mathrm{Yes}$
Modify the Hessian approximation in an attempt to get more accurate search directions. Calculation time is increased when the number of integer variables is large.
Node Selection  $a$
Default$\text{}=\mathrm{Depth First}$
Node selection strategy for branch and bound.
${\mathbf{Node Selection}}=\mathrm{Best of all}$
Large tree search; this method is the slowest as it solves all subproblem QPs independently.
${\mathbf{Node Selection}}=\mathrm{Best of two}$
Uses warm starts and less memory.
${\mathbf{Node Selection}}=\mathrm{Depth first}$
Uses more warm starts. If warm starts are applied, they can speed up the solution of mixed integer subproblems significantly when solving almost identical QPs.
Non Monotone  $i$
Default$\text{}=10$
Maximum number of successive iterations considered for the non-monotone trust region algorithm, allowing the penalty function to increase.
Constraint: $0<{\mathbf{Non Monotone}}<100$.
Objective Scale Bound  $r$
Default$\text{}=1.0$
When ${\mathbf{Scale Objective Function}}>0$ internally scale absolute function values greater than $1.0$ or Objective Scale Bound.
Constraint: ${\mathbf{Objective Scale Bound}}>0.0$.
Penalty  $r$
Default$\text{}=1000.0$
Initial penalty parameter, $\sigma$.
Constraint: ${\mathbf{Penalty}}\ge 0.0$.
Penalty Factor  $r$
Default$\text{}=10.0$
Factor for increasing penalty parameter $\sigma$ when the trust regions cannot be enlarged at a trial step.
Constraint: ${\mathbf{Penalty Factor}}>1.0$.
Print Level  $i$
Default$\text{}=0$
Specifies the desired output level of printing.
${\mathbf{Print Level}}=\mathrm{0}$
No output.
${\mathbf{Print Level}}=\mathrm{1}$
Final convergence analysis.
${\mathbf{Print Level}}=\mathrm{2}$
One line of intermediate results per iteration.
${\mathbf{Print Level}}=\mathrm{3}$
Detailed information printed per iteration.
QP Accuracy  $r$
Default$\text{}=\text{1.0e−10}$
Termination tolerance of the relaxed quadratic program subproblems.
Constraint: ${\mathbf{QP Accuracy}}>0.0$.
Scale Continuous Variables  $a$
Default$\text{}=\mathrm{Yes}$
Internally scale continuous variables values.
Scale Objective Function  $i$
Default$\text{}=1$
Internally scale objective function values.
${\mathbf{Scale Objective Function}}=\mathrm{0}$
No scaling.
${\mathbf{Scale Objective Function}}=\mathrm{1}$
Scale absolute values greater than Objective Scale Bound.
Warm Starts  $i$
Default$\text{}=100$
Maximum number of warm starts within the mixed integer QP solver, see Node Selection.
Constraint: ${\mathbf{Warm Starts}}\ge 0$.