EventSimulation Reference

EventSimulation.ActionType

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

source
EventSimulation.SchedulerType

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.

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

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

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

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

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

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

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

source
EventSimulation.SimResourceType

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

source
EventSimulation.SimQueueType

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

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

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

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

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

source
EventSimulation.PriorityTimeType

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.

source