NAG AD Library
e04us (lsq_gencon_deriv)

Settings help

AD Name Style:


AD Specification Language:

1 Purpose

e04us is the AD Library version of the primal routine e04usf. Based (in the C++ interface) on overload resolution, e04us can be used for primal, tangent and adjoint evaluation. It supports tangents and adjoints of first and second order.

2 Specification

Fortran Interface
Subroutine e04us_AD_f ( ad_handle, m, n, nclin, ncnln, lda, ldcj, ldfj, ldr, a, bl, bu, y, confun, objfun, iter, istate, c, cjac, f, fjac, clamda, objf, r, x, iwork, liwork, work, lwork, iuser, ruser, lwsav, iwsav, rwsav, ifail)
Integer, Intent (In) :: m, n, nclin, ncnln, lda, ldcj, ldfj, ldr, liwork, lwork
Integer, Intent (Inout) :: istate(n+nclin+ncnln), iuser(*), iwsav(610), ifail
Integer, Intent (Out) :: iter, iwork(liwork)
ADTYPE, Intent (In) :: a(lda,*), bl(n+nclin+ncnln), bu(n+nclin+ncnln), y(m)
ADTYPE, Intent (Inout) :: cjac(ldcj,*), fjac(ldfj,n), clamda(n+nclin+ncnln), r(ldr,n), x(n), ruser(*), rwsav(475)
ADTYPE, Intent (Out) :: c(max(1,ncnln)), f(m), objf, work(lwork)
Logical, Intent (Inout) :: lwsav(120)
Type (c_ptr), Intent (Inout) :: ad_handle
External :: confun, objfun
Corresponding to the overloaded C++ function, the Fortran interface provides five routines with names reflecting the type used for active real arguments. The actual subroutine and type names are formed by replacing AD and ADTYPE in the above as follows:
when ADTYPE is Real(kind=nag_wp) then AD is p0w
when ADTYPE is Type(nagad_a1w_w_rtype) then AD is a1w
when ADTYPE is Type(nagad_t1w_w_rtype) then AD is t1w
when ADTYPE is Type(nagad_a1t1w_w_rtype) then AD is a1t1w
when ADTYPE is Type(nagad_t2w_w_rtype) then AD is t2w
C++ Interface
#include <dco.hpp>
#include <nagad.h>
namespace nag {
namespace ad {
template <typename CONFUN_T, typename OBJFUN_T>
void e04us ( handle_t &ad_handle, const Integer &m, const Integer &n, const Integer &nclin, const Integer &ncnln, const Integer &lda, const Integer &ldcj, const Integer &ldfj, const Integer &ldr, const ADTYPE a[], const ADTYPE bl[], const ADTYPE bu[], const ADTYPE y[], CONFUN_T &&confun, OBJFUN_T &&objfun, Integer &iter, Integer istate[], ADTYPE c[], ADTYPE cjac[], ADTYPE f[], ADTYPE fjac[], ADTYPE clamda[], ADTYPE &objf, ADTYPE r[], ADTYPE x[], Integer iwork[], const Integer &liwork, ADTYPE work[], const Integer &lwork, logical lwsav[], Integer iwsav[], ADTYPE rwsav[], Integer &ifail)
}
}
The function is overloaded on ADTYPE which represents the type of active arguments. ADTYPE may be any of the following types:
double,
dco::ga1s<double>::type,
dco::gt1s<double>::type,
dco::gt1s<dco::gt1s<double>::type>::type,
dco::ga1s<dco::gt1s<double>::type>::type
Note: this function can be used with AD tools other than dco/c++. For details, please contact NAG.

3 Description

e04us is the AD Library version of the primal routine e04usf.
e04usf is designed to minimize an arbitrary smooth sum of squares function subject to constraints (which may include simple bounds on the variables, linear constraints and smooth nonlinear constraints) using a Sequential Quadratic Programming (SQP) method. As many first derivatives as possible should be supplied by you; any unspecified derivatives are approximated by finite differences. See the description of the optional parameter Derivative Level, in Section 12.1. It is not intended for large sparse problems.
e04usf may also be used for unconstrained, bound-constrained and linearly constrained optimization. For further information see Section 3 in the documentation for e04usf.

4 References

Gill P E, Murray W and Wright M H (1981) Practical Optimization Academic Press
Hock W and Schittkowski K (1981) Test Examples for Nonlinear Programming Codes. Lecture Notes in Economics and Mathematical Systems 187 Springer–Verlag

5 Arguments

