Copyright | Copyright (c) 2009-2013, David Sorokin <david.sorokin@gmail.com> |
---|---|

License | BSD3 |

Maintainer | David Sorokin <david.sorokin@gmail.com> |

Stability | experimental |

Safe Haskell | Safe-Inferred |

Language | Haskell98 |

Tested with: GHC 7.6.3

This module defines a queue that can use the specified strategies. So, having only
the `FCFS`

, `LCFS`

, `SIRO`

and `StaticPriorities`

strategies, you can build
4 x 4 x 4 = 64 different types of the queue, each of them will have its own
behaviour.

- type FCFSQueue a = Queue FCFS DoubleLinkedList FCFS DoubleLinkedList FCFS DoubleLinkedList a
- type LCFSQueue a = Queue FCFS DoubleLinkedList LCFS DoubleLinkedList FCFS DoubleLinkedList a
- type SIROQueue a = Queue FCFS DoubleLinkedList SIRO Vector FCFS DoubleLinkedList a
- type PriorityQueue a = Queue FCFS DoubleLinkedList StaticPriorities PriorityQueue FCFS DoubleLinkedList a
- data Queue si qi sm qm so qo a
- newFCFSQueue :: Int -> Simulation (FCFSQueue a)
- newLCFSQueue :: Int -> Simulation (LCFSQueue a)
- newSIROQueue :: Int -> Simulation (SIROQueue a)
- newPriorityQueue :: Int -> Simulation (PriorityQueue a)
- newQueue :: (QueueStrategy si qi, QueueStrategy sm qm, QueueStrategy so qo) => si -> sm -> so -> Int -> Simulation (Queue si qi sm qm so qo a)
- queueInputStrategy :: Queue si qi sm qm so qo a -> si
- queueStoringStrategy :: Queue si qi sm qm so qo a -> sm
- queueOutputStrategy :: Queue si qi sm qm so qo a -> so
- queueNull :: Queue si qi sm qm so qo a -> Event Bool
- queueFull :: Queue si qi sm qm so qo a -> Event Bool
- queueMaxCount :: Queue si qi sm qm so qo a -> Int
- queueCount :: Queue si qi sm qm so qo a -> Event Int
- queueLostCount :: Queue si qi sm qm so qo a -> Event Int
- queueInputCount :: Queue si qi sm qm so qo a -> Event Int
- queueStoreCount :: Queue si qi sm qm so qo a -> Event Int
- queueOutputRequestCount :: Queue si qi sm qm so qo a -> Event Int
- queueOutputCount :: Queue si qi sm qm so qo a -> Event Int
- queueLoadFactor :: Queue si qi sm qm so qo a -> Event Double
- queueInputRate :: Queue si qi sm qm so qo a -> Event Double
- queueStoreRate :: Queue si qi sm qm so qo a -> Event Double
- queueOutputRequestRate :: Queue si qi sm qm so qo a -> Event Double
- queueOutputRate :: Queue si qi sm qm so qo a -> Event Double
- queueWaitTime :: Queue si qi sm qm so qo a -> Event (SamplingStats Double)
- queueTotalWaitTime :: Queue si qi sm qm so qo a -> Event (SamplingStats Double)
- queueInputWaitTime :: Queue si qi sm qm so qo a -> Event (SamplingStats Double)
- queueOutputWaitTime :: Queue si qi sm qm so qo a -> Event (SamplingStats Double)
- dequeue :: (DequeueStrategy si qi, DequeueStrategy sm qm, EnqueueStrategy so qo) => Queue si qi sm qm so qo a -> Process a
- dequeueWithOutputPriority :: (DequeueStrategy si qi, DequeueStrategy sm qm, PriorityQueueStrategy so qo po) => Queue si qi sm qm so qo a -> po -> Process a
- tryDequeue :: (DequeueStrategy si qi, DequeueStrategy sm qm) => Queue si qi sm qm so qo a -> Event (Maybe a)
- enqueue :: (EnqueueStrategy si qi, EnqueueStrategy sm qm, DequeueStrategy so qo) => Queue si qi sm qm so qo a -> a -> Process ()
- enqueueWithInputPriority :: (PriorityQueueStrategy si qi pi, EnqueueStrategy sm qm, DequeueStrategy so qo) => Queue si qi sm qm so qo a -> pi -> a -> Process ()
- enqueueWithStoringPriority :: (EnqueueStrategy si qi, PriorityQueueStrategy sm qm pm, DequeueStrategy so qo) => Queue si qi sm qm so qo a -> pm -> a -> Process ()
- enqueueWithInputStoringPriorities :: (PriorityQueueStrategy si qi pi, PriorityQueueStrategy sm qm pm, DequeueStrategy so qo) => Queue si qi sm qm so qo a -> pi -> pm -> a -> Process ()
- tryEnqueue :: (EnqueueStrategy sm qm, DequeueStrategy so qo) => Queue si qi sm qm so qo a -> a -> Event Bool
- tryEnqueueWithStoringPriority :: (PriorityQueueStrategy sm qm pm, DequeueStrategy so qo) => Queue si qi sm qm so qo a -> pm -> a -> Event Bool
- enqueueOrLost :: (EnqueueStrategy sm qm, DequeueStrategy so qo) => Queue si qi sm qm so qo a -> a -> Event Bool
- enqueueOrLost_ :: (EnqueueStrategy sm qm, DequeueStrategy so qo) => Queue si qi sm qm so qo a -> a -> Event ()
- enqueueWithStoringPriorityOrLost :: (PriorityQueueStrategy sm qm pm, DequeueStrategy so qo) => Queue si qi sm qm so qo a -> pm -> a -> Event Bool
- enqueueWithStoringPriorityOrLost_ :: (PriorityQueueStrategy sm qm pm, DequeueStrategy so qo) => Queue si qi sm qm so qo a -> pm -> a -> Event ()
- waitWhileFullQueue :: Queue si qi sm qm so qo a -> Process ()
- queueSummary :: (Show si, Show sm, Show so) => Queue si qi sm qm so qo a -> Int -> Event ShowS
- queueNullChanged :: Queue si qi sm qm so qo a -> Signal Bool
- queueNullChanged_ :: Queue si qi sm qm so qo a -> Signal ()
- queueFullChanged :: Queue si qi sm qm so qo a -> Signal Bool
- queueFullChanged_ :: Queue si qi sm qm so qo a -> Signal ()
- queueCountChanged :: Queue si qi sm qm so qo a -> Signal Int
- queueCountChanged_ :: Queue si qi sm qm so qo a -> Signal ()
- queueLostCountChanged :: Queue si qi sm qm so qo a -> Signal Int
- queueLostCountChanged_ :: Queue si qi sm qm so qo a -> Signal ()
- queueInputCountChanged :: Queue si qi sm qm so qo a -> Signal Int
- queueInputCountChanged_ :: Queue si qi sm qm so qo a -> Signal ()
- queueStoreCountChanged :: Queue si qi sm qm so qo a -> Signal Int
- queueStoreCountChanged_ :: Queue si qi sm qm so qo a -> Signal ()
- queueOutputRequestCountChanged :: Queue si qi sm qm so qo a -> Signal Int
- queueOutputRequestCountChanged_ :: Queue si qi sm qm so qo a -> Signal ()
- queueOutputCountChanged :: Queue si qi sm qm so qo a -> Signal Int
- queueOutputCountChanged_ :: Queue si qi sm qm so qo a -> Signal ()
- queueLoadFactorChanged :: Queue si qi sm qm so qo a -> Signal Double
- queueLoadFactorChanged_ :: Queue si qi sm qm so qo a -> Signal ()
- queueWaitTimeChanged :: Queue si qi sm qm so qo a -> Signal (SamplingStats Double)
- queueWaitTimeChanged_ :: Queue si qi sm qm so qo a -> Signal ()
- queueTotalWaitTimeChanged :: Queue si qi sm qm so qo a -> Signal (SamplingStats Double)
- queueTotalWaitTimeChanged_ :: Queue si qi sm qm so qo a -> Signal ()
- queueInputWaitTimeChanged :: Queue si qi sm qm so qo a -> Signal (SamplingStats Double)
- queueInputWaitTimeChanged_ :: Queue si qi sm qm so qo a -> Signal ()
- queueOutputWaitTimeChanged :: Queue si qi sm qm so qo a -> Signal (SamplingStats Double)
- queueOutputWaitTimeChanged_ :: Queue si qi sm qm so qo a -> Signal ()
- enqueueInitiated :: Queue si qi sm qm so qo a -> Signal a
- enqueueStored :: Queue si qi sm qm so qo a -> Signal a
- enqueueLost :: Queue si qi sm qm so qo a -> Signal a
- dequeueRequested :: Queue si qi sm qm so qo a -> Signal ()
- dequeueExtracted :: Queue si qi sm qm so qo a -> Signal a
- queueChanged_ :: Queue si qi sm qm so qo a -> Signal ()

