# NAG FL Interfacee04vjf (nlp2_​sparse_​jacobian)

Note: this routine is deprecated. Replaced by e04srf.
This was a sparsity structure defining routine for e04vhf which has been superseded by e04srf. e04srf is part of the NAG optimization modelling suite (see Section 3.1 in the E04 Chapter Introduction) which uses the problem defining facilities common to that suite.

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

e04vjf may be used before e04vhf to determine the sparsity pattern for the Jacobian.

## 2Specification

Fortran Interface
 Subroutine e04vjf ( nf, n, a, lena, nea, leng, neg, x, xlow, xupp, cw, iw, rw,
 Integer, Intent (In) :: nf, n, lena, leng, lencw, leniw, lenrw Integer, Intent (Inout) :: iw(leniw), iuser(*), ifail Integer, Intent (Out) :: iafun(lena), javar(lena), nea, igfun(leng), jgvar(leng), neg Real (Kind=nag_wp), Intent (In) :: x(n), xlow(n), xupp(n) Real (Kind=nag_wp), Intent (Inout) :: rw(lenrw), ruser(*) Real (Kind=nag_wp), Intent (Out) :: a(lena) Character (8), Intent (InOut) :: cw(lencw), cuser(*) External :: usrfun
#include <nag.h>
 void e04vjf_ (const Integer *nf, const Integer *n, void (NAG_CALL *usrfun)(Integer *status, const Integer *n, const double x[], const Integer *needf, const Integer *nf, double f[], const Integer *needg, const Integer *leng, double g[], char cuser[], Integer iuser[], double ruser[], const Charlen length_cuser),Integer iafun[], Integer javar[], double a[], const Integer *lena, Integer *nea, Integer igfun[], Integer jgvar[], const Integer *leng, Integer *neg, const double x[], const double xlow[], const double xupp[], char cw[], const Integer *lencw, Integer iw[], const Integer *leniw, double rw[], const Integer *lenrw, char cuser[], Integer iuser[], double ruser[], Integer *ifail, const Charlen length_cw, const Charlen length_cuser)
The routine may be called by the names e04vjf or nagf_opt_nlp2_sparse_jacobian.

## 3Description

When using e04vhf, if you set the optional parameter ${\mathbf{Derivative Option}}=0$ and usrfun provides none of the derivatives, you may need to call e04vjf to determine the input arrays iafun, javar, a, igfun and jgvar. These arrays define the pattern of nonzeros in the Jacobian matrix. A typical sequence of calls could be
```Call e04vgf (cw, lencw, ... )
Call e04vjf (nf, n, ... )
Call e04vlf ('Derivative Option = 0', cw, ... )
Call e04vhf (start, nf, ... )```
e04vjf determines the sparsity pattern for the Jacobian and identifies the constant elements automatically. To do so, e04vjf approximates the problem functions, $F\left(x\right)$, at three random perturbations of the given initial point $x$. If an element of the approximate Jacobian is the same at all three points, then it is taken to be constant. If it is zero, it is taken to be identically zero. Since the random points are not chosen close together, the heuristic will correctly classify the Jacobian elements in the vast majority of cases. In general, e04vjf finds that the Jacobian can be permuted to the form:
 $( G(x) A3 A2 A4 ) ,$
where ${A}_{2}$, ${A}_{3}$ and ${A}_{4}$ are constant. Note that $G\left(x\right)$ might contain elements that are also constant, but e04vjf must classify them as nonlinear. This is because e04vhf ‘removes’ linear variables from the calculation of $F$ by setting them to zero before calling usrfun. A knowledgeable user would be able to move such elements from $F\left(x\right)$ in usrfun and enter them as part of iafun, javar and a for e04vhf.

## 4References

Hock W and Schittkowski K (1981) Test Examples for Nonlinear Programming Codes. Lecture Notes in Economics and Mathematical Systems 187 Springer–Verlag

## 5Arguments

Note: all optional parameters are described in detail in Section 12.1 in e04vhf.
1: $\mathbf{nf}$Integer Input
On entry: $\mathit{nf}$, the number of problem functions in $F\left(x\right)$, including the objective function (if any) and the linear and nonlinear constraints. Simple upper and lower bounds on $x$ can be defined using the arguments xlow and xupp and should not be included in $F$.
Constraint: ${\mathbf{nf}}>0$.
2: $\mathbf{n}$Integer Input
On entry: $n$, the number of variables.
Constraint: ${\mathbf{n}}>0$.
3: $\mathbf{usrfun}$Subroutine, supplied by the user. External Procedure
usrfun must define the problem functions $F\left(x\right)$. This subroutine is passed to e04vjf as the external argument usrfun.
The specification of usrfun is:
Fortran Interface
 Subroutine usrfun ( n, x, nf, f, leng, g,
 Integer, Intent (In) :: n, needf, nf, needg, leng Integer, Intent (Inout) :: status, iuser(*) Real (Kind=nag_wp), Intent (In) :: x(n) Real (Kind=nag_wp), Intent (Inout) :: f(nf), g(leng), ruser(*) Character (8), Intent (InOut) :: cuser(*)
 void usrfun (Integer *status, const Integer *n, const double x[], const Integer *needf, const Integer *nf, double f[], const Integer *needg, const Integer *leng, double g[], char cuser[], Integer iuser[], double ruser[], const Charlen length_cuser)
1: $\mathbf{status}$Integer Input/Output
On entry: indicates the first call to usrfun.
${\mathbf{status}}=0$
There is nothing special about the current call to usrfun.
${\mathbf{status}}=1$
e04vjf is calling your subroutine for the first time. Some data may need to be input or computed and saved.
On exit: may be used to indicate that you are unable to evaluate $F$ at the current $x$. (For example, the problem functions may not be defined there).
e04vjf evaluates $F\left(x\right)$ at random perturbation of the initial point $x$, say ${x}_{p}$. If the functions cannot be evaluated at ${x}_{p}$, you can set ${\mathbf{status}}=-1$, e04vjf will use another random perturbation.
If for some reason you wish to terminate the current problem, set ${\mathbf{status}}\le -2$.
2: $\mathbf{n}$Integer Input
On entry: $n$, the number of variables, as defined in the call to e04vjf.
3: $\mathbf{x}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
On entry: the variables $x$ at which the problem functions are to be calculated. The array $x$ must not be altered.
4: $\mathbf{needf}$Integer Input
On entry: indicates if f must be assigned during the call to usrfun (see f).
5: $\mathbf{nf}$Integer Input
On entry: $\mathit{nf}$, the number of problem functions.
6: $\mathbf{f}\left({\mathbf{nf}}\right)$Real (Kind=nag_wp) array Input/Output
On entry: this will be set by e04vjf.
On exit: the computed $F\left(x\right)$ according to the setting of needf.
If ${\mathbf{needf}}=0$, f is not required and is ignored.
If ${\mathbf{needf}}>0$, the components of $F\left(x\right)$ must be calculated and assigned to f. e04vjf will always call usrfun with ${\mathbf{needf}}>0$.
To simplify the code, you may ignore the value of needf and compute $F\left(x\right)$ on every entry to usrfun.
7: $\mathbf{needg}$Integer Input
On entry: e04vjf will call usrfun with ${\mathbf{needg}}=0$ to indicate that g is not required.
8: $\mathbf{leng}$Integer Input
On entry: the dimension of the array g as declared in the (sub)program from which e04vjf is called.
9: $\mathbf{g}\left({\mathbf{leng}}\right)$Real (Kind=nag_wp) array Input/Output
On entry: concerns the calculations of the derivatives of the function $f\left(x\right)$.
On exit: e04vjf will always call usrfun with ${\mathbf{needg}}=0$: g is not required to be set on exit but must be declared correctly.
10: $\mathbf{cuser}\left(*\right)$Character(8) array User Workspace
11: $\mathbf{iuser}\left(*\right)$Integer array User Workspace
12: $\mathbf{ruser}\left(*\right)$Real (Kind=nag_wp) array User Workspace
usrfun is called with the arguments cuser, iuser and ruser as supplied to e04vjf. You should use the arrays cuser, iuser and ruser to supply information to usrfun.
usrfun must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which e04vjf is called. Arguments denoted as Input must not be changed by this procedure.
Note: usrfun should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by e04vjf. If your code inadvertently does return any NaNs or infinities, e04vjf is likely to produce unexpected results.
4: $\mathbf{iafun}\left({\mathbf{lena}}\right)$Integer array Output
5: $\mathbf{javar}\left({\mathbf{lena}}\right)$Integer array Output
6: $\mathbf{a}\left({\mathbf{lena}}\right)$Real (Kind=nag_wp) array Output
On exit: define the coordinates $\left(i,j\right)$ and values ${A}_{ij}$ of the nonzero elements of the linear part $A$ of the function $F\left(x\right)=f\left(x\right)+Ax$.
In particular, nea triples $\left({\mathbf{iafun}}\left(k\right),{\mathbf{javar}}\left(k\right),{\mathbf{a}}\left(k\right)\right)$ define the row and column indices $i={\mathbf{iafun}}\left(k\right)$ and $j={\mathbf{javar}}\left(k\right)$ of the element ${A}_{ij}={\mathbf{a}}\left(k\right)$.
7: $\mathbf{lena}$Integer Input
On entry: the dimension of the arrays iafun, javar and a that hold $\left(i,j,{A}_{ij}\right)$ as declared in the (sub)program from which e04vjf is called. lena should be an overestimate of the number of elements in the linear part of the Jacobian.
Constraint: ${\mathbf{lena}}\ge 1$.
8: $\mathbf{nea}$Integer Output
On exit: is the number of nonzero entries in $A$ such that $F\left(x\right)=f\left(x\right)+Ax$.
9: $\mathbf{igfun}\left({\mathbf{leng}}\right)$Integer array Output
10: $\mathbf{jgvar}\left({\mathbf{leng}}\right)$Integer array Output
On exit: define the coordinates $\left(i,j\right)$ of the nonzero elements of $G$, the nonlinear part of the derivatives $J\left(x\right)=G\left(x\right)+A$ of the function $F\left(x\right)=f\left(x\right)+Ax$.
11: $\mathbf{leng}$Integer Input
On entry: the dimension of the arrays igfun and jgvar that define the varying Jacobian elements $\left(i,j,{G}_{ij}\right)$ as declared in the (sub)program from which e04vjf is called. leng should be an overestimate of the number of elements in the nonlinear part of the Jacobian.
Constraint: ${\mathbf{leng}}\ge 1$.
12: $\mathbf{neg}$Integer Output
On exit: the number of nonzero entries in $G$.
13: $\mathbf{x}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
On entry: an initial estimate of the variables $x$. The contents of $x$ will be used by e04vjf in the call of usrfun, and so each element of x should be within the bounds given by xlow and xupp.
14: $\mathbf{xlow}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
15: $\mathbf{xupp}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
On entry: contain the lower and upper bounds ${l}_{x}$ and ${u}_{x}$ on the variables $x$.
To specify a nonexistent lower bound ${\left[{l}_{x}\right]}_{j}=-\infty$, set ${\mathbf{xlow}}\left(j\right)\le -\mathit{bigbnd}$, where $\mathit{bigbnd}$ is the optional parameter Infinite Bound Size. To specify a nonexistent upper bound ${\mathbf{xupp}}\left(j\right)\ge \mathit{bigbnd}$.
To fix the $j$th variable (say, ${x}_{j}=\beta$, where $|\beta |<\mathit{bigbnd}$), set ${\mathbf{xlow}}\left(j\right)={\mathbf{xupp}}\left(j\right)=\beta$.
16: $\mathbf{cw}\left({\mathbf{lencw}}\right)$Character(8) array Communication Array
17: $\mathbf{lencw}$Integer Input
On entry: the dimension of the array cw as declared in the (sub)program from which e04vjf is called.
Constraint: ${\mathbf{lencw}}\ge 600$.
18: $\mathbf{iw}\left({\mathbf{leniw}}\right)$Integer array Communication Array
19: $\mathbf{leniw}$Integer Input
On entry: the dimension of the array iw as declared in the (sub)program from which e04vjf is called.
Constraint: ${\mathbf{leniw}}\ge 600$.
20: $\mathbf{rw}\left({\mathbf{lenrw}}\right)$Real (Kind=nag_wp) array Communication Array
21: $\mathbf{lenrw}$Integer Input
On entry: the dimension of the array rw as declared in the (sub)program from which e04vjf is called.
Constraint: ${\mathbf{lenrw}}\ge 600$.
22: $\mathbf{cuser}\left(*\right)$Character(8) array User Workspace
23: $\mathbf{iuser}\left(*\right)$Integer array User Workspace
24: $\mathbf{ruser}\left(*\right)$Real (Kind=nag_wp) array User Workspace
cuser, iuser and ruser are not used by e04vjf, but are passed directly to usrfun and may be used to pass information to this routine.
25: $\mathbf{ifail}$Integer Input/Output
On entry: ifail must be set to $0$, $-1$ or $1$ to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of $0$ causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of $-1$ means that an error message is printed while a value of $1$ means that it is not.
If halting is not appropriate, the value $-1$ or $1$ is recommended. If message printing is undesirable, then the value $1$ is recommended. Otherwise, the value $0$ is recommended. When the value $-\mathbf{1}$ or $\mathbf{1}$ is used it is essential to test the value of ifail on exit.
On exit: ${\mathbf{ifail}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6Error Indicators and Warnings

If on entry ${\mathbf{ifail}}=0$ or $-1$, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
${\mathbf{ifail}}=1$
On entry, ${\mathbf{lencw}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{lencw}}\ge 600$.
On entry, ${\mathbf{leniw}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{leniw}}\ge 600$.
On entry, ${\mathbf{lenrw}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{lenrw}}\ge 600$.
The initialization routine e04vgf has not been called.
${\mathbf{ifail}}=2$
On entry, ${\mathbf{lena}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{lena}}\ge 1$.
On entry, ${\mathbf{leng}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{leng}}\ge 1$.
${\mathbf{ifail}}=3$
User-supplied routine usrfun indicates that functions are undefined near given point x.
You have indicated that the problem functions are undefined by setting ${\mathbf{status}}=-1$ on exit from usrfun. This exit occurs if e04vjf is unable to find a point at which the functions are defined.
${\mathbf{ifail}}=4$
User-supplied routine usrfun requested termination.
You have indicated the wish to terminate the call to e04vjf by setting status to a value $\text{}<-1$ on exit from usrfun.
${\mathbf{ifail}}=5$
Either lena or leng is too small. Increase both of them and corresponding array sizes. ${\mathbf{lena}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{leng}}=⟨\mathit{\text{value}}⟩$.
${\mathbf{ifail}}=6$
Cannot estimate Jacobian structure at given point x.
${\mathbf{ifail}}=7$
Internal error: memory allocation failed when attempting to allocate workspace sizes $⟨\mathit{\text{value}}⟩$, $⟨\mathit{\text{value}}⟩$ and $⟨\mathit{\text{value}}⟩$. Please contact NAG.
${\mathbf{ifail}}=8$
${\mathbf{ifail}}=-99$
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

Not applicable.

## 8Parallelism and Performance

e04vjf makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

None.

## 10Example

This example shows how to call e04vjf to determine the sparsity pattern of the Jacobian before calling e04vhf to solve a sparse nonlinear programming problem without providing the Jacobian information in usrfun.
It is a reformulation of Problem 74 from Hock and Schittkowski (1981) and involves the minimization of the nonlinear function
 $f(x) = 10−6 x33 + 23 × 10−6 x43+3 x3+2 x4$
subject to the bounds
 $-0.55≤x1≤ 0.55, -0.55≤x2≤ 0.55, 0≤x3≤ 1200, 0≤x4≤ 1200,$
to the nonlinear constraints
 $1000sin(-x1-0.25)+1000sin(-x2-0.25)-x3 = -894.8, 1000sin(x1-0.25)+1000sin(x1-x2-0.25)-x4 = -894.8, 1000sin(x2-0.25)+1000sin(x2-x1-0.25) = -1294.8,$
and to the linear constraints
 $-x1+x2≥-0.55, -x1-x2≥-0.55.$
The initial point, which is infeasible, is
 $x0 = ( 0, 0, 0, 0 ) T ,$
and $f\left({x}_{0}\right)=0$.
The optimal solution (to five figures) is
 $x*=(0.11887,-0.39623,679.94,1026.0)T,$
and $f\left({x}^{*}\right)=5126.4$. All the nonlinear constraints are active at the solution.
The formulation of the problem combines the constraints and the objective into a single vector ($F$).
 $F = ( 1000 sin(-x1-0.25) + 1000 sin(-x2-0.25) - x3 1000 sin(x1-0.25) + 1000 sin(x1-x2-0.25) - x4 1000 sin(x2-0.25) + 1000 sin(x2-x1-0.25) -x1 + x2 x1 - x2 10−6 x33 + 23 × 10−6 x43 + 3x3 + 2x4 )$

### 10.1Program Text

Program Text (e04vjfe.f90)

### 10.2Program Data

Program Data (e04vjfe.d)

### 10.3Program Results

Program Results (e04vjfe.r)