In addition to the arguments present in the interface of the primal routine, e04us includes some arguments specific to AD.
A brief summary of the AD specific arguments is given below. For the remainder, links are provided to the corresponding argument from the primal routine. A tooltip popup for all arguments can be found by hovering over the argument name in Section 2 and in this section.
1: ad_handlenag::ad::handle_t Input/Output
On entry: a configuration object that holds information on the differentiation strategy. Details on setting the AD strategy are described in AD handle object in the NAG AD Library Introduction.
2: m – Integer Input
3: n – Integer Input
4: nclin – Integer Input
5: ncnln – Integer Input
6: lda – Integer Input
7: ldcj – Integer Input
8: ldfj – Integer Input
9: ldr – Integer Input
10: a(lda, *) – ADTYPE array Input
11: bl(n+nclin+ncnln) – ADTYPE array Input
12: bu(n+nclin+ncnln) – ADTYPE array Input
13: y(m) – ADTYPE array Input
14: confun – Callable Input
confun needs to be callable with the specification listed below. This can be a C++ lambda, a functor or a (static member) function pointer. If using a lambda, parameters can be captured safely by reference. No copies of the callable are made internally.
If a null pointer is used as the argument, then a NAG supplied routine will be used as the argument for this parameter (C++ only).
For the Fortran interface, the NAG supplied routine e04ud_AD_m may be used as the actual argument for this parameter.
The specification of confun is:
Fortran Interface
Subroutine confun ( ad_handle, mode, ncnln, n, ldcj, needc, x, c, cjac, nstate, iuser, ruser)
Integer, Intent (In) :: ncnln, n, ldcj, needc(ncnln), nstate
Integer, Intent (Inout) :: mode, iuser(*)
ADTYPE, Intent (In) :: x(n)
ADTYPE, Intent (Inout) :: cjac(ldcj,n), ruser(*)
ADTYPE, Intent (Out) :: c(ncnln)
Type (c_ptr), Intent (Inout) :: ad_handle
C++ Interface
auto confun = [&]( const handle_t &ad_handle, Integer &mode, const Integer &ncnln, const Integer &n, const Integer &ldcj, const Integer needc[], const ADTYPE x[], ADTYPE c[], ADTYPE cjac[], const Integer &nstate)
1: ad_handlenag::ad::handle_t Input/Output
On entry: a handle to the AD handle object.
2: mode – Integer Input/Output
3: ncnln – Integer Input
4: n – Integer Input
5: ldcj – Integer Input
6: needc – Integer array Input
7: xADTYPE array Input
8: cADTYPE array Output
9: cjacADTYPE array Input/Output
10: nstate – Integer Input
*: iuser – Integer array User Workspace
*: ruserADTYPE array User Workspace
15: objfun – Callable Input
objfun needs to be callable with the specification listed below. This can be a C++ lambda, a functor or a (static member) function pointer. If using a lambda, parameters can be captured safely by reference. No copies of the callable are made internally.
The specification of objfun is:
Fortran Interface
Subroutine objfun ( ad_handle, mode, m, n, ldfj, needfi, x, f, fjac, nstate, iuser, ruser)
Integer, Intent (In) :: m, n, ldfj, needfi, nstate
Integer, Intent (Inout) :: mode, iuser(*)
ADTYPE, Intent (In) :: x(n)
ADTYPE, Intent (Inout) :: fjac(ldfj,n), ruser(*)
ADTYPE, Intent (Out) :: f(m)
Type (c_ptr), Intent (Inout) :: ad_handle
C++ Interface
auto objfun = [&]( const handle_t &ad_handle, Integer &mode, const Integer &m, const Integer &n, const Integer &ldfj, const Integer &needfi, const ADTYPE x[], ADTYPE f[], ADTYPE fjac[], const Integer &nstate)
1: ad_handlenag::ad::handle_t Input/Output
On entry: a handle to the AD handle object.
2: mode – Integer Input/Output
3: m – Integer Input
4: n – Integer Input
5: ldfj – Integer Input
6: needfi – Integer Input
7: xADTYPE array Input
8: fADTYPE array Output
9: fjacADTYPE array Input/Output
10: nstate – Integer Input
*: iuser – Integer array User Workspace
*: ruserADTYPE array User Workspace
16: iter – Integer Output
17: istate(n+nclin+ncnln) – Integer array Input/Output
18: c(max(1,ncnln)) – ADTYPE array Output
19: cjac(ldcj, *) – ADTYPE array Input/Output
Please consult Overwriting of Inputs in the NAG AD Library Introduction.
20: f(m) – ADTYPE array Output
21: fjac(ldfj, n) – ADTYPE array Input/Output
Please consult Overwriting of Inputs in the NAG AD Library Introduction.
22: clamda(n+nclin+ncnln) – ADTYPE array Input/Output
Please consult Overwriting of Inputs in the NAG AD Library Introduction.
23: objfADTYPE Output
24: r(ldr, n) – ADTYPE array Input/Output
Please consult Overwriting of Inputs in the NAG AD Library Introduction.
25: x(n) – ADTYPE array Input/Output
Please consult Overwriting of Inputs in the NAG AD Library Introduction.
26: iwork(liwork) – Integer array Workspace
27: liwork – Integer Input
28: work(lwork) – ADTYPE array Workspace
29: lwork – Integer Input
*: iuser(*) – Integer array User Workspace
*: ruser(*) – ADTYPE array User Workspace
Please consult Overwriting of Inputs in the NAG AD Library Introduction.
30: lwsav(120) – logical array Communication Array
The arrays lwsav, iwsav and rwsav must not be altered between calls to any of the routines routine, routine or routine.
31: iwsav(610) – Integer array Communication Array
The arrays lwsav, iwsav and rwsav must not be altered between calls to any of the routines routine, routine or routine.
32: rwsav(475) – ADTYPE array Communication Array
The arrays lwsav, iwsav and rwsav must not be altered between calls to any of the routines routine, routine or routine.
33: ifail – Integer Input/Output

