Class MultiLevelBucketQueue<E>

java.lang.Object
org.simplesim.core.scheduling.MultiLevelBucketQueue<E>
Type Parameters:
E - Event type
All Implemented Interfaces:
EventQueue<E>

public class MultiLevelBucketQueue<E> extends Object implements EventQueue<E>
A multi-level queue is a layered event queue with three tiers suitable for a large amount of events.

Both multi-level queue implementations are based on the article "MList: An efficient pending event set structure for discrete event simulation" by Rick Siow Mong Goh and Ian Li-Jin Thng. They are structured in three tiers:

  1. current event tier for events before minTimerTier2
  2. near future tier for events since minTimeTier2 but before minTimeTier3
  3. far future tier for events from minTimeTier3 to maxTimeTier3
MultiLevelBucketQueue uses buckets of events of the same time-stamp. This is versatile if there are many event with the same time-stamp.

MultiLevelEventQueue uses EventQueueEntry to couple time and events. This is versatile if there are many events with different time-stamps.

See Also:
  • Constructor Details

    • MultiLevelBucketQueue

      public MultiLevelBucketQueue(int chunkSize)
      Constructor to enable setting the average chunk size of the second sorting tier.

      Only for optimization purpose, see documentation in refillTier2. Generally, use default constructor.

      Parameters:
      chunkSize -
    • MultiLevelBucketQueue

      public MultiLevelBucketQueue()
  • Method Details

    • isEmpty

      public boolean isEmpty()
      Description copied from interface: EventQueue
      Checks if the queue is empty.
      Specified by:
      isEmpty in interface EventQueue<E>
      Returns:
      true if the queue is empty, false otherwise
    • size

      public int size()
      Description copied from interface: EventQueue
      Returns the number of elements in the queue.
      Specified by:
      size in interface EventQueue<E>
      Returns:
      number of queue entries
    • getMin

      public Time getMin()
      Description copied from interface: EventQueue
      Gets the minimal time stamp.

      An empty event queue may result in non-deterministic behavior and is not checked!

      Specified by:
      getMin in interface EventQueue<E>
      Returns:
      current minimal time stamp (does not test if queue is empty!)
    • enqueue

      public void enqueue(E event, Time time)
      Description copied from interface: EventQueue
      Enqueues an event at the given time.

      Note that only distinct events may be added to the queue. If the very same event already exists, it may be overwritten.

      Specified by:
      enqueue in interface EventQueue<E>
      Parameters:
      event - the event to be added to the queue
      time - the time stamp of the event, must be a future time
    • dequeue

      public E dequeue()
      Description copied from interface: EventQueue
      Dequeues the event with the smallest time stamp.

      If there are several events with the same time stamp, the result can be any of these events

      Specified by:
      dequeue in interface EventQueue<E>
      Returns:
      event with the smallest time stamp or null if the queue is empty
      See Also:
    • dequeueAll

      public List<E> dequeueAll()
      Description copied from interface: EventQueue
      Dequeues all elements with the smallest time stamp. A call to this method is equivalent to dequeueAll(getMin()).

      An empty event queue may result in non-deterministic behavior and is not checked!

      Specified by:
      dequeueAll in interface EventQueue<E>
      Returns:
      a list containing all events with the minimum time stamp or an empty list if the event queue is empty.
      See Also:
    • dequeueAll

      public List<E> dequeueAll(Time time)
      Description copied from interface: EventQueue
      Dequeues all elements with the given time stamp.

      An empty event queue may result in non-deterministic behavior and is not checked!

      Specified by:
      dequeueAll in interface EventQueue<E>
      Parameters:
      time - the time stamp of the events to dequeue
      Returns:
      a list containing all events with this time stamp or an empty list if there are not events at the given time
    • dequeue

      public Time dequeue(E event)
      Description copied from interface: EventQueue
      Removes the entry of the given event.
      Specified by:
      dequeue in interface EventQueue<E>
      Parameters:
      event - the event to be removed from the queue
      Returns:
      time stamp of the dequeued event or null if the event was not part of the queue
    • getTime

      public Time getTime(E event)
      Description copied from interface: EventQueue
      Gets the time of the given event but does not dequeue it.
      Specified by:
      getTime in interface EventQueue<E>
      Parameters:
      event - the event to retrieve the time for
      Returns:
      time stamp of the event or null if the event does not exist