e04uf {NAGFWrappers}R Documentation

e04uf: Minimum, function of several variables, sequential QP method, nonlinear constraints, using function values and optionally first derivatives (reverse communication, comprehensive)

Description

e04uf is designed to minimize an arbitrary smooth 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. It is not intended for large sparse problems.

e04uf may also be used for unconstrained, bound-constrained and linearly constrained optimization.

e04uf uses reverse communication for evaluating the objective function, the nonlinear constraint functions and any of their derivatives.

Usage

e04uf(irevcm, nclin, a, bl, bu, iter, istate, c, cjac, clamda, objf, objgrd, r, x, iwork, work, cwsav, lwsav, iwsav, rwsav, optlist,
      n = nrow(objgrd),
      ncnln = nrow(c))

Arguments

irevcm

integer

Must be set to 0.

must remain unchanged, unless you wish to terminate the solution to the current problem. In this case irevcm may be set to a negative value and then e04uf will take a final exit with ifail set to this value of irevcm.

nclin

integer

n_L

, the number of general linear constraints.

a

double array

The ith row of the array a must contain the ith row of the matrix A_L of general linear constraints in eqn1. That is, the ith row contains the coefficients of the ith general linear constraint for i=1 . . . nclin.

bl

double array

bu

double array

Bl must contain the lower bounds and bu the upper bounds, for all the constraints in the following order. The first n elements of each array must contain the bounds on the variables, the next n_L elements the bounds for the general linear constraints (if any) and the next n_N elements the bounds for the general nonlinear constraints (if any). To specify a nonexistent lower bound (i.e., l_j = - infinity), set bl[j] <= - bigbnd, and to specify a nonexistent upper bound (i.e., u_j = + infinity), set bu[j] >= bigbnd; the default value of bigbnd is 10^20, but this may be changed by the optional argument infiniteboundsize. To specify the jth constraint as an equality, set bl[j] = bu[j] = β, say, where abs(β) < bigbnd.

iter

integer

Must remain unchanged from a previous call to e04uf.

istate

integer array

Need not be set if the (default) optional argument coldstart is used.

c

double array

Need not be set.

If irevcm=4, 6 and needc[i] > 0, c[i] must contain the value of the ith constraint at x. The remaining elements of c, corresponding to the non-positive elements of needc, are ignored.

cjac

double array

In general, cjac need not be initialized before the call to e04uf. However, if the optional argument derivativelevel=2, 3, you may optionally set the constant elements of cjac. Such constant elements need not be re-assigned on subsequent intermediate exits.

If irevcm=5, 6 and needc[i] > 0, the ith row of cjac must contain the available elements of the vector \nablac_i given by

\nablac_i = (( \partial c_i)/( \partial x_1) , ( \partial c_i)/( \partial x_2) , . . . , ( \partial c_i)/( \partial x_n))^T,

where ( \partial c_i)/( \partial x_j) is the partial derivative of the ith constraint with respect to the jth variable, evaluated at the point x. The remaining rows of cjac, corresponding to non-positive elements of needc, are ignored.

clamda

double array

Need not be set if the (default) optional argument coldstart is used.

objf

double

Need not be set.

If irevcm=1, 3, objf must be set to the value of the objective function at x.

objgrd

double array

Need not be set.

If irevcm=2, 3, objgrd must contain the available elements of the gradient evaluated at x.

r

double array

Need not be initialized if the (default) optional argument coldstart is used.

x

double array

An initial estimate of the solution.

iwork

integer array

work

double array

cwsav

string array

string array

lwsav

boolean array

iwsav

integer array

rwsav

double array

The arrays lwsav, iwsav, rwsav and cwsav must not be altered between calls to any of the functions e04wb, e04uf, e04ud e04ue.

optlist

options list

Optional parameters may be listed, as shown in the following table:

Name Type Default
Central Difference Interval double Default values are computed
Cold Start Default
Warm Start
Crash Tolerance double Default = 0.01
Defaults
Derivative Level integer Default = 3
Difference Interval double Default values are computed
Feasibility Tolerance double Default = sqrt(ε)
Function Precision double Default = ε^0.9
Hessian Default = NO
Infinite Bound Size double Default = 10^20
Infinite Step Size double Default = max(bigbnd, 10^20)
Line Search Tolerance double Default = 0.9
Linear Feasibility Tolerance double Default = sqrt(ε)
Nonlinear Feasibility Tolerance double Default = ε^0.33 or sqrt(ε)
List
Nolist
Major Iteration Limit integer Default = max(50, 3(n + n_L) + 10n_N)
Iteration Limit
Iters
Itns
Major Print Level integer
Major Print Level integer
Print Level = 0
Print Level = 0
Minor Iteration Limit integer Default = max(50, 3(n + n_L + n_N))
Minor Print Level integer Default = 0
Monitoring File integer Default = - 1
Optimality Tolerance double Default = ε_r^0.8
Start Objective Check At Variable integer Default = 1
Stop Objective Check At Variable integer Default = n
Start Constraint Check At Variable integer Default = 1
Stop Constraint Check At Variable integer Default = n
Step Limit double Default = 2.0
Verify Level integer Default = 0
Verify
Verify Constraint Gradients
Verify Gradients
Verify Objective Gradients
n

integer: default = nrow(objgrd)

n

, the number of variables.

ncnln

integer: default = nrow(c)

n_N

, the number of nonlinear constraints.

Details

R interface to the NAG Fortran routine E04UFF.

Value

IREVCM

integer

Specifies what values the calling program must assign to arguments of e04uf before re-entering the function.

irevcm = 1

: Set objf to the value of the objective function F(x).

irevcm = 2

: Set objgrd[<j] to the value ( \partial F)/( \partial x_j) if available for j=1 . . . n.

irevcm = 3

: Set objf and objgrd[j] as for irevcm = 1 and irevcm = 2.

irevcm = 4

: Set c[i] to the value of the constraint function c_i(x), for each i such that needc[i] > 0.

irevcm = 5

: Set cjac[i, j] to the value ( \partial c_i)/( \partial x_j) if available, for each i such that needc[i] > 0 and j = 1 , 2 , . . . , n.

irevcm = 6

: Set c[i] and cjac[i, j] as for irevcm = 4 and irevcm = 5.

irevcm = 0

.

ITER

integer

The number of major iterations performed.

ISTATE

integer array

The status of the constraints in the QP working set at the point returned in x. The significance of each possible value of istate[j] is as follows:

C

double array

If ncnln > 0, c[i] contains the value of the ith nonlinear constraint function c_i at the final iterate for i=1 . . . ncnln.

CJAC

double array

If ncnln > 0, cjac contains the Jacobian matrix of the nonlinear constraint functions at the final iterate, i.e., cjac[i, j] contains the partial derivative of the ith constraint function with respect to the jth variable for j=1 . . . n for i=1 . . . ncnln.

CLAMDA

double array

The values of the QP multipliers from the last QP subproblem. clamda[j] should be non-negative if istate[j] = 1 and non-positive if istate[j] = 2.

OBJF

double

The value of the objective function at the final iterate.

OBJGRD

double array

The gradient of the objective function at the final iterate (or its finite difference approximation).

R

double array

If hessian=NO, r contains the upper triangular Cholesky factor R of Q^TtildeHQ, an estimate of the transformed and reordered Hessian of the Lagrangian at x (see eqn6 in the optional parameter description in the Fortran Library documentation).

X

double array

The point x at which the objective function, constraint functions or their derivatives are to be evaluated.

The final estimate of the solution.

NEEDC

integer array

If irevcm >= 4, needc specifies the indices of the elements of c and/or cjac that must be assigned. If needc[i] > 0, then the ith element of c and/or the available elements of the ith row of cjac must be evaluated at x.

IWORK

integer array

WORK

double array

The amounts of workspace provided and required may be (by default for e04uf) output on the current advisory message unit (as defined by x04ab). As an alternative to computing liwork and lwork from the formulae given above, you may prefer to obtain appropriate values from the output of a preliminary run with liwork and lwork set to 1. (e04uf will then terminate with ifail =9.)