# Queue Types

type FCFSQueue a = Queue FCFS DoubleLinkedList FCFS DoubleLinkedList FCFS DoubleLinkedList a Source

A type synonym for the ordinary FIFO queue also known as the FCFS (First Come - First Serviced) queue.

type LCFSQueue a = Queue FCFS DoubleLinkedList LCFS DoubleLinkedList FCFS DoubleLinkedList a Source

A type synonym for the ordinary LIFO queue also known as the LCFS (Last Come - First Serviced) queue.

type SIROQueue a = Queue FCFS DoubleLinkedList SIRO Vector FCFS DoubleLinkedList a Source

A type synonym for the SIRO (Serviced in Random Order) queue.

type PriorityQueue a = Queue FCFS DoubleLinkedList StaticPriorities PriorityQueue FCFS DoubleLinkedList a Source

A type synonym for the queue with static priorities applied when storing the elements in the queue.

data Queue si qi sm qm so qo a Source

Represents the queue using the specified strategies for input `si`

,
internal storing (in memory) `sm`

and output `so`

, where `a`

denotes
the type of items stored in the queue. Types `qi`

, `qm`

and `qo`

are
determined automatically and you should not care about them - they
are dependent types.

# Creating Queue

newFCFSQueue :: Int -> Simulation (FCFSQueue a) Source

