These functions describe how a random variable is distributed, for use in
rand_var(). Each takes the same parameters, in the same order, as R's
corresponding random number function:
Arguments
- head
The name under which the service knows the distribution.
- ...
The distribution's parameters, each a number, a numeric vector, or an expression without random variables.
- mean, sd
The mean and the standard deviation, as in
rnorm().- min, max
The smallest and the largest value, as in
runif().- rate
The rate, as in
rexp(); the mean is1 / rate.- prob
The probability of a 1, as in
rbinom(n, 1, prob).
Value
A distribution, to be passed to rand_var() or
set_distribution().
Details
normal(mean, sd), likernorm(): the mean and the standard deviation.uniform(min, max), likerunif(): the smallest and the largest value.exponential(rate), likerexp(): the rate, so that the mean is1 / rate.bernoulli(prob), likerbinom(n, 1, prob): 1 with probabilityprob, and 0 otherwise.
For any other distribution, draw a sample in R and pass it to
empirical(). distribution(head, ...) names a distribution that the
service offers but this package has no function for yet; the service
refuses a name it does not know.
Parameters that depend on a decision
A parameter may be an expression of decision variables rather than a number. The distribution then depends on the decision: a demand whose mean falls as the price rises, or a breakdown that becomes less likely the more is spent on maintenance. A parameter cannot contain a random variable.
A parameter given as a number is checked right away: a rate that is not
positive, a probability outside 0 to 1, or a min above max is an error.
A parameter given as an expression cannot be checked in advance, so give
the decision variables in it bounds that keep it in range.
Vector parameters
A parameter may be a vector. The distribution then describes that many
random variables, drawn independently: normal(c(6, 5, 4), 1) is three
normal variables with means 6, 5 and 4 and standard deviation 1. Each
parameter has length 1 or the common length.
Examples
m <- model()
lead_time <- rand_var(m, "lead_time", uniform(2, 5)) # between 2 and 5 days
gap <- rand_var(m, "gap", exponential(1 / 30)) # 30 minutes on average
fails <- rand_var(m, "fails", bernoulli(0.02)) # 1 with probability 0.02
# the more is spent on maintenance, the less likely a breakdown
spend <- num_var(m, "spend", lower = 0, upper = 10)
breaks <- rand_var(m, "breaks", bernoulli(0.2 - 0.015 * spend))