module Simulation.Aivika.Queue
(
FCFSQueue,
LCFSQueue,
SIROQueue,
PriorityQueue,
Queue,
newFCFSQueue,
newLCFSQueue,
newSIROQueue,
newPriorityQueue,
newQueue,
queueInputStrategy,
queueStoringStrategy,
queueOutputStrategy,
queueNull,
queueFull,
queueMaxCount,
queueCount,
queueLostCount,
queueInputCount,
queueStoreCount,
queueOutputRequestCount,
queueOutputCount,
queueLoadFactor,
queueInputRate,
queueStoreRate,
queueOutputRequestRate,
queueOutputRate,
queueWaitTime,
queueTotalWaitTime,
queueInputWaitTime,
queueOutputWaitTime,
dequeue,
dequeueWithOutputPriority,
tryDequeue,
enqueue,
enqueueWithInputPriority,
enqueueWithStoringPriority,
enqueueWithInputStoringPriorities,
tryEnqueue,
tryEnqueueWithStoringPriority,
enqueueOrLost,
enqueueOrLost_,
enqueueWithStoringPriorityOrLost,
enqueueWithStoringPriorityOrLost_,
waitWhileFullQueue,
queueSummary,
queueNullChanged,
queueNullChanged_,
queueFullChanged,
queueFullChanged_,
queueCountChanged,
queueCountChanged_,
queueLostCountChanged,
queueLostCountChanged_,
queueInputCountChanged,
queueInputCountChanged_,
queueStoreCountChanged,
queueStoreCountChanged_,
queueOutputRequestCountChanged,
queueOutputRequestCountChanged_,
queueOutputCountChanged,
queueOutputCountChanged_,
queueLoadFactorChanged,
queueLoadFactorChanged_,
queueWaitTimeChanged,
queueWaitTimeChanged_,
queueTotalWaitTimeChanged,
queueTotalWaitTimeChanged_,
queueInputWaitTimeChanged,
queueInputWaitTimeChanged_,
queueOutputWaitTimeChanged,
queueOutputWaitTimeChanged_,
enqueueInitiated,
enqueueStored,
enqueueLost,
dequeueRequested,
dequeueExtracted,
queueChanged_) where
import Data.IORef
import Data.Monoid
import Control.Monad
import Control.Monad.Trans
import Simulation.Aivika.Internal.Specs
import Simulation.Aivika.Internal.Simulation
import Simulation.Aivika.Internal.Dynamics
import Simulation.Aivika.Internal.Event
import Simulation.Aivika.Internal.Process
import Simulation.Aivika.Internal.Signal
import Simulation.Aivika.Signal
import Simulation.Aivika.Resource
import Simulation.Aivika.QueueStrategy
import Simulation.Aivika.Statistics
import Simulation.Aivika.Stream
import Simulation.Aivika.Processor
import qualified Simulation.Aivika.DoubleLinkedList as DLL
import qualified Simulation.Aivika.Vector as V
import qualified Simulation.Aivika.PriorityQueue as PQ
type FCFSQueue a =
Queue FCFS DLL.DoubleLinkedList FCFS DLL.DoubleLinkedList FCFS DLL.DoubleLinkedList a
type LCFSQueue a =
Queue FCFS DLL.DoubleLinkedList LCFS DLL.DoubleLinkedList FCFS DLL.DoubleLinkedList a
type SIROQueue a =
Queue FCFS DLL.DoubleLinkedList SIRO V.Vector FCFS DLL.DoubleLinkedList a
type PriorityQueue a =
Queue FCFS DLL.DoubleLinkedList StaticPriorities PQ.PriorityQueue FCFS DLL.DoubleLinkedList a
data Queue si qi sm qm so qo a =
Queue { queueMaxCount :: Int,
queueInputStrategy :: si,
queueStoringStrategy :: sm,
queueOutputStrategy :: so,
queueInputRes :: Resource si qi,
queueStore :: qm (QueueItem a),
queueOutputRes :: Resource so qo,
queueCountRef :: IORef Int,
queueLostCountRef :: IORef Int,
queueInputCountRef :: IORef Int,
queueStoreCountRef :: IORef Int,
queueOutputRequestCountRef :: IORef Int,
queueOutputCountRef :: IORef Int,
queueWaitTimeRef :: IORef (SamplingStats Double),
queueTotalWaitTimeRef :: IORef (SamplingStats Double),
queueInputWaitTimeRef :: IORef (SamplingStats Double),
queueOutputWaitTimeRef :: IORef (SamplingStats Double),
enqueueInitiatedSource :: SignalSource a,
enqueueLostSource :: SignalSource a,
enqueueStoredSource :: SignalSource a,
dequeueRequestedSource :: SignalSource (),
dequeueExtractedSource :: SignalSource a }
data QueueItem a =
QueueItem { itemValue :: a,
itemInputTime :: Double,
itemStoringTime :: Double
}
newFCFSQueue :: Int -> Simulation (FCFSQueue a)
newFCFSQueue = newQueue FCFS FCFS FCFS
newLCFSQueue :: Int -> Simulation (LCFSQueue a)
newLCFSQueue = newQueue FCFS LCFS FCFS
newSIROQueue :: Int -> Simulation (SIROQueue a)
newSIROQueue = newQueue FCFS SIRO FCFS
newPriorityQueue :: Int -> Simulation (PriorityQueue a)
newPriorityQueue = newQueue FCFS StaticPriorities FCFS
newQueue :: (QueueStrategy si qi,
QueueStrategy sm qm,
QueueStrategy so qo) =>
si
-> sm
-> so
-> Int
-> Simulation (Queue si qi sm qm so qo a)
newQueue si sm so count =
do i <- liftIO $ newIORef 0
l <- liftIO $ newIORef 0
ci <- liftIO $ newIORef 0
cm <- liftIO $ newIORef 0
cr <- liftIO $ newIORef 0
co <- liftIO $ newIORef 0
ri <- newResourceWithMaxCount si count (Just count)
qm <- newStrategyQueue sm
ro <- newResourceWithMaxCount so 0 (Just count)
w <- liftIO $ newIORef mempty
wt <- liftIO $ newIORef mempty
wi <- liftIO $ newIORef mempty
wo <- liftIO $ newIORef mempty
s1 <- newSignalSource
s2 <- newSignalSource
s3 <- newSignalSource
s4 <- newSignalSource
s5 <- newSignalSource
return Queue { queueMaxCount = count,
queueInputStrategy = si,
queueStoringStrategy = sm,
queueOutputStrategy = so,
queueInputRes = ri,
queueStore = qm,
queueOutputRes = ro,
queueCountRef = i,
queueLostCountRef = l,
queueInputCountRef = ci,
queueStoreCountRef = cm,
queueOutputRequestCountRef = cr,
queueOutputCountRef = co,
queueWaitTimeRef = w,
queueTotalWaitTimeRef = wt,
queueInputWaitTimeRef = wi,
queueOutputWaitTimeRef = wo,
enqueueInitiatedSource = s1,
enqueueLostSource = s2,
enqueueStoredSource = s3,
dequeueRequestedSource = s4,
dequeueExtractedSource = s5 }
queueNull :: Queue si qi sm qm so qo a -> Event Bool
queueNull q =
Event $ \p ->
do n <- readIORef (queueCountRef q)
return (n == 0)
queueNullChanged :: Queue si qi sm qm so qo a -> Signal Bool
queueNullChanged q =
mapSignalM (const $ queueNull q) (queueNullChanged_ q)
queueNullChanged_ :: Queue si qi sm qm so qo a -> Signal ()
queueNullChanged_ = queueCountChanged_
queueFull :: Queue si qi sm qm so qo a -> Event Bool
queueFull q =
Event $ \p ->
do n <- readIORef (queueCountRef q)
return (n == queueMaxCount q)
queueFullChanged :: Queue si qi sm qm so qo a -> Signal Bool
queueFullChanged q =
mapSignalM (const $ queueFull q) (queueFullChanged_ q)
queueFullChanged_ :: Queue si qi sm qm so qo a -> Signal ()
queueFullChanged_ = queueCountChanged_
queueCount :: Queue si qi sm qm so qo a -> Event Int
queueCount q =
Event $ \p -> readIORef (queueCountRef q)
queueCountChanged :: Queue si qi sm qm so qo a -> Signal Int
queueCountChanged q =
mapSignalM (const $ queueCount q) (queueCountChanged_ q)
queueCountChanged_ :: Queue si qi sm qm so qo a -> Signal ()
queueCountChanged_ q =
mapSignal (const ()) (enqueueStored q) <>
mapSignal (const ()) (dequeueExtracted q)
queueLostCount :: Queue si qi sm qm so qo a -> Event Int
queueLostCount q =
Event $ \p -> readIORef (queueLostCountRef q)
queueLostCountChanged :: Queue si qi sm qm so qo a -> Signal Int
queueLostCountChanged q =
mapSignalM (const $ queueLostCount q) (queueLostCountChanged_ q)
queueLostCountChanged_ :: Queue si qi sm qm so qo a -> Signal ()
queueLostCountChanged_ q =
mapSignal (const ()) (enqueueLost q)
queueInputCount :: Queue si qi sm qm so qo a -> Event Int
queueInputCount q =
Event $ \p -> readIORef (queueInputCountRef q)
queueInputCountChanged :: Queue si qi sm qm so qo a -> Signal Int
queueInputCountChanged q =
mapSignalM (const $ queueInputCount q) (queueInputCountChanged_ q)
queueInputCountChanged_ :: Queue si qi sm qm so qo a -> Signal ()
queueInputCountChanged_ q =
mapSignal (const ()) (enqueueInitiated q)
queueStoreCount :: Queue si qi sm qm so qo a -> Event Int
queueStoreCount q =
Event $ \p -> readIORef (queueStoreCountRef q)
queueStoreCountChanged :: Queue si qi sm qm so qo a -> Signal Int
queueStoreCountChanged q =
mapSignalM (const $ queueStoreCount q) (queueStoreCountChanged_ q)
queueStoreCountChanged_ :: Queue si qi sm qm so qo a -> Signal ()
queueStoreCountChanged_ q =
mapSignal (const ()) (enqueueStored q)
queueOutputRequestCount :: Queue si qi sm qm so qo a -> Event Int
queueOutputRequestCount q =
Event $ \p -> readIORef (queueOutputRequestCountRef q)
queueOutputRequestCountChanged :: Queue si qi sm qm so qo a -> Signal Int
queueOutputRequestCountChanged q =
mapSignalM (const $ queueOutputRequestCount q) (queueOutputRequestCountChanged_ q)
queueOutputRequestCountChanged_ :: Queue si qi sm qm so qo a -> Signal ()
queueOutputRequestCountChanged_ q =
mapSignal (const ()) (dequeueRequested q)
queueOutputCount :: Queue si qi sm qm so qo a -> Event Int
queueOutputCount q =
Event $ \p -> readIORef (queueOutputCountRef q)
queueOutputCountChanged :: Queue si qi sm qm so qo a -> Signal Int
queueOutputCountChanged q =
mapSignalM (const $ queueOutputCount q) (queueOutputCountChanged_ q)
queueOutputCountChanged_ :: Queue si qi sm qm so qo a -> Signal ()
queueOutputCountChanged_ q =
mapSignal (const ()) (dequeueExtracted q)
queueLoadFactor :: Queue si qi sm qm so qo a -> Event Double
queueLoadFactor q =
Event $ \p ->
do x <- readIORef (queueCountRef q)
let y = queueMaxCount q
return (fromIntegral x / fromIntegral y)
queueLoadFactorChanged :: Queue si qi sm qm so qo a -> Signal Double
queueLoadFactorChanged q =
mapSignalM (const $ queueLoadFactor q) (queueLoadFactorChanged_ q)
queueLoadFactorChanged_ :: Queue si qi sm qm so qo a -> Signal ()
queueLoadFactorChanged_ q =
mapSignal (const ()) (enqueueStored q) <>
mapSignal (const ()) (dequeueExtracted q)
queueInputRate :: Queue si qi sm qm so qo a -> Event Double
queueInputRate q =
Event $ \p ->
do x <- readIORef (queueInputCountRef q)
let t0 = spcStartTime $ pointSpecs p
t = pointTime p
return (fromIntegral x / (t t0))
queueStoreRate :: Queue si qi sm qm so qo a -> Event Double
queueStoreRate q =
Event $ \p ->
do x <- readIORef (queueStoreCountRef q)
let t0 = spcStartTime $ pointSpecs p
t = pointTime p
return (fromIntegral x / (t t0))
queueOutputRequestRate :: Queue si qi sm qm so qo a -> Event Double
queueOutputRequestRate q =
Event $ \p ->
do x <- readIORef (queueOutputRequestCountRef q)
let t0 = spcStartTime $ pointSpecs p
t = pointTime p
return (fromIntegral x / (t t0))
queueOutputRate :: Queue si qi sm qm so qo a -> Event Double
queueOutputRate q =
Event $ \p ->
do x <- readIORef (queueOutputCountRef q)
let t0 = spcStartTime $ pointSpecs p
t = pointTime p
return (fromIntegral x / (t t0))
queueWaitTime :: Queue si qi sm qm so qo a -> Event (SamplingStats Double)
queueWaitTime q =
Event $ \p -> readIORef (queueWaitTimeRef q)
queueWaitTimeChanged :: Queue si qi sm qm so qo a -> Signal (SamplingStats Double)
queueWaitTimeChanged q =
mapSignalM (const $ queueWaitTime q) (queueWaitTimeChanged_ q)
queueWaitTimeChanged_ :: Queue si qi sm qm so qo a -> Signal ()
queueWaitTimeChanged_ q =
mapSignal (const ()) (dequeueExtracted q)
queueTotalWaitTime :: Queue si qi sm qm so qo a -> Event (SamplingStats Double)
queueTotalWaitTime q =
Event $ \p -> readIORef (queueTotalWaitTimeRef q)
queueTotalWaitTimeChanged :: Queue si qi sm qm so qo a -> Signal (SamplingStats Double)
queueTotalWaitTimeChanged q =
mapSignalM (const $ queueTotalWaitTime q) (queueTotalWaitTimeChanged_ q)
queueTotalWaitTimeChanged_ :: Queue si qi sm qm so qo a -> Signal ()
queueTotalWaitTimeChanged_ q =
mapSignal (const ()) (dequeueExtracted q)
queueInputWaitTime :: Queue si qi sm qm so qo a -> Event (SamplingStats Double)
queueInputWaitTime q =
Event $ \p -> readIORef (queueInputWaitTimeRef q)
queueInputWaitTimeChanged :: Queue si qi sm qm so qo a -> Signal (SamplingStats Double)
queueInputWaitTimeChanged q =
mapSignalM (const $ queueInputWaitTime q) (queueInputWaitTimeChanged_ q)
queueInputWaitTimeChanged_ :: Queue si qi sm qm so qo a -> Signal ()
queueInputWaitTimeChanged_ q =
mapSignal (const ()) (enqueueStored q)
queueOutputWaitTime :: Queue si qi sm qm so qo a -> Event (SamplingStats Double)
queueOutputWaitTime q =
Event $ \p -> readIORef (queueOutputWaitTimeRef q)
queueOutputWaitTimeChanged :: Queue si qi sm qm so qo a -> Signal (SamplingStats Double)
queueOutputWaitTimeChanged q =
mapSignalM (const $ queueOutputWaitTime q) (queueOutputWaitTimeChanged_ q)
queueOutputWaitTimeChanged_ :: Queue si qi sm qm so qo a -> Signal ()
queueOutputWaitTimeChanged_ q =
mapSignal (const ()) (dequeueExtracted q)
dequeue :: (DequeueStrategy si qi,
DequeueStrategy sm qm,
EnqueueStrategy so qo)
=> Queue si qi sm qm so qo a
-> Process a
dequeue q =
do t <- liftEvent $ dequeueRequest q
requestResource (queueOutputRes q)
liftEvent $ dequeueExtract q t
dequeueWithOutputPriority :: (DequeueStrategy si qi,
DequeueStrategy sm qm,
PriorityQueueStrategy so qo po)
=> Queue si qi sm qm so qo a
-> po
-> Process a
dequeueWithOutputPriority q po =
do t <- liftEvent $ dequeueRequest q
requestResourceWithPriority (queueOutputRes q) po
liftEvent $ dequeueExtract q t
tryDequeue :: (DequeueStrategy si qi,
DequeueStrategy sm qm)
=> Queue si qi sm qm so qo a
-> Event (Maybe a)
tryDequeue q =
do x <- tryRequestResourceWithinEvent (queueOutputRes q)
if x
then do t <- dequeueRequest q
fmap Just $ dequeueExtract q t
else return Nothing
enqueue :: (EnqueueStrategy si qi,
EnqueueStrategy sm qm,
DequeueStrategy so qo)
=> Queue si qi sm qm so qo a
-> a
-> Process ()
enqueue q a =
do i <- liftEvent $ enqueueInitiate q a
requestResource (queueInputRes q)
liftEvent $ enqueueStore q i
enqueueWithInputPriority :: (PriorityQueueStrategy si qi pi,
EnqueueStrategy sm qm,
DequeueStrategy so qo)
=> Queue si qi sm qm so qo a
-> pi
-> a
-> Process ()
enqueueWithInputPriority q pi a =
do i <- liftEvent $ enqueueInitiate q a
requestResourceWithPriority (queueInputRes q) pi
liftEvent $ enqueueStore q i
enqueueWithStoringPriority :: (EnqueueStrategy si qi,
PriorityQueueStrategy sm qm pm,
DequeueStrategy so qo)
=> Queue si qi sm qm so qo a
-> pm
-> a
-> Process ()
enqueueWithStoringPriority q pm a =
do i <- liftEvent $ enqueueInitiate q a
requestResource (queueInputRes q)
liftEvent $ enqueueStoreWithPriority q pm i
enqueueWithInputStoringPriorities :: (PriorityQueueStrategy si qi pi,
PriorityQueueStrategy sm qm pm,
DequeueStrategy so qo)
=> Queue si qi sm qm so qo a
-> pi
-> pm
-> a
-> Process ()
enqueueWithInputStoringPriorities q pi pm a =
do i <- liftEvent $ enqueueInitiate q a
requestResourceWithPriority (queueInputRes q) pi
liftEvent $ enqueueStoreWithPriority q pm i
tryEnqueue :: (EnqueueStrategy sm qm,
DequeueStrategy so qo)
=> Queue si qi sm qm so qo a
-> a
-> Event Bool
tryEnqueue q a =
do x <- tryRequestResourceWithinEvent (queueInputRes q)
if x
then do enqueueInitiate q a >>= enqueueStore q
return True
else return False
tryEnqueueWithStoringPriority :: (PriorityQueueStrategy sm qm pm,
DequeueStrategy so qo)
=> Queue si qi sm qm so qo a
-> pm
-> a
-> Event Bool
tryEnqueueWithStoringPriority q pm a =
do x <- tryRequestResourceWithinEvent (queueInputRes q)
if x
then do enqueueInitiate q a >>= enqueueStoreWithPriority q pm
return True
else return False
enqueueOrLost :: (EnqueueStrategy sm qm,
DequeueStrategy so qo)
=> Queue si qi sm qm so qo a
-> a
-> Event Bool
enqueueOrLost q a =
do x <- tryRequestResourceWithinEvent (queueInputRes q)
if x
then do enqueueInitiate q a >>= enqueueStore q
return True
else do enqueueDeny q a
return False
enqueueWithStoringPriorityOrLost :: (PriorityQueueStrategy sm qm pm,
DequeueStrategy so qo)
=> Queue si qi sm qm so qo a
-> pm
-> a
-> Event Bool
enqueueWithStoringPriorityOrLost q pm a =
do x <- tryRequestResourceWithinEvent (queueInputRes q)
if x
then do enqueueInitiate q a >>= enqueueStoreWithPriority q pm
return True
else do enqueueDeny q a
return False
enqueueOrLost_ :: (EnqueueStrategy sm qm,
DequeueStrategy so qo)
=> Queue si qi sm qm so qo a
-> a
-> Event ()
enqueueOrLost_ q a =
do x <- enqueueOrLost q a
return ()
enqueueWithStoringPriorityOrLost_ :: (PriorityQueueStrategy sm qm pm,
DequeueStrategy so qo)
=> Queue si qi sm qm so qo a
-> pm
-> a
-> Event ()
enqueueWithStoringPriorityOrLost_ q pm a =
do x <- enqueueWithStoringPriorityOrLost q pm a
return ()
enqueueInitiated :: Queue si qi sm qm so qo a -> Signal a
enqueueInitiated q = publishSignal (enqueueInitiatedSource q)
enqueueStored :: Queue si qi sm qm so qo a -> Signal a
enqueueStored q = publishSignal (enqueueStoredSource q)
enqueueLost :: Queue si qi sm qm so qo a -> Signal a
enqueueLost q = publishSignal (enqueueLostSource q)
dequeueRequested :: Queue si qi sm qm so qo a -> Signal ()
dequeueRequested q = publishSignal (dequeueRequestedSource q)
dequeueExtracted :: Queue si qi sm qm so qo a -> Signal a
dequeueExtracted q = publishSignal (dequeueExtractedSource q)
enqueueInitiate :: Queue si qi sm qm so qo a
-> a
-> Event (QueueItem a)
enqueueInitiate q a =
Event $ \p ->
do let t = pointTime p
modifyIORef (queueInputCountRef q) (+ 1)
invokeEvent p $
triggerSignal (enqueueInitiatedSource q) a
return QueueItem { itemValue = a,
itemInputTime = t,
itemStoringTime = t
}
enqueueStore :: (EnqueueStrategy sm qm,
DequeueStrategy so qo)
=> Queue si qi sm qm so qo a
-> QueueItem a
-> Event ()
enqueueStore q i =
Event $ \p ->
do let i' = i { itemStoringTime = pointTime p }
invokeEvent p $
strategyEnqueue (queueStoringStrategy q) (queueStore q) i'
modifyIORef (queueCountRef q) (+ 1)
modifyIORef (queueStoreCountRef q) (+ 1)
invokeEvent p $
enqueueStat q i'
invokeEvent p $
releaseResourceWithinEvent (queueOutputRes q)
invokeEvent p $
triggerSignal (enqueueStoredSource q) (itemValue i')
enqueueStoreWithPriority :: (PriorityQueueStrategy sm qm pm,
DequeueStrategy so qo)
=> Queue si qi sm qm so qo a
-> pm
-> QueueItem a
-> Event ()
enqueueStoreWithPriority q pm i =
Event $ \p ->
do let i' = i { itemStoringTime = pointTime p }
invokeEvent p $
strategyEnqueueWithPriority (queueStoringStrategy q) (queueStore q) pm i'
modifyIORef (queueCountRef q) (+ 1)
modifyIORef (queueStoreCountRef q) (+ 1)
invokeEvent p $
enqueueStat q i'
invokeEvent p $
releaseResourceWithinEvent (queueOutputRes q)
invokeEvent p $
triggerSignal (enqueueStoredSource q) (itemValue i')
enqueueDeny :: Queue si qi sm qm so qo a
-> a
-> Event ()
enqueueDeny q a =
Event $ \p ->
do modifyIORef (queueLostCountRef q) $ (+) 1
invokeEvent p $
triggerSignal (enqueueLostSource q) a
enqueueStat :: Queue si qi sm qm so qo a
-> QueueItem a
-> Event ()
enqueueStat q i =
Event $ \p ->
do let t0 = itemInputTime i
t1 = itemStoringTime i
modifyIORef (queueInputWaitTimeRef q) $
addSamplingStats (t1 t0)
dequeueRequest :: Queue si qi sm qm so qo a
-> Event Double
dequeueRequest q =
Event $ \p ->
do modifyIORef (queueOutputRequestCountRef q) (+ 1)
invokeEvent p $
triggerSignal (dequeueRequestedSource q) ()
return $ pointTime p
dequeueExtract :: (DequeueStrategy si qi,
DequeueStrategy sm qm)
=> Queue si qi sm qm so qo a
-> Double
-> Event a
dequeueExtract q t' =
Event $ \p ->
do i <- invokeEvent p $
strategyDequeue (queueStoringStrategy q) (queueStore q)
modifyIORef (queueCountRef q) (+ ( 1))
modifyIORef (queueOutputCountRef q) (+ 1)
invokeEvent p $
dequeueStat q t' i
invokeEvent p $
releaseResourceWithinEvent (queueInputRes q)
invokeEvent p $
triggerSignal (dequeueExtractedSource q) (itemValue i)
return $ itemValue i
dequeueStat :: Queue si qi sm qm so qo a
-> Double
-> QueueItem a
-> Event ()
dequeueStat q t' i =
Event $ \p ->
do let t0 = itemInputTime i
t1 = itemStoringTime i
t = pointTime p
modifyIORef (queueOutputWaitTimeRef q) $
addSamplingStats (t t')
modifyIORef (queueTotalWaitTimeRef q) $
addSamplingStats (t t0)
modifyIORef (queueWaitTimeRef q) $
addSamplingStats (t t1)
waitWhileFullQueue :: Queue si qi sm qm so qo a -> Process ()
waitWhileFullQueue q =
do x <- liftEvent (queueFull q)
when x $
do processAwait (dequeueExtracted q)
waitWhileFullQueue q
queueChanged_ :: Queue si qi sm qm so qo a -> Signal ()
queueChanged_ q =
mapSignal (const ()) (enqueueInitiated q) <>
mapSignal (const ()) (enqueueStored q) <>
mapSignal (const ()) (enqueueLost q) <>
dequeueRequested q <>
mapSignal (const ()) (dequeueExtracted q)
queueSummary :: (Show si, Show sm, Show so) => Queue si qi sm qm so qo a -> Int -> Event ShowS
queueSummary q indent =
do let si = queueInputStrategy q
sm = queueStoringStrategy q
so = queueOutputStrategy q
null <- queueNull q
full <- queueFull q
let maxCount = queueMaxCount q
count <- queueCount q
lostCount <- queueLostCount q
inputCount <- queueInputCount q
storeCount <- queueStoreCount q
outputRequestCount <- queueOutputRequestCount q
outputCount <- queueOutputCount q
loadFactor <- queueLoadFactor q
inputRate <- queueInputRate q
storeRate <- queueStoreRate q
outputRequestRate <- queueOutputRequestRate q
outputRate <- queueOutputRate q
waitTime <- queueWaitTime q
totalWaitTime <- queueTotalWaitTime q
inputWaitTime <- queueInputWaitTime q
outputWaitTime <- queueOutputWaitTime q
let tab = replicate indent ' '
return $
showString tab .
showString "the input (enqueueing) strategy = " .
shows si .
showString "\n" .
showString tab .
showString "the storing (memory) strategy = " .
shows sm .
showString "\n" .
showString tab .
showString "the output (dequeueing) strategy = " .
shows so .
showString "\n" .
showString tab .
showString "empty? = " .
shows null .
showString "\n" .
showString tab .
showString "full? = " .
shows full .
showString "\n" .
showString tab .
showString "max. capacity = " .
shows maxCount .
showString "\n" .
showString tab .
showString "size = " .
shows count .
showString "\n" .
showString tab .
showString "the lost count (number of the lost items) = " .
shows lostCount .
showString "\n" .
showString tab .
showString "the input count (number of the input items that were enqueued) = " .
shows inputCount .
showString "\n" .
showString tab .
showString "the store count (number of the input items that were stored) = " .
shows storeCount .
showString "\n" .
showString tab .
showString "the output request count (number of requests for dequeueing an item) = " .
shows outputRequestCount .
showString "\n" .
showString tab .
showString "the output count (number of the output items that were dequeued) = " .
shows outputCount .
showString "\n" .
showString tab .
showString "the load factor (size / max. capacity) = " .
shows loadFactor .
showString "\n" .
showString tab .
showString "the input rate (how many input items were enqueued per time) = " .
shows inputRate .
showString "\n" .
showString tab .
showString "the store rate (how many input items were stored per time) = " .
shows storeRate .
showString "\n" .
showString tab .
showString "the output request rate (how many requests for dequeueing per time) = " .
shows outputRequestRate .
showString "\n" .
showString tab .
showString "the output rate (how many output items were dequeued per time) = " .
shows outputRate .
showString "\n" .
showString tab .
showString "the wait time (when was stored -> when was dequeued) = \n\n" .
samplingStatsSummary waitTime (2 + indent) .
showString "\n\n" .
showString tab .
showString "the total wait time (when the enqueueing was initiated -> when was dequeued) = \n\n" .
samplingStatsSummary totalWaitTime (2 + indent) .
showString "\n\n" .
showString tab .
showString "the input wait time (when the enqueueing was initiated -> when was stored) = \n\n" .
samplingStatsSummary inputWaitTime (2 + indent) .
showString "\n\n" .
showString tab .
showString "the output wait time (when was requested for dequeueing -> when was dequeued) = \n\n" .
samplingStatsSummary outputWaitTime (2 + indent)