Create a new FCFS queue with the specified capacity.

newLCFSQueue :: Int -> Simulation (LCFSQueue a) Source

Create a new LCFS queue with the specified capacity.

newSIROQueue :: Int -> Simulation (SIROQueue a) Source

Create a new SIRO queue with the specified capacity.

newPriorityQueue :: Int -> Simulation (PriorityQueue a) Source

Create a new priority queue with the specified capacity.

:: (QueueStrategy si qi, QueueStrategy sm qm, QueueStrategy so qo) | |

=> si | the strategy applied to the input (enqueuing) process |

-> sm | the strategy applied when storing items in the queue |

-> so | the strategy applied to the output (dequeuing) process |

-> Int | the queue capacity |

-> Simulation (Queue si qi sm qm so qo a) |

Create a new queue with the specified strategies and capacity.

# Queue Properties and Activities

queueInputStrategy :: Queue si qi sm qm so qo a -> si Source

The strategy applied to the input (enqueuing) process.

queueStoringStrategy :: Queue si qi sm qm so qo a -> sm Source

The strategy applied when storing (in memory) items in the queue.

queueOutputStrategy :: Queue si qi sm qm so qo a -> so Source

The strategy applied to the output (dequeuing) process.

queueNull :: Queue si qi sm qm so qo a -> Event Bool Source

Test whether the queue is empty.

See also `queueNullChanged`

and `queueNullChanged_`

.

queueFull :: Queue si qi sm qm so qo a -> Event Bool Source

Test whether the queue is full.

See also `queueFullChanged`

and `queueFullChanged_`

.

queueMaxCount :: Queue si qi sm qm so qo a -> Int Source

The queue capacity.

queueCount :: Queue si qi sm qm so qo a -> Event Int Source

Return the queue size.

See also `queueCountChanged`

and `queueCountChanged_`

.

queueLostCount :: Queue si qi sm qm so qo a -> Event Int Source

Return the number of lost items.

See also `queueLostCountChanged`

and `queueLostCountChanged_`

.

queueInputCount :: Queue si qi sm qm so qo a -> Event Int Source

Return the total number of input items that were enqueued.

See also `queueInputCountChanged`

and `queueInputCountChanged_`

.

queueStoreCount :: Queue si qi sm qm so qo a -> Event Int Source

Return the total number of input items that were stored.

See also `queueStoreCountChanged`

