Sampling
The simplest mechanism for generating discrete events is to have a clock clk
execute an action 𝜸
periodically. We can generate periodic events in various ways:
- sampling events with
periodic!(clk, 𝜸, Δt)
are executed at the clock sample rateΔt
, - conditional events with
event!(clk, 𝝃, 𝜸)
check the condition𝜸
at the clock's sample rateΔt
until it returnstrue
. Then𝝃
is executed.
Sampling is useful if we want to model repeated or periodic events interacting with a DES, check conditions, trace or visualize the system periodically.
Sampling introduces a time uncertainty into simulations since it triggers changes, takes measurements or checks for conditions only at a given time interval Δt.
Stochastic Event Sequences
Independent from the clock's sample rate you can have repeating events with fixed or stochastic inter-event times:
event!(clk, 𝜸, every, Δt)
whereΔt
is aNumber
,event!(clk, 𝜸, every, Δt)
whereΔt
is aDistribution
.
Thus you can create stochastic processes like arrivals or failures easily:
using DiscreteEvents, Distributions, Plots
c = Clock()
λ = 0.5
a = [0]
t = Float64[0.0]; y = Float64[0.0]
incra(c) = (a[1]+=1; push!(t, tau(c)); push!(y, a[1]))
event!(c, fun(incra, c), every, Exponential(1/λ))
run!(c, 100)
plot(t, y, linetype=:steppost, xlabel="t", ylabel="y", title="Poisson Process", legend=false)