# NAG Library Function Document

## 1Purpose

nag_opt_handle_set_nlnhess (e04rlc) is a part of the NAG optimization modelling suite and defines the structure of the Hessians of the nonlinear objective and constraints, on assumption that they are present in the problem. Alternatively, it may be used to define the Hessian of the Lagrangian.

## 2Specification

 #include #include
 void nag_opt_handle_set_nlnhess (void *handle, Integer idf, Integer nnzh, const Integer irowh[], const Integer icolh[], NagError *fail)

## 3Description

After the initialization function nag_opt_handle_init (e04rac) has been called and an objective function $f$ or nonlinear constraint function ${g}_{i}$ has been registered with nag_opt_handle_set_nlnobj (e04rgc) and nag_opt_handle_set_nlnconstr (e04rkc), nag_opt_handle_set_nlnhess (e04rlc) can be used to define the sparsity structure of the Hessians, $H$, of those functions (i.e., the second partial derivatives with respect to the decision variables) or a linear combination of them, called the Lagrangian.
• Defining ${\nabla }^{2}f\equiv \left(\begin{array}{cccc}\frac{{\partial }^{2}f}{{\partial }^{2}{x}_{1}}& \frac{{\partial }^{2}f}{\partial {x}_{2}\partial {x}_{1}}& \dots & \frac{{\partial }^{2}f}{\partial {x}_{n}\partial {x}_{1}}\\ \frac{{\partial }^{2}f}{\partial {x}_{1}\partial {x}_{2}}& \frac{{\partial }^{2}f}{{\partial }^{2}{x}_{2}}& \dots & \frac{{\partial }^{2}f}{\partial {x}_{n}\partial {x}_{2}}\\ ⋮& ⋮& \ddots & ⋮\\ \frac{{\partial }^{2}f}{\partial {x}_{1}\partial {x}_{n}}& \frac{{\partial }^{2}f}{\partial {x}_{2}\partial {x}_{n}}& \dots & \frac{{\partial }^{2}f}{{\partial }^{2}{x}_{n}}\end{array}\right)$;
• the Hessian of the Lagrangian function $\equiv \sigma {\nabla }^{2}f+\sum _{i=1}^{m}{\lambda }_{i}{\nabla }^{2}{g}_{i}$;
• the Hessian of the objective function $\equiv {\nabla }^{2}f$;
• the Hessian of the constraint functions $\equiv {\nabla }^{2}{g}_{i}$.
Each of the symmetric $n×n$ Hessian matrices will have its own sparsity structure, in general. These structures can be given in separate nag_opt_handle_set_nlnhess (e04rlc) calls, or merged together in the Lagrangian and given in one call.
The nonzero values of the Hessians at particular points in the decision variable space will be communicated to the NLP solver by user-supplied functions (e.g., hess for nag_opt_handle_solve_ipopt (e04stc)).
Some NLP solvers (e.g., nag_opt_handle_solve_ipopt (e04stc)) expect either all of the Hessians (for objective and nonlinear constraints) to be supplied by the user or none and they will terminate with an error indicator if only some but not all of the Hessians have been introduced by nag_opt_handle_set_nlnhess (e04rlc).
Some NLP solvers (e.g., nag_opt_handle_solve_ipopt (e04stc), again) will automatically switch to using internal approximations for the Hessians if none have been introduced by nag_opt_handle_set_nlnhess (e04rlc). This usually results in a slower convergence (more iterations to the solution) and might even result in no solution being attainable within the ordinary tolerances.

None.

## 5Arguments

