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Δtuntil 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Δtis aNumber,event!(clk, 𝜸, every, Δt)whereΔtis 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)