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

License | BSD3 |

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

Stability | experimental |

Safe Haskell | None |

Language | Haskell2010 |

Tested with: GHC 7.8.3

This module defines an infinite queue that can use the specified strategies.

- type FCFSQueue m a = Queue m FCFS FCFS a
- type LCFSQueue m a = Queue m LCFS FCFS a
- type SIROQueue m a = Queue m SIRO FCFS a
- type PriorityQueue m a = Queue m StaticPriorities FCFS a
- data Queue m sm so a
- newFCFSQueue :: MonadComp m => Event m (FCFSQueue m a)
- newLCFSQueue :: MonadComp m => Event m (LCFSQueue m a)
- newSIROQueue :: MonadComp m => Event m (SIROQueue m a)
- newPriorityQueue :: MonadComp m => Event m (PriorityQueue m a)
- newQueue :: (MonadComp m, QueueStrategy m sm, QueueStrategy m so) => sm -> so -> Event m (Queue m sm so a)
- enqueueStoringStrategy :: Queue m sm so a -> sm
- dequeueStrategy :: Queue m sm so a -> so
- queueNull :: MonadComp m => Queue m sm so a -> Event m Bool
- queueCount :: MonadComp m => Queue m sm so a -> Event m Int
- queueCountStats :: MonadComp m => Queue m sm so a -> Event m (TimingStats Int)
- enqueueStoreCount :: MonadComp m => Queue m sm so a -> Event m Int
- dequeueCount :: MonadComp m => Queue m sm so a -> Event m Int
- dequeueExtractCount :: MonadComp m => Queue m sm so a -> Event m Int
- enqueueStoreRate :: MonadComp m => Queue m sm so a -> Event m Double
- dequeueRate :: MonadComp m => Queue m sm so a -> Event m Double
- dequeueExtractRate :: MonadComp m => Queue m sm so a -> Event m Double
- queueWaitTime :: MonadComp m => Queue m sm so a -> Event m (SamplingStats Double)
- dequeueWaitTime :: MonadComp m => Queue m sm so a -> Event m (SamplingStats Double)
- queueRate :: MonadComp m => Queue m sm so a -> Event m Double
- dequeue :: (MonadComp m, DequeueStrategy m sm, EnqueueStrategy m so) => Queue m sm so a -> Process m a
- dequeueWithOutputPriority :: (MonadComp m, DequeueStrategy m sm, PriorityQueueStrategy m so po) => Queue m sm so a -> po -> Process m a
- tryDequeue :: (MonadComp m, DequeueStrategy m sm) => Queue m sm so a -> Event m (Maybe a)
- enqueue :: (MonadComp m, EnqueueStrategy m sm, DequeueStrategy m so) => Queue m sm so a -> a -> Event m ()
- enqueueWithStoringPriority :: (MonadComp m, PriorityQueueStrategy m sm pm, DequeueStrategy m so) => Queue m sm so a -> pm -> a -> Event m ()
- queueSummary :: (MonadComp m, Show sm, Show so) => Queue m sm so a -> Int -> Event m ShowS
- queueNullChanged :: MonadComp m => Queue m sm so a -> Signal m Bool
- queueNullChanged_ :: MonadComp m => Queue m sm so a -> Signal m ()
- queueCountChanged :: MonadComp m => Queue m sm so a -> Signal m Int
- queueCountChanged_ :: MonadComp m => Queue m sm so a -> Signal m ()
- enqueueStoreCountChanged :: MonadComp m => Queue m sm so a -> Signal m Int
- enqueueStoreCountChanged_ :: MonadComp m => Queue m sm so a -> Signal m ()
- dequeueCountChanged :: MonadComp m => Queue m sm so a -> Signal m Int
- dequeueCountChanged_ :: MonadComp m => Queue m sm so a -> Signal m ()
- dequeueExtractCountChanged :: MonadComp m => Queue m sm so a -> Signal m Int
- dequeueExtractCountChanged_ :: MonadComp m => Queue m sm so a -> Signal m ()
- queueWaitTimeChanged :: MonadComp m => Queue m sm so a -> Signal m (SamplingStats Double)
- queueWaitTimeChanged_ :: MonadComp m => Queue m sm so a -> Signal m ()
- dequeueWaitTimeChanged :: MonadComp m => Queue m sm so a -> Signal m (SamplingStats Double)
- dequeueWaitTimeChanged_ :: MonadComp m => Queue m sm so a -> Signal m ()
- queueRateChanged :: MonadComp m => Queue m sm so a -> Signal m Double
- queueRateChanged_ :: MonadComp m => Queue m sm so a -> Signal m ()
- enqueueStored :: MonadComp m => Queue m sm so a -> Signal m a
- dequeueRequested :: MonadComp m => Queue m sm so a -> Signal m ()
- dequeueExtracted :: MonadComp m => Queue m sm so a -> Signal m a
- queueChanged_ :: MonadComp m => Queue m sm so a -> Signal m ()