and `queueStoreCountChanged_`

.

queueOutputRequestCount :: Queue si qi sm qm so qo a -> Event Int Source

Return the total number of requests for dequeueing the items, not taking into account the attempts to dequeue immediately without suspension.

See also `queueOutputRequestCountChanged`

and `queueOutputRequestCountChanged_`

.

queueOutputCount :: Queue si qi sm qm so qo a -> Event Int Source

Return the total number of output items that were dequeued.

See also `queueOutputCountChanged`

and `queueOutputCountChanged_`

.

queueLoadFactor :: Queue si qi sm qm so qo a -> Event Double Source

Return the load factor: the queue size divided by its maximum size.

See also `queueLoadFactorChanged`

and `queueLoadFactorChanged_`

.

queueInputRate :: Queue si qi sm qm so qo a -> Event Double Source

Return the rate of the input items that were enqueued: how many items per time.

queueStoreRate :: Queue si qi sm qm so qo a -> Event Double Source

Return the rate of the items that were stored: how many items per time.

queueOutputRequestRate :: Queue si qi sm qm so qo a -> Event Double Source

Return the rate of the requests for dequeueing the items: how many requests per time. It does not include the attempts to dequeue immediately without suspension.

queueOutputRate :: Queue si qi sm qm so qo a -> Event Double Source

Return the rate of the output items that were dequeued: how many items per time.

queueWaitTime :: Queue si qi sm qm so qo a -> Event (SamplingStats Double) Source

Return the wait time from the time at which the item was stored in the queue to the time at which it was dequeued.

See also `queueWaitTimeChanged`

and `queueWaitTimeChanged_`

.

queueTotalWaitTime :: Queue si qi sm qm so qo a -> Event (SamplingStats Double) Source

Return the total wait time from the time at which the enqueueing operation was initiated to the time at which the item was dequeued.

In some sense, `queueTotalWaitTime == queueInputWaitTime + queueWaitTime`

.

See also `queueTotalWaitTimeChanged`

and `queueTotalWaitTimeChanged_`

.

queueInputWaitTime :: Queue si qi sm qm so qo a -> Event (SamplingStats Double) Source

Return the input wait time from the time at which the enqueueing operation was initiated to the time at which the item was stored in the queue.

See also `queueInputWaitTimeChanged`

and `queueInputWaitTimeChanged_`

.

queueOutputWaitTime :: Queue si qi sm qm so qo a -> Event (SamplingStats Double) Source

Return the output wait time from the time at which the item was requested for dequeueing to the time at which it was actually dequeued.

See also `queueOutputWaitTimeChanged`

and `queueOutputWaitTimeChanged_`

.

# Dequeuing and Enqueuing

:: (DequeueStrategy si qi, DequeueStrategy sm qm, EnqueueStrategy so qo) | |

=> Queue si qi sm qm so qo a | the queue |

-> Process a | the dequeued value |

Dequeue suspending the process if the queue is empty.

dequeueWithOutputPriority Source

:: (DequeueStrategy si qi, DequeueStrategy sm qm, PriorityQueueStrategy so qo po) | |

=> Queue si qi sm qm so qo a | the queue |

-> po | the priority for output |

-> Process a | the dequeued value |

Dequeue with the output priority suspending the process if the queue is empty.

:: (DequeueStrategy si qi, DequeueStrategy sm qm) | |

=> Queue si qi sm qm so qo a | the queue |

-> Event (Maybe a) | the dequeued value of |

Try to dequeue immediately.

:: (EnqueueStrategy si qi, EnqueueStrategy sm qm, DequeueStrategy so qo) | |

=> Queue si qi sm qm so qo a | the queue |

-> a | the item to enqueue |

-> Process () |

Enqueue the item suspending the process if the queue is full.

enqueueWithInputPriority Source

:: (PriorityQueueStrategy si qi pi, EnqueueStrategy sm qm, DequeueStrategy so qo) | |

=> Queue si qi sm qm so qo a | the queue |

-> pi | the priority for input |

-> a | the item to enqueue |

-> Process () |

Enqueue with the input priority the item suspending the process if the queue is full.

enqueueWithStoringPriority Source

:: (EnqueueStrategy si qi, PriorityQueueStrategy sm qm pm, DequeueStrategy so qo) | |

