lincon: Linear Constraints

Description Usage Arguments Details Value See Also Examples

Description

Define linear equality and inequality constraints of the form

A x + d dir val

Usage

1
2
lincon(A, d=rep(0, nrow(A)), dir=rep("==",nrow(A)), val=rep(0, nrow(A)), 
   id=1:ncol(A), use=rep(TRUE,nrow(A)), name=rownames(A))

Arguments

A

Numeric matrix of the constraint coefficients.

d

Numeric vector.

dir

Character vector with the directions of the constraints. Each element must be one of "<=", "==", and ">=".

val

Numeric vector with threshold values.

id

Vector (if present), 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.

use

Logical vector indicating the constraints to be included in the optimization problem. If use[i]=FALSE, then linear constraint i does not affect the result, but the value of the linear function A[i,] x + d[i] will be reported by function validate.

name

Vector with names of the constraints.

Details

Define linear inequality and equality constraints of the form

A x + d dir val

(component wise). If parameter id is specified, then vector x contains only the indicated variables.

Value

An object of class linCon.

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
### Quadratic programming with linear constraints       ###
### Example from animal breeding                        ###
### The mean kinship in the offspring x'Qx+d is minized ###
### and the mean breeding value is restricted.          ###

data(phenotype)
data(myQ)

A   <- t(model.matrix(~Sex+BV-1, data=phenotype))
A[,1:5]
val <- c(0.5, 0.5, 0.40)
dir <- c("==","==",">=")

mycop <- cop(f  = quadfun(Q=myQ, d=0.001, name="Kinship", id=rownames(myQ)), 
             lb = lbcon(0,  id=phenotype$Indiv), 
             ub = ubcon(NA, id=phenotype$Indiv),
             lc = lincon(A=A, dir=dir, val=val, id=phenotype$Indiv))

res <- solvecop(mycop, solver="cccp", quiet=FALSE)

validate(mycop, res)

#            valid solver  status
#             TRUE   cccp optimal
#
#   Variable     Value      Bound    OK?
#   -------------------------------------
#   Kinship      0.0322 min        :      
#   -------------------------------------
#   lower bounds all x  >=  lb     : TRUE 
#   Sexfemale    0.5    ==  0.5    : TRUE 
#   Sexmale      0.5    ==  0.5    : TRUE 
#   BV           0.4    >=  0.4    : TRUE 
#   -------------------------------------

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