A random variable stands for a quantity that is not known when the decision is made, such as tomorrow's demand. It can be used in expressions like a decision variable, but the service does not choose its value: in each scenario, the value is drawn from the variable's distribution. Within one scenario, every use of the variable has the same value. Two random variables declared separately are drawn independently.
Usage
rand_var(m, name, dist = NULL, length = NULL, n)
add_rand_var(m, name, dist = NULL, length = NULL, n)Arguments
- m
A
model().- name
The random variable's name, unique within the model.
- dist
A distribution such as
normal(100, 15)(seedistribution()), or anempirical()sample with one value per scenario. It may be left out and given later withset_distribution().- length
How many random variables to declare under this name. Left
NULL, the number follows from the length of the distribution's parameters.- n
The former name of
length, still accepted for now, with a warning.
Value
The random variable, an expression with one element per random variable declared.
add_rand_var() returns the model, invisibly.
Details
A random variable has no bounds; its distribution says which values it can take.
A distribution with vector parameters declares several random variables
under one name, which behave like an R vector: rand_var(m, "hours", normal(c(6, 5, 4), 1)) declares hours[1], hours[2] and hours[3].
With scalar parameters and length given, it declares that many variables
with the same distribution. Either way, the elements are drawn independently of each
other. Random variables that move together, such as demand and price, are
best declared from observed data with set_empirical().
add_rand_var() declares the variable in the same way but returns the
model, for use in a pipe; m$name then retrieves the variable.