=> Queue si qi sm qm so qo a | the queue |

-> pm | the priority for storing |

-> a | the item to enqueue |

-> Process () |

Enqueue with the storing priority the item suspending the process if the queue is full.

enqueueWithInputStoringPriorities Source

:: (PriorityQueueStrategy si qi pi, PriorityQueueStrategy sm qm pm, DequeueStrategy so qo) | |

=> Queue si qi sm qm so qo a | the queue |

-> pi | the priority for input |

-> pm | the priority for storing |

-> a | the item to enqueue |

-> Process () |

Enqueue with the input and storing priorities the item suspending the process if the queue is full.

:: (EnqueueStrategy sm qm, DequeueStrategy so qo) | |

=> Queue si qi sm qm so qo a | the queue |

-> a | the item which we try to enqueue |

-> Event Bool |

Try to enqueue the item. Return `False`

in the monad if the queue is full.

tryEnqueueWithStoringPriority Source

:: (PriorityQueueStrategy sm qm pm, DequeueStrategy so qo) | |

=> Queue si qi sm qm so qo a | the queue |

-> pm | the priority for storing |

-> a | the item which we try to enqueue |

-> Event Bool |

Try to enqueue with the storing priority the item. Return `False`

in
the monad if the queue is full.

:: (EnqueueStrategy sm qm, DequeueStrategy so qo) | |

=> Queue si qi sm qm so qo a | the queue |

-> a | the item which we try to enqueue |

-> Event Bool |

Try to enqueue the item. If the queue is full then the item will be lost
and `False`

will be returned.

:: (EnqueueStrategy sm qm, DequeueStrategy so qo) | |

=> Queue si qi sm qm so qo a | the queue |

-> a | the item which we try to enqueue |

-> Event () |

Try to enqueue the item. If the queue is full then the item will be lost.

enqueueWithStoringPriorityOrLost Source

:: (PriorityQueueStrategy sm qm pm, DequeueStrategy so qo) | |

=> Queue si qi sm qm so qo a | the queue |

-> pm | the priority for storing |

-> a | the item which we try to enqueue |

-> Event Bool |

Try to enqueue with the storing priority the item. If the queue is full
then the item will be lost and `False`

will be returned.

enqueueWithStoringPriorityOrLost_ Source

:: (PriorityQueueStrategy sm qm pm, DequeueStrategy so qo) | |

=> Queue si qi sm qm so qo a | the queue |

-> pm | the priority for storing |

-> a | the item which we try to enqueue |

-> Event () |

Try to enqueue with the storing priority the item. If the queue is full then the item will be lost.

# Awaiting

waitWhileFullQueue :: Queue si qi sm qm so qo a -> Process () Source

Wait while the queue is full.

# Summary

queueSummary :: (Show si, Show sm, Show so) => Queue si qi sm qm so qo a -> Int -> Event ShowS Source

Return the summary for the queue with desciption of its properties and activities using the specified indent.

# Derived Signals for Properties

queueNullChanged :: Queue si qi sm qm so qo a -> Signal Bool Source

Signal when the `queueNull`

property value has changed.

queueNullChanged_ :: Queue si qi sm qm so qo a -> Signal () Source

Signal when the `queueNull`

property value has changed.

queueFullChanged :: Queue si qi sm qm so qo a -> Signal Bool Source

Signal when the `queueFull`

property value has changed.

queueFullChanged_ :: Queue si qi sm qm so qo a -> Signal () Source

Signal when the `queueFull`

property value has changed.

queueCountChanged :: Queue si qi sm qm so qo a -> Signal Int Source

Signal when the `queueCount`

property value has changed.

queueCountChanged_ :: Queue si qi sm qm so qo a -> Signal () Source

Signal when the `queueCount`

property value has changed.

queueLostCountChanged :: Queue si qi sm qm so qo a -> Signal Int Source

Signal when the `queueLostCount`

property value has changed.

queueLostCountChanged_ :: Queue si qi sm qm so qo a -> Signal () Source

Signal when the `queueLostCount`

property value has changed.

queueInputCountChanged :: Queue si qi sm qm so qo a -> Signal Int Source

Signal when the `queueInputCount`

property value has changed.