1:    $\mathbf{handle}$void *Input
On entry: the handle to the problem. It needs to be initialized by nag_opt_handle_init (e04rac) and must not be changed.
2:    $\mathbf{idf}$IntegerInput
On entry: specifies the quantities for which a sparsity structure is provided in nnzh, irowh and icolh.
${\mathbf{idf}}=-1$
The sparsity structure of the Hessian of the Lagrangian is provided.
${\mathbf{idf}}=0$
The sparsity structure of the Hessian of the objective function is provided.
${\mathbf{idf}}>0$
The sparsity structure of the Hessian of the idfth constraint function is provided.
The value of idf will also determine how an NLP solver will call the user-supplied functions that evaluate these nonzeros at particular points of the decision variable space, i.e., whether the solver will expect the nonzero values of the objective and constraint Hessians in separate calls or merged in the Lagrangian Hessian, in one call. See, for example, hess of nag_opt_handle_solve_ipopt (e04stc).
Constraint: $-1\le {\mathbf{idf}}\le \mathit{ncnln}$.
Note: $\mathit{ncnln}$, the number of nonlinear constraints registered with the handle.
3:    $\mathbf{nnzh}$IntegerInput
On entry: the number of nonzero elements in the upper triangle of the matrix $H$.
Constraint: ${\mathbf{nnzh}}>0$.
4:    $\mathbf{irowh}\left[{\mathbf{nnzh}}\right]$const IntegerInput
5:    $\mathbf{icolh}\left[{\mathbf{nnzh}}\right]$const IntegerInput
On entry: arrays irowh and icolh store the nonzeros of the upper triangle of the matrix $H$ in coordinate storage (CS) format (see Section 2.1.1 in the f11 Chapter Introduction). irowh specifies one-based row indices, icolh specifies one-based column indices and specifies the values of the nonzero elements in such a way that ${h}_{ij}=\mathit{H}\left[l-1\right]$ where $i={\mathbf{irowh}}\left[l-1\right]$ and $j={\mathbf{icolh}}\left[\mathit{l}-1\right]$, for $\mathit{l}=1,2,\dots ,{\mathbf{nnzh}}$. No particular order is expected, but elements should not repeat.
Constraint: $1\le {\mathbf{irowh}}\left[\mathit{l}-1\right]\le {\mathbf{icolh}}\left[\mathit{l}-1\right]\le n$, for $\mathit{l}=1,2,\dots ,{\mathbf{nnzh}}$.
6:    $\mathbf{fail}$NagError *Input/Output
The NAG error argument (see Section 3.7 in How to Use the NAG Library and its Documentation).

## 6Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 2.3.1.2 in How to Use the NAG Library and its Documentation for further information.
On entry, ${\mathbf{idf}}=〈\mathit{\text{value}}〉$.
The structure of the Hessian of nonlinear function linked to the given idf has already been defined.
The structure of the Hessian of the Lagrangian has already been defined.
The structure of the individual Hessians has already been defined, the Hessian of the Lagrangian cannot be defined.
On entry, argument $〈\mathit{\text{value}}〉$ had an illegal value.
NE_HANDLE
The supplied handle does not define a valid handle to the data structure for the NAG optimization modelling suite. It has not been initialized by nag_opt_handle_init (e04rac) or it has been corrupted.
NE_INT
On entry, ${\mathbf{nnzh}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{nnzh}}>0$.
NE_INT_2
On entry, ${\mathbf{idf}}=〈\mathit{\text{value}}〉$.
Constraint: $〈\mathit{\text{value}}〉\le {\mathbf{idf}}\le 〈\mathit{\text{value}}〉$.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 2.7.6 in How to Use the NAG Library and its Documentation for further information.
NE_INVALID_CS
On entry, $i=〈\mathit{\text{value}}〉$, ${\mathbf{icolh}}\left[\mathit{i}-1\right]=〈\mathit{\text{value}}〉$ and $n=〈\mathit{\text{value}}〉$.
Constraint: $1\le {\mathbf{icolh}}\left[\mathit{i}-1\right]\le n$.
On entry, $i=〈\mathit{\text{value}}〉$, ${\mathbf{irowh}}\left[\mathit{i}-1\right]=〈\mathit{\text{value}}〉$ and ${\mathbf{icolh}}\left[\mathit{i}-1\right]=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{irowh}}\left[\mathit{i}-1\right]\le {\mathbf{icolh}}\left[\mathit{i}-1\right]$ (elements within the upper triangle).
On entry, $i=〈\mathit{\text{value}}〉$, ${\mathbf{irowh}}\left[\mathit{i}-1\right]=〈\mathit{\text{value}}〉$ and $n=〈\mathit{\text{value}}〉$.
Constraint: $1\le {\mathbf{irowh}}\left[\mathit{i}-1\right]\le n$.
On entry, more than one element of structural matrix $H$ has row index $〈\mathit{\text{value}}〉$ and column index $〈\mathit{\text{value}}〉$.
Constraint: each element of structural matrix $H$ must have a unique row and column index.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 2.7.5 in How to Use the NAG Library and its Documentation for further information.
NE_PHASE
Neither nonlinear objective nor nonlinear constraints are present. The structure of the Hessian cannot be defined.
No nonlinear objective has been defined, its Hessian cannot be set.
The problem cannot be modified in this phase any more, the solver has already been called.

Not applicable.

## 8Parallelism and Performance

nag_opt_handle_set_nlnhess (e04rlc) is not threaded in any implementation.