CWSAV

string array

The arrays lwsav, iwsav, rwsav and cwsav must not be altered between calls to any of the functions e04wb, e04uf, e04ud e04ue.

string array

The arrays lwsav, iwsav, rwsav and cwsav must not be altered between calls to any of the functions e04wb, e04uf, e04ud e04ue.

LWSAV

boolean array

The arrays lwsav, iwsav, rwsav and cwsav must not be altered between calls to any of the functions e04wb, e04uf, e04ud e04ue.

IWSAV

integer array

The arrays lwsav, iwsav, rwsav and cwsav must not be altered between calls to any of the functions e04wb, e04uf, e04ud e04ue.

RWSAV

double array

The arrays lwsav, iwsav, rwsav and cwsav must not be altered between calls to any of the functions e04wb, e04uf, e04ud e04ue.

IFAIL

integer

ifail =0

unless the function detects an error or a warning has been flagged (see the Errors section in Fortran library documentation).

Author(s)

NAG

References

http://www.nag.co.uk/numeric/FL/nagdoc_fl23/pdf/E04/e04uff.pdf

Examples


optlist <- list()

ifail <- 0
iwork <- as.matrix(mat.or.vec(0, 0))
work <- as.matrix(mat.or.vec(0, 0))
cwsav <- as.matrix(mat.or.vec(0, 0))
lwsav <- as.matrix(mat.or.vec(0, 0))
iwsav <- as.matrix(mat.or.vec(0, 0))
rwsav <- as.matrix(mat.or.vec(0, 0))

irevcm <- 0

nclin <- 1

a <- matrix(c(1, 1, 1, 1), nrow = 1, ncol = 4, byrow = TRUE)



bl <- matrix(c(1, 1, 1, 1, -1e+25, -1e+25, 25), nrow = 7, 
    ncol = 1, byrow = TRUE)



bu <- matrix(c(5, 5, 5, 5, 20, 40, 1e+25), nrow = 7, 
    ncol = 1, byrow = TRUE)



iter <- 0

istate <- as.matrix(mat.or.vec(7, 1))

c <- matrix(c(0, 0), nrow = 2, ncol = 1, byrow = TRUE)



cjac <- matrix(c(0, 0, 0, 0, 0, 0, 0, 0), nrow = 2, 
    ncol = 4, byrow = TRUE)



clamda <- as.matrix(mat.or.vec(7, 1))

objf <- 0

objgrd <- as.matrix(mat.or.vec(4, 1))

r <- as.matrix(mat.or.vec(4, 4))

x <- matrix(c(1, 5, 5, 1), nrow = 4, ncol = 1, byrow = TRUE)



iwork <- as.matrix(mat.or.vec(17, 1))

work <- as.matrix(mat.or.vec(192, 1))

