harConstraints {hitandrun} | R Documentation |
Constraint formulation utility functions
Description
These utility functions generate linear constraints
Usage
simplexConstraints(n)
lowerBoundConstraint(n, i, x)
upperBoundConstraint(n, i, x)
lowerRatioConstraint(n, i, j, x)
upperRatioConstraint(n, i, j, x)
exactRatioConstraint(n, i, j, x)
ordinalConstraint(n, i, j)
mergeConstraints(...)
Arguments
n |
Number of dimensions (vector components) |
i |
Index of first component |
j |
Index of second component |
x |
Scalar bound |
... |
Constraint definitions, or a single list of constraint definitions |
Details
See har
for a description of the constraint format.
simplexConstraints
encodes the n-simplex: and
lowerBoundConstraint
encodes
upperBoundConstraint
encodes
lowerRatioConstraint
encodes
upperRatioConstraint
encodes
exactRatioConstraint
encodes
ordinalConstraint
encodes
mergeConstraints
merges the constraints it is given. Alternatively, the function takes a single list of constraint definitions which are to be merged.
Value
A constraint definition (concatenation of the given constraint definitions).
Author(s)
Gert van Valkenhoef
See Also
eliminateRedundant
hitandrun
har
Examples
# create an ordinal constraint
c1 <- ordinalConstraint(2, 1, 2)
stopifnot(c1$constr == c(-1, 1))
stopifnot(c1$rhs == c(0))
stopifnot(c1$dir == c("<="))
# create our own constraints
c2 <- list(constr=t(c(-1, 0)), rhs=c(0), dir=c("<="))
c3 <- list(constr=t(c(1, 1)), rhs=c(1), dir=c("<="))
# merge the constraints into a single definition
c <- mergeConstraints(c1, c2, c3)
stopifnot(c$constr == rbind(c(-1, 1), c(-1, 0), c(1, 1)))
stopifnot(c$rhs == c(0, 0, 1))
stopifnot(c$dir == c("<=", "<=", "<="))
# test the alternative (list) method
l <- mergeConstraints(list(c1, c2, c3))
stopifnot(c$constr == l$constr)
stopifnot(c$rhs == l$rhs)
stopifnot(c$dir == l$dir)
# test iteratively merging
l <- mergeConstraints(mergeConstraints(c1, c2), c3)
stopifnot(c$constr == l$constr)
stopifnot(c$rhs == l$rhs)
stopifnot(c$dir == l$dir)