desmod.queue
¶
Queue classes useful for modeling.
A queue may be used for inter-process message passing, resource pools,
event sequences, and many other modeling applications. The Queue
class implements a simulation-aware, general-purpose queue useful for these
modeling applications.
The PriorityQueue
class is an alternative to Queue
that
dequeues items in priority-order instead of Queue
’s FIFO discipline.
-
class
desmod.queue.
Queue
(env: simpy.core.Environment, capacity: Union[int, float] = inf, hard_cap: bool = False, items: Iterable[ItemType] = (), name: Optional[str] = None)[source]¶ Simulation queue of arbitrary items.
Queue is similar to
simpy.Store
. It provides a simulation-aware first-in first-out (FIFO) queue useful for passing messages between simulation processes or managing a pool of objects needed by multiple processes.Items are enqueued and dequeued using
put()
andget()
.Parameters: - env – Simulation environment.
- capacity – Capacity of the queue; infinite by default.
- hard_cap – If specified, the queue overflows when the capacity is reached.
- items – Optional sequence of items to pre-populate the queue.
- name – Optional name to associate with the queue.
-
capacity
= None¶ Capacity of the queue (maximum number of items).
-
size
¶ Number of items in queue.
-
remaining
¶ Remaining queue capacity.
-
is_empty
¶ Indicates whether the queue is empty.
-
is_full
¶ Indicates whether the queue is full.
-
class
desmod.queue.
PriorityQueue
(env: simpy.core.Environment, capacity: Union[int, float] = inf, hard_cap: bool = False, items: Iterable[ItemType] = (), name: Optional[str] = None)[source]¶ Specialized queue where items are dequeued in priority order.
Items in PriorityQueue must be orderable (implement
__lt__()
). Unorderable items may be used with PriorityQueue by wrapping withPriorityItem
.Items that evaluate less-than other items will be dequeued first.
-
get
¶ alias of
QueueGetEvent
-
is_empty
¶ Indicates whether the queue is empty.
-
is_full
¶ Indicates whether the queue is full.
-
peek
() → ItemType¶ Peek at the next item in the queue.
-
put
¶ alias of
QueuePutEvent
-
remaining
¶ Remaining queue capacity.
-
size
¶ Number of items in queue.
-
when_any
¶ alias of
QueueWhenAnyEvent
-
when_at_least
¶ alias of
QueueWhenAtLeastEvent
-
when_at_most
¶ alias of
QueueWhenAtMostEvent
-
when_empty
¶ alias of
QueueWhenEmptyEvent
-
when_full
¶ alias of
QueueWhenFullEvent
-
when_not_full
¶ alias of
QueueWhenNotFullEvent
-
-
class
desmod.queue.
PriorityItem
[source]¶ Wrap items with explicit priority for use with
PriorityQueue
.Parameters: - priority – Orderable priority value. Smaller values are dequeued first.
- item – Arbitrary item. Only the priority is determines dequeue order, so the item itself does not have to be orderable.
-
priority
¶ Alias for field number 0
-
item
¶ Alias for field number 1