quadcon: Quadratic Constraint

Description Usage Arguments Details Value See Also Examples

Description

Define a quadratic constraint of the form

x' Q x + a' x + d <= val

Usage

1
2
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 x. Variable names must be consistent across constraints.

name

Name for the constraint.

use

Logical value indicating if the constraint should be included in the optimization problem. If use=FALSE, then constraint does not affect the result, but the value of the quadratic function will be reported by function validate.

Details

Define a quadratic inequality constraint of the form

x' Q x + a' x + d <= 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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
### 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 
#   -------------------------------------

optiSolve documentation built on Oct. 13, 2021, 5:08 p.m.