quadcon {optiSolve} | R Documentation |
Quadratic Constraint
Description
Define a quadratic constraint of the form
x'Qx + a' x + d \leq val
Usage
quadcon(Q, a=rep(0, nrow(Q)), d=0, dir="<=", val,
id=1:nrow(Q), name="quadratic", use=TRUE)
Arguments
Q |
Numeric symmetric matrix of the constraint coefficients. |
a |
Numeric vector. |
d |
Numeric value. |
dir |
Character string |
val |
Numeric threshold value, which is the upper bound for the quadratic function. |
id |
Vector defining the names of the variables to which the constraint applies. Each variable name corresponds to one component of |
name |
Name for the constraint. |
use |
Logical value indicating if the constraint should be included in the optimization problem. If |
Details
Define a quadratic inequality constraint of the form
x'Qx + a' x + d \leq val.
Vector x
contains only the variables included in argument id
.
Value
An object of class quadCon
.
See Also
The main function for solving constrained programming problems is solvecop
.
Examples
### Linear programming with linear and quadratic constraints ###
### Example from animal breeding ###
### The mean breeding value BV is maximized whereas the ###
### mean kinship in the offspring x'Qx+d is restricted ###
data(phenotype)
data(myQ)
A <- t(model.matrix(~Sex-1, data=phenotype))
A[,1:5]
val <- c(0.5, 0.5)
dir <- c("==","==")
mycop <- cop(f = linfun(a=phenotype$BV, id=phenotype$Indiv, name="BV"),
max= TRUE,
lb = lbcon(0, id=phenotype$Indiv),
ub = ubcon(NA, id=phenotype$Indiv),
lc = lincon(A=A, dir=dir, val=val, id=phenotype$Indiv),
qc = quadcon(Q=myQ, d=0.001, val=0.035, name="Kinship", id=rownames(myQ)))
res <- solvecop(mycop, solver="cccp2", quiet=FALSE)
validate(mycop, res)
# valid solver status
# TRUE cccp2 optimal
#
# Variable Value Bound OK?
# -------------------------------------
# BV 0.7667 max :
# -------------------------------------
# lower bounds all x >= lb : TRUE
# Sexfemale 0.5 == 0.5 : TRUE
# Sexmale 0.5 == 0.5 : TRUE
# Kinship 0.035 <= 0.035 : TRUE
# -------------------------------------