e04wd {NAGFWrappers}R Documentation

e04wd: Solves the nonlinear programming (NP) problem

Description

e04wd 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.

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

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

The initialization function e04wc must have been called before to calling e04wd.

Usage

e04wd(a, bl, bu, confun, objfun, istate, ccon, cjac, clamda, h, x, optlist,
      n = nrow(x),
      nclin = nrow(a),
      ncnln = nrow(cjac))

Arguments

a

double array

The ith row of a contains 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; where bigbnd is the optional argument infiniteboundsize. To specify the jth constraint as an equality, set bl[j] = bu[j] = β, say, where abs(β) < bigbnd.

confun

function

confun must calculate the vector c(x) of nonlinear constraint functions and (optionally) its Jacobian, ( \partial c)/( \partial x), for a specified n-vector x. If there are no nonlinear constraints (i.e., ncnln = 0), e04wd will never call confun, so it may be the dummy function e04wdp. (e04wdp is included in the NAG Library). If there are nonlinear constraints, the first call to confun will occur before the first call to objfun.

(MODE,CCON,CJAC) = confun(mode,ncnln,n,needc,x,cjac,nstate)

objfun

function

objfun must calculate the objective function F(x) and (optionally) its gradient g(x) = ( \partial F)/( \partial x) for a specified n-vector x.

(MODE,OBJF,GRAD) = objfun(mode,n,x,grad,nstate)

istate

integer array

Is an integer array that need not be initialized if e04wd is called with the coldstart option (the default).

ccon

double array

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

cjac

double array

In general, cjac need not be initialized before the call to e04wd. However, if derivativelevel=2, 3, any constant elements of cjac may be initialized. Such elements need not be reassigned on subsequent calls to confun.

clamda

double array

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

h

double array

H need not be initialized if the (default) optional argument coldstart is used, and will be set to the identity.

x

double array

An initial estimate of the solution.

optlist

options list

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

Name Type Default
Central Difference Interval double Default = ε_r^(1)/(3)
Check Frequency integer Default = 60
Cold Start Default
Warm Start
Crash Option integer Default = 3
Crash Tolerance double Default = 0.1
Defaults
Derivative Level integer Default = 3
Derivative Linesearch Default
Nonderivative Linesearch
Difference Interval double Default = sqrt(ε_r)
Dump File integer Default = 0
Load File integer Default = 0
Elastic Weight double Default = 10^4
Expand Frequency integer Default = 10000
Factorization Frequency integer Default = 50
Function Precision double Default = ε^0.8
Hessian Full Memory Default if n <= 75
Hessian Limited Memory Default if n > 75
Hessian Frequency integer Default = 99999999
Hessian Updates integer Default = hessianfrequency if hessianfullmemory, 10 otherwise
Infinite Bound Size double Default = 10^20
Iterations Limit integer Default = max(1000010max(nn_L + n_N))
Linesearch Tolerance double Default = 0.9
Nolist Default
List
LU Density Tolerance double Default = 0.6
LU Singularity Tolerance double Default = ε^(2)/(3)
LU Factor Tolerance double Default = 1.10
LU Update Tolerance double Default = 1.10
LU Partial Pivoting Default
LU Complete Pivoting
LU Rook Pivoting
Major Feasibility Tolerance double Default = max(10^ - 6sqrt(ε))
Major Optimality Tolerance double Default = 2max(10^ - 6sqrt(ε))
Major Iterations Limit integer Default = max(10003max(nn_L + n_N))
Major Print Level integer Default = 000001
Major Step Limit double Default = 2.0
Minimize Default
Maximize
Feasible Point
Minor Feasibility Tolerance
Feasibility Tolerance double Default = max10^ - 6sqrt(ε)
Minor Iterations Limit integer Default = 500
Minor Print Level integer Default = 1
New Basis File integer Default = 0
Backup Basis File integer Default = 0
Save Frequency integer Default = 100
New Superbasics Limit integer Default = 99
Old Basis File integer Default = 0
Partial Price integer Default = 1
Pivot Tolerance double Default = ε^(2)/(3)
Print File integer Default = 0
Print Frequency integer Default = 100
Proximal Point Method integer Default = 1
Punch File integer Default = 0
Insert File integer Default = 0
QPSolver Cholesky Default
QPSolver CG
QPSolver QN
Reduced Hessian Dimension integer Default = min(2000n)
Scale Option integer Default = 0
Scale Tolerance double Default = 0.9
Scale Print
Solution File integer Default = 0
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
Summary File integer Default = 0
Summary Frequency integer Default = 100
Superbasics Limit integer Default = n
Suppress Parameters
System Information No Default
System Information Yes
Timing Level integer Default = 0
Unbounded Objective double Default = 1.0E+15
Unbounded Step Size double Default = bigbnd
Verify Level integer Default = 0
Violation Limit double Default = 1.0E+6
n

