EventSimulation Reference
EventSimulation
— Module.EventSimulation is an event-based discrete event simulation engine.
EventSimulation.Action
— Type.Structure holding an information that what
should be executed by scheduler at time when
; what
should accept one argument of type Scheduler
.
EventSimulation.AbstractState
— Type.Abstract type for holding state of the simulation
EventSimulation.EmptyState
— Type.Simplest concrete type implementing AbstractState
that does not hold any data
EventSimulation.Scheduler
— Type.Holds information about current simulation state Contains the following fields:
now
current simulation timeevent_queue
priority queue ofActions
planned to be executedstate
user defined subtype ofAbstractState
of the simulationmonitor
function that is called before event is triggered must accept two argumentsScheduler
andΔ
, a difference between time of event to be executed and time of last executed event
If two Action
s have identical when
time in event_queue
then the order of their execution is undefined
When monitor
is executed the event to happen is still on event_queue
, but time is updated to time when the event is to be executed (i.e. monitor
sees the state of the simulation just before the event is triggered). Therefore for calculating summary statistics monitor
may assume that the simulation spent Δ
time in this state. Function monitor
should not modify event_queue[1]
as EventSimulation assumes that the event to be triggered after monitor
executes will not be modified. Additionally it it not guaranteed that event_queue[1]
will be executed after monitor
finishes because simulation might terminate earlier.
EventSimulation.register!
— Function.register!(s, what, Δ)
Put what
at time s.now+Δ
to s.event_queue
. what
must accept exactly one argument of type Scheduler
. The function does not check if Δ
is a valid (finite) number. Returns inserted Action
.
EventSimulation.repeat_register!
— Function.repeat_register!(s, what, interval)
Put what
to s.event_queue
repeatedly in time intervals specified by interval
function, which must accept one argument of type Scheduler
. what
must accept exactly one argument of type Scheduler
. interval
function is called after the previous event was executed. Returns nothing
. Calling terminate!
in function interval
will not stop the simulation. Instead, if interval
returns nothing
the action is not scheduled and repeat_register
will effectively terminate.
EventSimulation.bulk_register!
— Function.bulk_register!(s, who, what, Δ, randomize)
Put event at time s.now+Δ
to s.event_queue
that will execute what(scheduler, w)
for all w
in who
. If randomize
is false
then who
is traversed in natural order otherwise it is traversed in random order. what
must accept exactly two arguments of type Scheduler
and eltype(who)
. The function does not check if Δ
is a valid (finite) number. Returns inserted bulk Action
.
Function is designed to efficiently handle case when the same action has to be executed at the same simulation time by many agents.
EventSimulation.repeat_bulk_register!
— Function.repeat_bulk_register!(s, who, what, interval, randomize)
Repeat bulk_register!
at time intervals specified by interval
function, which must accept Scheduler
argument. interval
function is called after the previous event was executed. what
must accept exactly two arguments of type Scheduler
and typeof(who)
. Returns nothing
. Calling terminate!
in function interval
will not stop the simulation. Instead, if interval
returns nothing
the action is not scheduled and repeat_register
will effectively terminate.
EventSimulation.interrupt!
— Function.interrupt!(s, a)
First occurrence of Action
a
is replaced by no-op in event queue. This way there is no need to fix heap in this operation and it is fast. Returns true
if a
was found in queue and false
otherwise.
EventSimulation.terminate!
— Function.terminate!(s)
Empties s.event_queue
which will lead to termination of simulation unless it is refilled before execution returns to go!
. Useful for event-triggered termination of simulation.
EventSimulation.go!
— Function.go!(s, until)
Runs simulation defined by s
until s.now
is greater or equal than until
or s.event_queue
is empty (i.e. nothing is left to be done). By default until
equals Inf
.
Abstract class for reservoirs. SimQueue
and SimResource
are concrete types implementing it.
EventSimulation.SimResource
— Type.Resource type for holding numeric values (like amount of liquid). It stores current quantity
of matter and its allowed lo
and hi
amounts. Servers can get matter from the resource with optional maximum number of requests pending for fulfillment.
Fields:
quantity
current quantity in resourcelo
minimum quantity of resourcehi
maximum quantity of resourcefifo_requests
iftrue
requests
is FIFO, otherwise LIFOmax_requests
maximumrequests
sizerequests
vector of request and requested quantity
Functions in requests
must accept one argument Scheduler
, so they should know the amount they requested. When resource arrives to a queue there is a try to immediately dispatch it to pending requests. When new request arrives there is a try to immediately fulfill it.
Initially an empty SimResource
with no requests is constructed. Initial quantity
, lo
and hi
may be provided. By default SimResource
is empty, and has minimum quantity of zero and unbounded maximum.
EventSimulation.ResourceRequest
— Type.Internal structure that remembers that quantity
was requested by request
.
EventSimulation.SimQueue
— Type.SimQueue type for holding arbitrary objects O
. It allows objects to be waiting in a queue with optional maximum queue size. Servers can get objects from the queue with optional maximum number of requests pending for fulfillment.
Fields:
fifo_queue
iftrue
queue
is FIFO, otherwise LIFOmax_queue
maximumqueue
sizequeue
vector of objects in a queuefifo_requests
iftrue
requests
is FIFO, otherwise LIFOmax_requests
maximumrequests
sizerequests
vector of request functions
Functions in requests
must accept two arguments Scheduler
and O
. When O
arrives to a queue there is a try to immediately feed it to pending requests. When new request arrives there is a try to immediately provide it with O
.
Initially an empty SimQueue
with no requests is constructed. By default queue
and requests
have FIFO policy and are unbounded.
EventSimulation.request!
— Function.request!(s, r, quantity, request)
request!(s, q, request)
Function used to register request for resource in SimResource
or object from SimQueue
.
In SimResource
requested quantity
must be provided and request
accepts only Scheduler
argument (it must know what it wanted). Returns tuple of:
true
if successfull andfalse
when too many requests were madeResourceRequest
object created
In SimResource
function request
must accept one argument Scheduler
. In SimQueue
function request
must accept two arguments Scheduler
and object.
EventSimulation.waive!
— Function.waive!(r, res_request)
waive!(q, request)
Allows to remove first occurence that would be served of res_request
from SimResource
or request
from SimQueue
.
Returns true
on success and false
if res_request
or request
respectively was not found.
EventSimulation.provide!
— Function.provide!(s, r, quantity)
provide!(s, q, object)
Allows to fill SimResource
with quantity
or SimQueue
with object
.
In SimResource
changes the balance of r.quantity
. Given quantity may be any number, but the balance of SimResource
will be changed only in lo
-hi
range. Returns the actual change in SimResource
balance.
In SimQueue
adds object
to q.queue
. Returns true
on success and false
if there were too many objects in queue already.
EventSimulation.withdraw!
— Function.withdraw!(q, object)
Allows to remove first occurrence that would be served of object
from SimQueue
.
Returns true
on success and false
if object
was not found.
EventSimulation.PriorityTime
— Type.Subtype of Real
defining a lexicographically comparable pair of Real
. It is designed to be used by Scheduler
where standard real numbers run to a problem of undefined order of undefined order of removal from priority queue.
PriorityTime
two fields time
and priority
may have different types, but both have to be subtypes of Real
. priority
should be used to determine order of execution of Action
s that have the same time. Two actions with identical time
and priority
have undefined oreder of execution so this should be avoided.
PriorityTime
type has defined lexicographic order and +
, -
. It is immutable, has a custom hash
function and conversions from Real
types.