queueInputCountChanged_ :: Queue si qi sm qm so qo a -> Signal () Source

Signal when the `queueInputCount`

property value has changed.

queueStoreCountChanged :: Queue si qi sm qm so qo a -> Signal Int Source

Signal when the `queueStoreCount`

property value has changed.

queueStoreCountChanged_ :: Queue si qi sm qm so qo a -> Signal () Source

Signal when the `queueStoreCount`

property value has changed.

queueOutputRequestCountChanged :: Queue si qi sm qm so qo a -> Signal Int Source

Signal when the `queueOutputRequestCount`

property value has changed.

queueOutputRequestCountChanged_ :: Queue si qi sm qm so qo a -> Signal () Source

Signal when the `queueOutputRequestCount`

property value has changed.

queueOutputCountChanged :: Queue si qi sm qm so qo a -> Signal Int Source

Signal when the `queueOutputCount`

property value has changed.

queueOutputCountChanged_ :: Queue si qi sm qm so qo a -> Signal () Source

Signal when the `queueOutputCount`

property value has changed.

queueLoadFactorChanged :: Queue si qi sm qm so qo a -> Signal Double Source

Signal when the `queueLoadFactor`

property value has changed.

queueLoadFactorChanged_ :: Queue si qi sm qm so qo a -> Signal () Source

Signal when the `queueLoadFactor`

property value has changed.

queueWaitTimeChanged :: Queue si qi sm qm so qo a -> Signal (SamplingStats Double) Source

Signal when the `queueWaitTime`

property value has changed.

queueWaitTimeChanged_ :: Queue si qi sm qm so qo a -> Signal () Source

Signal when the `queueWaitTime`

property value has changed.

queueTotalWaitTimeChanged :: Queue si qi sm qm so qo a -> Signal (SamplingStats Double) Source

Signal when the `queueTotalWaitTime`

property value has changed.

queueTotalWaitTimeChanged_ :: Queue si qi sm qm so qo a -> Signal () Source

Signal when the `queueTotalWaitTime`

property value has changed.

queueInputWaitTimeChanged :: Queue si qi sm qm so qo a -> Signal (SamplingStats Double) Source

Signal when the `queueInputWaitTime`

property value has changed.

queueInputWaitTimeChanged_ :: Queue si qi sm qm so qo a -> Signal () Source

Signal when the `queueInputWaitTime`

property value has changed.

queueOutputWaitTimeChanged :: Queue si qi sm qm so qo a -> Signal (SamplingStats Double) Source

Signal when the `queueOutputWaitTime`

property value has changed.

queueOutputWaitTimeChanged_ :: Queue si qi sm qm so qo a -> Signal () Source

Signal when the `queueOutputWaitTime`

property value has changed.

# Basic Signals

enqueueInitiated :: Queue si qi sm qm so qo a -> Signal a Source

Return a signal that notifies when the enqueuing operation is initiated.

enqueueStored :: Queue si qi sm qm so qo a -> Signal a Source

Return a signal that notifies when the enqueuing operation is completed and the item is stored in the internal memory of the queue.

enqueueLost :: Queue si qi sm qm so qo a -> Signal a Source

Return a signal which notifies that the item was lost when
attempting to add it to the full queue with help of
`enqueueOrLost`

, `enqueueOrLost_`

or similar functions that imply
that the element can be lost. All their names are ending with `OrLost`

or `OrLost_`

.

In other cases the enqueued items are not lost but the corresponded process
can suspend until the internal queue storage is freed. Although there is one
exception from this rule. If the process trying to enqueue a new element was
suspended but then canceled through `cancelProcess`

from the outside then
the item will not be added.

dequeueRequested :: Queue si qi sm qm so qo a -> Signal () Source

Return a signal that notifies when the dequeuing operation was requested.

dequeueExtracted :: Queue si qi sm qm so qo a -> Signal a Source

Return a signal that notifies when the item was extracted from the internal storage of the queue and prepared for immediate receiving by the dequeuing process.

# Overall Signal

queueChanged_ :: Queue si qi sm qm so qo a -> Signal () Source

Signal whenever any property of the queue changes.

The property must have the corresponded signal. There are also characteristics similar to the properties but that have no signals. As a rule, such characteristics already depend on the simulation time and therefore they may change at any time point.