integer: default = nrow(x)

n

, the number of variables.

nclin

integer: default = nrow(a)

n_L

, the number of general linear constraints.

ncnln

integer: default = nrow(cjac)

n_N

, the number of nonlinear constraints.

Details

R interface to the NAG Fortran routine E04WDF.

Value

MAJITS

integer

The number of major iterations performed.

ISTATE

integer array

Describes the status of the constraints l <= r(x) <= u. For the jth lower or upper bound, j = 1 , 2 , . . . , n + nclin + ncnln, the possible values of istate[j] are as follows (see the figure in the Fortran library documentation). δ is the appropriate feasibility tolerance.

CCON

double array

If ncnln > 0, ccon[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. (See the discussion of argument cjac under confun.)

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.

GRAD

double array

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

H

double array

Contains the Hessian of the Lagrangian at the final estimate x.

X

double array

The final estimate of the solution.

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/e04wdf.pdf

Examples


optlist <- list()

ifail <- 0
confun = function(mode, ncnln, n, needc, x, cjac, 
    nstate) {
    ldcj <- nrow(cjac)
    
    ccon <- as.matrix(mat.or.vec(ncnln, 1))
    
    if (nstate == 1) {
        
        cjac <- as.matrix(mat.or.vec(ncnln, n))
        
    }
    
    if (needc[1] > 0) {
        
        if (mode == 0 || mode == 2) {
            
            ccon[1] <- x[1]^2 + x[2]^2 + x[3]^2 + x[4]^2
            
        }
        if (mode == 1 || mode == 2) {
            
            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) {
        
        if (mode == 0 || mode == 2) {
            
            ccon[2] <- x[1] %*% x[2] %*% x[3] %*% x[4]
            
        }
        if (mode == 1 || mode == 2) {
            
            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]
            
        }
    }
    list(MODE = as.integer(mode), CCON = as.matrix(ccon), CJAC = as.matrix(cjac))
}
objfun = function(mode, n, x, grad, nstate) {
    
    
    if (mode == 0 || mode == 2) {
        
        objf <- x[1] %*% x[4] %*% (x[1] + x[2] + x[3]) + x[3]
        
    }
    
    if (mode == 1 || mode == 2) {
        
        grad[1] <- x[4] %*% (2 %*% x[1] + x[2] + x[3])
        
        grad[2] <- x[1] %*% x[4]
        
        grad[3] <- x[1] %*% x[4] + 1
        
        grad[4] <- x[1] %*% (x[1] + x[2] + x[3])
        
    }
    list(MODE = as.integer(mode), OBJF = objf, GRAD = as.matrix(grad))
}

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)



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

ccon <- as.matrix(mat.or.vec(2, 1))

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

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

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

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



e04wd(a, bl, bu, confun, objfun, istate, ccon, cjac, 
    clamda, h, x, optlist) 


[Package NAGFWrappers version 24.0 Index]