module Simulation.Aivika.GPSS.Facility
(
Facility,
FacilityPreemptMode(..),
FacilityPreemptTransfer,
newFacility,
facilityCount,
facilityCountStats,
facilityCaptureCount,
facilityUtilisationCount,
facilityUtilisationCountStats,
facilityQueueCount,
facilityQueueCountStats,
facilityTotalWaitTime,
facilityWaitTime,
facilityTotalHoldingTime,
facilityHoldingTime,
facilityInterrupted,
seizeFacility,
releaseFacility,
preemptFacility,
returnFacility,
resetFacility,
facilityCountChanged,
facilityCountChanged_,
facilityCaptureCountChanged,
facilityCaptureCountChanged_,
facilityUtilisationCountChanged,
facilityUtilisationCountChanged_,
facilityQueueCountChanged,
facilityQueueCountChanged_,
facilityWaitTimeChanged,
facilityWaitTimeChanged_,
facilityHoldingTimeChanged,
facilityHoldingTimeChanged_,
facilityChanged_) where
import Data.IORef
import Data.Monoid
import Data.Maybe
import Control.Monad
import Control.Monad.Trans
import Control.Exception
import Simulation.Aivika.Internal.Specs
import Simulation.Aivika.Internal.Simulation
import Simulation.Aivika.Internal.Event
import Simulation.Aivika.Internal.Cont
import Simulation.Aivika.Internal.Process
import Simulation.Aivika.QueueStrategy
import Simulation.Aivika.Statistics
import Simulation.Aivika.Signal
import Simulation.Aivika.GPSS.Transact
import Simulation.Aivika.GPSS.TransactQueueStrategy
data Facility a =
Facility { Facility a -> IORef Int
facilityCountRef :: IORef Int,
Facility a -> IORef (TimingStats Int)
facilityCountStatsRef :: IORef (TimingStats Int),
Facility a -> SignalSource Int
facilityCountSource :: SignalSource Int,
Facility a -> IORef Int
facilityCaptureCountRef :: IORef Int,
Facility a -> SignalSource Int
facilityCaptureCountSource :: SignalSource Int,
Facility a -> IORef Int
facilityUtilisationCountRef :: IORef Int,
Facility a -> IORef (TimingStats Int)
facilityUtilisationCountStatsRef :: IORef (TimingStats Int),
Facility a -> SignalSource Int
facilityUtilisationCountSource :: SignalSource Int,
Facility a -> IORef Int
facilityQueueCountRef :: IORef Int,
Facility a -> IORef (TimingStats Int)
facilityQueueCountStatsRef :: IORef (TimingStats Int),
Facility a -> SignalSource Int
facilityQueueCountSource :: SignalSource Int,
Facility a -> IORef Double
facilityTotalWaitTimeRef :: IORef Double,
Facility a -> IORef (SamplingStats Double)
facilityWaitTimeRef :: IORef (SamplingStats Double),
Facility a -> SignalSource ()
facilityWaitTimeSource :: SignalSource (),
Facility a -> IORef Double
facilityTotalHoldingTimeRef :: IORef Double,
Facility a -> IORef (SamplingStats Double)
facilityHoldingTimeRef :: IORef (SamplingStats Double),
Facility a -> SignalSource ()
facilityHoldingTimeSource :: SignalSource (),
Facility a -> IORef (Maybe (FacilityOwnerItem a))
facilityOwnerRef :: IORef (Maybe (FacilityOwnerItem a)),
Facility a
-> StrategyQueue
(TransactQueueStrategy FCFS) (FacilityDelayedItem a)
facilityDelayChain :: StrategyQueue (TransactQueueStrategy FCFS) (FacilityDelayedItem a),
Facility a
-> StrategyQueue
(TransactQueueStrategy LCFS) (FacilityInterruptedItem a)
facilityInterruptChain :: StrategyQueue (TransactQueueStrategy LCFS) (FacilityInterruptedItem a),
Facility a
-> StrategyQueue
(TransactQueueStrategy FCFS) (FacilityPendingItem a)
facilityPendingChain :: StrategyQueue (TransactQueueStrategy FCFS) (FacilityPendingItem a) }
data FacilityOwnerItem a =
FacilityOwnerItem { FacilityOwnerItem a -> Transact a
ownerItemTransact :: Transact a,
FacilityOwnerItem a -> Double
ownerItemTime :: Double,
FacilityOwnerItem a -> Bool
ownerItemPreempting :: Bool,
FacilityOwnerItem a -> Bool
ownerItemInterrupting :: Bool,
FacilityOwnerItem a -> Double
ownerItemAccHoldingTime :: Double }
data FacilityDelayedItem a =
FacilityDelayedItem { FacilityDelayedItem a -> Transact a
delayedItemTransact :: Transact a,
FacilityDelayedItem a -> Double
delayedItemTime :: Double,
FacilityDelayedItem a -> Bool
delayedItemPreempting :: Bool,
FacilityDelayedItem a -> Bool
delayedItemInterrupting :: Bool,
FacilityDelayedItem a -> FrozenCont ()
delayedItemCont :: FrozenCont () }
data FacilityInterruptedItem a =
FacilityInterruptedItem { FacilityInterruptedItem a -> Transact a
interruptedItemTransact :: Transact a,
FacilityInterruptedItem a -> Double
interruptedItemTime :: Double,
FacilityInterruptedItem a -> Bool
interruptedItemPreempting :: Bool,
FacilityInterruptedItem a -> Bool
interruptedItemInterrupting :: Bool,
FacilityInterruptedItem a -> Maybe Double
interruptedItemRemainingTime :: Maybe Double,
FacilityInterruptedItem a -> Maybe (FacilityPreemptTransfer a)
interruptedItemTransfer :: Maybe (FacilityPreemptTransfer a),
FacilityInterruptedItem a -> Double
interruptedItemAccHoldingTime :: Double }
data FacilityPendingItem a =
FacilityPendingItem { FacilityPendingItem a -> Transact a
pendingItemTransact :: Transact a,
FacilityPendingItem a -> Double
pendingItemTime :: Double,
FacilityPendingItem a -> Bool
pendingItemPreempting :: Bool,
FacilityPendingItem a -> Bool
pendingItemInterrupting :: Bool,
FacilityPendingItem a -> FrozenCont ()
pendingItemCont :: FrozenCont () }
instance Eq (Facility a) where
Facility a
x == :: Facility a -> Facility a -> Bool
== Facility a
y = Facility a -> IORef Int
forall a. Facility a -> IORef Int
facilityCountRef Facility a
x IORef Int -> IORef Int -> Bool
forall a. Eq a => a -> a -> Bool
== Facility a -> IORef Int
forall a. Facility a -> IORef Int
facilityCountRef Facility a
y
data FacilityPreemptMode a =
FacilityPreemptMode { FacilityPreemptMode a -> Bool
facilityPriorityMode :: Bool,
FacilityPreemptMode a -> Maybe (FacilityPreemptTransfer a)
facilityTransfer :: Maybe (FacilityPreemptTransfer a),
FacilityPreemptMode a -> Bool
facilityRemoveMode :: Bool
}
type FacilityPreemptTransfer a = Transact a -> Maybe Double -> Process ()
defaultFacilityPreemptMode :: FacilityPreemptMode a
defaultFacilityPreemptMode :: FacilityPreemptMode a
defaultFacilityPreemptMode =
FacilityPreemptMode :: forall a.
Bool
-> Maybe (FacilityPreemptTransfer a)
-> Bool
-> FacilityPreemptMode a
FacilityPreemptMode { facilityPriorityMode :: Bool
facilityPriorityMode = Bool
False,
facilityTransfer :: Maybe (FacilityPreemptTransfer a)
facilityTransfer = Maybe (FacilityPreemptTransfer a)
forall a. Maybe a
Nothing,
facilityRemoveMode :: Bool
facilityRemoveMode = Bool
False
}
newFacility :: Event (Facility a)
newFacility :: Event (Facility a)
newFacility =
(Point -> IO (Facility a)) -> Event (Facility a)
forall a. (Point -> IO a) -> Event a
Event ((Point -> IO (Facility a)) -> Event (Facility a))
-> (Point -> IO (Facility a)) -> Event (Facility a)
forall a b. (a -> b) -> a -> b
$ \Point
p ->
do let r :: Run
r = Point -> Run
pointRun Point
p
t :: Double
t = Point -> Double
pointTime Point
p
IORef Int
countRef <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
1
IORef (TimingStats Int)
countStatsRef <- TimingStats Int -> IO (IORef (TimingStats Int))
forall a. a -> IO (IORef a)
newIORef (TimingStats Int -> IO (IORef (TimingStats Int)))
-> TimingStats Int -> IO (IORef (TimingStats Int))
forall a b. (a -> b) -> a -> b
$ Double -> Int -> TimingStats Int
forall a. TimingData a => Double -> a -> TimingStats a
returnTimingStats Double
t Int
1
SignalSource Int
countSource <- Run -> Simulation (SignalSource Int) -> IO (SignalSource Int)
forall a. Run -> Simulation a -> IO a
invokeSimulation Run
r Simulation (SignalSource Int)
forall a. Simulation (SignalSource a)
newSignalSource
IORef Int
captureCountRef <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
SignalSource Int
captureCountSource <- Run -> Simulation (SignalSource Int) -> IO (SignalSource Int)
forall a. Run -> Simulation a -> IO a
invokeSimulation Run
r Simulation (SignalSource Int)
forall a. Simulation (SignalSource a)
newSignalSource
IORef Int
utilCountRef <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
IORef (TimingStats Int)
utilCountStatsRef <- TimingStats Int -> IO (IORef (TimingStats Int))
forall a. a -> IO (IORef a)
newIORef (TimingStats Int -> IO (IORef (TimingStats Int)))
-> TimingStats Int -> IO (IORef (TimingStats Int))
forall a b. (a -> b) -> a -> b
$ Double -> Int -> TimingStats Int
forall a. TimingData a => Double -> a -> TimingStats a
returnTimingStats Double
t Int
0
SignalSource Int
utilCountSource <- Run -> Simulation (SignalSource Int) -> IO (SignalSource Int)
forall a. Run -> Simulation a -> IO a
invokeSimulation Run
r Simulation (SignalSource Int)
forall a. Simulation (SignalSource a)
newSignalSource
IORef Int
queueCountRef <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
IORef (TimingStats Int)
queueCountStatsRef <- TimingStats Int -> IO (IORef (TimingStats Int))
forall a. a -> IO (IORef a)
newIORef (TimingStats Int -> IO (IORef (TimingStats Int)))
-> TimingStats Int -> IO (IORef (TimingStats Int))
forall a b. (a -> b) -> a -> b
$ Double -> Int -> TimingStats Int
forall a. TimingData a => Double -> a -> TimingStats a
returnTimingStats Double
t Int
0
SignalSource Int
queueCountSource <- Run -> Simulation (SignalSource Int) -> IO (SignalSource Int)
forall a. Run -> Simulation a -> IO a
invokeSimulation Run
r Simulation (SignalSource Int)
forall a. Simulation (SignalSource a)
newSignalSource
IORef Double
totalWaitTimeRef <- Double -> IO (IORef Double)
forall a. a -> IO (IORef a)
newIORef Double
0
IORef (SamplingStats Double)
waitTimeRef <- SamplingStats Double -> IO (IORef (SamplingStats Double))
forall a. a -> IO (IORef a)
newIORef SamplingStats Double
forall a. SamplingData a => SamplingStats a
emptySamplingStats
SignalSource ()
waitTimeSource <- Run -> Simulation (SignalSource ()) -> IO (SignalSource ())
forall a. Run -> Simulation a -> IO a
invokeSimulation Run
r Simulation (SignalSource ())
forall a. Simulation (SignalSource a)
newSignalSource
IORef Double
totalHoldingTimeRef <- Double -> IO (IORef Double)
forall a. a -> IO (IORef a)
newIORef Double
0
IORef (SamplingStats Double)
holdingTimeRef <- SamplingStats Double -> IO (IORef (SamplingStats Double))
forall a. a -> IO (IORef a)
newIORef SamplingStats Double
forall a. SamplingData a => SamplingStats a
emptySamplingStats
SignalSource ()
holdingTimeSource <- Run -> Simulation (SignalSource ()) -> IO (SignalSource ())
forall a. Run -> Simulation a -> IO a
invokeSimulation Run
r Simulation (SignalSource ())
forall a. Simulation (SignalSource a)
newSignalSource
IORef (Maybe (FacilityOwnerItem a))
ownerRef <- Maybe (FacilityOwnerItem a)
-> IO (IORef (Maybe (FacilityOwnerItem a)))
forall a. a -> IO (IORef a)
newIORef Maybe (FacilityOwnerItem a)
forall a. Maybe a
Nothing
StrategyQueue (TransactQueueStrategy FCFS) (FacilityDelayedItem a)
delayChain <- Run
-> Simulation
(StrategyQueue
(TransactQueueStrategy FCFS) (FacilityDelayedItem a))
-> IO
(StrategyQueue
(TransactQueueStrategy FCFS) (FacilityDelayedItem a))
forall a. Run -> Simulation a -> IO a
invokeSimulation Run
r (Simulation
(StrategyQueue
(TransactQueueStrategy FCFS) (FacilityDelayedItem a))
-> IO
(StrategyQueue
(TransactQueueStrategy FCFS) (FacilityDelayedItem a)))
-> Simulation
(StrategyQueue
(TransactQueueStrategy FCFS) (FacilityDelayedItem a))
-> IO
(StrategyQueue
(TransactQueueStrategy FCFS) (FacilityDelayedItem a))
forall a b. (a -> b) -> a -> b
$ TransactQueueStrategy FCFS
-> Simulation
(StrategyQueue
(TransactQueueStrategy FCFS) (FacilityDelayedItem a))
forall s i. QueueStrategy s => s -> Simulation (StrategyQueue s i)
newStrategyQueue (FCFS -> TransactQueueStrategy FCFS
forall s. s -> TransactQueueStrategy s
TransactQueueStrategy FCFS
FCFS)
StrategyQueue
(TransactQueueStrategy LCFS) (FacilityInterruptedItem a)
interruptChain <- Run
-> Simulation
(StrategyQueue
(TransactQueueStrategy LCFS) (FacilityInterruptedItem a))
-> IO
(StrategyQueue
(TransactQueueStrategy LCFS) (FacilityInterruptedItem a))
forall a. Run -> Simulation a -> IO a
invokeSimulation Run
r (Simulation
(StrategyQueue
(TransactQueueStrategy LCFS) (FacilityInterruptedItem a))
-> IO
(StrategyQueue
(TransactQueueStrategy LCFS) (FacilityInterruptedItem a)))
-> Simulation
(StrategyQueue
(TransactQueueStrategy LCFS) (FacilityInterruptedItem a))
-> IO
(StrategyQueue
(TransactQueueStrategy LCFS) (FacilityInterruptedItem a))
forall a b. (a -> b) -> a -> b
$ TransactQueueStrategy LCFS
-> Simulation
(StrategyQueue
(TransactQueueStrategy LCFS) (FacilityInterruptedItem a))
forall s i. QueueStrategy s => s -> Simulation (StrategyQueue s i)
newStrategyQueue (LCFS -> TransactQueueStrategy LCFS
forall s. s -> TransactQueueStrategy s
TransactQueueStrategy LCFS
LCFS)
StrategyQueue (TransactQueueStrategy FCFS) (FacilityPendingItem a)
pendingChain <- Run
-> Simulation
(StrategyQueue
(TransactQueueStrategy FCFS) (FacilityPendingItem a))
-> IO
(StrategyQueue
(TransactQueueStrategy FCFS) (FacilityPendingItem a))
forall a. Run -> Simulation a -> IO a
invokeSimulation Run
r (Simulation
(StrategyQueue
(TransactQueueStrategy FCFS) (FacilityPendingItem a))
-> IO
(StrategyQueue
(TransactQueueStrategy FCFS) (FacilityPendingItem a)))
-> Simulation
(StrategyQueue
(TransactQueueStrategy FCFS) (FacilityPendingItem a))
-> IO
(StrategyQueue
(TransactQueueStrategy FCFS) (FacilityPendingItem a))
forall a b. (a -> b) -> a -> b
$ TransactQueueStrategy FCFS
-> Simulation
(StrategyQueue
(TransactQueueStrategy FCFS) (FacilityPendingItem a))
forall s i. QueueStrategy s => s -> Simulation (StrategyQueue s i)
newStrategyQueue (FCFS -> TransactQueueStrategy FCFS
forall s. s -> TransactQueueStrategy s
TransactQueueStrategy FCFS
FCFS)
Facility a -> IO (Facility a)
forall (m :: * -> *) a. Monad m => a -> m a
return Facility :: forall a.
IORef Int
-> IORef (TimingStats Int)
-> SignalSource Int
-> IORef Int
-> SignalSource Int
-> IORef Int
-> IORef (TimingStats Int)
-> SignalSource Int
-> IORef Int
-> IORef (TimingStats Int)
-> SignalSource Int
-> IORef Double
-> IORef (SamplingStats Double)
-> SignalSource ()
-> IORef Double
-> IORef (SamplingStats Double)
-> SignalSource ()
-> IORef (Maybe (FacilityOwnerItem a))
-> StrategyQueue
(TransactQueueStrategy FCFS) (FacilityDelayedItem a)
-> StrategyQueue
(TransactQueueStrategy LCFS) (FacilityInterruptedItem a)
-> StrategyQueue
(TransactQueueStrategy FCFS) (FacilityPendingItem a)
-> Facility a
Facility { facilityCountRef :: IORef Int
facilityCountRef = IORef Int
countRef,
facilityCountStatsRef :: IORef (TimingStats Int)
facilityCountStatsRef = IORef (TimingStats Int)
countStatsRef,
facilityCountSource :: SignalSource Int
facilityCountSource = SignalSource Int
countSource,
facilityCaptureCountRef :: IORef Int
facilityCaptureCountRef = IORef Int
captureCountRef,
facilityCaptureCountSource :: SignalSource Int
facilityCaptureCountSource = SignalSource Int
captureCountSource,
facilityUtilisationCountRef :: IORef Int
facilityUtilisationCountRef = IORef Int
utilCountRef,
facilityUtilisationCountStatsRef :: IORef (TimingStats Int)
facilityUtilisationCountStatsRef = IORef (TimingStats Int)
utilCountStatsRef,
facilityUtilisationCountSource :: SignalSource Int
facilityUtilisationCountSource = SignalSource Int
utilCountSource,
facilityQueueCountRef :: IORef Int
facilityQueueCountRef = IORef Int
queueCountRef,
facilityQueueCountStatsRef :: IORef (TimingStats Int)
facilityQueueCountStatsRef = IORef (TimingStats Int)
queueCountStatsRef,
facilityQueueCountSource :: SignalSource Int
facilityQueueCountSource = SignalSource Int
queueCountSource,
facilityTotalWaitTimeRef :: IORef Double
facilityTotalWaitTimeRef = IORef Double
totalWaitTimeRef,
facilityWaitTimeRef :: IORef (SamplingStats Double)
facilityWaitTimeRef = IORef (SamplingStats Double)
waitTimeRef,
facilityWaitTimeSource :: SignalSource ()
facilityWaitTimeSource = SignalSource ()
waitTimeSource,
facilityTotalHoldingTimeRef :: IORef Double
facilityTotalHoldingTimeRef = IORef Double
totalHoldingTimeRef,
facilityHoldingTimeRef :: IORef (SamplingStats Double)
facilityHoldingTimeRef = IORef (SamplingStats Double)
holdingTimeRef,
facilityHoldingTimeSource :: SignalSource ()
facilityHoldingTimeSource = SignalSource ()
holdingTimeSource,
facilityOwnerRef :: IORef (Maybe (FacilityOwnerItem a))
facilityOwnerRef = IORef (Maybe (FacilityOwnerItem a))
ownerRef,
facilityDelayChain :: StrategyQueue (TransactQueueStrategy FCFS) (FacilityDelayedItem a)
facilityDelayChain = StrategyQueue (TransactQueueStrategy FCFS) (FacilityDelayedItem a)
delayChain,
facilityInterruptChain :: StrategyQueue
(TransactQueueStrategy LCFS) (FacilityInterruptedItem a)
facilityInterruptChain = StrategyQueue
(TransactQueueStrategy LCFS) (FacilityInterruptedItem a)
interruptChain,
facilityPendingChain :: StrategyQueue (TransactQueueStrategy FCFS) (FacilityPendingItem a)
facilityPendingChain = StrategyQueue (TransactQueueStrategy FCFS) (FacilityPendingItem a)
pendingChain }
facilityCount :: Facility a -> Event Int
facilityCount :: Facility a -> Event Int
facilityCount Facility a
r =
(Point -> IO Int) -> Event Int
forall a. (Point -> IO a) -> Event a
Event ((Point -> IO Int) -> Event Int) -> (Point -> IO Int) -> Event Int
forall a b. (a -> b) -> a -> b
$ \Point
p -> IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (Facility a -> IORef Int
forall a. Facility a -> IORef Int
facilityCountRef Facility a
r)
facilityCountStats :: Facility a -> Event (TimingStats Int)
facilityCountStats :: Facility a -> Event (TimingStats Int)
facilityCountStats Facility a
r =
(Point -> IO (TimingStats Int)) -> Event (TimingStats Int)
forall a. (Point -> IO a) -> Event a
Event ((Point -> IO (TimingStats Int)) -> Event (TimingStats Int))
-> (Point -> IO (TimingStats Int)) -> Event (TimingStats Int)
forall a b. (a -> b) -> a -> b
$ \Point
p -> IORef (TimingStats Int) -> IO (TimingStats Int)
forall a. IORef a -> IO a
readIORef (Facility a -> IORef (TimingStats Int)
forall a. Facility a -> IORef (TimingStats Int)
facilityCountStatsRef Facility a
r)
facilityCountChanged :: Facility a -> Signal Int
facilityCountChanged :: Facility a -> Signal Int
facilityCountChanged Facility a
r =
SignalSource Int -> Signal Int
forall a. SignalSource a -> Signal a
publishSignal (SignalSource Int -> Signal Int) -> SignalSource Int -> Signal Int
forall a b. (a -> b) -> a -> b
$ Facility a -> SignalSource Int
forall a. Facility a -> SignalSource Int
facilityCountSource Facility a
r
facilityCountChanged_ :: Facility a -> Signal ()
facilityCountChanged_ :: Facility a -> Signal ()
facilityCountChanged_ Facility a
r =
(Int -> ()) -> Signal Int -> Signal ()
forall a b. (a -> b) -> Signal a -> Signal b
mapSignal (() -> Int -> ()
forall a b. a -> b -> a
const ()) (Signal Int -> Signal ()) -> Signal Int -> Signal ()
forall a b. (a -> b) -> a -> b
$ Facility a -> Signal Int
forall a. Facility a -> Signal Int
facilityCountChanged Facility a
r
facilityCaptureCount :: Facility a -> Event Int
facilityCaptureCount :: Facility a -> Event Int
facilityCaptureCount Facility a
r =
(Point -> IO Int) -> Event Int
forall a. (Point -> IO a) -> Event a
Event ((Point -> IO Int) -> Event Int) -> (Point -> IO Int) -> Event Int
forall a b. (a -> b) -> a -> b
$ \Point
p -> IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (Facility a -> IORef Int
forall a. Facility a -> IORef Int
facilityCaptureCountRef Facility a
r)
facilityCaptureCountChanged :: Facility a -> Signal Int
facilityCaptureCountChanged :: Facility a -> Signal Int
facilityCaptureCountChanged Facility a
r =
SignalSource Int -> Signal Int
forall a. SignalSource a -> Signal a
publishSignal (SignalSource Int -> Signal Int) -> SignalSource Int -> Signal Int
forall a b. (a -> b) -> a -> b
$ Facility a -> SignalSource Int
forall a. Facility a -> SignalSource Int
facilityCaptureCountSource Facility a
r
facilityCaptureCountChanged_ :: Facility a -> Signal ()
facilityCaptureCountChanged_ :: Facility a -> Signal ()
facilityCaptureCountChanged_ Facility a
r =
(Int -> ()) -> Signal Int -> Signal ()
forall a b. (a -> b) -> Signal a -> Signal b
mapSignal (() -> Int -> ()
forall a b. a -> b -> a
const ()) (Signal Int -> Signal ()) -> Signal Int -> Signal ()
forall a b. (a -> b) -> a -> b
$ Facility a -> Signal Int
forall a. Facility a -> Signal Int
facilityCaptureCountChanged Facility a
r
facilityUtilisationCount :: Facility a -> Event Int
facilityUtilisationCount :: Facility a -> Event Int
facilityUtilisationCount Facility a
r =
(Point -> IO Int) -> Event Int
forall a. (Point -> IO a) -> Event a
Event ((Point -> IO Int) -> Event Int) -> (Point -> IO Int) -> Event Int
forall a b. (a -> b) -> a -> b
$ \Point
p -> IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (Facility a -> IORef Int
forall a. Facility a -> IORef Int
facilityUtilisationCountRef Facility a
r)
facilityUtilisationCountStats :: Facility a -> Event (TimingStats Int)
facilityUtilisationCountStats :: Facility a -> Event (TimingStats Int)
facilityUtilisationCountStats Facility a
r =
(Point -> IO (TimingStats Int)) -> Event (TimingStats Int)
forall a. (Point -> IO a) -> Event a
Event ((Point -> IO (TimingStats Int)) -> Event (TimingStats Int))
-> (Point -> IO (TimingStats Int)) -> Event (TimingStats Int)
forall a b. (a -> b) -> a -> b
$ \Point
p -> IORef (TimingStats Int) -> IO (TimingStats Int)
forall a. IORef a -> IO a
readIORef (Facility a -> IORef (TimingStats Int)
forall a. Facility a -> IORef (TimingStats Int)
facilityUtilisationCountStatsRef Facility a
r)
facilityUtilisationCountChanged :: Facility a -> Signal Int
facilityUtilisationCountChanged :: Facility a -> Signal Int
facilityUtilisationCountChanged Facility a
r =
SignalSource Int -> Signal Int
forall a. SignalSource a -> Signal a
publishSignal (SignalSource Int -> Signal Int) -> SignalSource Int -> Signal Int
forall a b. (a -> b) -> a -> b
$ Facility a -> SignalSource Int
forall a. Facility a -> SignalSource Int
facilityUtilisationCountSource Facility a
r
facilityUtilisationCountChanged_ :: Facility a -> Signal ()
facilityUtilisationCountChanged_ :: Facility a -> Signal ()
facilityUtilisationCountChanged_ Facility a
r =
(Int -> ()) -> Signal Int -> Signal ()
forall a b. (a -> b) -> Signal a -> Signal b
mapSignal (() -> Int -> ()
forall a b. a -> b -> a
const ()) (Signal Int -> Signal ()) -> Signal Int -> Signal ()
forall a b. (a -> b) -> a -> b
$ Facility a -> Signal Int
forall a. Facility a -> Signal Int
facilityUtilisationCountChanged Facility a
r
facilityQueueCount :: Facility a -> Event Int
facilityQueueCount :: Facility a -> Event Int
facilityQueueCount Facility a
r =
(Point -> IO Int) -> Event Int
forall a. (Point -> IO a) -> Event a
Event ((Point -> IO Int) -> Event Int) -> (Point -> IO Int) -> Event Int
forall a b. (a -> b) -> a -> b
$ \Point
p -> IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (Facility a -> IORef Int
forall a. Facility a -> IORef Int
facilityQueueCountRef Facility a
r)
facilityQueueCountStats :: Facility a -> Event (TimingStats Int)
facilityQueueCountStats :: Facility a -> Event (TimingStats Int)
facilityQueueCountStats Facility a
r =
(Point -> IO (TimingStats Int)) -> Event (TimingStats Int)
forall a. (Point -> IO a) -> Event a
Event ((Point -> IO (TimingStats Int)) -> Event (TimingStats Int))
-> (Point -> IO (TimingStats Int)) -> Event (TimingStats Int)
forall a b. (a -> b) -> a -> b
$ \Point
p -> IORef (TimingStats Int) -> IO (TimingStats Int)
forall a. IORef a -> IO a
readIORef (Facility a -> IORef (TimingStats Int)
forall a. Facility a -> IORef (TimingStats Int)
facilityQueueCountStatsRef Facility a
r)
facilityQueueCountChanged :: Facility a -> Signal Int
facilityQueueCountChanged :: Facility a -> Signal Int
facilityQueueCountChanged Facility a
r =
SignalSource Int -> Signal Int
forall a. SignalSource a -> Signal a
publishSignal (SignalSource Int -> Signal Int) -> SignalSource Int -> Signal Int
forall a b. (a -> b) -> a -> b
$ Facility a -> SignalSource Int
forall a. Facility a -> SignalSource Int
facilityQueueCountSource Facility a
r
facilityQueueCountChanged_ :: Facility a -> Signal ()
facilityQueueCountChanged_ :: Facility a -> Signal ()
facilityQueueCountChanged_ Facility a
r =
(Int -> ()) -> Signal Int -> Signal ()
forall a b. (a -> b) -> Signal a -> Signal b
mapSignal (() -> Int -> ()
forall a b. a -> b -> a
const ()) (Signal Int -> Signal ()) -> Signal Int -> Signal ()
forall a b. (a -> b) -> a -> b
$ Facility a -> Signal Int
forall a. Facility a -> Signal Int
facilityQueueCountChanged Facility a
r
facilityTotalWaitTime :: Facility a -> Event Double
facilityTotalWaitTime :: Facility a -> Event Double
facilityTotalWaitTime Facility a
r =
(Point -> IO Double) -> Event Double
forall a. (Point -> IO a) -> Event a
Event ((Point -> IO Double) -> Event Double)
-> (Point -> IO Double) -> Event Double
forall a b. (a -> b) -> a -> b
$ \Point
p -> IORef Double -> IO Double
forall a. IORef a -> IO a
readIORef (Facility a -> IORef Double
forall a. Facility a -> IORef Double
facilityTotalWaitTimeRef Facility a
r)
facilityWaitTime :: Facility a -> Event (SamplingStats Double)
facilityWaitTime :: Facility a -> Event (SamplingStats Double)
facilityWaitTime Facility a
r =
(Point -> IO (SamplingStats Double))
-> Event (SamplingStats Double)
forall a. (Point -> IO a) -> Event a
Event ((Point -> IO (SamplingStats Double))
-> Event (SamplingStats Double))
-> (Point -> IO (SamplingStats Double))
-> Event (SamplingStats Double)
forall a b. (a -> b) -> a -> b
$ \Point
p -> IORef (SamplingStats Double) -> IO (SamplingStats Double)
forall a. IORef a -> IO a
readIORef (Facility a -> IORef (SamplingStats Double)
forall a. Facility a -> IORef (SamplingStats Double)
facilityWaitTimeRef Facility a
r)
facilityWaitTimeChanged :: Facility a -> Signal (SamplingStats Double)
facilityWaitTimeChanged :: Facility a -> Signal (SamplingStats Double)
facilityWaitTimeChanged Facility a
r =
(() -> Event (SamplingStats Double))
-> Signal () -> Signal (SamplingStats Double)
forall a b. (a -> Event b) -> Signal a -> Signal b
mapSignalM (\() -> Facility a -> Event (SamplingStats Double)
forall a. Facility a -> Event (SamplingStats Double)
facilityWaitTime Facility a
r) (Signal () -> Signal (SamplingStats Double))
-> Signal () -> Signal (SamplingStats Double)
forall a b. (a -> b) -> a -> b
$ Facility a -> Signal ()
forall a. Facility a -> Signal ()
facilityWaitTimeChanged_ Facility a
r
facilityWaitTimeChanged_ :: Facility a -> Signal ()
facilityWaitTimeChanged_ :: Facility a -> Signal ()
facilityWaitTimeChanged_ Facility a
r =
SignalSource () -> Signal ()
forall a. SignalSource a -> Signal a
publishSignal (SignalSource () -> Signal ()) -> SignalSource () -> Signal ()
forall a b. (a -> b) -> a -> b
$ Facility a -> SignalSource ()
forall a. Facility a -> SignalSource ()
facilityWaitTimeSource Facility a
r
facilityTotalHoldingTime :: Facility a -> Event Double
facilityTotalHoldingTime :: Facility a -> Event Double
facilityTotalHoldingTime Facility a
r =
(Point -> IO Double) -> Event Double
forall a. (Point -> IO a) -> Event a
Event ((Point -> IO Double) -> Event Double)
-> (Point -> IO Double) -> Event Double
forall a b. (a -> b) -> a -> b
$ \Point
p -> IORef Double -> IO Double
forall a. IORef a -> IO a
readIORef (Facility a -> IORef Double
forall a. Facility a -> IORef Double
facilityTotalHoldingTimeRef Facility a
r)
facilityHoldingTime :: Facility a -> Event (SamplingStats Double)
facilityHoldingTime :: Facility a -> Event (SamplingStats Double)
facilityHoldingTime Facility a
r =
(Point -> IO (SamplingStats Double))
-> Event (SamplingStats Double)
forall a. (Point -> IO a) -> Event a
Event ((Point -> IO (SamplingStats Double))
-> Event (SamplingStats Double))
-> (Point -> IO (SamplingStats Double))
-> Event (SamplingStats Double)
forall a b. (a -> b) -> a -> b
$ \Point
p -> IORef (SamplingStats Double) -> IO (SamplingStats Double)
forall a. IORef a -> IO a
readIORef (Facility a -> IORef (SamplingStats Double)
forall a. Facility a -> IORef (SamplingStats Double)
facilityHoldingTimeRef Facility a
r)
facilityHoldingTimeChanged :: Facility a -> Signal (SamplingStats Double)
facilityHoldingTimeChanged :: Facility a -> Signal (SamplingStats Double)
facilityHoldingTimeChanged Facility a
r =
(() -> Event (SamplingStats Double))
-> Signal () -> Signal (SamplingStats Double)
forall a b. (a -> Event b) -> Signal a -> Signal b
mapSignalM (\() -> Facility a -> Event (SamplingStats Double)
forall a. Facility a -> Event (SamplingStats Double)
facilityHoldingTime Facility a
r) (Signal () -> Signal (SamplingStats Double))
-> Signal () -> Signal (SamplingStats Double)
forall a b. (a -> b) -> a -> b
$ Facility a -> Signal ()
forall a. Facility a -> Signal ()
facilityHoldingTimeChanged_ Facility a
r
facilityHoldingTimeChanged_ :: Facility a -> Signal ()
facilityHoldingTimeChanged_ :: Facility a -> Signal ()
facilityHoldingTimeChanged_ Facility a
r =
SignalSource () -> Signal ()
forall a. SignalSource a -> Signal a
publishSignal (SignalSource () -> Signal ()) -> SignalSource () -> Signal ()
forall a b. (a -> b) -> a -> b
$ Facility a -> SignalSource ()
forall a. Facility a -> SignalSource ()
facilityHoldingTimeSource Facility a
r
facilityInterrupted :: Facility a -> Event Bool
facilityInterrupted :: Facility a -> Event Bool
facilityInterrupted Facility a
r =
(Point -> IO Bool) -> Event Bool
forall a. (Point -> IO a) -> Event a
Event ((Point -> IO Bool) -> Event Bool)
-> (Point -> IO Bool) -> Event Bool
forall a b. (a -> b) -> a -> b
$ \Point
p ->
do Maybe (FacilityOwnerItem a)
x <- IORef (Maybe (FacilityOwnerItem a))
-> IO (Maybe (FacilityOwnerItem a))
forall a. IORef a -> IO a
readIORef (Facility a -> IORef (Maybe (FacilityOwnerItem a))
forall a. Facility a -> IORef (Maybe (FacilityOwnerItem a))
facilityOwnerRef Facility a
r)
case Maybe (FacilityOwnerItem a)
x of
Maybe (FacilityOwnerItem a)
Nothing -> Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
Just FacilityOwnerItem a
a -> Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return (FacilityOwnerItem a -> Bool
forall a. FacilityOwnerItem a -> Bool
ownerItemPreempting FacilityOwnerItem a
a)
seizeFacility :: Facility a
-> Transact a
-> Process ()
seizeFacility :: Facility a -> Transact a -> Process ()
seizeFacility Facility a
r Transact a
transact =
(ProcessId -> Cont ()) -> Process ()
forall a. (ProcessId -> Cont a) -> Process a
Process ((ProcessId -> Cont ()) -> Process ())
-> (ProcessId -> Cont ()) -> Process ()
forall a b. (a -> b) -> a -> b
$ \ProcessId
pid ->
(ContParams () -> Event ()) -> Cont ()
forall a. (ContParams a -> Event ()) -> Cont a
Cont ((ContParams () -> Event ()) -> Cont ())
-> (ContParams () -> Event ()) -> Cont ()
forall a b. (a -> b) -> a -> b
$ \ContParams ()
c ->
(Point -> IO ()) -> Event ()
forall a. (Point -> IO a) -> Event a
Event ((Point -> IO ()) -> Event ()) -> (Point -> IO ()) -> Event ()
forall a b. (a -> b) -> a -> b
$ \Point
p ->
do let t :: Double
t = Point -> Double
pointTime Point
p
Bool
f <- do Bool
f1 <- Point -> Event Bool -> IO Bool
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event Bool -> IO Bool) -> Event Bool -> IO Bool
forall a b. (a -> b) -> a -> b
$ StrategyQueue (TransactQueueStrategy FCFS) (FacilityDelayedItem a)
-> Event Bool
forall s i. QueueStrategy s => StrategyQueue s i -> Event Bool
strategyQueueNull (Facility a
-> StrategyQueue
(TransactQueueStrategy FCFS) (FacilityDelayedItem a)
forall a.
Facility a
-> StrategyQueue
(TransactQueueStrategy FCFS) (FacilityDelayedItem a)
facilityDelayChain Facility a
r)
if Bool
f1
then do Bool
f2 <- Point -> Event Bool -> IO Bool
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event Bool -> IO Bool) -> Event Bool -> IO Bool
forall a b. (a -> b) -> a -> b
$ StrategyQueue
(TransactQueueStrategy LCFS) (FacilityInterruptedItem a)
-> Event Bool
forall s i. QueueStrategy s => StrategyQueue s i -> Event Bool
strategyQueueNull (Facility a
-> StrategyQueue
(TransactQueueStrategy LCFS) (FacilityInterruptedItem a)
forall a.
Facility a
-> StrategyQueue
(TransactQueueStrategy LCFS) (FacilityInterruptedItem a)
facilityInterruptChain Facility a
r)
if Bool
f2
then Point -> Event Bool -> IO Bool
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event Bool -> IO Bool) -> Event Bool -> IO Bool
forall a b. (a -> b) -> a -> b
$ StrategyQueue (TransactQueueStrategy FCFS) (FacilityPendingItem a)
-> Event Bool
forall s i. QueueStrategy s => StrategyQueue s i -> Event Bool
strategyQueueNull (Facility a
-> StrategyQueue
(TransactQueueStrategy FCFS) (FacilityPendingItem a)
forall a.
Facility a
-> StrategyQueue
(TransactQueueStrategy FCFS) (FacilityPendingItem a)
facilityPendingChain Facility a
r)
else Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
else Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
if Bool
f
then Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$
ContParams () -> Cont () -> Event ()
forall a. ContParams a -> Cont a -> Event ()
invokeCont ContParams ()
c (Cont () -> Event ()) -> Cont () -> Event ()
forall a b. (a -> b) -> a -> b
$
ProcessId -> Process () -> Cont ()
forall a. ProcessId -> Process a -> Cont a
invokeProcess ProcessId
pid (Process () -> Cont ()) -> Process () -> Cont ()
forall a b. (a -> b) -> a -> b
$
Facility a -> Transact a -> Process ()
forall a. Facility a -> Transact a -> Process ()
seizeFacility' Facility a
r Transact a
transact
else do FrozenCont ()
c <- Point -> Event (FrozenCont ()) -> IO (FrozenCont ())
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event (FrozenCont ()) -> IO (FrozenCont ()))
-> Event (FrozenCont ()) -> IO (FrozenCont ())
forall a b. (a -> b) -> a -> b
$
ContParams () -> () -> Event () -> Event (FrozenCont ())
forall a. ContParams a -> a -> Event () -> Event (FrozenCont a)
freezeContReentering ContParams ()
c () (Event () -> Event (FrozenCont ()))
-> Event () -> Event (FrozenCont ())
forall a b. (a -> b) -> a -> b
$
ContParams () -> Cont () -> Event ()
forall a. ContParams a -> Cont a -> Event ()
invokeCont ContParams ()
c (Cont () -> Event ()) -> Cont () -> Event ()
forall a b. (a -> b) -> a -> b
$
ProcessId -> Process () -> Cont ()
forall a. ProcessId -> Process a -> Cont a
invokeProcess ProcessId
pid (Process () -> Cont ()) -> Process () -> Cont ()
forall a b. (a -> b) -> a -> b
$
Facility a -> Transact a -> Process ()
forall a. Facility a -> Transact a -> Process ()
seizeFacility Facility a
r Transact a
transact
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$
StrategyQueue (TransactQueueStrategy FCFS) (FacilityDelayedItem a)
-> Int -> FacilityDelayedItem a -> Event ()
forall s p i.
PriorityQueueStrategy s p =>
StrategyQueue s i -> p -> i -> Event ()
strategyEnqueueWithPriority
(Facility a
-> StrategyQueue
(TransactQueueStrategy FCFS) (FacilityDelayedItem a)
forall a.
Facility a
-> StrategyQueue
(TransactQueueStrategy FCFS) (FacilityDelayedItem a)
facilityDelayChain Facility a
r)
(Transact a -> Int
forall a. Transact a -> Int
transactPriority Transact a
transact)
(Transact a
-> Double -> Bool -> Bool -> FrozenCont () -> FacilityDelayedItem a
forall a.
Transact a
-> Double -> Bool -> Bool -> FrozenCont () -> FacilityDelayedItem a
FacilityDelayedItem Transact a
transact Double
t Bool
False Bool
False FrozenCont ()
c)
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$ Facility a -> Int -> Event ()
forall a. Facility a -> Int -> Event ()
updateFacilityQueueCount Facility a
r Int
1
seizeFacility' :: Facility a
-> Transact a
-> Process ()
seizeFacility' :: Facility a -> Transact a -> Process ()
seizeFacility' Facility a
r Transact a
transact =
(ProcessId -> Cont ()) -> Process ()
forall a. (ProcessId -> Cont a) -> Process a
Process ((ProcessId -> Cont ()) -> Process ())
-> (ProcessId -> Cont ()) -> Process ()
forall a b. (a -> b) -> a -> b
$ \ProcessId
pid ->
(ContParams () -> Event ()) -> Cont ()
forall a. (ContParams a -> Event ()) -> Cont a
Cont ((ContParams () -> Event ()) -> Cont ())
-> (ContParams () -> Event ()) -> Cont ()
forall a b. (a -> b) -> a -> b
$ \ContParams ()
c ->
(Point -> IO ()) -> Event ()
forall a. (Point -> IO a) -> Event a
Event ((Point -> IO ()) -> Event ()) -> (Point -> IO ()) -> Event ()
forall a b. (a -> b) -> a -> b
$ \Point
p ->
do let t :: Double
t = Point -> Double
pointTime Point
p
Maybe (FacilityOwnerItem a)
a <- IORef (Maybe (FacilityOwnerItem a))
-> IO (Maybe (FacilityOwnerItem a))
forall a. IORef a -> IO a
readIORef (Facility a -> IORef (Maybe (FacilityOwnerItem a))
forall a. Facility a -> IORef (Maybe (FacilityOwnerItem a))
facilityOwnerRef Facility a
r)
case Maybe (FacilityOwnerItem a)
a of
Maybe (FacilityOwnerItem a)
Nothing ->
do IORef (Maybe (FacilityOwnerItem a))
-> Maybe (FacilityOwnerItem a) -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (Facility a -> IORef (Maybe (FacilityOwnerItem a))
forall a. Facility a -> IORef (Maybe (FacilityOwnerItem a))
facilityOwnerRef Facility a
r) (Maybe (FacilityOwnerItem a) -> IO ())
-> Maybe (FacilityOwnerItem a) -> IO ()
forall a b. (a -> b) -> a -> b
$ FacilityOwnerItem a -> Maybe (FacilityOwnerItem a)
forall a. a -> Maybe a
Just (Transact a
-> Double -> Bool -> Bool -> Double -> FacilityOwnerItem a
forall a.
Transact a
-> Double -> Bool -> Bool -> Double -> FacilityOwnerItem a
FacilityOwnerItem Transact a
transact Double
t Bool
False Bool
False Double
0)
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$ Facility a -> Double -> Event ()
forall a. Facility a -> Double -> Event ()
updateFacilityWaitTime Facility a
r Double
0
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$ Facility a -> Int -> Event ()
forall a. Facility a -> Int -> Event ()
updateFacilityCount Facility a
r (-Int
1)
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$ Facility a -> Int -> Event ()
forall a. Facility a -> Int -> Event ()
updateFacilityCaptureCount Facility a
r Int
1
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$ Facility a -> Int -> Event ()
forall a. Facility a -> Int -> Event ()
updateFacilityUtilisationCount Facility a
r Int
1
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$ ContParams () -> () -> Event ()
forall a. ContParams a -> a -> Event ()
resumeCont ContParams ()
c ()
Just FacilityOwnerItem a
owner ->
do FrozenCont ()
c <- Point -> Event (FrozenCont ()) -> IO (FrozenCont ())
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event (FrozenCont ()) -> IO (FrozenCont ()))
-> Event (FrozenCont ()) -> IO (FrozenCont ())
forall a b. (a -> b) -> a -> b
$
ContParams () -> () -> Event () -> Event (FrozenCont ())
forall a. ContParams a -> a -> Event () -> Event (FrozenCont a)
freezeContReentering ContParams ()
c () (Event () -> Event (FrozenCont ()))
-> Event () -> Event (FrozenCont ())
forall a b. (a -> b) -> a -> b
$
ContParams () -> Cont () -> Event ()
forall a. ContParams a -> Cont a -> Event ()
invokeCont ContParams ()
c (Cont () -> Event ()) -> Cont () -> Event ()
forall a b. (a -> b) -> a -> b
$
ProcessId -> Process () -> Cont ()
forall a. ProcessId -> Process a -> Cont a
invokeProcess ProcessId
pid (Process () -> Cont ()) -> Process () -> Cont ()
forall a b. (a -> b) -> a -> b
$
Facility a -> Transact a -> Process ()
forall a. Facility a -> Transact a -> Process ()
seizeFacility Facility a
r Transact a
transact
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$
StrategyQueue (TransactQueueStrategy FCFS) (FacilityDelayedItem a)
-> Int -> FacilityDelayedItem a -> Event ()
forall s p i.
PriorityQueueStrategy s p =>
StrategyQueue s i -> p -> i -> Event ()
strategyEnqueueWithPriority
(Facility a
-> StrategyQueue
(TransactQueueStrategy FCFS) (FacilityDelayedItem a)
forall a.
Facility a
-> StrategyQueue
(TransactQueueStrategy FCFS) (FacilityDelayedItem a)
facilityDelayChain Facility a
r)
(Transact a -> Int
forall a. Transact a -> Int
transactPriority Transact a
transact)
(Transact a
-> Double -> Bool -> Bool -> FrozenCont () -> FacilityDelayedItem a
forall a.
Transact a
-> Double -> Bool -> Bool -> FrozenCont () -> FacilityDelayedItem a
FacilityDelayedItem Transact a
transact Double
t Bool
False Bool
False FrozenCont ()
c)
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$ Facility a -> Int -> Event ()
forall a. Facility a -> Int -> Event ()
updateFacilityQueueCount Facility a
r Int
1
preemptFacility :: Facility a
-> Transact a
-> FacilityPreemptMode a
-> Process ()
preemptFacility :: Facility a -> Transact a -> FacilityPreemptMode a -> Process ()
preemptFacility Facility a
r Transact a
transact FacilityPreemptMode a
mode =
(ProcessId -> Cont ()) -> Process ()
forall a. (ProcessId -> Cont a) -> Process a
Process ((ProcessId -> Cont ()) -> Process ())
-> (ProcessId -> Cont ()) -> Process ()
forall a b. (a -> b) -> a -> b
$ \ProcessId
pid ->
(ContParams () -> Event ()) -> Cont ()
forall a. (ContParams a -> Event ()) -> Cont a
Cont ((ContParams () -> Event ()) -> Cont ())
-> (ContParams () -> Event ()) -> Cont ()
forall a b. (a -> b) -> a -> b
$ \ContParams ()
c ->
(Point -> IO ()) -> Event ()
forall a. (Point -> IO a) -> Event a
Event ((Point -> IO ()) -> Event ()) -> (Point -> IO ()) -> Event ()
forall a b. (a -> b) -> a -> b
$ \Point
p ->
do let t :: Double
t = Point -> Double
pointTime Point
p
Maybe (FacilityOwnerItem a)
a <- IORef (Maybe (FacilityOwnerItem a))
-> IO (Maybe (FacilityOwnerItem a))
forall a. IORef a -> IO a
readIORef (Facility a -> IORef (Maybe (FacilityOwnerItem a))
forall a. Facility a -> IORef (Maybe (FacilityOwnerItem a))
facilityOwnerRef Facility a
r)
case Maybe (FacilityOwnerItem a)
a of
Maybe (FacilityOwnerItem a)
Nothing ->
do IORef (Maybe (FacilityOwnerItem a))
-> Maybe (FacilityOwnerItem a) -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (Facility a -> IORef (Maybe (FacilityOwnerItem a))
forall a. Facility a -> IORef (Maybe (FacilityOwnerItem a))
facilityOwnerRef Facility a
r) (Maybe (FacilityOwnerItem a) -> IO ())
-> Maybe (FacilityOwnerItem a) -> IO ()
forall a b. (a -> b) -> a -> b
$ FacilityOwnerItem a -> Maybe (FacilityOwnerItem a)
forall a. a -> Maybe a
Just (Transact a
-> Double -> Bool -> Bool -> Double -> FacilityOwnerItem a
forall a.
Transact a
-> Double -> Bool -> Bool -> Double -> FacilityOwnerItem a
FacilityOwnerItem Transact a
transact Double
t Bool
True Bool
False Double
0)
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$ Facility a -> Double -> Event ()
forall a. Facility a -> Double -> Event ()
updateFacilityWaitTime Facility a
r Double
0
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$ Facility a -> Int -> Event ()
forall a. Facility a -> Int -> Event ()
updateFacilityCount Facility a
r (-Int
1)
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$ Facility a -> Int -> Event ()
forall a. Facility a -> Int -> Event ()
updateFacilityCaptureCount Facility a
r Int
1
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$ Facility a -> Int -> Event ()
forall a. Facility a -> Int -> Event ()
updateFacilityUtilisationCount Facility a
r Int
1
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$ ContParams () -> () -> Event ()
forall a. ContParams a -> a -> Event ()
resumeCont ContParams ()
c ()
Just owner :: FacilityOwnerItem a
owner@(FacilityOwnerItem Transact a
transact0 Double
t0 Bool
preempting0 Bool
interrupting0 Double
acc0)
| (Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ FacilityPreemptMode a -> Bool
forall a. FacilityPreemptMode a -> Bool
facilityPriorityMode FacilityPreemptMode a
mode) Bool -> Bool -> Bool
&& Bool
interrupting0 ->
do FrozenCont ()
c <- Point -> Event (FrozenCont ()) -> IO (FrozenCont ())
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event (FrozenCont ()) -> IO (FrozenCont ()))
-> Event (FrozenCont ()) -> IO (FrozenCont ())
forall a b. (a -> b) -> a -> b
$
ContParams () -> () -> Event () -> Event (FrozenCont ())
forall a. ContParams a -> a -> Event () -> Event (FrozenCont a)
freezeContReentering ContParams ()
c () (Event () -> Event (FrozenCont ()))
-> Event () -> Event (FrozenCont ())
forall a b. (a -> b) -> a -> b
$
ContParams () -> Cont () -> Event ()
forall a. ContParams a -> Cont a -> Event ()
invokeCont ContParams ()
c (Cont () -> Event ()) -> Cont () -> Event ()
forall a b. (a -> b) -> a -> b
$
ProcessId -> Process () -> Cont ()
forall a. ProcessId -> Process a -> Cont a
invokeProcess ProcessId
pid (Process () -> Cont ()) -> Process () -> Cont ()
forall a b. (a -> b) -> a -> b
$
Facility a -> Transact a -> FacilityPreemptMode a -> Process ()
forall a.
Facility a -> Transact a -> FacilityPreemptMode a -> Process ()
preemptFacility Facility a
r Transact a
transact FacilityPreemptMode a
mode
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$
StrategyQueue (TransactQueueStrategy FCFS) (FacilityPendingItem a)
-> Int -> FacilityPendingItem a -> Event ()
forall s p i.
PriorityQueueStrategy s p =>
StrategyQueue s i -> p -> i -> Event ()
strategyEnqueueWithPriority
(Facility a
-> StrategyQueue
(TransactQueueStrategy FCFS) (FacilityPendingItem a)
forall a.
Facility a
-> StrategyQueue
(TransactQueueStrategy FCFS) (FacilityPendingItem a)
facilityPendingChain Facility a
r)
(Transact a -> Int
forall a. Transact a -> Int
transactPriority Transact a
transact)
(Transact a
-> Double -> Bool -> Bool -> FrozenCont () -> FacilityPendingItem a
forall a.
Transact a
-> Double -> Bool -> Bool -> FrozenCont () -> FacilityPendingItem a
FacilityPendingItem Transact a
transact Double
t Bool
True Bool
True FrozenCont ()
c)
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$ Facility a -> Int -> Event ()
forall a. Facility a -> Int -> Event ()
updateFacilityQueueCount Facility a
r Int
1
Just owner :: FacilityOwnerItem a
owner@(FacilityOwnerItem Transact a
transact0 Double
t0 Bool
preempting0 Bool
interrupting0 Double
acc0)
| FacilityPreemptMode a -> Bool
forall a. FacilityPreemptMode a -> Bool
facilityPriorityMode FacilityPreemptMode a
mode Bool -> Bool -> Bool
&& (Transact a -> Int
forall a. Transact a -> Int
transactPriority Transact a
transact Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Transact a -> Int
forall a. Transact a -> Int
transactPriority Transact a
transact0) ->
do FrozenCont ()
c <- Point -> Event (FrozenCont ()) -> IO (FrozenCont ())
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event (FrozenCont ()) -> IO (FrozenCont ()))
-> Event (FrozenCont ()) -> IO (FrozenCont ())
forall a b. (a -> b) -> a -> b
$
ContParams () -> () -> Event () -> Event (FrozenCont ())
forall a. ContParams a -> a -> Event () -> Event (FrozenCont a)
freezeContReentering ContParams ()
c () (Event () -> Event (FrozenCont ()))
-> Event () -> Event (FrozenCont ())
forall a b. (a -> b) -> a -> b
$
ContParams () -> Cont () -> Event ()
forall a. ContParams a -> Cont a -> Event ()
invokeCont ContParams ()
c (Cont () -> Event ()) -> Cont () -> Event ()
forall a b. (a -> b) -> a -> b
$
ProcessId -> Process () -> Cont ()
forall a. ProcessId -> Process a -> Cont a
invokeProcess ProcessId
pid (Process () -> Cont ()) -> Process () -> Cont ()
forall a b. (a -> b) -> a -> b
$
Facility a -> Transact a -> FacilityPreemptMode a -> Process ()
forall a.
Facility a -> Transact a -> FacilityPreemptMode a -> Process ()
preemptFacility Facility a
r Transact a
transact FacilityPreemptMode a
mode
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$
StrategyQueue (TransactQueueStrategy FCFS) (FacilityDelayedItem a)
-> Int -> FacilityDelayedItem a -> Event ()
forall s p i.
PriorityQueueStrategy s p =>
StrategyQueue s i -> p -> i -> Event ()
strategyEnqueueWithPriority
(Facility a
-> StrategyQueue
(TransactQueueStrategy FCFS) (FacilityDelayedItem a)
forall a.
Facility a
-> StrategyQueue
(TransactQueueStrategy FCFS) (FacilityDelayedItem a)
facilityDelayChain Facility a
r)
(Transact a -> Int
forall a. Transact a -> Int
transactPriority Transact a
transact)
(Transact a
-> Double -> Bool -> Bool -> FrozenCont () -> FacilityDelayedItem a
forall a.
Transact a
-> Double -> Bool -> Bool -> FrozenCont () -> FacilityDelayedItem a
FacilityDelayedItem Transact a
transact Double
t Bool
True Bool
True FrozenCont ()
c)
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$ Facility a -> Int -> Event ()
forall a. Facility a -> Int -> Event ()
updateFacilityQueueCount Facility a
r Int
1
Just owner :: FacilityOwnerItem a
owner@(FacilityOwnerItem Transact a
transact0 Double
t0 Bool
preempting0 Bool
interrupting0 Double
acc0)
| (Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ FacilityPreemptMode a -> Bool
forall a. FacilityPreemptMode a -> Bool
facilityRemoveMode FacilityPreemptMode a
mode) ->
do IORef (Maybe (FacilityOwnerItem a))
-> Maybe (FacilityOwnerItem a) -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (Facility a -> IORef (Maybe (FacilityOwnerItem a))
forall a. Facility a -> IORef (Maybe (FacilityOwnerItem a))
facilityOwnerRef Facility a
r) (Maybe (FacilityOwnerItem a) -> IO ())
-> Maybe (FacilityOwnerItem a) -> IO ()
forall a b. (a -> b) -> a -> b
$ FacilityOwnerItem a -> Maybe (FacilityOwnerItem a)
forall a. a -> Maybe a
Just (Transact a
-> Double -> Bool -> Bool -> Double -> FacilityOwnerItem a
forall a.
Transact a
-> Double -> Bool -> Bool -> Double -> FacilityOwnerItem a
FacilityOwnerItem Transact a
transact Double
t Bool
True Bool
True Double
0)
ProcessId
pid0 <- Point -> Event ProcessId -> IO ProcessId
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event ProcessId -> IO ProcessId)
-> Event ProcessId -> IO ProcessId
forall a b. (a -> b) -> a -> b
$ Transact a -> Event ProcessId
forall a. Transact a -> Event ProcessId
requireTransactProcessId Transact a
transact0
Maybe Double
t2 <- Point -> Event (Maybe Double) -> IO (Maybe Double)
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event (Maybe Double) -> IO (Maybe Double))
-> Event (Maybe Double) -> IO (Maybe Double)
forall a b. (a -> b) -> a -> b
$ ProcessId -> Event (Maybe Double)
processInterruptionTime ProcessId
pid0
let dt0 :: Maybe Double
dt0 = (Double -> Double) -> Maybe Double -> Maybe Double
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\Double
x -> Double
x Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
t) Maybe Double
t2
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$
StrategyQueue
(TransactQueueStrategy LCFS) (FacilityInterruptedItem a)
-> Int -> FacilityInterruptedItem a -> Event ()
forall s p i.
PriorityQueueStrategy s p =>
StrategyQueue s i -> p -> i -> Event ()
strategyEnqueueWithPriority
(Facility a
-> StrategyQueue
(TransactQueueStrategy LCFS) (FacilityInterruptedItem a)
forall a.
Facility a
-> StrategyQueue
(TransactQueueStrategy LCFS) (FacilityInterruptedItem a)
facilityInterruptChain Facility a
r)
(Transact a -> Int
forall a. Transact a -> Int
transactPriority Transact a
transact0)
(Transact a
-> Double
-> Bool
-> Bool
-> Maybe Double
-> Maybe (FacilityPreemptTransfer a)
-> Double
-> FacilityInterruptedItem a
forall a.
Transact a
-> Double
-> Bool
-> Bool
-> Maybe Double
-> Maybe (FacilityPreemptTransfer a)
-> Double
-> FacilityInterruptedItem a
FacilityInterruptedItem Transact a
transact0 Double
t Bool
preempting0 Bool
interrupting0 Maybe Double
dt0 (FacilityPreemptMode a -> Maybe (FacilityPreemptTransfer a)
forall a.
FacilityPreemptMode a -> Maybe (FacilityPreemptTransfer a)
facilityTransfer FacilityPreemptMode a
mode) (Double
acc0 Double -> Double -> Double
forall a. Num a => a -> a -> a
+ (Double
t Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
t0)))
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$ Facility a -> Int -> Event ()
forall a. Facility a -> Int -> Event ()
updateFacilityQueueCount Facility a
r Int
1
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$ Facility a -> Double -> Event ()
forall a. Facility a -> Double -> Event ()
updateFacilityWaitTime Facility a
r Double
0
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$ Facility a -> Int -> Event ()
forall a. Facility a -> Int -> Event ()
updateFacilityCaptureCount Facility a
r Int
1
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$ Transact a -> Event ()
forall a. Transact a -> Event ()
transactPreemptionBegin Transact a
transact0
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$ ContParams () -> () -> Event ()
forall a. ContParams a -> a -> Event ()
resumeCont ContParams ()
c ()
Just owner :: FacilityOwnerItem a
owner@(FacilityOwnerItem Transact a
transact0 Double
t0 Bool
preempting0 Bool
interrupting0 Double
acc0)
| FacilityPreemptMode a -> Bool
forall a. FacilityPreemptMode a -> Bool
facilityRemoveMode FacilityPreemptMode a
mode ->
do IORef (Maybe (FacilityOwnerItem a))
-> Maybe (FacilityOwnerItem a) -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (Facility a -> IORef (Maybe (FacilityOwnerItem a))
forall a. Facility a -> IORef (Maybe (FacilityOwnerItem a))
facilityOwnerRef Facility a
r) (Maybe (FacilityOwnerItem a) -> IO ())
-> Maybe (FacilityOwnerItem a) -> IO ()
forall a b. (a -> b) -> a -> b
$ FacilityOwnerItem a -> Maybe (FacilityOwnerItem a)
forall a. a -> Maybe a
Just (Transact a
-> Double -> Bool -> Bool -> Double -> FacilityOwnerItem a
forall a.
Transact a
-> Double -> Bool -> Bool -> Double -> FacilityOwnerItem a
FacilityOwnerItem Transact a
transact Double
t Bool
True Bool
True Double
0)
ProcessId
pid0 <- Point -> Event ProcessId -> IO ProcessId
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event ProcessId -> IO ProcessId)
-> Event ProcessId -> IO ProcessId
forall a b. (a -> b) -> a -> b
$ Transact a -> Event ProcessId
forall a. Transact a -> Event ProcessId
requireTransactProcessId Transact a
transact0
Maybe Double
t2 <- Point -> Event (Maybe Double) -> IO (Maybe Double)
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event (Maybe Double) -> IO (Maybe Double))
-> Event (Maybe Double) -> IO (Maybe Double)
forall a b. (a -> b) -> a -> b
$ ProcessId -> Event (Maybe Double)
processInterruptionTime ProcessId
pid0
let dt0 :: Maybe Double
dt0 = (Double -> Double) -> Maybe Double -> Maybe Double
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\Double
x -> Double
x Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
t) Maybe Double
t2
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$ Facility a -> Double -> Event ()
forall a. Facility a -> Double -> Event ()
updateFacilityWaitTime Facility a
r Double
0
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$ Facility a -> Int -> Event ()
forall a. Facility a -> Int -> Event ()
updateFacilityCaptureCount Facility a
r Int
1
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$ Facility a -> Double -> Event ()
forall a. Facility a -> Double -> Event ()
updateFacilityHoldingTime Facility a
r (Double
acc0 Double -> Double -> Double
forall a. Num a => a -> a -> a
+ (Double
t Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
t0))
case FacilityPreemptMode a -> Maybe (FacilityPreemptTransfer a)
forall a.
FacilityPreemptMode a -> Maybe (FacilityPreemptTransfer a)
facilityTransfer FacilityPreemptMode a
mode of
Maybe (FacilityPreemptTransfer a)
Nothing ->
SimulationRetry -> IO ()
forall e a. Exception e => e -> IO a
throwIO (SimulationRetry -> IO ()) -> SimulationRetry -> IO ()
forall a b. (a -> b) -> a -> b
$
String -> SimulationRetry
SimulationRetry
String
"The transfer destination is not specified for the removed preempted transact: preemptFacility"
Just FacilityPreemptTransfer a
transfer ->
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$ Transact a -> Process () -> Event ()
forall a. Transact a -> Process () -> Event ()
transferTransact Transact a
transact0 (FacilityPreemptTransfer a
transfer Transact a
transact0 Maybe Double
dt0)
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$ ContParams () -> () -> Event ()
forall a. ContParams a -> a -> Event ()
resumeCont ContParams ()
c ()
returnFacility :: Facility a
-> Transact a
-> Process ()
returnFacility :: Facility a -> Transact a -> Process ()
returnFacility Facility a
r Transact a
transact = Facility a -> Transact a -> Bool -> Process ()
forall a. Facility a -> Transact a -> Bool -> Process ()
releaseFacility' Facility a
r Transact a
transact Bool
True
releaseFacility :: Facility a
-> Transact a
-> Process ()
releaseFacility :: Facility a -> Transact a -> Process ()
releaseFacility Facility a
r Transact a
transact = Facility a -> Transact a -> Bool -> Process ()
forall a. Facility a -> Transact a -> Bool -> Process ()
releaseFacility' Facility a
r Transact a
transact Bool
False
releaseFacility' :: Facility a
-> Transact a
-> Bool
-> Process ()
releaseFacility' :: Facility a -> Transact a -> Bool -> Process ()
releaseFacility' Facility a
r Transact a
transact Bool
preempting =
(ProcessId -> Cont ()) -> Process ()
forall a. (ProcessId -> Cont a) -> Process a
Process ((ProcessId -> Cont ()) -> Process ())
-> (ProcessId -> Cont ()) -> Process ()
forall a b. (a -> b) -> a -> b
$ \ProcessId
pid ->
(ContParams () -> Event ()) -> Cont ()
forall a. (ContParams a -> Event ()) -> Cont a
Cont ((ContParams () -> Event ()) -> Cont ())
-> (ContParams () -> Event ()) -> Cont ()
forall a b. (a -> b) -> a -> b
$ \ContParams ()
c ->
(Point -> IO ()) -> Event ()
forall a. (Point -> IO a) -> Event a
Event ((Point -> IO ()) -> Event ()) -> (Point -> IO ()) -> Event ()
forall a b. (a -> b) -> a -> b
$ \Point
p ->
do let t :: Double
t = Point -> Double
pointTime Point
p
Maybe (FacilityOwnerItem a)
a <- IORef (Maybe (FacilityOwnerItem a))
-> IO (Maybe (FacilityOwnerItem a))
forall a. IORef a -> IO a
readIORef (Facility a -> IORef (Maybe (FacilityOwnerItem a))
forall a. Facility a -> IORef (Maybe (FacilityOwnerItem a))
facilityOwnerRef Facility a
r)
case Maybe (FacilityOwnerItem a)
a of
Maybe (FacilityOwnerItem a)
Nothing ->
SimulationRetry -> IO ()
forall e a. Exception e => e -> IO a
throwIO (SimulationRetry -> IO ()) -> SimulationRetry -> IO ()
forall a b. (a -> b) -> a -> b
$
String -> SimulationRetry
SimulationRetry
String
"There is no owner of the facility: releaseFacility'"
Just owner :: FacilityOwnerItem a
owner@(FacilityOwnerItem Transact a
transact0 Double
t0 Bool
preempting0 Bool
interrupting0 Double
acc0) | Transact a
transact0 Transact a -> Transact a -> Bool
forall a. Eq a => a -> a -> Bool
== Transact a
transact Bool -> Bool -> Bool
&& Bool
preempting0 Bool -> Bool -> Bool
forall a. Eq a => a -> a -> Bool
/= Bool
preempting ->
SimulationRetry -> IO ()
forall e a. Exception e => e -> IO a
throwIO (SimulationRetry -> IO ()) -> SimulationRetry -> IO ()
forall a b. (a -> b) -> a -> b
$
String -> SimulationRetry
SimulationRetry
String
"The mismatch use of releaseFacility and returnFacility: releaseFacility'"
Just owner :: FacilityOwnerItem a
owner@(FacilityOwnerItem Transact a
transact0 Double
t0 Bool
preempting0 Bool
interrupting0 Double
acc0) | Transact a
transact0 Transact a -> Transact a -> Bool
forall a. Eq a => a -> a -> Bool
== Transact a
transact ->
do IORef (Maybe (FacilityOwnerItem a))
-> Maybe (FacilityOwnerItem a) -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (Facility a -> IORef (Maybe (FacilityOwnerItem a))
forall a. Facility a -> IORef (Maybe (FacilityOwnerItem a))
facilityOwnerRef Facility a
r) Maybe (FacilityOwnerItem a)
forall a. Maybe a
Nothing
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$ Facility a -> Int -> Event ()
forall a. Facility a -> Int -> Event ()
updateFacilityUtilisationCount Facility a
r (-Int
1)
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$ Facility a -> Double -> Event ()
forall a. Facility a -> Double -> Event ()
updateFacilityHoldingTime Facility a
r (Double
acc0 Double -> Double -> Double
forall a. Num a => a -> a -> a
+ (Double
t Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
t0))
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$ Facility a -> Int -> Event ()
forall a. Facility a -> Int -> Event ()
updateFacilityCount Facility a
r Int
1
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$ Double -> Event () -> Event ()
enqueueEvent Double
t (Event () -> Event ()) -> Event () -> Event ()
forall a b. (a -> b) -> a -> b
$ Facility a -> Event ()
forall a. Facility a -> Event ()
tryCaptureFacility Facility a
r
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$ ContParams () -> () -> Event ()
forall a. ContParams a -> a -> Event ()
resumeCont ContParams ()
c ()
Just FacilityOwnerItem a
owner ->
SimulationRetry -> IO ()
forall e a. Exception e => e -> IO a
throwIO (SimulationRetry -> IO ()) -> SimulationRetry -> IO ()
forall a b. (a -> b) -> a -> b
$
String -> SimulationRetry
SimulationRetry
String
"The facility has another owner: releaseFacility'"
tryCaptureFacility :: Facility a -> Event ()
tryCaptureFacility :: Facility a -> Event ()
tryCaptureFacility Facility a
r =
(Point -> IO ()) -> Event ()
forall a. (Point -> IO a) -> Event a
Event ((Point -> IO ()) -> Event ()) -> (Point -> IO ()) -> Event ()
forall a b. (a -> b) -> a -> b
$ \Point
p ->
do let t :: Double
t = Point -> Double
pointTime Point
p
Maybe (FacilityOwnerItem a)
a <- IORef (Maybe (FacilityOwnerItem a))
-> IO (Maybe (FacilityOwnerItem a))
forall a. IORef a -> IO a
readIORef (Facility a -> IORef (Maybe (FacilityOwnerItem a))
forall a. Facility a -> IORef (Maybe (FacilityOwnerItem a))
facilityOwnerRef Facility a
r)
case Maybe (FacilityOwnerItem a)
a of
Maybe (FacilityOwnerItem a)
Nothing ->
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$ Facility a -> Event ()
forall a. Facility a -> Event ()
captureFacility Facility a
r
Just FacilityOwnerItem a
owner -> () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
captureFacility :: Facility a -> Event ()
captureFacility :: Facility a -> Event ()
captureFacility Facility a
r =
(Point -> IO ()) -> Event ()
forall a. (Point -> IO a) -> Event a
Event ((Point -> IO ()) -> Event ()) -> (Point -> IO ()) -> Event ()
forall a b. (a -> b) -> a -> b
$ \Point
p ->
do let t :: Double
t = Point -> Double
pointTime Point
p
Bool
f <- Point -> Event Bool -> IO Bool
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event Bool -> IO Bool) -> Event Bool -> IO Bool
forall a b. (a -> b) -> a -> b
$ StrategyQueue (TransactQueueStrategy FCFS) (FacilityPendingItem a)
-> Event Bool
forall s i. QueueStrategy s => StrategyQueue s i -> Event Bool
strategyQueueNull (Facility a
-> StrategyQueue
(TransactQueueStrategy FCFS) (FacilityPendingItem a)
forall a.
Facility a
-> StrategyQueue
(TransactQueueStrategy FCFS) (FacilityPendingItem a)
facilityPendingChain Facility a
r)
if Bool -> Bool
not Bool
f
then do FacilityPendingItem Transact a
transact Double
t0 Bool
preempting Bool
interrupting FrozenCont ()
c0 <- Point
-> Event (FacilityPendingItem a) -> IO (FacilityPendingItem a)
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event (FacilityPendingItem a) -> IO (FacilityPendingItem a))
-> Event (FacilityPendingItem a) -> IO (FacilityPendingItem a)
forall a b. (a -> b) -> a -> b
$ StrategyQueue (TransactQueueStrategy FCFS) (FacilityPendingItem a)
-> Event (FacilityPendingItem a)
forall s i. DequeueStrategy s => StrategyQueue s i -> Event i
strategyDequeue (Facility a
-> StrategyQueue
(TransactQueueStrategy FCFS) (FacilityPendingItem a)
forall a.
Facility a
-> StrategyQueue
(TransactQueueStrategy FCFS) (FacilityPendingItem a)
facilityPendingChain Facility a
r)
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$ Facility a -> Int -> Event ()
forall a. Facility a -> Int -> Event ()
updateFacilityQueueCount Facility a
r (-Int
1)
Maybe (ContParams ())
c <- Point
-> Event (Maybe (ContParams ())) -> IO (Maybe (ContParams ()))
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event (Maybe (ContParams ())) -> IO (Maybe (ContParams ())))
-> Event (Maybe (ContParams ())) -> IO (Maybe (ContParams ()))
forall a b. (a -> b) -> a -> b
$ FrozenCont () -> Event (Maybe (ContParams ()))
forall a. FrozenCont a -> Event (Maybe (ContParams a))
unfreezeCont FrozenCont ()
c0
case Maybe (ContParams ())
c of
Maybe (ContParams ())
Nothing ->
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$ Facility a -> Event ()
forall a. Facility a -> Event ()
captureFacility Facility a
r
Just ContParams ()
c ->
do IORef (Maybe (FacilityOwnerItem a))
-> Maybe (FacilityOwnerItem a) -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (Facility a -> IORef (Maybe (FacilityOwnerItem a))
forall a. Facility a -> IORef (Maybe (FacilityOwnerItem a))
facilityOwnerRef Facility a
r) (Maybe (FacilityOwnerItem a) -> IO ())
-> Maybe (FacilityOwnerItem a) -> IO ()
forall a b. (a -> b) -> a -> b
$ FacilityOwnerItem a -> Maybe (FacilityOwnerItem a)
forall a. a -> Maybe a
Just (Transact a
-> Double -> Bool -> Bool -> Double -> FacilityOwnerItem a
forall a.
Transact a
-> Double -> Bool -> Bool -> Double -> FacilityOwnerItem a
FacilityOwnerItem Transact a
transact Double
t Bool
preempting Bool
interrupting Double
0)
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$ Facility a -> Double -> Event ()
forall a. Facility a -> Double -> Event ()
updateFacilityWaitTime Facility a
r (Double
t Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
t0)
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$ Facility a -> Int -> Event ()
forall a. Facility a -> Int -> Event ()
updateFacilityUtilisationCount Facility a
r Int
1
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$ Facility a -> Int -> Event ()
forall a. Facility a -> Int -> Event ()
updateFacilityCaptureCount Facility a
r Int
1
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$ Facility a -> Int -> Event ()
forall a. Facility a -> Int -> Event ()
updateFacilityCount Facility a
r (-Int
1)
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$ Double -> Event () -> Event ()
enqueueEvent Double
t (Event () -> Event ()) -> Event () -> Event ()
forall a b. (a -> b) -> a -> b
$ ContParams () -> () -> Event ()
forall a. ContParams a -> a -> Event ()
reenterCont ContParams ()
c ()
else do Bool
f <- Point -> Event Bool -> IO Bool
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event Bool -> IO Bool) -> Event Bool -> IO Bool
forall a b. (a -> b) -> a -> b
$ StrategyQueue
(TransactQueueStrategy LCFS) (FacilityInterruptedItem a)
-> Event Bool
forall s i. QueueStrategy s => StrategyQueue s i -> Event Bool
strategyQueueNull (Facility a
-> StrategyQueue
(TransactQueueStrategy LCFS) (FacilityInterruptedItem a)
forall a.
Facility a
-> StrategyQueue
(TransactQueueStrategy LCFS) (FacilityInterruptedItem a)
facilityInterruptChain Facility a
r)
if Bool -> Bool
not Bool
f
then do FacilityInterruptedItem Transact a
transact Double
t0 Bool
preempting Bool
interrupting Maybe Double
dt0 Maybe (FacilityPreemptTransfer a)
transfer0 Double
acc0 <- Point
-> Event (FacilityInterruptedItem a)
-> IO (FacilityInterruptedItem a)
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event (FacilityInterruptedItem a)
-> IO (FacilityInterruptedItem a))
-> Event (FacilityInterruptedItem a)
-> IO (FacilityInterruptedItem a)
forall a b. (a -> b) -> a -> b
$ StrategyQueue
(TransactQueueStrategy LCFS) (FacilityInterruptedItem a)
-> Event (FacilityInterruptedItem a)
forall s i. DequeueStrategy s => StrategyQueue s i -> Event i
strategyDequeue (Facility a
-> StrategyQueue
(TransactQueueStrategy LCFS) (FacilityInterruptedItem a)
forall a.
Facility a
-> StrategyQueue
(TransactQueueStrategy LCFS) (FacilityInterruptedItem a)
facilityInterruptChain Facility a
r)
ProcessId
pid <- Point -> Event ProcessId -> IO ProcessId
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event ProcessId -> IO ProcessId)
-> Event ProcessId -> IO ProcessId
forall a b. (a -> b) -> a -> b
$ Transact a -> Event ProcessId
forall a. Transact a -> Event ProcessId
requireTransactProcessId Transact a
transact
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$ Facility a -> Int -> Event ()
forall a. Facility a -> Int -> Event ()
updateFacilityQueueCount Facility a
r (-Int
1)
Bool
f <- Point -> Event Bool -> IO Bool
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event Bool -> IO Bool) -> Event Bool -> IO Bool
forall a b. (a -> b) -> a -> b
$ ProcessId -> Event Bool
processCancelled ProcessId
pid
case Bool
f of
Bool
True ->
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$ Facility a -> Event ()
forall a. Facility a -> Event ()
captureFacility Facility a
r
Bool
False ->
do IORef (Maybe (FacilityOwnerItem a))
-> Maybe (FacilityOwnerItem a) -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (Facility a -> IORef (Maybe (FacilityOwnerItem a))
forall a. Facility a -> IORef (Maybe (FacilityOwnerItem a))
facilityOwnerRef Facility a
r) (Maybe (FacilityOwnerItem a) -> IO ())
-> Maybe (FacilityOwnerItem a) -> IO ()
forall a b. (a -> b) -> a -> b
$ FacilityOwnerItem a -> Maybe (FacilityOwnerItem a)
forall a. a -> Maybe a
Just (Transact a
-> Double -> Bool -> Bool -> Double -> FacilityOwnerItem a
forall a.
Transact a
-> Double -> Bool -> Bool -> Double -> FacilityOwnerItem a
FacilityOwnerItem Transact a
transact Double
t Bool
preempting Bool
interrupting Double
acc0)
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$ Facility a -> Double -> Event ()
forall a. Facility a -> Double -> Event ()
updateFacilityWaitTime Facility a
r (Double
t Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
t0)
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$ Facility a -> Int -> Event ()
forall a. Facility a -> Int -> Event ()
updateFacilityUtilisationCount Facility a
r Int
1
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$ Facility a -> Int -> Event ()
forall a. Facility a -> Int -> Event ()
updateFacilityCount Facility a
r (-Int
1)
case Maybe (FacilityPreemptTransfer a)
transfer0 of
Maybe (FacilityPreemptTransfer a)
Nothing -> () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Just FacilityPreemptTransfer a
transfer ->
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$ Transact a -> Process () -> Event ()
forall a. Transact a -> Process () -> Event ()
transferTransact Transact a
transact (FacilityPreemptTransfer a
transfer Transact a
transact Maybe Double
dt0)
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$ Transact a -> Event ()
forall a. Transact a -> Event ()
transactPreemptionEnd Transact a
transact
else do Bool
f <- Point -> Event Bool -> IO Bool
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event Bool -> IO Bool) -> Event Bool -> IO Bool
forall a b. (a -> b) -> a -> b
$ StrategyQueue (TransactQueueStrategy FCFS) (FacilityDelayedItem a)
-> Event Bool
forall s i. QueueStrategy s => StrategyQueue s i -> Event Bool
strategyQueueNull (Facility a
-> StrategyQueue
(TransactQueueStrategy FCFS) (FacilityDelayedItem a)
forall a.
Facility a
-> StrategyQueue
(TransactQueueStrategy FCFS) (FacilityDelayedItem a)
facilityDelayChain Facility a
r)
if Bool -> Bool
not Bool
f
then do FacilityDelayedItem Transact a
transact Double
t0 Bool
preempting Bool
interrupting FrozenCont ()
c0 <- Point
-> Event (FacilityDelayedItem a) -> IO (FacilityDelayedItem a)
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event (FacilityDelayedItem a) -> IO (FacilityDelayedItem a))
-> Event (FacilityDelayedItem a) -> IO (FacilityDelayedItem a)
forall a b. (a -> b) -> a -> b
$ StrategyQueue (TransactQueueStrategy FCFS) (FacilityDelayedItem a)
-> Event (FacilityDelayedItem a)
forall s i. DequeueStrategy s => StrategyQueue s i -> Event i
strategyDequeue (Facility a
-> StrategyQueue
(TransactQueueStrategy FCFS) (FacilityDelayedItem a)
forall a.
Facility a
-> StrategyQueue
(TransactQueueStrategy FCFS) (FacilityDelayedItem a)
facilityDelayChain Facility a
r)
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$ Facility a -> Int -> Event ()
forall a. Facility a -> Int -> Event ()
updateFacilityQueueCount Facility a
r (-Int
1)
Maybe (ContParams ())
c <- Point
-> Event (Maybe (ContParams ())) -> IO (Maybe (ContParams ()))
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event (Maybe (ContParams ())) -> IO (Maybe (ContParams ())))
-> Event (Maybe (ContParams ())) -> IO (Maybe (ContParams ()))
forall a b. (a -> b) -> a -> b
$ FrozenCont () -> Event (Maybe (ContParams ()))
forall a. FrozenCont a -> Event (Maybe (ContParams a))
unfreezeCont FrozenCont ()
c0
case Maybe (ContParams ())
c of
Maybe (ContParams ())
Nothing ->
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$ Facility a -> Event ()
forall a. Facility a -> Event ()
captureFacility Facility a
r
Just ContParams ()
c ->
do IORef (Maybe (FacilityOwnerItem a))
-> Maybe (FacilityOwnerItem a) -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (Facility a -> IORef (Maybe (FacilityOwnerItem a))
forall a. Facility a -> IORef (Maybe (FacilityOwnerItem a))
facilityOwnerRef Facility a
r) (Maybe (FacilityOwnerItem a) -> IO ())
-> Maybe (FacilityOwnerItem a) -> IO ()
forall a b. (a -> b) -> a -> b
$ FacilityOwnerItem a -> Maybe (FacilityOwnerItem a)
forall a. a -> Maybe a
Just (Transact a
-> Double -> Bool -> Bool -> Double -> FacilityOwnerItem a
forall a.
Transact a
-> Double -> Bool -> Bool -> Double -> FacilityOwnerItem a
FacilityOwnerItem Transact a
transact Double
t Bool
preempting Bool
interrupting Double
0)
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$ Facility a -> Double -> Event ()
forall a. Facility a -> Double -> Event ()
updateFacilityWaitTime Facility a
r (Double
t Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
t0)
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$ Facility a -> Int -> Event ()
forall a. Facility a -> Int -> Event ()
updateFacilityUtilisationCount Facility a
r Int
1
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$ Facility a -> Int -> Event ()
forall a. Facility a -> Int -> Event ()
updateFacilityCaptureCount Facility a
r Int
1
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$ Facility a -> Int -> Event ()
forall a. Facility a -> Int -> Event ()
updateFacilityCount Facility a
r (-Int
1)
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$ Double -> Event () -> Event ()
enqueueEvent Double
t (Event () -> Event ()) -> Event () -> Event ()
forall a b. (a -> b) -> a -> b
$ ContParams () -> () -> Event ()
forall a. ContParams a -> a -> Event ()
reenterCont ContParams ()
c ()
else () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
facilityChanged_ :: Facility a -> Signal ()
facilityChanged_ :: Facility a -> Signal ()
facilityChanged_ Facility a
r =
Facility a -> Signal ()
forall a. Facility a -> Signal ()
facilityCountChanged_ Facility a
r Signal () -> Signal () -> Signal ()
forall a. Semigroup a => a -> a -> a
<>
Facility a -> Signal ()
forall a. Facility a -> Signal ()
facilityCaptureCountChanged_ Facility a
r Signal () -> Signal () -> Signal ()
forall a. Semigroup a => a -> a -> a
<>
Facility a -> Signal ()
forall a. Facility a -> Signal ()
facilityUtilisationCountChanged_ Facility a
r Signal () -> Signal () -> Signal ()
forall a. Semigroup a => a -> a -> a
<>
Facility a -> Signal ()
forall a. Facility a -> Signal ()
facilityQueueCountChanged_ Facility a
r
updateFacilityCount :: Facility a -> Int -> Event ()
updateFacilityCount :: Facility a -> Int -> Event ()
updateFacilityCount Facility a
r Int
delta =
(Point -> IO ()) -> Event ()
forall a. (Point -> IO a) -> Event a
Event ((Point -> IO ()) -> Event ()) -> (Point -> IO ()) -> Event ()
forall a b. (a -> b) -> a -> b
$ \Point
p ->
do Int
a <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (Facility a -> IORef Int
forall a. Facility a -> IORef Int
facilityCountRef Facility a
r)
let a' :: Int
a' = Int
a Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
delta
Int
a' Int -> IO () -> IO ()
`seq` IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (Facility a -> IORef Int
forall a. Facility a -> IORef Int
facilityCountRef Facility a
r) Int
a'
IORef (TimingStats Int)
-> (TimingStats Int -> TimingStats Int) -> IO ()
forall a. IORef a -> (a -> a) -> IO ()
modifyIORef' (Facility a -> IORef (TimingStats Int)
forall a. Facility a -> IORef (TimingStats Int)
facilityCountStatsRef Facility a
r) ((TimingStats Int -> TimingStats Int) -> IO ())
-> (TimingStats Int -> TimingStats Int) -> IO ()
forall a b. (a -> b) -> a -> b
$
Double -> Int -> TimingStats Int -> TimingStats Int
forall a.
TimingData a =>
Double -> a -> TimingStats a -> TimingStats a
addTimingStats (Point -> Double
pointTime Point
p) Int
a'
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$
SignalSource Int -> Int -> Event ()
forall a. SignalSource a -> a -> Event ()
triggerSignal (Facility a -> SignalSource Int
forall a. Facility a -> SignalSource Int
facilityCountSource Facility a
r) Int
a'
updateFacilityCaptureCount :: Facility a -> Int -> Event ()
updateFacilityCaptureCount :: Facility a -> Int -> Event ()
updateFacilityCaptureCount Facility a
r Int
delta =
(Point -> IO ()) -> Event ()
forall a. (Point -> IO a) -> Event a
Event ((Point -> IO ()) -> Event ()) -> (Point -> IO ()) -> Event ()
forall a b. (a -> b) -> a -> b
$ \Point
p ->
do Int
a <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (Facility a -> IORef Int
forall a. Facility a -> IORef Int
facilityCaptureCountRef Facility a
r)
let a' :: Int
a' = Int
a Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
delta
Int
a' Int -> IO () -> IO ()
`seq` IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (Facility a -> IORef Int
forall a. Facility a -> IORef Int
facilityCaptureCountRef Facility a
r) Int
a'
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$
SignalSource Int -> Int -> Event ()
forall a. SignalSource a -> a -> Event ()
triggerSignal (Facility a -> SignalSource Int
forall a. Facility a -> SignalSource Int
facilityCaptureCountSource Facility a
r) Int
a'
updateFacilityQueueCount :: Facility a -> Int -> Event ()
updateFacilityQueueCount :: Facility a -> Int -> Event ()
updateFacilityQueueCount Facility a
r Int
delta =
(Point -> IO ()) -> Event ()
forall a. (Point -> IO a) -> Event a
Event ((Point -> IO ()) -> Event ()) -> (Point -> IO ()) -> Event ()
forall a b. (a -> b) -> a -> b
$ \Point
p ->
do Int
a <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (Facility a -> IORef Int
forall a. Facility a -> IORef Int
facilityQueueCountRef Facility a
r)
let a' :: Int
a' = Int
a Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
delta
Int
a' Int -> IO () -> IO ()
`seq` IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (Facility a -> IORef Int
forall a. Facility a -> IORef Int
facilityQueueCountRef Facility a
r) Int
a'
IORef (TimingStats Int)
-> (TimingStats Int -> TimingStats Int) -> IO ()
forall a. IORef a -> (a -> a) -> IO ()
modifyIORef' (Facility a -> IORef (TimingStats Int)
forall a. Facility a -> IORef (TimingStats Int)
facilityQueueCountStatsRef Facility a
r) ((TimingStats Int -> TimingStats Int) -> IO ())
-> (TimingStats Int -> TimingStats Int) -> IO ()
forall a b. (a -> b) -> a -> b
$
Double -> Int -> TimingStats Int -> TimingStats Int
forall a.
TimingData a =>
Double -> a -> TimingStats a -> TimingStats a
addTimingStats (Point -> Double
pointTime Point
p) Int
a'
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$
SignalSource Int -> Int -> Event ()
forall a. SignalSource a -> a -> Event ()
triggerSignal (Facility a -> SignalSource Int
forall a. Facility a -> SignalSource Int
facilityQueueCountSource Facility a
r) Int
a'
updateFacilityUtilisationCount :: Facility a -> Int -> Event ()
updateFacilityUtilisationCount :: Facility a -> Int -> Event ()
updateFacilityUtilisationCount Facility a
r Int
delta =
(Point -> IO ()) -> Event ()
forall a. (Point -> IO a) -> Event a
Event ((Point -> IO ()) -> Event ()) -> (Point -> IO ()) -> Event ()
forall a b. (a -> b) -> a -> b
$ \Point
p ->
do Int
a <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (Facility a -> IORef Int
forall a. Facility a -> IORef Int
facilityUtilisationCountRef Facility a
r)
let a' :: Int
a' = Int
a Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
delta
Int
a' Int -> IO () -> IO ()
`seq` IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (Facility a -> IORef Int
forall a. Facility a -> IORef Int
facilityUtilisationCountRef Facility a
r) Int
a'
IORef (TimingStats Int)
-> (TimingStats Int -> TimingStats Int) -> IO ()
forall a. IORef a -> (a -> a) -> IO ()
modifyIORef' (Facility a -> IORef (TimingStats Int)
forall a. Facility a -> IORef (TimingStats Int)
facilityUtilisationCountStatsRef Facility a
r) ((TimingStats Int -> TimingStats Int) -> IO ())
-> (TimingStats Int -> TimingStats Int) -> IO ()
forall a b. (a -> b) -> a -> b
$
Double -> Int -> TimingStats Int -> TimingStats Int
forall a.
TimingData a =>
Double -> a -> TimingStats a -> TimingStats a
addTimingStats (Point -> Double
pointTime Point
p) Int
a'
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$
SignalSource Int -> Int -> Event ()
forall a. SignalSource a -> a -> Event ()
triggerSignal (Facility a -> SignalSource Int
forall a. Facility a -> SignalSource Int
facilityUtilisationCountSource Facility a
r) Int
a'
updateFacilityWaitTime :: Facility a -> Double -> Event ()
updateFacilityWaitTime :: Facility a -> Double -> Event ()
updateFacilityWaitTime Facility a
r Double
delta =
(Point -> IO ()) -> Event ()
forall a. (Point -> IO a) -> Event a
Event ((Point -> IO ()) -> Event ()) -> (Point -> IO ()) -> Event ()
forall a b. (a -> b) -> a -> b
$ \Point
p ->
do Double
a <- IORef Double -> IO Double
forall a. IORef a -> IO a
readIORef (Facility a -> IORef Double
forall a. Facility a -> IORef Double
facilityTotalWaitTimeRef Facility a
r)
let a' :: Double
a' = Double
a Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
delta
Double
a' Double -> IO () -> IO ()
`seq` IORef Double -> Double -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (Facility a -> IORef Double
forall a. Facility a -> IORef Double
facilityTotalWaitTimeRef Facility a
r) Double
a'
IORef (SamplingStats Double)
-> (SamplingStats Double -> SamplingStats Double) -> IO ()
forall a. IORef a -> (a -> a) -> IO ()
modifyIORef' (Facility a -> IORef (SamplingStats Double)
forall a. Facility a -> IORef (SamplingStats Double)
facilityWaitTimeRef Facility a
r) ((SamplingStats Double -> SamplingStats Double) -> IO ())
-> (SamplingStats Double -> SamplingStats Double) -> IO ()
forall a b. (a -> b) -> a -> b
$
Double -> SamplingStats Double -> SamplingStats Double
forall a. SamplingData a => a -> SamplingStats a -> SamplingStats a
addSamplingStats Double
delta
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$
SignalSource () -> () -> Event ()
forall a. SignalSource a -> a -> Event ()
triggerSignal (Facility a -> SignalSource ()
forall a. Facility a -> SignalSource ()
facilityWaitTimeSource Facility a
r) ()
updateFacilityHoldingTime :: Facility a -> Double -> Event ()
updateFacilityHoldingTime :: Facility a -> Double -> Event ()
updateFacilityHoldingTime Facility a
r Double
delta =
(Point -> IO ()) -> Event ()
forall a. (Point -> IO a) -> Event a
Event ((Point -> IO ()) -> Event ()) -> (Point -> IO ()) -> Event ()
forall a b. (a -> b) -> a -> b
$ \Point
p ->
do Double
a <- IORef Double -> IO Double
forall a. IORef a -> IO a
readIORef (Facility a -> IORef Double
forall a. Facility a -> IORef Double
facilityTotalHoldingTimeRef Facility a
r)
let a' :: Double
a' = Double
a Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
delta
Double
a' Double -> IO () -> IO ()
`seq` IORef Double -> Double -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (Facility a -> IORef Double
forall a. Facility a -> IORef Double
facilityTotalHoldingTimeRef Facility a
r) Double
a'
IORef (SamplingStats Double)
-> (SamplingStats Double -> SamplingStats Double) -> IO ()
forall a. IORef a -> (a -> a) -> IO ()
modifyIORef' (Facility a -> IORef (SamplingStats Double)
forall a. Facility a -> IORef (SamplingStats Double)
facilityHoldingTimeRef Facility a
r) ((SamplingStats Double -> SamplingStats Double) -> IO ())
-> (SamplingStats Double -> SamplingStats Double) -> IO ()
forall a b. (a -> b) -> a -> b
$
Double -> SamplingStats Double -> SamplingStats Double
forall a. SamplingData a => a -> SamplingStats a -> SamplingStats a
addSamplingStats Double
delta
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$
SignalSource () -> () -> Event ()
forall a. SignalSource a -> a -> Event ()
triggerSignal (Facility a -> SignalSource ()
forall a. Facility a -> SignalSource ()
facilityHoldingTimeSource Facility a
r) ()
resetFacility :: Facility a -> Event ()
resetFacility :: Facility a -> Event ()
resetFacility Facility a
r =
(Point -> IO ()) -> Event ()
forall a. (Point -> IO a) -> Event a
Event ((Point -> IO ()) -> Event ()) -> (Point -> IO ()) -> Event ()
forall a b. (a -> b) -> a -> b
$ \Point
p ->
do let t :: Double
t = Point -> Double
pointTime Point
p
Int
count <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (Facility a -> IORef Int
forall a. Facility a -> IORef Int
facilityCountRef Facility a
r)
IORef (TimingStats Int) -> TimingStats Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (Facility a -> IORef (TimingStats Int)
forall a. Facility a -> IORef (TimingStats Int)
facilityCountStatsRef Facility a
r) (TimingStats Int -> IO ()) -> TimingStats Int -> IO ()
forall a b. (a -> b) -> a -> b
$
Double -> Int -> TimingStats Int
forall a. TimingData a => Double -> a -> TimingStats a
returnTimingStats Double
t Int
count
IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (Facility a -> IORef Int
forall a. Facility a -> IORef Int
facilityCaptureCountRef Facility a
r) Int
0
Int
utilCount <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (Facility a -> IORef Int
forall a. Facility a -> IORef Int
facilityUtilisationCountRef Facility a
r)
IORef (TimingStats Int) -> TimingStats Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (Facility a -> IORef (TimingStats Int)
forall a. Facility a -> IORef (TimingStats Int)
facilityUtilisationCountStatsRef Facility a
r) (TimingStats Int -> IO ()) -> TimingStats Int -> IO ()
forall a b. (a -> b) -> a -> b
$
Double -> Int -> TimingStats Int
forall a. TimingData a => Double -> a -> TimingStats a
returnTimingStats Double
t Int
utilCount
Int
queueCount <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (Facility a -> IORef Int
forall a. Facility a -> IORef Int
facilityQueueCountRef Facility a
r)
IORef (TimingStats Int) -> TimingStats Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (Facility a -> IORef (TimingStats Int)
forall a. Facility a -> IORef (TimingStats Int)
facilityQueueCountStatsRef Facility a
r) (TimingStats Int -> IO ()) -> TimingStats Int -> IO ()
forall a b. (a -> b) -> a -> b
$
Double -> Int -> TimingStats Int
forall a. TimingData a => Double -> a -> TimingStats a
returnTimingStats Double
t Int
queueCount
IORef Double -> Double -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (Facility a -> IORef Double
forall a. Facility a -> IORef Double
facilityTotalWaitTimeRef Facility a
r) Double
0
IORef (SamplingStats Double) -> SamplingStats Double -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (Facility a -> IORef (SamplingStats Double)
forall a. Facility a -> IORef (SamplingStats Double)
facilityWaitTimeRef Facility a
r) SamplingStats Double
forall a. SamplingData a => SamplingStats a
emptySamplingStats
IORef Double -> Double -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (Facility a -> IORef Double
forall a. Facility a -> IORef Double
facilityTotalHoldingTimeRef Facility a
r) Double
0
IORef (SamplingStats Double) -> SamplingStats Double -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (Facility a -> IORef (SamplingStats Double)
forall a. Facility a -> IORef (SamplingStats Double)
facilityHoldingTimeRef Facility a
r) SamplingStats Double
forall a. SamplingData a => SamplingStats a
emptySamplingStats
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$
SignalSource Int -> Int -> Event ()
forall a. SignalSource a -> a -> Event ()
triggerSignal (Facility a -> SignalSource Int
forall a. Facility a -> SignalSource Int
facilityCaptureCountSource Facility a
r) Int
0
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$
SignalSource () -> () -> Event ()
forall a. SignalSource a -> a -> Event ()
triggerSignal (Facility a -> SignalSource ()
forall a. Facility a -> SignalSource ()
facilityWaitTimeSource Facility a
r) ()
Point -> Event () -> IO ()
forall a. Point -> Event a -> IO a
invokeEvent Point
p (Event () -> IO ()) -> Event () -> IO ()
forall a b. (a -> b) -> a -> b
$
SignalSource () -> () -> Event ()
forall a. SignalSource a -> a -> Event ()
triggerSignal (Facility a -> SignalSource ()
forall a. Facility a -> SignalSource ()
facilityHoldingTimeSource Facility a
r) ()