module Simulation.Aivika.Trans.Operation
(
Operation,
newOperation,
newPreemptibleOperation,
operationProcess,
operationTotalUtilisationTime,
operationTotalPreemptionTime,
operationUtilisationTime,
operationPreemptionTime,
operationUtilisationFactor,
operationPreemptionFactor,
resetOperation,
operationSummary,
operationTotalUtilisationTimeChanged,
operationTotalUtilisationTimeChanged_,
operationTotalPreemptionTimeChanged,
operationTotalPreemptionTimeChanged_,
operationUtilisationTimeChanged,
operationUtilisationTimeChanged_,
operationPreemptionTimeChanged,
operationPreemptionTimeChanged_,
operationUtilisationFactorChanged,
operationUtilisationFactorChanged_,
operationPreemptionFactorChanged,
operationPreemptionFactorChanged_,
operationUtilising,
operationUtilised,
operationPreemptionBeginning,
operationPreemptionEnding,
operationChanged_) where
import Data.Monoid
import Control.Monad
import Control.Monad.Trans
import Simulation.Aivika.Trans.Ref.Base
import Simulation.Aivika.Trans.DES
import Simulation.Aivika.Trans.Parameter
import Simulation.Aivika.Trans.Simulation
import Simulation.Aivika.Trans.Dynamics
import Simulation.Aivika.Trans.Internal.Specs
import Simulation.Aivika.Trans.Internal.Event
import Simulation.Aivika.Trans.Signal
import Simulation.Aivika.Trans.Cont
import Simulation.Aivika.Trans.Process
import Simulation.Aivika.Trans.Activity
import Simulation.Aivika.Trans.Server
import Simulation.Aivika.Trans.Statistics
data Operation m a b =
Operation { forall (m :: * -> *) a b. Operation m a b -> a -> Process m b
operationInitProcess :: a -> Process m b,
forall (m :: * -> *) a b. Operation m a b -> Bool
operationProcessPreemptible :: Bool,
forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationStartTimeRef :: Ref m Double,
forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationLastTimeRef :: Ref m Double,
forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationTotalUtilisationTimeRef :: Ref m Double,
forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationTotalPreemptionTimeRef :: Ref m Double,
forall (m :: * -> *) a b.
Operation m a b -> Ref m (SamplingStats Double)
operationUtilisationTimeRef :: Ref m (SamplingStats Double),
forall (m :: * -> *) a b.
Operation m a b -> Ref m (SamplingStats Double)
operationPreemptionTimeRef :: Ref m (SamplingStats Double),
forall (m :: * -> *) a b. Operation m a b -> SignalSource m a
operationUtilisingSource :: SignalSource m a,
forall (m :: * -> *) a b. Operation m a b -> SignalSource m (a, b)
operationUtilisedSource :: SignalSource m (a, b),
forall (m :: * -> *) a b. Operation m a b -> SignalSource m a
operationPreemptionBeginningSource :: SignalSource m a,
forall (m :: * -> *) a b. Operation m a b -> SignalSource m a
operationPreemptionEndingSource :: SignalSource m a
}
newOperation :: MonadDES m
=> (a -> Process m b)
-> Event m (Operation m a b)
{-# INLINABLE newOperation #-}
newOperation :: forall (m :: * -> *) a b.
MonadDES m =>
(a -> Process m b) -> Event m (Operation m a b)
newOperation = forall (m :: * -> *) a b.
MonadDES m =>
Bool -> (a -> Process m b) -> Event m (Operation m a b)
newPreemptibleOperation Bool
False
newPreemptibleOperation :: MonadDES m
=> Bool
-> (a -> Process m b)
-> Event m (Operation m a b)
{-# INLINABLE newPreemptibleOperation #-}
newPreemptibleOperation :: forall (m :: * -> *) a b.
MonadDES m =>
Bool -> (a -> Process m b) -> Event m (Operation m a b)
newPreemptibleOperation Bool
preemptible a -> Process m b
provide =
do Double
t0 <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
DynamicsLift t m =>
Dynamics m a -> t m a
liftDynamics forall (m :: * -> *). Monad m => Dynamics m Double
time
Ref m Double
r' <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadRef m => a -> Simulation m (Ref m a)
newRef Double
t0
Ref m Double
r0 <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadRef m => a -> Simulation m (Ref m a)
newRef Double
t0
Ref m Double
r1 <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadRef m => a -> Simulation m (Ref m a)
newRef Double
0
Ref m Double
r2 <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadRef m => a -> Simulation m (Ref m a)
newRef Double
0
Ref m (SamplingStats Double)
r3 <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadRef m => a -> Simulation m (Ref m a)
newRef forall a. SamplingData a => SamplingStats a
emptySamplingStats
Ref m (SamplingStats Double)
r4 <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadRef m => a -> Simulation m (Ref m a)
newRef forall a. SamplingData a => SamplingStats a
emptySamplingStats
SignalSource m a
s1 <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation forall (m :: * -> *) a.
MonadDES m =>
Simulation m (SignalSource m a)
newSignalSource
SignalSource m (a, b)
s2 <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation forall (m :: * -> *) a.
MonadDES m =>
Simulation m (SignalSource m a)
newSignalSource
SignalSource m a
s3 <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation forall (m :: * -> *) a.
MonadDES m =>
Simulation m (SignalSource m a)
newSignalSource
SignalSource m a
s4 <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation forall (m :: * -> *) a.
MonadDES m =>
Simulation m (SignalSource m a)
newSignalSource
forall (m :: * -> *) a. Monad m => a -> m a
return Operation { operationInitProcess :: a -> Process m b
operationInitProcess = a -> Process m b
provide,
operationProcessPreemptible :: Bool
operationProcessPreemptible = Bool
preemptible,
operationStartTimeRef :: Ref m Double
operationStartTimeRef = Ref m Double
r',
operationLastTimeRef :: Ref m Double
operationLastTimeRef = Ref m Double
r0,
operationTotalUtilisationTimeRef :: Ref m Double
operationTotalUtilisationTimeRef = Ref m Double
r1,
operationTotalPreemptionTimeRef :: Ref m Double
operationTotalPreemptionTimeRef = Ref m Double
r2,
operationUtilisationTimeRef :: Ref m (SamplingStats Double)
operationUtilisationTimeRef = Ref m (SamplingStats Double)
r3,
operationPreemptionTimeRef :: Ref m (SamplingStats Double)
operationPreemptionTimeRef = Ref m (SamplingStats Double)
r4,
operationUtilisingSource :: SignalSource m a
operationUtilisingSource = SignalSource m a
s1,
operationUtilisedSource :: SignalSource m (a, b)
operationUtilisedSource = SignalSource m (a, b)
s2,
operationPreemptionBeginningSource :: SignalSource m a
operationPreemptionBeginningSource = SignalSource m a
s3,
operationPreemptionEndingSource :: SignalSource m a
operationPreemptionEndingSource = SignalSource m a
s4 }
operationProcess :: MonadDES m => Operation m a b -> a -> Process m b
{-# INLINABLE operationProcess #-}
operationProcess :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> a -> Process m b
operationProcess Operation m a b
op a
a =
do Double
t0 <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
DynamicsLift t m =>
Dynamics m a -> t m a
liftDynamics forall (m :: * -> *). Monad m => Dynamics m Double
time
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
EventLift t m =>
Event m a -> t m a
liftEvent forall a b. (a -> b) -> a -> b
$
forall (m :: * -> *) a. SignalSource m a -> a -> Event m ()
triggerSignal (forall (m :: * -> *) a b. Operation m a b -> SignalSource m a
operationUtilisingSource Operation m a b
op) a
a
(b
b, Double
dt) <- if forall (m :: * -> *) a b. Operation m a b -> Bool
operationProcessPreemptible Operation m a b
op
then forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> a -> Process m (b, Double)
operationProcessPreempting Operation m a b
op a
a
else do b
b <- forall (m :: * -> *) a b. Operation m a b -> a -> Process m b
operationInitProcess Operation m a b
op a
a
forall (m :: * -> *) a. Monad m => a -> m a
return (b
b, Double
0)
Double
t1 <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
DynamicsLift t m =>
Dynamics m a -> t m a
liftDynamics forall (m :: * -> *). Monad m => Dynamics m Double
time
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
EventLift t m =>
Event m a -> t m a
liftEvent forall a b. (a -> b) -> a -> b
$
do forall (m :: * -> *) a.
MonadRef m =>
Ref m a -> (a -> a) -> Event m ()
modifyRef (forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationTotalUtilisationTimeRef Operation m a b
op) (forall a. Num a => a -> a -> a
+ (Double
t1 forall a. Num a => a -> a -> a
- Double
t0 forall a. Num a => a -> a -> a
- Double
dt))
forall (m :: * -> *) a.
MonadRef m =>
Ref m a -> (a -> a) -> Event m ()
modifyRef (forall (m :: * -> *) a b.
Operation m a b -> Ref m (SamplingStats Double)
operationUtilisationTimeRef Operation m a b
op) forall a b. (a -> b) -> a -> b
$
forall a. SamplingData a => a -> SamplingStats a -> SamplingStats a
addSamplingStats (Double
t1 forall a. Num a => a -> a -> a
- Double
t0 forall a. Num a => a -> a -> a
- Double
dt)
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> Event m ()
writeRef (forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationLastTimeRef Operation m a b
op) Double
t1
forall (m :: * -> *) a. SignalSource m a -> a -> Event m ()
triggerSignal (forall (m :: * -> *) a b. Operation m a b -> SignalSource m (a, b)
operationUtilisedSource Operation m a b
op) (a
a, b
b)
forall (m :: * -> *) a. Monad m => a -> m a
return b
b
operationProcessPreempting :: MonadDES m => Operation m a b -> a -> Process m (b, Double)
{-# INLINABLE operationProcessPreempting #-}
operationProcessPreempting :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> a -> Process m (b, Double)
operationProcessPreempting Operation m a b
op a
a =
do ProcessId m
pid <- forall (m :: * -> *). MonadDES m => Process m (ProcessId m)
processId
Double
t0 <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
DynamicsLift t m =>
Dynamics m a -> t m a
liftDynamics forall (m :: * -> *). Monad m => Dynamics m Double
time
Ref m Double
rs <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadRef m => a -> Simulation m (Ref m a)
newRef Double
0
Ref m Double
r0 <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadRef m => a -> Simulation m (Ref m a)
newRef Double
t0
DisposableEvent m
h1 <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
EventLift t m =>
Event m a -> t m a
liftEvent forall a b. (a -> b) -> a -> b
$
forall (m :: * -> *) a.
Signal m a -> (a -> Event m ()) -> Event m (DisposableEvent m)
handleSignal (forall (m :: * -> *). MonadDES m => ProcessId m -> Signal m ()
processPreemptionBeginning ProcessId m
pid) forall a b. (a -> b) -> a -> b
$ \() ->
do Double
t0 <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
DynamicsLift t m =>
Dynamics m a -> t m a
liftDynamics forall (m :: * -> *). Monad m => Dynamics m Double
time
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> Event m ()
writeRef Ref m Double
r0 Double
t0
forall (m :: * -> *) a. SignalSource m a -> a -> Event m ()
triggerSignal (forall (m :: * -> *) a b. Operation m a b -> SignalSource m a
operationPreemptionBeginningSource Operation m a b
op) a
a
DisposableEvent m
h2 <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
EventLift t m =>
Event m a -> t m a
liftEvent forall a b. (a -> b) -> a -> b
$
forall (m :: * -> *) a.
Signal m a -> (a -> Event m ()) -> Event m (DisposableEvent m)
handleSignal (forall (m :: * -> *). MonadDES m => ProcessId m -> Signal m ()
processPreemptionEnding ProcessId m
pid) forall a b. (a -> b) -> a -> b
$ \() ->
do Double
t0 <- forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef Ref m Double
r0
Double
t1 <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
DynamicsLift t m =>
Dynamics m a -> t m a
liftDynamics forall (m :: * -> *). Monad m => Dynamics m Double
time
let dt :: Double
dt = Double
t1 forall a. Num a => a -> a -> a
- Double
t0
forall (m :: * -> *) a.
MonadRef m =>
Ref m a -> (a -> a) -> Event m ()
modifyRef Ref m Double
rs (forall a. Num a => a -> a -> a
+ Double
dt)
forall (m :: * -> *) a.
MonadRef m =>
Ref m a -> (a -> a) -> Event m ()
modifyRef (forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationTotalPreemptionTimeRef Operation m a b
op) (forall a. Num a => a -> a -> a
+ Double
dt)
forall (m :: * -> *) a.
MonadRef m =>
Ref m a -> (a -> a) -> Event m ()
modifyRef (forall (m :: * -> *) a b.
Operation m a b -> Ref m (SamplingStats Double)
operationPreemptionTimeRef Operation m a b
op) forall a b. (a -> b) -> a -> b
$
forall a. SamplingData a => a -> SamplingStats a -> SamplingStats a
addSamplingStats Double
dt
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> Event m ()
writeRef (forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationLastTimeRef Operation m a b
op) Double
t1
forall (m :: * -> *) a. SignalSource m a -> a -> Event m ()
triggerSignal (forall (m :: * -> *) a b. Operation m a b -> SignalSource m a
operationPreemptionEndingSource Operation m a b
op) a
a
let m1 :: Process m (b, Double)
m1 =
do b
b <- forall (m :: * -> *) a b. Operation m a b -> a -> Process m b
operationInitProcess Operation m a b
op a
a
Double
dt <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
EventLift t m =>
Event m a -> t m a
liftEvent forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef Ref m Double
rs
forall (m :: * -> *) a. Monad m => a -> m a
return (b
b, Double
dt)
m2 :: Process m ()
m2 =
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
EventLift t m =>
Event m a -> t m a
liftEvent forall a b. (a -> b) -> a -> b
$
do forall (m :: * -> *). DisposableEvent m -> Event m ()
disposeEvent DisposableEvent m
h1
forall (m :: * -> *). DisposableEvent m -> Event m ()
disposeEvent DisposableEvent m
h2
forall (m :: * -> *) a b.
MonadDES m =>
Process m a -> Process m b -> Process m a
finallyProcess Process m (b, Double)
m1 Process m ()
m2
operationTotalUtilisationTime :: MonadDES m => Operation m a b -> Event m Double
{-# INLINABLE operationTotalUtilisationTime #-}
operationTotalUtilisationTime :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Event m Double
operationTotalUtilisationTime Operation m a b
op =
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event forall a b. (a -> b) -> a -> b
$ \Point m
p -> forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationTotalUtilisationTimeRef Operation m a b
op)
operationTotalUtilisationTimeChanged :: MonadDES m => Operation m a b -> Signal m Double
{-# INLINABLE operationTotalUtilisationTimeChanged #-}
operationTotalUtilisationTimeChanged :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m Double
operationTotalUtilisationTimeChanged Operation m a b
op =
forall (m :: * -> *) a b.
MonadDES m =>
(a -> Event m b) -> Signal m a -> Signal m b
mapSignalM (forall a b. a -> b -> a
const forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Event m Double
operationTotalUtilisationTime Operation m a b
op) (forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m ()
operationTotalUtilisationTimeChanged_ Operation m a b
op)
operationTotalUtilisationTimeChanged_ :: MonadDES m => Operation m a b -> Signal m ()
{-# INLINABLE operationTotalUtilisationTimeChanged_ #-}
operationTotalUtilisationTimeChanged_ :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m ()
operationTotalUtilisationTimeChanged_ Operation m a b
op =
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (forall a b. a -> b -> a
const ()) (forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m (a, b)
operationUtilised Operation m a b
op)
operationTotalPreemptionTime :: MonadDES m => Operation m a b -> Event m Double
{-# INLINABLE operationTotalPreemptionTime #-}
operationTotalPreemptionTime :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Event m Double
operationTotalPreemptionTime Operation m a b
op =
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event forall a b. (a -> b) -> a -> b
$ \Point m
p -> forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationTotalPreemptionTimeRef Operation m a b
op)
operationTotalPreemptionTimeChanged :: MonadDES m => Operation m a b -> Signal m Double
{-# INLINABLE operationTotalPreemptionTimeChanged #-}
operationTotalPreemptionTimeChanged :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m Double
operationTotalPreemptionTimeChanged Operation m a b
op =
forall (m :: * -> *) a b.
MonadDES m =>
(a -> Event m b) -> Signal m a -> Signal m b
mapSignalM (forall a b. a -> b -> a
const forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Event m Double
operationTotalPreemptionTime Operation m a b
op) (forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m ()
operationTotalPreemptionTimeChanged_ Operation m a b
op)
operationTotalPreemptionTimeChanged_ :: MonadDES m => Operation m a b -> Signal m ()
{-# INLINABLE operationTotalPreemptionTimeChanged_ #-}
operationTotalPreemptionTimeChanged_ :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m ()
operationTotalPreemptionTimeChanged_ Operation m a b
op =
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (forall a b. a -> b -> a
const ()) (forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m a
operationPreemptionEnding Operation m a b
op)
operationUtilisationTime :: MonadDES m => Operation m a b -> Event m (SamplingStats Double)
{-# INLINABLE operationUtilisationTime #-}
operationUtilisationTime :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Event m (SamplingStats Double)
operationUtilisationTime Operation m a b
op =
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event forall a b. (a -> b) -> a -> b
$ \Point m
p -> forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (forall (m :: * -> *) a b.
Operation m a b -> Ref m (SamplingStats Double)
operationUtilisationTimeRef Operation m a b
op)
operationUtilisationTimeChanged :: MonadDES m => Operation m a b -> Signal m (SamplingStats Double)
{-# INLINABLE operationUtilisationTimeChanged #-}
operationUtilisationTimeChanged :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m (SamplingStats Double)
operationUtilisationTimeChanged Operation m a b
op =
forall (m :: * -> *) a b.
MonadDES m =>
(a -> Event m b) -> Signal m a -> Signal m b
mapSignalM (forall a b. a -> b -> a
const forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Event m (SamplingStats Double)
operationUtilisationTime Operation m a b
op) (forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m ()
operationUtilisationTimeChanged_ Operation m a b
op)
operationUtilisationTimeChanged_ :: MonadDES m => Operation m a b -> Signal m ()
{-# INLINABLE operationUtilisationTimeChanged_ #-}
operationUtilisationTimeChanged_ :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m ()
operationUtilisationTimeChanged_ Operation m a b
op =
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (forall a b. a -> b -> a
const ()) (forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m (a, b)
operationUtilised Operation m a b
op)
operationPreemptionTime :: MonadDES m => Operation m a b -> Event m (SamplingStats Double)
{-# INLINABLE operationPreemptionTime #-}
operationPreemptionTime :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Event m (SamplingStats Double)
operationPreemptionTime Operation m a b
op =
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event forall a b. (a -> b) -> a -> b
$ \Point m
p -> forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (forall (m :: * -> *) a b.
Operation m a b -> Ref m (SamplingStats Double)
operationPreemptionTimeRef Operation m a b
op)
operationPreemptionTimeChanged :: MonadDES m => Operation m a b -> Signal m (SamplingStats Double)
{-# INLINABLE operationPreemptionTimeChanged #-}
operationPreemptionTimeChanged :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m (SamplingStats Double)
operationPreemptionTimeChanged Operation m a b
op =
forall (m :: * -> *) a b.
MonadDES m =>
(a -> Event m b) -> Signal m a -> Signal m b
mapSignalM (forall a b. a -> b -> a
const forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Event m (SamplingStats Double)
operationPreemptionTime Operation m a b
op) (forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m ()
operationPreemptionTimeChanged_ Operation m a b
op)
operationPreemptionTimeChanged_ :: MonadDES m => Operation m a b -> Signal m ()
{-# INLINABLE operationPreemptionTimeChanged_ #-}
operationPreemptionTimeChanged_ :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m ()
operationPreemptionTimeChanged_ Operation m a b
op =
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (forall a b. a -> b -> a
const ()) (forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m a
operationPreemptionEnding Operation m a b
op)
operationUtilisationFactor :: MonadDES m => Operation m a b -> Event m Double
{-# INLINABLE operationUtilisationFactor #-}
operationUtilisationFactor :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Event m Double
operationUtilisationFactor Operation m a b
op =
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event forall a b. (a -> b) -> a -> b
$ \Point m
p ->
do Double
t0 <- forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationStartTimeRef Operation m a b
op)
Double
t1 <- forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationLastTimeRef Operation m a b
op)
Double
x <- forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationTotalUtilisationTimeRef Operation m a b
op)
forall (m :: * -> *) a. Monad m => a -> m a
return (Double
x forall a. Fractional a => a -> a -> a
/ (Double
t1 forall a. Num a => a -> a -> a
- Double
t0))
operationUtilisationFactorChanged :: MonadDES m => Operation m a b -> Signal m Double
{-# INLINABLE operationUtilisationFactorChanged #-}
operationUtilisationFactorChanged :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m Double
operationUtilisationFactorChanged Operation m a b
op =
forall (m :: * -> *) a b.
MonadDES m =>
(a -> Event m b) -> Signal m a -> Signal m b
mapSignalM (forall a b. a -> b -> a
const forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Event m Double
operationUtilisationFactor Operation m a b
op) (forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m ()
operationUtilisationFactorChanged_ Operation m a b
op)
operationUtilisationFactorChanged_ :: MonadDES m => Operation m a b -> Signal m ()
{-# INLINABLE operationUtilisationFactorChanged_ #-}
operationUtilisationFactorChanged_ :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m ()
operationUtilisationFactorChanged_ Operation m a b
op =
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (forall a b. a -> b -> a
const ()) (forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m (a, b)
operationUtilised Operation m a b
op) forall a. Semigroup a => a -> a -> a
<>
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (forall a b. a -> b -> a
const ()) (forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m a
operationPreemptionEnding Operation m a b
op)
operationPreemptionFactor :: MonadDES m => Operation m a b -> Event m Double
{-# INLINABLE operationPreemptionFactor #-}
operationPreemptionFactor :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Event m Double
operationPreemptionFactor Operation m a b
op =
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event forall a b. (a -> b) -> a -> b
$ \Point m
p ->
do Double
t0 <- forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationStartTimeRef Operation m a b
op)
Double
t1 <- forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationLastTimeRef Operation m a b
op)
Double
x <- forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationTotalPreemptionTimeRef Operation m a b
op)
forall (m :: * -> *) a. Monad m => a -> m a
return (Double
x forall a. Fractional a => a -> a -> a
/ (Double
t1 forall a. Num a => a -> a -> a
- Double
t0))
operationPreemptionFactorChanged :: MonadDES m => Operation m a b -> Signal m Double
{-# INLINABLE operationPreemptionFactorChanged #-}
operationPreemptionFactorChanged :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m Double
operationPreemptionFactorChanged Operation m a b
op =
forall (m :: * -> *) a b.
MonadDES m =>
(a -> Event m b) -> Signal m a -> Signal m b
mapSignalM (forall a b. a -> b -> a
const forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Event m Double
operationPreemptionFactor Operation m a b
op) (forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m ()
operationPreemptionFactorChanged_ Operation m a b
op)
operationPreemptionFactorChanged_ :: MonadDES m => Operation m a b -> Signal m ()
{-# INLINABLE operationPreemptionFactorChanged_ #-}
operationPreemptionFactorChanged_ :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m ()
operationPreemptionFactorChanged_ Operation m a b
op =
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (forall a b. a -> b -> a
const ()) (forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m (a, b)
operationUtilised Operation m a b
op) forall a. Semigroup a => a -> a -> a
<>
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (forall a b. a -> b -> a
const ()) (forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m a
operationPreemptionEnding Operation m a b
op)
operationUtilising :: MonadDES m => Operation m a b -> Signal m a
{-# INLINABLE operationUtilising #-}
operationUtilising :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m a
operationUtilising = forall (m :: * -> *) a. SignalSource m a -> Signal m a
publishSignal forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a b. Operation m a b -> SignalSource m a
operationUtilisingSource
operationUtilised :: MonadDES m => Operation m a b -> Signal m (a, b)
{-# INLINABLE operationUtilised #-}
operationUtilised :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m (a, b)
operationUtilised = forall (m :: * -> *) a. SignalSource m a -> Signal m a
publishSignal forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a b. Operation m a b -> SignalSource m (a, b)
operationUtilisedSource
operationPreemptionBeginning :: MonadDES m => Operation m a b -> Signal m a
{-# INLINABLE operationPreemptionBeginning #-}
operationPreemptionBeginning :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m a
operationPreemptionBeginning = forall (m :: * -> *) a. SignalSource m a -> Signal m a
publishSignal forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a b. Operation m a b -> SignalSource m a
operationPreemptionBeginningSource
operationPreemptionEnding :: MonadDES m => Operation m a b -> Signal m a
{-# INLINABLE operationPreemptionEnding #-}
operationPreemptionEnding :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m a
operationPreemptionEnding = forall (m :: * -> *) a. SignalSource m a -> Signal m a
publishSignal forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a b. Operation m a b -> SignalSource m a
operationPreemptionEndingSource
operationChanged_ :: MonadDES m => Operation m a b -> Signal m ()
{-# INLINABLE operationChanged_ #-}
operationChanged_ :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m ()
operationChanged_ Operation m a b
op =
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (forall a b. a -> b -> a
const ()) (forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m a
operationUtilising Operation m a b
op) forall a. Semigroup a => a -> a -> a
<>
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (forall a b. a -> b -> a
const ()) (forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m (a, b)
operationUtilised Operation m a b
op) forall a. Semigroup a => a -> a -> a
<>
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (forall a b. a -> b -> a
const ()) (forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m a
operationPreemptionEnding Operation m a b
op)
operationSummary :: MonadDES m => Operation m a b -> Int -> Event m ShowS
{-# INLINABLE operationSummary #-}
operationSummary :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Int -> Event m ShowS
operationSummary Operation m a b
op Int
indent =
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event forall a b. (a -> b) -> a -> b
$ \Point m
p ->
do Double
t0 <- forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationStartTimeRef Operation m a b
op)
Double
t1 <- forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationLastTimeRef Operation m a b
op)
Double
tx1 <- forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationTotalUtilisationTimeRef Operation m a b
op)
Double
tx2 <- forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationTotalPreemptionTimeRef Operation m a b
op)
let xf1 :: Double
xf1 = Double
tx1 forall a. Fractional a => a -> a -> a
/ (Double
t1 forall a. Num a => a -> a -> a
- Double
t0)
xf2 :: Double
xf2 = Double
tx2 forall a. Fractional a => a -> a -> a
/ (Double
t1 forall a. Num a => a -> a -> a
- Double
t0)
SamplingStats Double
xs1 <- forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (forall (m :: * -> *) a b.
Operation m a b -> Ref m (SamplingStats Double)
operationUtilisationTimeRef Operation m a b
op)
SamplingStats Double
xs2 <- forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (forall (m :: * -> *) a b.
Operation m a b -> Ref m (SamplingStats Double)
operationPreemptionTimeRef Operation m a b
op)
let tab :: [Char]
tab = forall a. Int -> a -> [a]
replicate Int
indent Char
' '
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$
[Char] -> ShowS
showString [Char]
tab forall b c a. (b -> c) -> (a -> b) -> a -> c
.
[Char] -> ShowS
showString [Char]
"total utilisation time = " forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> ShowS
shows Double
tx1 forall b c a. (b -> c) -> (a -> b) -> a -> c
.
[Char] -> ShowS
showString [Char]
"\n" forall b c a. (b -> c) -> (a -> b) -> a -> c
.
[Char] -> ShowS
showString [Char]
tab forall b c a. (b -> c) -> (a -> b) -> a -> c
.
[Char] -> ShowS
showString [Char]
"total preemption time = " forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> ShowS
shows Double
tx2 forall b c a. (b -> c) -> (a -> b) -> a -> c
.
[Char] -> ShowS
showString [Char]
"\n" forall b c a. (b -> c) -> (a -> b) -> a -> c
.
[Char] -> ShowS
showString [Char]
tab forall b c a. (b -> c) -> (a -> b) -> a -> c
.
[Char] -> ShowS
showString [Char]
"utilisation factor (from 0 to 1) = " forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> ShowS
shows Double
xf1 forall b c a. (b -> c) -> (a -> b) -> a -> c
.
[Char] -> ShowS
showString [Char]
"\n" forall b c a. (b -> c) -> (a -> b) -> a -> c
.
[Char] -> ShowS
showString [Char]
tab forall b c a. (b -> c) -> (a -> b) -> a -> c
.
[Char] -> ShowS
showString [Char]
"preemption factor (from 0 to 1) = " forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> ShowS
shows Double
xf2 forall b c a. (b -> c) -> (a -> b) -> a -> c
.
[Char] -> ShowS
showString [Char]
"\n" forall b c a. (b -> c) -> (a -> b) -> a -> c
.
[Char] -> ShowS
showString [Char]
tab forall b c a. (b -> c) -> (a -> b) -> a -> c
.
[Char] -> ShowS
showString [Char]
"utilisation time:\n\n" forall b c a. (b -> c) -> (a -> b) -> a -> c
.
forall a. Show a => SamplingStats a -> Int -> ShowS
samplingStatsSummary SamplingStats Double
xs1 (Int
2 forall a. Num a => a -> a -> a
+ Int
indent) forall b c a. (b -> c) -> (a -> b) -> a -> c
.
[Char] -> ShowS
showString [Char]
"\n\n" forall b c a. (b -> c) -> (a -> b) -> a -> c
.
[Char] -> ShowS
showString [Char]
tab forall b c a. (b -> c) -> (a -> b) -> a -> c
.
[Char] -> ShowS
showString [Char]
"preemption time:\n\n" forall b c a. (b -> c) -> (a -> b) -> a -> c
.
forall a. Show a => SamplingStats a -> Int -> ShowS
samplingStatsSummary SamplingStats Double
xs2 (Int
2 forall a. Num a => a -> a -> a
+ Int
indent)
resetOperation :: MonadDES m => Operation m a b -> Event m ()
{-# INLINABLE resetOperation #-}
resetOperation :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Event m ()
resetOperation Operation m a b
op =
do Double
t0 <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
DynamicsLift t m =>
Dynamics m a -> t m a
liftDynamics forall (m :: * -> *). Monad m => Dynamics m Double
time
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> Event m ()
writeRef (forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationStartTimeRef Operation m a b
op) Double
t0
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> Event m ()
writeRef (forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationLastTimeRef Operation m a b
op) Double
t0
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> Event m ()
writeRef (forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationTotalUtilisationTimeRef Operation m a b
op) Double
0
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> Event m ()
writeRef (forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationTotalPreemptionTimeRef Operation m a b
op) Double
0
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> Event m ()
writeRef (forall (m :: * -> *) a b.
Operation m a b -> Ref m (SamplingStats Double)
operationUtilisationTimeRef Operation m a b
op) forall a. SamplingData a => SamplingStats a
emptySamplingStats
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> Event m ()
writeRef (forall (m :: * -> *) a b.
Operation m a b -> Ref m (SamplingStats Double)
operationPreemptionTimeRef Operation m a b
op) forall a. SamplingData a => SamplingStats a
emptySamplingStats