NAG Library Function Document
nag_opt_sparse_nlp_jacobian (e04vjc)
1 Purpose
nag_opt_sparse_nlp_jacobian (e04vjc) may be used before
nag_opt_sparse_nlp_solve (e04vhc) to determine the sparsity pattern for the Jacobian.
2 Specification
#include <nag.h> |
#include <nage04.h> |
void |
nag_opt_sparse_nlp_jacobian (Integer nf,
Integer n,
void |
(*usrfun)(Integer *status,
Integer n,
const double x[],
Integer needf,
Integer nf,
double f[],
Integer needg,
Integer leng,
double g[],
Nag_Comm *comm),
|
|
Integer iafun[],
Integer javar[],
double a[],
Integer lena,
Integer *nea,
Integer igfun[],
Integer jgvar[],
Integer leng,
Integer *neg,
const double x[],
const double xlow[],
const double xupp[],
Nag_E04State *state,
Nag_Comm *comm,
NagError *fail) |
|
3 Description
When using
nag_opt_sparse_nlp_solve (e04vhc), if you set the optional argument
and
usrfun provides none of the derivatives, you may need to call nag_opt_sparse_nlp_jacobian (e04vjc) 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
e04vgc (&state, ... );
e04vjc (nf, n, ... );
e04vlc ("Derivative Option = 0", &state, ... );
e04vhc (start, nf, ... );
nag_opt_sparse_nlp_jacobian (e04vjc) determines the sparsity pattern for the Jacobian and identifies the constant elements automatically. To do so, nag_opt_sparse_nlp_jacobian (e04vjc) approximates the problem functions,
, at three random perturbations of the given initial point
. 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, nag_opt_sparse_nlp_jacobian (e04vjc) finds that the Jacobian can be permuted to the form:
where
,
and
are constant. Note that
might contain elements that are also constant, but nag_opt_sparse_nlp_jacobian (e04vjc) must classify them as nonlinear. This is because
nag_opt_sparse_nlp_solve (e04vhc) ‘removes’ linear variables from the calculation of
by setting them to zero before calling
usrfun. A knowledgeable user would be able to move such elements from
in
usrfun and enter them as part of
iafun,
javar and
a for
nag_opt_sparse_nlp_solve (e04vhc).
4 References
Hock W and Schittkowski K (1981) Test Examples for Nonlinear Programming Codes. Lecture Notes in Economics and Mathematical Systems 187 Springer–Verlag
5 Arguments
Note: all optional arguments are described in detail in
Section 12.1 in nag_opt_sparse_nlp_solve (e04vhc).
- 1:
nf – IntegerInput
On entry:
, the number of problem functions in
, including the objective function (if any) and the linear and nonlinear constraints. Simple upper and lower bounds on
can be defined using the arguments
xlow and
xupp and should not be included in
.
Constraint:
.
- 2:
n – IntegerInput
On entry: , the number of variables.
Constraint:
.
- 3:
usrfun – function, supplied by the userExternal Function
usrfun must define the problem functions
. This function is passed to nag_opt_sparse_nlp_jacobian (e04vjc) as the external argument
usrfun.
The specification of
usrfun is:
void |
usrfun (Integer *status,
Integer n,
const double x[],
Integer needf,
Integer nf,
double f[],
Integer needg,
Integer leng,
double g[],
Nag_Comm *comm)
|
|
- 1:
status – Integer *Input/Output
On entry: indicates the first call to
usrfun.
- There is nothing special about the current call to usrfun.
- nag_opt_sparse_nlp_jacobian (e04vjc) is calling your function 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
at the current
. (For example, the problem functions may not be defined there).
nag_opt_sparse_nlp_jacobian (e04vjc) evaluates at random perturbation of the initial point , say . If the functions cannot be evaluated at , you can set , nag_opt_sparse_nlp_jacobian (e04vjc) will use another random perturbation.
If for some reason you wish to terminate the current problem, set .
- 2:
n – IntegerInput
On entry: , the number of variables, as defined in the call to nag_opt_sparse_nlp_jacobian (e04vjc).
- 3:
x[n] – const doubleInput
On entry: the variables at which the problem functions are to be calculated. The array must not be altered.
- 4:
needf – IntegerInput
On entry: indicates if
f must be assigned during the call to
usrfun (see
f).
- 5:
nf – IntegerInput
On entry: , the number of problem functions.
- 6:
f[nf] – doubleInput/Output
On entry: this will be set by nag_opt_sparse_nlp_jacobian (e04vjc).
On exit: the computed
according to the setting of
needf.
If
,
f is not required and is ignored.
If
, the components of
must be calculated and assigned to
f. nag_opt_sparse_nlp_jacobian (e04vjc) will always call
usrfun with
.
To simplify the code, you may ignore the value of
needf and compute
on every entry to
usrfun.
- 7:
needg – IntegerInput
On entry: nag_opt_sparse_nlp_jacobian (e04vjc) will call
usrfun with
to indicate that
g is not required.
- 8:
leng – IntegerInput
On entry: the dimension of the array
g.
- 9:
g[leng] – doubleInput/Output
On entry: concerns the calculations of the derivatives of the function .
On exit: nag_opt_sparse_nlp_jacobian (e04vjc) will always call
usrfun with
:
g is not required to be set on exit but must be declared correctly.
- 10:
comm – Nag_Comm *
Pointer to structure of type Nag_Comm; the following members are relevant to
usrfun.
- user – double *
- iuser – Integer *
- p – Pointer
The type Pointer will be
void *. Before calling nag_opt_sparse_nlp_jacobian (e04vjc) you may allocate memory and initialize these pointers with various quantities for use by
usrfun when called from nag_opt_sparse_nlp_jacobian (e04vjc) (see
Section 3.2.1.1 in the Essential Introduction).
- 4:
iafun[lena] – IntegerOutput
- 5:
javar[lena] – IntegerOutput
- 6:
a[lena] – doubleOutput
On exit: define the coordinates
and values
of the nonzero elements of the linear part
of the function
.
In particular,
nea triples
define the row and column indices
and
of the element
.
- 7:
lena – IntegerInput
On entry: the dimension of the arrays
iafun,
javar and
a that hold
.
lena should be an
overestimate of the number of elements in the linear part of the Jacobian.
Constraint:
.
- 8:
nea – Integer *Output
On exit: is the number of nonzero entries in such that .
- 9:
igfun[leng] – IntegerOutput
- 10:
jgvar[leng] – IntegerOutput
On exit: define the coordinates of the nonzero elements of , the nonlinear part of the derivatives of the function .
- 11:
leng – IntegerInput
On entry: the dimension of the arrays
igfun and
jgvar that define the varying Jacobian elements
.
leng should be an
overestimate of the number of elements in the nonlinear part of the Jacobian.
Constraint:
.
- 12:
neg – Integer *Output
On exit: the number of nonzero entries in .
- 13:
x[n] – const doubleInput
On entry: an initial estimate of the variables
. The contents of
will be used by nag_opt_sparse_nlp_jacobian (e04vjc) in the call of
usrfun, and so each element of
x should be within the bounds given by
xlow and
xupp.
- 14:
xlow[n] – const doubleInput
- 15:
xupp[n] – const doubleInput
On entry: contain the lower and upper bounds
and
on the variables
.
To specify a nonexistent lower bound , set , where is the optional argument . To specify a nonexistent upper bound .
To fix the th variable (say, , where ), set .
- 16:
state – Nag_E04State *Communication Structure
state contains internal information required for functions in this suite. It must not be modified in any way.
- 17:
comm – Nag_Comm *Communication Structure
-
The NAG communication argument (see
Section 3.2.1.1 in the Essential Introduction).
- 18:
fail – NagError *Input/Output
-
The NAG error argument (see
Section 3.6 in the Essential Introduction).
6 Error Indicators and Warnings
- NE_ALLOC_FAIL
-
Internal error: memory allocation failed when attempting to allocate workspace sizes , and .
- NE_ALLOC_INSUFFICIENT
-
Internal memory allocation was insufficient. Please contact
NAG.
- NE_ARRAY_TOO_SMALL
-
Either
lena or
leng is too small. Increase both of them and corresponding array sizes.
and
.
- NE_BAD_PARAM
-
On entry, argument had an illegal value.
- NE_E04VGC_NOT_INIT
-
Initialization function
nag_opt_sparse_nlp_init (e04vgc) has not been called.
- NE_INT
-
On entry, .
Constraint: .
On entry, .
Constraint: .
- 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.
- NE_JACOBIAN_STRUCTURE_FAIL
-
Cannot estimate Jacobian structure at given point
x.
- NE_USER_STOP
-
User-supplied function
usrfun requested termination.
- NE_USRFUN_UNDEFINED
-
User-supplied function
usrfun indicates that functions are undefined near given point
x.
7 Accuracy
Not applicable.
8 Parallelism and Performance
nag_opt_sparse_nlp_jacobian (e04vjc) is not threaded by NAG in any implementation.
nag_opt_sparse_nlp_jacobian (e04vjc) 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
Users' Note for your implementation for any additional implementation-specific information.
None.
10 Example
This example shows how to call nag_opt_sparse_nlp_jacobian (e04vjc) to determine the sparsity pattern of the Jacobian before calling
nag_opt_sparse_nlp_solve (e04vhc) 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
subject to the bounds
to the nonlinear constraints
and to the linear constraints
The initial point, which is infeasible, is
and
.
The optimal solution (to five figures) is
and
. All the nonlinear constraints are active at the solution.
The formulation of the problem combines the constraints and the objective into a single vector (
).
10.1 Program Text
Program Text (e04vjce.c)
10.2 Program Data
Program Data (e04vjce.d)
10.3 Program Results
Program Results (e04vjce.r)