e04nf {NAGFWrappers} | R Documentation |
e04nf solves general quadratic programming problems. It is not intended for large sparse problems.
e04nf(a, bl, bu, cvec, h, qphess, istate, x, optlist, n = nrow(x), nclin = nrow(a))
a |
double array The ith row of a must contain the coefficients of the ith general linear constraint for i=1 . . . m_L. If nclin=0, a is not referenced. |
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, and the next m_L elements the bounds for the general linear 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. |
cvec |
double array The coefficients of the explicit linear term of the objective function when the problem is of type LP, QP2 (the default) and QP4. If the problem is of type FP, QP1, or QP3, cvec is not referenced. |
h |
double array May be used to store the quadratic term H of the QP objective function if desired. In some cases, you need not use h to store H explicitly (see the specification of function qphess). The elements of h are referenced only by function qphess. The number of rows of H is denoted by m, whose default value is n. (The optional argument hessianrows may be used to specify a value of m < n.) |
double array
May be used to store the quadratic term H of the QP objective function if desired. In some cases, you need not use h to store H explicitly (see the specification of function qphess). The elements of h are referenced only by function qphess. The number of rows of H is denoted by m, whose default value is n. (The optional argument hessianrows may be used to specify a value of m < n.)
qphess |
function In general, you need not provide a version of qphess, because a ‘default’ function with name e04nfu is included in the Library. However, the algorithm of e04nf requires only the product of H or H^TH and a vector x; and in some cases you may obtain increased efficiency by providing a version of qphess that avoids the need to define the elements of the matrices H or H^TH explicitly.
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
istate |
integer array Need not be set if the (default) optional argument coldstart is used. If the optional argument warmstart has been chosen, istate specifies the desired status of the constraints at the start of the feasibility phase. More precisely, the first n elements of istate refer to the upper and lower bounds on the variables, and the next m_L elements refer to the general linear constraints (if any). Possible values for istate[j] are as follows: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
x |
double array An initial estimate of the solution. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
optlist |
options list Optional parameters may be listed, as shown in the following table:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
n |
integer: default = nrow(x) n, the number of variables. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
nclin |
integer: default = nrow(a) m_L, the number of general linear constraints. |
R interface to the NAG Fortran routine E04NFF.
ISTATE |
integer array The status of the constraints in the working set at the point returned in x. The significance of each possible value of istate[j] is as follows: |
X |
double array The point at which e04nf terminated. If ifail =0, ifail =1, ifail =4, x contains an estimate of the solution. |
ITER |
integer The total number of iterations performed. |
OBJ |
double The value of the objective function at x if x is feasible, or the sum of infeasibilities at x otherwise. If the problem is of type FP and x is feasible, obj is set to zero. |
AX |
double array The final values of the linear constraints Ax. If nclin = 0, ax is not referenced. |
CLAMDA |
double array The values of the Lagrange multipliers for each constraint with respect to the current working set. The first n elements contain the multipliers for the bound constraints on the variables, and the next m_L elements contain the multipliers for the general linear constraints (if any). If istate[j] = 0 (i.e., constraint j is not in the working set), clamda[j] is zero. If x is optimal, clamda[j] should be non-negative if istate[j] = 1, non-positive if istate[j] = 2 and zero if istate[j] = 4. |
IFAIL |
integer ifail =0unless the function detects an error or a warning has been flagged (see the Errors section in Fortran library documentation). |
NAG
http://www.nag.co.uk/numeric/FL/nagdoc_fl23/pdf/E04/e04nff.pdf
optlist <- list() ifail <- 0 qphess = function(n, jthcol, h, x, iwsav) { ldh <- nrow(h) if (iwsav[365] == 3 || iwsav[365] == 4) { hx <- h %*% x } else if (iwsav[365] == 5 || iwsav[365] == 6) { hx <- t(h) %*% h %*% x } else { hx <- as.matrix(mat.or.vec(n, 1)) } list(HX = as.matrix(hx), IWSAV = as.matrix(iwsav)) } a <- matrix(c(1, 1, 1, 1, 1, 1, 1, 0.15, 0.04, 0.02, 0.04, 0.02, 0.01, 0.03, 0.03, 0.05, 0.08, 0.02, 0.06, 0.01, 0, 0.02, 0.04, 0.01, 0.02, 0.02, 0, 0, 0.02, 0.03, 0, 0, 0.01, 0, 0, 0.7, 0.75, 0.8, 0.75, 0.8, 0.97, 0, 0.02, 0.06, 0.08, 0.12, 0.02, 0.01, 0.97), nrow = 7, ncol = 7, byrow = TRUE) bl <- matrix(c(-0.01, -0.1, -0.01, -0.04, -0.1, -0.01, -0.01, -0.13, -1e+25, -1e+25, -1e+25, -1e+25, -0.0992, -0.003), nrow = 14, ncol = 1, byrow = TRUE) bu <- matrix(c(0.01, 0.15, 0.03, 0.02, 0.05, 1e+25, 1e+25, -0.13, -0.0049, -0.0064, -0.0037, -0.0012, 1e+25, 0.002), nrow = 14, ncol = 1, byrow = TRUE) cvec <- matrix(c(-0.02, -0.2, -0.2, -0.2, -0.2, 0.04, 0.04), nrow = 7, ncol = 1, byrow = TRUE) h <- matrix(c(2, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, -2, -2, 0, 0, 0, 0, 0, -2, -2), nrow = 7, ncol = 7, byrow = TRUE) istate <- as.matrix(mat.or.vec(14, 1)) x <- matrix(c(-0.01, -0.03, 0, -0.01, -0.1, 0.02, 0.01), nrow = 7, ncol = 1, byrow = TRUE) e04nf(a, bl, bu, cvec, h, qphess, istate, x, optlist)