simpype.random
¶
Random
is a custom dictionary accepting the following format as value:
sim = simpype.Simulation(id = 'test')
myrand = simpype.Random(sim, {
initial_time : lambda_function
...
})
Where each dictionary element is so defined:
initial_time
is the element key and must be of int or float type. It represents the initial simulation time at which thelambda_function
is invoked;lambda_function
is the element value. It is mandatory that for the value to be a lambda function. Such function must return a value, usually a int or a float;
An example of random dictionary initialization is the following:
sim = simpype.Simulation(id = 'test')
myrand = simpype.Random(sim, {
# From t=0 to t=10, the random variable returns
# the constant value of 3.0
0 : lambda: 3.0,
# From t=10 to t=20, the random variable returns
# value uniformly distributed between 2.5 and 3.5
10 : lambda: random.uniform(2.5, 3.5),
# From t=20 to t=inf, the random variable returns
# a value exponentially distributed with lambda 0.20
20 : lambda: random.expovariate(0.20)
})
A second example of random dictionary with generation interrupts is the following:
sim = simpype.Simulation(id = 'test')
myrand = simpype.Random(sim, {
# From t=0 to t=10, the random variable returns
# the constant value of 3.0 after time 10.
# From time 0 to 10, no random variable is generated
10 : lambda: 3.0,
# From t=10 to t=20, no random variable is generated
10 : lambda: None,
# From t=20 to t=30, the random variable returns
# a value exponentially distributed with lambda 0.20
20 : lambda: random.expovariate(0.20)
# From t=30 to t=inf, no random variable is generated
30 : lambda: None
})
Produce a random value:
# Simulation time = 5.0
random_value = myrand.value # random_value = 3.0
...
# Simulation time = 15.0
random_value = myrand.value # random_value = 3.2476115513945767
...
# Simulation time = 25.0
random_value = myrand.value # random_value = 7.374759019459148
-
class
simpype.random.
Random
(sim, step_dict)¶ SimPype’s random class that may return different values depending on the simulation time.
Parameters: - sim (
Simulation
) – The SimPype simulation object. - step_dict (dict) – The dictionary storing the random steps.
-
sim
¶ The SimPype simulation object.
Type: Simulation
-
env
¶ The SimPy environment object.
Type: simpy.Environment
-
step_dict
¶ The dictionary storing the random steps.
Type: dict
-
step_list
¶ The list storing the sorted random steps.
Type: list
-
value
¶ Returns a random value given the current simulation time.
Returns: Value as returned by the the lambda
function.
- sim (