EventSimulation Reference

EventSimulation Reference

EventSimulationModule.

EventSimulation is an event-based discrete event simulation engine.

Structure holding an information that what should be executed by scheduler at time when; what should accept one argument of type Scheduler.

Abstract type for holding state of the simulation

Simplest concrete type implementing AbstractState that does not hold any data

Holds information about current simulation state Contains the following fields:

  • now current simulation time
  • event_queue priority queue of Actions planned to be executed
  • state user defined subtype of AbstractState of the simulation
  • monitor function that is called before event is triggered must accept two arguments Scheduler and Δ, 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.

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.

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.

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.

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.

interrupt!(s, a)

First occurrence of Actiona 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.

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.

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 resource
  • lo minimum quantity of resource
  • hi maximum quantity of resource
  • fifo_requests if truerequests is FIFO, otherwise LIFO
  • max_requests maximum requests size
  • requests 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.

Internal structure that remembers that quantity was requested by request.

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 if truequeue is FIFO, otherwise LIFO
  • max_queue maximum queue size
  • queue vector of objects in a queue
  • fifo_requests if truerequests is FIFO, otherwise LIFO
  • max_requests maximum requests size
  • requests 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.

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 and false when too many requests were made
  • ResourceRequest object created

In SimResource function request must accept one argument Scheduler. In SimQueue function request must accept two arguments Scheduler and object.

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.

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.

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.

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 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.