6 Error Indicators and Warnings

e04us preserves all error codes from e04usf and in addition can return:
ifail=-89
An unexpected AD error has been triggered by this routine. Please contact NAG.
See Error Handling in the NAG AD Library Introduction for further information.
ifail=-199
The routine was called using a strategy that has not yet been implemented.
See AD Strategies in the NAG AD Library Introduction for further information.
ifail=-444
A C++ exception was thrown.
The error message will show the details of the C++ exception text.
ifail=-899
Dynamic memory allocation failed for AD.
See Error Handling in the NAG AD Library Introduction for further information.

7 Accuracy

Not applicable.

8 Parallelism and Performance

e04us is not threaded in any implementation.

9 Further Comments

None.

10 Example

The following examples are variants of the example for e04usf, modified to demonstrate calling the NAG AD Library.
Description of the primal example.
This example is based on Problem 57 in Hock and Schittkowski (1981) and involves the minimization of the sum of squares function
F(x) = 12 i=1 44 (yi-fi(x)) 2 ,  
where
fi (x) = x1 + (0.49-x1) e -x2 (ai-8)  
and
i yi ai i yi ai 1 0.49 8 23 0.41 22 2 0.49 8 24 0.40 22 3 0.48 10 25 0.42 24 4 0.47 10 26 0.40 24 5 0.48 10 27 0.40 24 6 0.47 10 28 0.41 26 7 0.46 12 29 0.40 26 8 0.46 12 30 0.41 26 9 0.45 12 31 0.41 28 10 0.43 12 32 0.40 28 11 0.45 14 33 0.40 30 12 0.43 14 34 0.40 30 13 0.43 14 35 0.38 30 14 0.44 16 36 0.41 32 15 0.43 16 37 0.40 32 16 0.43 16 38 0.40 34 17 0.46 18 39 0.41 36 18 0.45 18 40 0.38 36 19 0.42 20 41 0.40 38 20 0.42 20 42 0.40 38 21 0.43 20 43 0.39 40 22 0.41 22 44 0.39 42  
subject to the bounds
x1-0.4 x2-4.0  
to the general linear constraint
x1+x21.0  
and to the nonlinear constraint
0.49x2-x1 x2 0.09 .  
The initial point, which is infeasible, is
x0=(0.4,0.0)T  
and F(x0)=0.002241.
The optimal solution (to five figures) is
x*=(0.41995,1.28484)T,  
and F(x*)=0.01423. The nonlinear constraint is active at the solution.
The document for e04uq includes an example program to solve the same problem using some of the optional parameters described in Section 12.

10.1 Adjoint modes

Language Source File Data Results
Fortran e04us_a1t1w_fe.f90 e04us_a1t1w_fe.d e04us_a1t1w_fe.r
Fortran e04us_a1w_fe.f90 e04us_a1w_fe.d e04us_a1w_fe.r
C++ e04us_a1_algo_dcoe.cpp None e04us_a1_algo_dcoe.r
C++ e04us_a1t1_algo_dcoe.cpp None e04us_a1t1_algo_dcoe.r

10.2 Tangent modes

Language Source File Data Results
Fortran e04us_t1w_fe.f90 e04us_t1w_fe.d e04us_t1w_fe.r
Fortran e04us_t2w_fe.f90 e04us_t2w_fe.d e04us_t2w_fe.r
C++ e04us_t1_algo_dcoe.cpp None e04us_t1_algo_dcoe.r
C++ e04us_t2_algo_dcoe.cpp None e04us_t2_algo_dcoe.r

10.3 Passive mode

Language Source File Data Results
Fortran e04us_p0w_fe.f90 e04us_p0w_fe.d e04us_p0w_fe.r
C++ e04us_passive_dcoe.cpp None e04us_passive_dcoe.r