# Queue Types

type FCFSQueue m a = Queue m FCFS FCFS a Source

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

type LCFSQueue m a = Queue m LCFS FCFS a Source

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

type SIROQueue m a = Queue m SIRO FCFS a Source

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

type PriorityQueue m a = Queue m StaticPriorities FCFS a Source

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

Represents an infinite queue using the specified strategies for
internal storing (in memory), `sm`

, and dequeueing (output), `so`

, where `a`

denotes
the type of items stored in the queue. As usual, type `m`

denotes
the underlying computation within which the simulation executes.

(MonadComp m, Show sm, Show so, ResultItemable (ResultValue sm), ResultItemable (ResultValue so)) => ResultProvider (Queue m sm so a) m |

# Creating Queue

newFCFSQueue :: MonadComp m => Event m (FCFSQueue m a) Source

Create a new infinite FCFS queue.

newLCFSQueue :: MonadComp m => Event m (LCFSQueue m a) Source

Create a new infinite LCFS queue.

newSIROQueue :: MonadComp m => Event m (SIROQueue m a) Source

Create a new infinite SIRO queue.

newPriorityQueue :: MonadComp m => Event m (PriorityQueue m a) Source

Create a new infinite priority queue.

:: (MonadComp m, QueueStrategy m sm, QueueStrategy m so) | |

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

-> so | the strategy applied to the dequeueing (output) processes when the queue is empty |

-> Event m (Queue m sm so a) |

Create a new infinite queue with the specified strategies.

# Queue Properties and Activities

enqueueStoringStrategy :: Queue m sm so a -> sm Source

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

dequeueStrategy :: Queue m sm so a -> so Source

The strategy applied to the dequeueing (output) processes.

queueNull :: MonadComp m => Queue m sm so a -> Event m Bool Source

Test whether the queue is empty.

See also `queueNullChanged`

and `queueNullChanged_`

.

queueCount :: MonadComp m => Queue m sm so a -> Event m Int Source

Return the current queue size.

See also `queueCountStats`

, `queueCountChanged`

and `queueCountChanged_`

.

queueCountStats :: MonadComp m => Queue m sm so a -> Event m (TimingStats Int) Source

Return the queue size statistics.

enqueueStoreCount :: MonadComp m => Queue m sm so a -> Event m Int Source

Return the total number of input items that were stored.

See also `enqueueStoreCountChanged`

and `enqueueStoreCountChanged_`

.

dequeueCount :: MonadComp m => Queue m sm so a -> Event m Int Source

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

See also `dequeueCountChanged`

and `dequeueCountChanged_`

.

dequeueExtractCount :: MonadComp m => Queue m sm so a -> Event m Int Source

Return the total number of output items that were actually dequeued.

See also `dequeueExtractCountChanged`

and `dequeueExtractCountChanged_`

.

enqueueStoreRate :: MonadComp m => Queue m sm so a -> Event m Double Source

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

dequeueRate :: MonadComp m => Queue m sm so a -> Event m Double Source

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

dequeueExtractRate :: MonadComp m => Queue m sm so a -> Event m Double Source

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

