Calendar Queue
   HOME

TheInfoList



OR:

A calendar queue (CQ) is a
priority queue In computer science, a priority queue is an abstract data-type similar to a regular queue or stack data structure in which each element additionally has a ''priority'' associated with it. In a priority queue, an element with high priority is se ...
(queue in which every element has associated priority and the dequeue operation removes the highest priority element). It is analogous to desk calendar, which is used by humans for ordering future events by date.
Discrete event simulation A discrete-event simulation (DES) models the operation of a system as a (discrete) sequence of events in time. Each event occurs at a particular instant in time and marks a change of state in the system. Between consecutive events, no change in the ...
s require a future event list (FEL) structure that sorts pending events according to their time. Such simulators require a good and efficient
data structure In computer science, a data structure is a data organization, management, and storage format that is usually chosen for efficient access to data. More precisely, a data structure is a collection of data values, the relationships among them, a ...
as time spent on queue management can be significant. The calendar queue (with optimum bucket size) can approach O(1) average performance. Calendar queues are closely related to
bucket queue A bucket queue is a data structure that implements the priority queue abstract data type: it maintains a dynamic collection of elements with numerical priorities and allows quick access to the element with minimum (or maximum) priority. In the bu ...
s but differ from them in how they are searched and in being dynamically resized.


Implementation

Theoretically, like a bucket queue, a calendar queue consists of an array of
linked list In computer science, a linked list is a linear collection of data elements whose order is not given by their physical placement in memory. Instead, each element points to the next. It is a data structure consisting of a collection of nodes whic ...
s. Sometimes each index in the array is also referred to as a bucket. The bucket has specified width and its linked list holds events whose timestamp maps to that bucket. A desk calendar has 365 buckets for each day with a width of one day. Each array element contains one pointer that is the head of the corresponding linked list. If the array name is “month” then month 1is a pointer to the list of events scheduled for the 12th month of the year (the vector index starts from 0). The complete calendar thus consists of an array of 12 pointers and a collection of up to 12 linked lists. In calendar queue, enqueue (addition in a
queue __NOTOC__ Queue () may refer to: * Queue area, or queue, a line or area where people wait for goods or services Arts, entertainment, and media *''ACM Queue'', a computer magazine * The Queue (Sorokin novel), ''The Queue'' (Sorokin novel), a 198 ...
) and dequeue (deleting from a queue) of events in FEL is based on event time. Let the calendar queue with ''n'' buckets with ''w'' width. Then enqueue of an event with time ''t'' operates on bucket \frac \mod n . And more than two events scheduled in the bucket according to the increased timestamp. To dequeue events from the calendar queue, it keeps track of current year and day. Then it searches for the earliest event within that bucket and dequeue it. (In contrast, a bucket queue would merely return any element from the first nonempty bucket, without determining which element in that bucket is earliest.)


Calendar Queue Resize Operation

If the number of events in the queue is much smaller or much larger than the number of buckets, it will not function efficiently. The solution is to allow the number of buckets to correspondingly grow and shrink as the queue grows and shrinks. To simplify the resize operation, the ''Nb'' (number of buckets) in a CQ is often chosen to be the power of two, i.e., Nb=2^n;↵ The number of buckets is doubled or halved each time the ''Ne'' (number of events) exceeds 2''Nb'' or decreases below ''Nb''/2 respectively. When ''Nb'' is resized, the new width ''w'' has to be calculated as well. The new ''w'' that is adopted will be estimated by sampling the average inter-event time gap from the first few hundred events starting at the current bucket position. Thereafter, a new Calendar queue is created and all the events in the old calendar will be recopied over.


References

* * * *{{citation , last1 = Tan , first1 = Kah Leong , last2 = Thng , first2 = Li-Jin , contribution = SNOOPy Calendar Queue , doi = 10.1109/wsc.2000.899756 , publisher = IEEE , title = 2000 Winter Simulation Conference Proceedings, s2cid = 2982776 Priority queues