Learn R Programming

hitandrun (version 0.5-6)

harConstraints: 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

Value

A constraint definition (concatenation of the given constraint definitions).

Details

See har for a description of the constraint format.

simplexConstraints encodes the n-simplex: \(\forall_k w_{k} \geq 0\) and \(\sum_k w_k = 1\)

lowerBoundConstraint encodes \(w_{i} \geq x\)

upperBoundConstraint encodes \(w_{i} \leq x\)

lowerRatioConstraint encodes \(w_{i} / w_{j} \geq x\)

upperRatioConstraint encodes \(w_{i} / w_{j} \leq x\)

exactRatioConstraint encodes \(w_{i} / w_{j} = x\)

ordinalConstraint encodes \(w_{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.

See Also

eliminateRedundant hitandrun har

Examples

Run this code
# NOT RUN {
# 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)
# }

Run the code above in your browser using DataLab