EventSimulation Reference
EventSimulation — ModuleEventSimulation is an event-based discrete event simulation engine.
EventSimulation.Action — TypeStructure holding an information that what should be executed by scheduler at time when; what should accept one argument of type Scheduler.
EventSimulation.AbstractState — TypeAbstract type for holding state of the simulation
EventSimulation.EmptyState — TypeSimplest concrete type implementing AbstractState that does not hold any data
EventSimulation.Scheduler — TypeHolds information about current simulation state Contains the following fields:
nowcurrent simulation timeevent_queuepriority queue ofActionsplanned to be executedstateuser defined subtype ofAbstractStateof the simulationmonitorfunction that is called before event is triggered must accept two argumentsSchedulerandΔ, a difference between time of event to be executed and time of last executed event
If two Actions 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! — Functionregister!(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! — Functionrepeat_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! — Functionbulk_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! — Functionrepeat_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! — Functioninterrupt!(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! — Functionterminate!(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! — Functiongo!(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.
EventSimulation.AbstractReservoir — TypeAbstract class for reservoirs. SimQueue and SimResource are concrete types implementing it.
EventSimulation.SimResource — TypeResource 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:
quantitycurrent quantity in resourcelominimum quantity of resourcehimaximum quantity of resourcefifo_requestsiftruerequestsis FIFO, otherwise LIFOmax_requestsmaximumrequestssizerequestsvector 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 — TypeInternal structure that remembers that quantity was requested by request.
EventSimulation.SimQueue — TypeSimQueue 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_queueiftruequeueis FIFO, otherwise LIFOmax_queuemaximumqueuesizequeuevector of objects in a queuefifo_requestsiftruerequestsis FIFO, otherwise LIFOmax_requestsmaximumrequestssizerequestsvector 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! — Functionrequest!(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:
trueif successfull andfalsewhen too many requests were madeResourceRequestobject created
In SimResource function request must accept one argument Scheduler. In SimQueue function request must accept two arguments Scheduler and object.
EventSimulation.waive! — Functionwaive!(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! — Functionprovide!(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! — Functionwithdraw!(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 — TypeSubtype 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 Actions 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.