queueWaitTime :: MonadComp m => Queue m sm so a -> Event m (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_`

.

dequeueWaitTime :: MonadComp m => Queue m sm so a -> Event m (SamplingStats Double) Source

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

See also `dequeueWaitTimeChanged`

and `dequeueWaitTimeChanged_`

.

queueRate :: MonadComp m => Queue m sm so a -> Event m Double Source

Return a long-term average queue rate calculated as the average queue size divided by the average wait time.

See also `queueRateChanged`

and `queueRateChanged_`

.

# Dequeuing and Enqueuing

:: (MonadComp m, DequeueStrategy m sm, EnqueueStrategy m so) | |

=> Queue m sm so a | the queue |

-> Process m a | the dequeued value |

Dequeue suspending the process if the queue is empty.

dequeueWithOutputPriority Source

:: (MonadComp m, DequeueStrategy m sm, PriorityQueueStrategy m so po) | |

=> Queue m sm so a | the queue |

-> po | the priority for output |

-> Process m a | the dequeued value |

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

:: (MonadComp m, DequeueStrategy m sm) | |

=> Queue m sm so a | the queue |

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

Try to dequeue immediately.

:: (MonadComp m, EnqueueStrategy m sm, DequeueStrategy m so) | |

=> Queue m sm so a | the queue |

-> a | the item to enqueue |

-> Event m () |

Enqueue the item.

enqueueWithStoringPriority Source

:: (MonadComp m, PriorityQueueStrategy m sm pm, DequeueStrategy m so) | |

=> Queue m sm so a | the queue |

-> pm | the priority for storing |

-> a | the item to enqueue |

-> Event m () |

Enqueue with the storing priority the item.

# Summary

queueSummary :: (MonadComp m, Show sm, Show so) => Queue m sm so a -> Int -> Event m ShowS Source

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

# Derived Signals for Properties

queueNullChanged :: MonadComp m => Queue m sm so a -> Signal m Bool Source

Signal when the `queueNull`

property value has changed.

queueNullChanged_ :: MonadComp m => Queue m sm so a -> Signal m () Source

Signal when the `queueNull`

property value has changed.

queueCountChanged :: MonadComp m => Queue m sm so a -> Signal m Int Source

Signal when the `queueCount`

property value has changed.

queueCountChanged_ :: MonadComp m => Queue m sm so a -> Signal m () Source

Signal when the `queueCount`

property value has changed.

enqueueStoreCountChanged :: MonadComp m => Queue m sm so a -> Signal m Int Source

Signal when the `enqueueStoreCount`

property value has changed.

enqueueStoreCountChanged_ :: MonadComp m => Queue m sm so a -> Signal m () Source

Signal when the `enqueueStoreCount`

property value has changed.

dequeueCountChanged :: MonadComp m => Queue m sm so a -> Signal m Int Source

Signal when the `dequeueCount`

property value has changed.

dequeueCountChanged_ :: MonadComp m => Queue m sm so a -> Signal m () Source

Signal when the `dequeueCount`

property value has changed.

dequeueExtractCountChanged :: MonadComp m => Queue m sm so a -> Signal m Int Source

Signal when the `dequeueExtractCount`

property value has changed.

dequeueExtractCountChanged_ :: MonadComp m => Queue m sm so a -> Signal m () Source

Signal when the `dequeueExtractCount`

property value has changed.

queueWaitTimeChanged :: MonadComp m => Queue m sm so a -> Signal m (SamplingStats Double) Source

Signal when the `queueWaitTime`

property value has changed.

queueWaitTimeChanged_ :: MonadComp m => Queue m sm so a -> Signal m () Source

Signal when the `queueWaitTime`

property value has changed.

dequeueWaitTimeChanged :: MonadComp m => Queue m sm so a -> Signal m (SamplingStats Double) Source

Signal when the `dequeueWaitTime`

property value has changed.

dequeueWaitTimeChanged_ :: MonadComp m => Queue m sm so a -> Signal m () Source

Signal when the `dequeueWaitTime`

property value has changed.

queueRateChanged :: MonadComp m => Queue m sm so a -> Signal m Double Source

Signal when the `queueRate`

property value has changed.

queueRateChanged_ :: MonadComp m => Queue m sm so a -> Signal m () Source

Signal when the `queueRate`

property value has changed.

# Basic Signals

enqueueStored :: MonadComp m => Queue m sm so a -> Signal m a Source

Return a signal that notifies when the enqueued item is stored in the internal memory of the queue.

dequeueRequested :: MonadComp m => Queue m sm so a -> Signal m () Source

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

dequeueExtracted :: MonadComp m => Queue m sm so a -> Signal m 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_ :: MonadComp m => Queue m sm so a -> Signal m () 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.