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: kwk0\forall_k w_{k} \geq 0 and kwk=1\sum_k w_k = 1

lowerBoundConstraint encodes wixw_{i} \geq x

upperBoundConstraint encodes wixw_{i} \leq x

lowerRatioConstraint encodes wi/wjxw_{i} / w_{j} \geq x

upperRatioConstraint encodes wi/wjxw_{i} / w_{j} \leq x

exactRatioConstraint encodes wi/wj=xw_{i} / w_{j} = x

ordinalConstraint encodes wiwjw_{i} \geq w_{j}

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)

[Package hitandrun version 0.5-6 Index]