module Simulation.Aivika.Trans.Signal.Random
(
newRandomSignal,
newRandomUniformSignal,
newRandomUniformIntSignal,
newRandomTriangularSignal,
newRandomNormalSignal,
newRandomLogNormalSignal,
newRandomExponentialSignal,
newRandomErlangSignal,
newRandomPoissonSignal,
newRandomBinomialSignal,
newRandomGammaSignal,
newRandomBetaSignal,
newRandomWeibullSignal,
newRandomDiscreteSignal) where
import Control.Monad
import Control.Monad.Trans
import Simulation.Aivika.Trans.DES
import Simulation.Aivika.Trans.Generator
import Simulation.Aivika.Trans.Parameter
import Simulation.Aivika.Trans.Parameter.Random
import Simulation.Aivika.Trans.Simulation
import Simulation.Aivika.Trans.Dynamics
import Simulation.Aivika.Trans.Event
import Simulation.Aivika.Trans.Composite
import Simulation.Aivika.Trans.Process
import Simulation.Aivika.Trans.Signal
import Simulation.Aivika.Trans.Statistics
import Simulation.Aivika.Trans.Arrival
newRandomSignal :: MonadDES m
=> Parameter m (Double, a)
-> Composite m (Signal m (Arrival a))
{-# INLINABLE newRandomSignal #-}
newRandomSignal delay =
do source <- liftSimulation newSignalSource
let loop t0 =
do (delay, a) <- liftParameter delay
when (delay > 0) $
holdProcess delay
t2 <- liftDynamics time
let arrival = Arrival { arrivalValue = a,
arrivalTime = t2,
arrivalDelay =
case t0 of
Nothing -> Nothing
Just t0 -> Just delay }
liftEvent $
triggerSignal source arrival
loop (Just t2)
pid <- liftSimulation newProcessId
liftEvent $
runProcessUsingId pid $
loop Nothing
disposableComposite $
DisposableEvent $
cancelProcessWithId pid
return $ publishSignal source
newRandomUniformSignal :: MonadDES m
=> Double
-> Double
-> Composite m (Signal m (Arrival Double))
{-# INLINABLE newRandomUniformSignal #-}
newRandomUniformSignal min max =
newRandomSignal $
randomUniform min max >>= \x ->
return (x, x)
newRandomUniformIntSignal :: MonadDES m
=> Int
-> Int
-> Composite m (Signal m (Arrival Int))
{-# INLINABLE newRandomUniformIntSignal #-}
newRandomUniformIntSignal min max =
newRandomSignal $
randomUniformInt min max >>= \x ->
return (fromIntegral x, x)
newRandomTriangularSignal :: MonadDES m
=> Double
-> Double
-> Double
-> Composite m (Signal m (Arrival Double))
{-# INLINABLE newRandomTriangularSignal #-}
newRandomTriangularSignal min median max =
newRandomSignal $
randomTriangular min median max >>= \x ->
return (x, x)
newRandomNormalSignal :: MonadDES m
=> Double
-> Double
-> Composite m (Signal m (Arrival Double))
{-# INLINABLE newRandomNormalSignal #-}
newRandomNormalSignal mu nu =
newRandomSignal $
randomNormal mu nu >>= \x ->
return (x, x)
newRandomLogNormalSignal :: MonadDES m
=> Double
-> Double
-> Composite m (Signal m (Arrival Double))
{-# INLINABLE newRandomLogNormalSignal #-}
newRandomLogNormalSignal mu nu =
newRandomSignal $
randomLogNormal mu nu >>= \x ->
return (x, x)
newRandomExponentialSignal :: MonadDES m
=> Double
-> Composite m (Signal m (Arrival Double))
{-# INLINABLE newRandomExponentialSignal #-}
newRandomExponentialSignal mu =
newRandomSignal $
randomExponential mu >>= \x ->
return (x, x)
newRandomErlangSignal :: MonadDES m
=> Double
-> Int
-> Composite m (Signal m (Arrival Double))
{-# INLINABLE newRandomErlangSignal #-}
newRandomErlangSignal beta m =
newRandomSignal $
randomErlang beta m >>= \x ->
return (x, x)
newRandomPoissonSignal :: MonadDES m
=> Double
-> Composite m (Signal m (Arrival Int))
{-# INLINABLE newRandomPoissonSignal #-}
newRandomPoissonSignal mu =
newRandomSignal $
randomPoisson mu >>= \x ->
return (fromIntegral x, x)
newRandomBinomialSignal :: MonadDES m
=> Double
-> Int
-> Composite m (Signal m (Arrival Int))
{-# INLINABLE newRandomBinomialSignal #-}
newRandomBinomialSignal prob trials =
newRandomSignal $
randomBinomial prob trials >>= \x ->
return (fromIntegral x, x)
newRandomGammaSignal :: MonadDES m
=> Double
-> Double
-> Composite m (Signal m (Arrival Double))
{-# INLINABLE newRandomGammaSignal #-}
newRandomGammaSignal kappa theta =
newRandomSignal $
randomGamma kappa theta >>= \x ->
return (x, x)
newRandomBetaSignal :: MonadDES m
=> Double
-> Double
-> Composite m (Signal m (Arrival Double))
{-# INLINABLE newRandomBetaSignal #-}
newRandomBetaSignal alpha beta =
newRandomSignal $
randomBeta alpha beta >>= \x ->
return (x, x)
newRandomWeibullSignal :: MonadDES m
=> Double
-> Double
-> Composite m (Signal m (Arrival Double))
{-# INLINABLE newRandomWeibullSignal #-}
newRandomWeibullSignal alpha beta =
newRandomSignal $
randomWeibull alpha beta >>= \x ->
return (x, x)
newRandomDiscreteSignal :: MonadDES m
=> DiscretePDF Double
-> Composite m (Signal m (Arrival Double))
{-# INLINABLE newRandomDiscreteSignal #-}
newRandomDiscreteSignal dpdf =
newRandomSignal $
randomDiscrete dpdf >>= \x ->
return (x, x)