if (ifail == 0) {
    
    ans <- e04uf(irevcm, nclin, a, bl, bu, iter, istate, c, cjac, 
        clamda, objf, objgrd, r, x, iwork, work, cwsav, lwsav, 
        iwsav, rwsav, optlist)
    irevcm <- ans$IREVCM
    iter <- ans$ITER
    istate <- ans$ISTATE
    c <- ans$C
    cjac <- ans$CJAC
    clamda <- ans$CLAMDA
    objf <- ans$OBJF
    objgrd <- ans$OBJGRD
    r <- ans$R
    x <- ans$X
    needc <- ans$NEEDC
    iwork <- ans$IWORK
    work <- ans$WORK
    cwsav <- ans$CWSAV
    lwsav <- ans$LWSAV
    iwsav <- ans$IWSAV
    rwsav <- ans$RWSAV
    ifail <- ans$IFAIL
    while (irevcm > 0) {
        if (irevcm == 1 || irevcm == 3) {
            
            objf <- x[1] %*% x[4] %*% (x[1] + x[2] + x[3]) + 
                x[3]
            
        }
        if (irevcm == 2 || irevcm == 3) {
            
            objgrd[1] <- x[4] %*% (2 %*% x[1] + x[2] + x[3])
            
            objgrd[2] <- x[1] %*% x[4]
            
            objgrd[3] <- x[1] %*% x[4] + 1
            
            objgrd[4] <- x[1] %*% (x[1] + x[2] + x[3])
            
        }
        if (irevcm == 4 || irevcm == 6) {
            
            if (needc[1] > 0) {
                
                c[1] <- x[1]^2 + x[2]^2 + x[3]^2 + x[4]^2
                
            }
            if (needc[2] > 0) {
                
                c[2] <- x[1] %*% x[2] %*% x[3] %*% x[4]
                
            }
        }
        if (irevcm == 5 || irevcm == 6) {
            
            if (needc[1] > 0) {
                
                cjac[1, 1] <- 2 %*% x[1]
                
                cjac[1, 2] <- 2 %*% x[2]
                
                cjac[1, 3] <- 2 %*% x[3]
                
                cjac[1, 4] <- 2 %*% x[4]
                
            }
            if (needc[2] > 0) {
                
                cjac[2, 1] <- x[2] %*% x[3] %*% x[4]
                
                cjac[2, 2] <- x[1] %*% x[3] %*% x[4]
                
                cjac[2, 3] <- x[1] %*% x[2] %*% x[4]
                
                cjac[2, 4] <- x[1] %*% x[2] %*% x[3]
                
            }
        }
        ans <- e04uf(irevcm, nclin, a, bl, bu, iter, istate, 
            c, cjac, clamda, objf, objgrd, r, x, iwork, work, 
            cwsav, lwsav, iwsav, rwsav, optlist)
        irevcm <- ans$IREVCM
        iter <- ans$ITER
        istate <- ans$ISTATE
        c <- ans$C
        cjac <- ans$CJAC
        clamda <- ans$CLAMDA
        objf <- ans$OBJF
        objgrd <- ans$OBJGRD
        r <- ans$R
        x <- ans$X
        needc <- ans$NEEDC
        iwork <- ans$IWORK
        work <- ans$WORK
        cwsav <- ans$CWSAV
        lwsav <- ans$LWSAV
        iwsav <- ans$IWSAV
        rwsav <- ans$RWSAV
        ifail <- ans$IFAIL
    }
    if (ifail == 0) {
        
        writeLines(toString(cat(sprintf("\n Varbl Istate Value Lagr Mult\n", 
            "\n"))))
        
        
        for (i in c(1:4)) {
            istate <- ans$ISTATE
            
            x <- ans$X
            
            clamda <- ans$CLAMDA
            
            writeLines(toString(cat(sprintf(" V %3d %3d %14.4f %12.4f \n", 
                i, istate[i], x[i], clamda[i], "\n"))))
            
        }
        
        ax <- a %*% x
        writeLines(toString(cat(sprintf("\n L Con Istate Value Lagr Mult\n", 
            "\n"))))
        
        
        for (i in c(5:(4 + nclin))) {
            j <- i - 4
            
            istate <- ans$ISTATE
            
            
            clamda <- ans$CLAMDA
            writeLines(toString(cat(sprintf(" L %3d %3d %14.4f %12.4f\n", 
                j, istate[i], ax[j], clamda[i], "\n"))))
            
        }
        writeLines(toString(cat(sprintf("\n L Con Istate Value Lagr Mult\n", 
            "\n"))))
        
        
        for (i in c((5 + nclin):(6 + nclin))) {
            j <- i - 4 - nclin
            
            istate <- ans$ISTATE
            
            c <- ans$C
            
            clamda <- ans$CLAMDA
            
            writeLines(toString(cat(sprintf(" N %3d %3d %14.4f%12.4f\n", 
                j, istate[i], c[j], clamda[i], "\n"))))
            
        }
        objf <- ans$OBJF
        
        writeLines(toString(cat(sprintf("\n Final objective value = %15.7f\n", 
            objf, "\n"))))
        
        
    }
} 


[Package NAGFWrappers version 24.0 Index]