pypdevsbbl.generic.queues module¶
PythonPDEVS Queue for storing items that are waiting to be processed.
-
class
pypdevsbbl.generic.queues.SimpleQueue(name: str, fc=<function <lambda>>, K=inf, dr=inf, contents=(), req_am=False)[source]¶ Bases:
pypdevs.DEVS.AtomicDEVSQueue with reneging that allows items to wait for storage.
Items can only be dequeued when a requestdequeue input is obtained. This makes it so the queue don’t have to handle the complexities concerning automatic dequeueing. See the
Queuefor more details on automatic dequeueing.Reneging will happen automatically if needs be. The requestrenege will renege the last item in the queue.
The enqueue will send the outputs to the overflow output if capacity >= K.
Note
We will be using a maxheap in this queue.
Parameters: - name (str) – The name of the Queue.
- fc (def) – Queueing Discipline. I.e. the priority assigning
function. Takes the current time, the value and a
unique index as arguments. Defaults to
pypdevsbbl.extra.queues.FIFO(). - K (int) – The maximal capacity of the Queue. Defaults to INFINITY (= no maximal capacity).
- dr (numeric) – Standard reneging time delay. Cannot be negative. Defaults to INFINITY (= no reneging).
- contents (iter) – A list of contents to be inserted into the queue on startup. Defaults to an empty tuple.
- req_am (bool) – When
True, the message in a dequeue/renege request indicates the amount that should be released. WhenFalse, no matter which message arrives on these ports, only a single item is released. Defaults toFalse.
State: - queue (heap) – The internal heap for this priority queue.
- dr (numeric) – The renege time delay.
- T (numeric) – Current absolute time.
- rd (bool) – If a dequeue operation was requested.
- rr (bool) – If a renege operation was requested.
- ovf (any) – The overflowing items.
Input Ports: - enqueue (any) – Obtains values and queues them.
- dr (numeric) – A new minimal time in the system value. Cannot be negative.
- requestdequeue – Indicates that items must dequeue. When
req_amisTrue, it expects a natural number. Otherwise, any arriving value is accepted and a single item will be dequeued. - requestrenege – Indicates that the last item in the queue must depart on
the renege port. When
req_amisTrue, it expects a natural number. Otherwise, any arriving value is accepted and a single item will be reneged.
Output Ports: - dequeue (any) – Outputs the next item if it exists.
- renege (any) – Outputs reneged items.
- overflow (any) – Outputs overflowing items.
-
minRen(init=inf, it=None)[source]¶ Obtain the item that has a minimal reneging time.
Also compare it to the given item.
Parameters: - init (numeric) – The initial value to compare it to.
- it (any) – The item that is linked to the
initvalue.
Returns: Tuple in the shape of
(time, item)wheretimeis the time delay until next renege anditemthe item that must be reneged.
-
maxRen(init=-inf, it=None)[source]¶ Obtain the item that has a maximal reneging time.
Also compare it to the given item.
Parameters: - init (numeric) – The initial value to compare it to.
- it (any) – The item that is linked to the
initvalue.
Returns: Tuple in the shape of
(time, item)wheretimeis the time delay until the last renege anditemthe item that must be reneged last.
-
class
pypdevsbbl.generic.queues.QueueTracker(name: str, dt=inf, size=0, value=None)[source]¶ Bases:
pypdevs.DEVS.AtomicDEVSHelper block for the
SimpleQueueto be linked in theQueue.Instead of using a
ConstantGenerator, this block will be used to periodically request dequeues. It also keeps track of the current queue size, meaning that, whenever the queue is empty, it can pause until the next input.Parameters: - name (str) – The name for the block.
- dt (numeric) – Standard time delay between messages. Defaults to INFINITY. Cannot be zero or negative.
- size (int) – The queue size to start from. Must be positive or zero. Defaults to 0.
- value (any) – The value to output instead of the queue size.
When
None, the queue size is used. Defaults toNone.
State: - dt (numeric) – The time delay between messages.
- el (numeric) – The elapsed time since the last event.
- size (int) – The current queue size.
Input Ports: - dt (numeric) – Updates the time delay.
- enter (any) – An item entered the queue.
- leave (any) – An item left the queue.
Output Ports: size (int) – The queue size or a predefined value.
-
class
pypdevsbbl.generic.queues.Queue(name: str, fc=<function <lambda>>, K=inf, dd=inf, dr=inf, contents=(), req_am=False)[source]¶ Bases:
pypdevs.DEVS.CoupledDEVSQueue with reneging that allows items to wait for storage.
This queue will be a wrapper around the
SimpleQueueand allows for automatic dequeueing by continuously sending messages to the requestdequeue input.The names of the internal
SimpleQueueandQueueTrackerwill be made up of this Queue’s name, appended with-queueand-trackerrespectively.Note
If you don’t want to use automatic dequeueing, it’s more efficient to make use of the
SimpleQueueinstead.Note
We will be using a maxheap in this queue.
Parameters: - name (str) – The name of the Queue.
- fc (def) – Queueing Discipline. I.e. the priority assigning function.
Takes the current time, the value and a unique index as
arguments. Defaults to
pypdevsbbl.extra.queues.FIFO(). - K (int) – The maximal capacity of the Queue. Defaults to INFINITY (= no maximal capacity).
- dd (numeric) – Standard dequeueing time delay. Cannot be zero or negative. Defaults to INFINITY (= no automatic dequeueing).
- dr (numeric) – Standard reneging time delay. Cannot be negative. Defaults to INFINITY (= no reneging).
- contents (iter) – A list of contents to be inserted into the queue on startup. Defaults to an empty tuple.
- req_am (bool) – When
True, the message in a dequeue/renege request indicates the amount that should be released. WhenFalse, no matter which message arrives on these ports, only a single item is released. Defaults toFalse.
Input Ports: - enqueue (any) – Obtains values and queues them.
- dd (numeric) – A new minimal time until dequeue. Cannot be zero or negative.
- dr (numeric) – A new minimal time in the system value. Cannot be negative.
- requestdequeue – Indicates that items must dequeue. When
req_amisTrue, it expects a natural number. Otherwise, any arriving value is accepted and a single item will be dequeued. - requestrenege – Indicates that the last item in the queue must depart on the
renege port. When
req_amisTrue, it expects a natural number. Otherwise, any arriving value is accepted and a single item will be reneged.
Output Ports: - dequeue (any) – Outputs the next item if it exists.
- renege (any) – Outputs reneged items.
- overflow (any) – Outputs overflowing items.
- count (int) – Current queue size.
-
class
pypdevsbbl.generic.queues.Retain(name: str, ind: bool = True)[source]¶ Bases:
pypdevs.DEVS.AtomicDEVSRetains an item until the next arrival or next time instance.
- There are two modes:
- individual: Will only output the previous item.
- collection: Will collect all arrived items in the same time instance and will output a list of all these items.
Parameters: - name (str) – The name of the block.
- ind (bool) – When true, this block uses the “individual” mode. Otherwise, the “collection” mode is used.
State: - old (any) – The previous item (or a list thereof).
- cur (any) – The current item.
Input Ports: input (any) – An item that needs to be remembered.
Output Ports: - previous (any) – The previous item (or a list thereof).
- current (any) – The current item.
-
class
pypdevsbbl.generic.queues.Advance(name)[source]¶ Bases:
pypdevs.DEVS.AtomicDEVSReneging queue where each item holds their own delay.
This block is inspired by the
ADVANCEblock from GPSS.Note
The input and the delay must arrive at exactly the same time. When in doubt, use the
pypdevsbbl.generic.routing.Syncblock to ensure this happens.Warning
The items traveling through must be unique!
Warning
When using pausing, it is pertinent that the items traveling through the block are hashable.
Parameters: name (str) – The name of the block.
State: - items (dict) – All the scheduled items in the “queue”, with their expected delay.
- least (tuple) – The item to leave the block first, in the form
of
(item, time). - paused (set) – Set of items that are currently paused. Note that the items must be hashable.
Input Ports: - input (any) – The item to schedule. Must arrive at the same time as the delay input.
- delay (numeric) – The delay of the item. Must arrive at the same time as the input message.
- pause (list) – A list of tuples
(item, bool)indicative of whether or not the item must pause.
Output Ports: output (any) – The item, at the pre-scheduled delay.