e04uc {NAGFWrappers} R Documentation

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

### Description

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

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

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

### Usage

e04uc(a, bl, bu, confun, objfun, istate, cjac, clamda, r, 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; 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.

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 element vector x. If there are no nonlinear constraints (i.e., ncnln = 0), confun will never be called by e04uc and confun may be the dummy function e04udm. (e04udm 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,C,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,OBJGRD) = objfun(mode,n,x,objgrd,nstate) 

istate

integer array

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

cjac

double array

In general, cjac need not be initialized before the call to e04uc. However, if derivativelevel=2, 3, you may optionally set the constant elements of cjac (see argument nstate in the description of confun). Such constant elements need not be re-assigned on subsequent calls to confun.

clamda

double array

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

r

double array

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

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 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 no 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 Default for e04uc = 10 Print Level integer Default for e04uc = 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 integer Verify Constraint Gradients integer Verify Gradients integer Verify Objective Gradients integer
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 E04UCF.

### Value

 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. (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. 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). If hessian=YES, r contains the upper triangular Cholesky factor R of H, the approximate (untransformed) Hessian of the Lagrangian, with the variables in the natural order. 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).

NAG

### Examples


optlist <- list()

ifail <- 0
confun = function(mode, ncnln, n, needc, x, cjac,
nstate) {
ldcj <- nrow(cjac)

c <- as.matrix(mat.or.vec(ncnln, 1))

if (nstate == 1) {

cjac <- as.matrix(mat.or.vec(ldcj, n))

}

if (needc[1] > 0) {

if (mode == 0 || mode == 2) {

c[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) {

c[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), C = as.matrix(c), CJAC = as.matrix(cjac))
}
objfun = function(mode, n, x, objgrd, nstate) {

if (mode == 0 || mode == 2) {

objf <- x[1] %*% x[4] %*% (x[1] + x[2] + x[3]) + x[3]

}
else {

objf <- 0
}

if (mode == 1 || mode == 2) {

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])

}
list(MODE = as.integer(mode), OBJF = objf, OBJGRD = as.matrix(objgrd))
}

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))

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

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

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

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

e04uc(a, bl, bu, confun, objfun, istate, cjac, clamda,
r, x, optlist)



[Package NAGFWrappers version 24.0 Index]