-- |
-- Module     : Simulation.Aivika.Activity.Random
-- Copyright  : Copyright (c) 2009-2017, David Sorokin <david.sorokin@gmail.com>
-- License    : BSD3
-- Maintainer : David Sorokin <david.sorokin@gmail.com>
-- Stability  : experimental
-- Tested with: GHC 8.0.1
--
-- This module defines some useful predefined activities that
-- hold the current process for the corresponding random time
-- interval, when processing every input element.
--

module Simulation.Aivika.Activity.Random
       (newRandomUniformActivity,
        newRandomUniformIntActivity,
        newRandomTriangularActivity,
        newRandomNormalActivity,
        newRandomLogNormalActivity,
        newRandomExponentialActivity,
        newRandomErlangActivity,
        newRandomPoissonActivity,
        newRandomBinomialActivity,
        newRandomGammaActivity,
        newRandomBetaActivity,
        newRandomWeibullActivity,
        newRandomDiscreteActivity,
        newPreemptibleRandomUniformActivity,
        newPreemptibleRandomUniformIntActivity,
        newPreemptibleRandomTriangularActivity,
        newPreemptibleRandomNormalActivity,
        newPreemptibleRandomLogNormalActivity,
        newPreemptibleRandomExponentialActivity,
        newPreemptibleRandomErlangActivity,
        newPreemptibleRandomPoissonActivity,
        newPreemptibleRandomBinomialActivity,
        newPreemptibleRandomGammaActivity,
        newPreemptibleRandomBetaActivity,
        newPreemptibleRandomWeibullActivity,
        newPreemptibleRandomDiscreteActivity) where

import Simulation.Aivika.Generator
import Simulation.Aivika.Simulation
import Simulation.Aivika.Process
import Simulation.Aivika.Process.Random
import Simulation.Aivika.Activity

-- | Create a new activity that holds the process for a random time interval
-- distributed uniformly, when processing every input element.
--
-- By default, it is assumed that the activity process cannot be preempted,
-- because the handling of possible task preemption is rather costly
-- operation.
newRandomUniformActivity :: Double
                            -- ^ the minimum time interval
                            -> Double
                            -- ^ the maximum time interval
                            -> Simulation (Activity () a a)
newRandomUniformActivity :: forall a. Double -> Double -> Simulation (Activity () a a)
newRandomUniformActivity =
  forall a. Bool -> Double -> Double -> Simulation (Activity () a a)
newPreemptibleRandomUniformActivity Bool
False

-- | Create a new activity that holds the process for a random time interval
-- distributed uniformly, when processing every input element.
--
-- By default, it is assumed that the activity process cannot be preempted,
-- because the handling of possible task preemption is rather costly
-- operation.
newRandomUniformIntActivity :: Int
                               -- ^ the minimum time interval
                               -> Int
                               -- ^ the maximum time interval
                               -> Simulation (Activity () a a)
newRandomUniformIntActivity :: forall a. Int -> Int -> Simulation (Activity () a a)
newRandomUniformIntActivity =
  forall a. Bool -> Int -> Int -> Simulation (Activity () a a)
newPreemptibleRandomUniformIntActivity Bool
False

-- | Create a new activity that holds the process for a random time interval
-- having the triangular distribution, when processing every input element.
--
-- By default, it is assumed that the activity process cannot be preempted,
-- because the handling of possible task preemption is rather costly
-- operation.
newRandomTriangularActivity :: Double
                               -- ^ the minimum time interval
                               -> Double
                               -- ^ the median of the time interval
                               -> Double
                               -- ^ the maximum time interval
                               -> Simulation (Activity () a a)
newRandomTriangularActivity :: forall a.
Double -> Double -> Double -> Simulation (Activity () a a)
newRandomTriangularActivity =
  forall a.
Bool -> Double -> Double -> Double -> Simulation (Activity () a a)
newPreemptibleRandomTriangularActivity Bool
False

-- | Create a new activity that holds the process for a random time interval
-- distributed normally, when processing every input element.
--
-- By default, it is assumed that the activity process cannot be preempted,
-- because the handling of possible task preemption is rather costly
-- operation.
newRandomNormalActivity :: Double
                           -- ^ the mean time interval
                           -> Double
                           -- ^ the time interval deviation
                           -> Simulation (Activity () a a)
newRandomNormalActivity :: forall a. Double -> Double -> Simulation (Activity () a a)
newRandomNormalActivity =
  forall a. Bool -> Double -> Double -> Simulation (Activity () a a)
newPreemptibleRandomNormalActivity Bool
False
         
-- | Create a new activity that holds the process for a random time interval
-- having the lognormal distribution, when processing every input element.
--
-- By default, it is assumed that the activity process cannot be preempted,
-- because the handling of possible task preemption is rather costly
-- operation.
newRandomLogNormalActivity :: Double
                              -- ^ the mean of a normal distribution which
                              -- this distribution is derived from
                              -> Double
                              -- ^ the deviation of a normal distribution which
                              -- this distribution is derived from
                              -> Simulation (Activity () a a)
newRandomLogNormalActivity :: forall a. Double -> Double -> Simulation (Activity () a a)
newRandomLogNormalActivity =
  forall a. Bool -> Double -> Double -> Simulation (Activity () a a)
newPreemptibleRandomLogNormalActivity Bool
False

-- | Create a new activity that holds the process for a random time interval
-- distributed exponentially with the specified mean (the reciprocal of the rate),
-- when processing every input element.
--
-- By default, it is assumed that the activity process cannot be preempted,
-- because the handling of possible task preemption is rather costly
-- operation.
newRandomExponentialActivity :: Double
                                -- ^ the mean time interval (the reciprocal of the rate)
                                -> Simulation (Activity () a a)
newRandomExponentialActivity :: forall a. Double -> Simulation (Activity () a a)
newRandomExponentialActivity =
  forall a. Bool -> Double -> Simulation (Activity () a a)
newPreemptibleRandomExponentialActivity Bool
False
         
-- | Create a new activity that holds the process for a random time interval
-- having the Erlang distribution with the specified scale (the reciprocal of the rate)
-- and shape parameters, when processing every input element.
--
-- By default, it is assumed that the activity process cannot be preempted,
-- because the handling of possible task preemption is rather costly
-- operation.
newRandomErlangActivity :: Double
                           -- ^ the scale (the reciprocal of the rate)
                           -> Int
                           -- ^ the shape
                           -> Simulation (Activity () a a)
newRandomErlangActivity :: forall a. Double -> Int -> Simulation (Activity () a a)
newRandomErlangActivity =
  forall a. Bool -> Double -> Int -> Simulation (Activity () a a)
newPreemptibleRandomErlangActivity Bool
False

-- | Create a new activity that holds the process for a random time interval
-- having the Poisson distribution with the specified mean, when processing
-- every input element.
--
-- By default, it is assumed that the activity process cannot be preempted,
-- because the handling of possible task preemption is rather costly
-- operation.
newRandomPoissonActivity :: Double
                            -- ^ the mean time interval
                            -> Simulation (Activity () a a)
newRandomPoissonActivity :: forall a. Double -> Simulation (Activity () a a)
newRandomPoissonActivity =
  forall a. Bool -> Double -> Simulation (Activity () a a)
newPreemptibleRandomPoissonActivity Bool
False

-- | Create a new activity that holds the process for a random time interval
-- having the binomial distribution with the specified probability and trials,
-- when processing every input element.
--
-- By default, it is assumed that the activity process cannot be preempted,
-- because the handling of possible task preemption is rather costly
-- operation.
newRandomBinomialActivity :: Double
                             -- ^ the probability
                             -> Int
                             -- ^ the number of trials
                             -> Simulation (Activity () a a)
newRandomBinomialActivity :: forall a. Double -> Int -> Simulation (Activity () a a)
newRandomBinomialActivity =
  forall a. Bool -> Double -> Int -> Simulation (Activity () a a)
newPreemptibleRandomBinomialActivity Bool
False

-- | Create a new activity that holds the process for a random time interval
-- having the Gamma distribution with the specified shape and scale,
-- when processing every input element.
--
-- By default, it is assumed that the activity process cannot be preempted,
-- because the handling of possible task preemption is rather costly
-- operation.
newRandomGammaActivity :: Double
                          -- ^ the shape
                          -> Double
                          -- ^ the scale (a reciprocal of the rate)
                          -> Simulation (Activity () a a)
newRandomGammaActivity :: forall a. Double -> Double -> Simulation (Activity () a a)
newRandomGammaActivity =
  forall a. Bool -> Double -> Double -> Simulation (Activity () a a)
newPreemptibleRandomGammaActivity Bool
False

-- | Create a new activity that holds the process for a random time interval
-- having the Beta distribution with the specified shape parameters (alpha and beta),
-- when processing every input element.
--
-- By default, it is assumed that the activity process cannot be preempted,
-- because the handling of possible task preemption is rather costly
-- operation.
newRandomBetaActivity :: Double
                         -- ^ shape (alpha)
                         -> Double
                         -- ^ shape (beta)
                         -> Simulation (Activity () a a)
newRandomBetaActivity :: forall a. Double -> Double -> Simulation (Activity () a a)
newRandomBetaActivity =
  forall a. Bool -> Double -> Double -> Simulation (Activity () a a)
newPreemptibleRandomBetaActivity Bool
False

-- | Create a new activity that holds the process for a random time interval
-- having the Weibull distribution with the specified shape and scale,
-- when processing every input element.
--
-- By default, it is assumed that the activity process cannot be preempted,
-- because the handling of possible task preemption is rather costly
-- operation.
newRandomWeibullActivity :: Double
                            -- ^ shape
                            -> Double
                            -- ^ scale
                            -> Simulation (Activity () a a)
newRandomWeibullActivity :: forall a. Double -> Double -> Simulation (Activity () a a)
newRandomWeibullActivity =
  forall a. Bool -> Double -> Double -> Simulation (Activity () a a)
newPreemptibleRandomWeibullActivity Bool
False

-- | Create a new activity that holds the process for a random time interval
-- having the specified discrete distribution, when processing every input element.
--
-- By default, it is assumed that the activity process cannot be preempted,
-- because the handling of possible task preemption is rather costly
-- operation.
newRandomDiscreteActivity :: DiscretePDF Double
                             -- ^ the discrete probability density function
                             -> Simulation (Activity () a a)
newRandomDiscreteActivity :: forall a. DiscretePDF Double -> Simulation (Activity () a a)
newRandomDiscreteActivity =
  forall a.
Bool -> DiscretePDF Double -> Simulation (Activity () a a)
newPreemptibleRandomDiscreteActivity Bool
False

-- | Create a new activity that holds the process for a random time interval
-- distributed uniformly, when processing every input element.
newPreemptibleRandomUniformActivity :: Bool
                                       -- ^ whether the activity process can be preempted
                                       -> Double
                                       -- ^ the minimum time interval
                                       -> Double
                                       -- ^ the maximum time interval
                                       -> Simulation (Activity () a a)
newPreemptibleRandomUniformActivity :: forall a. Bool -> Double -> Double -> Simulation (Activity () a a)
newPreemptibleRandomUniformActivity Bool
preemptible Double
min Double
max =
  forall a b.
Bool -> (a -> Process b) -> Simulation (Activity () a b)
newPreemptibleActivity Bool
preemptible forall a b. (a -> b) -> a -> b
$ \a
a ->
  do Double -> Double -> Process ()
randomUniformProcess_ Double
min Double
max
     forall (m :: * -> *) a. Monad m => a -> m a
return a
a

-- | Create a new activity that holds the process for a random time interval
-- distributed uniformly, when processing every input element.
newPreemptibleRandomUniformIntActivity :: Bool
                                          -- ^ whether the activity process can be preempted
                                          -> Int
                                          -- ^ the minimum time interval
                                          -> Int
                                          -- ^ the maximum time interval
                                          -> Simulation (Activity () a a)
newPreemptibleRandomUniformIntActivity :: forall a. Bool -> Int -> Int -> Simulation (Activity () a a)
newPreemptibleRandomUniformIntActivity Bool
preemptible Int
min Int
max =
  forall a b.
Bool -> (a -> Process b) -> Simulation (Activity () a b)
newPreemptibleActivity Bool
preemptible forall a b. (a -> b) -> a -> b
$ \a
a ->
  do Int -> Int -> Process ()
randomUniformIntProcess_ Int
min Int
max
     forall (m :: * -> *) a. Monad m => a -> m a
return a
a

-- | Create a new activity that holds the process for a random time interval
-- having the triangular distribution, when processing every input element.
newPreemptibleRandomTriangularActivity :: Bool
                                          -- ^ whether the activity process can be preempted
                                          -> Double
                                          -- ^ the minimum time interval
                                          -> Double
                                          -- ^ the median of the time interval
                                          -> Double
                                          -- ^ the maximum time interval
                                          -> Simulation (Activity () a a)
newPreemptibleRandomTriangularActivity :: forall a.
Bool -> Double -> Double -> Double -> Simulation (Activity () a a)
newPreemptibleRandomTriangularActivity Bool
preemptible Double
min Double
median Double
max =
  forall a b.
Bool -> (a -> Process b) -> Simulation (Activity () a b)
newPreemptibleActivity Bool
preemptible forall a b. (a -> b) -> a -> b
$ \a
a ->
  do Double -> Double -> Double -> Process ()
randomTriangularProcess_ Double
min Double
median Double
max
     forall (m :: * -> *) a. Monad m => a -> m a
return a
a

-- | Create a new activity that holds the process for a random time interval
-- distributed normally, when processing every input element.
newPreemptibleRandomNormalActivity :: Bool
                                      -- ^ whether the activity process can be preempted
                                      -> Double
                                      -- ^ the mean time interval
                                      -> Double
                                      -- ^ the time interval deviation
                                      -> Simulation (Activity () a a)
newPreemptibleRandomNormalActivity :: forall a. Bool -> Double -> Double -> Simulation (Activity () a a)
newPreemptibleRandomNormalActivity Bool
preemptible Double
mu Double
nu =
  forall a b.
Bool -> (a -> Process b) -> Simulation (Activity () a b)
newPreemptibleActivity Bool
preemptible forall a b. (a -> b) -> a -> b
$ \a
a ->
  do Double -> Double -> Process ()
randomNormalProcess_ Double
mu Double
nu
     forall (m :: * -> *) a. Monad m => a -> m a
return a
a

-- | Create a new activity that holds the process for a random time interval
-- having the lognormal distribution, when processing every input element.
newPreemptibleRandomLogNormalActivity :: Bool
                                         -- ^ whether the activity process can be preempted
                                         -> Double
                                         -- ^ the mean of a normal distribution which
                                         -- this distribution is derived from
                                         -> Double
                                         -- ^ the deviation of a normal distribution which
                                         -- this distribution is derived from
                                         -> Simulation (Activity () a a)
newPreemptibleRandomLogNormalActivity :: forall a. Bool -> Double -> Double -> Simulation (Activity () a a)
newPreemptibleRandomLogNormalActivity Bool
preemptible Double
mu Double
nu =
  forall a b.
Bool -> (a -> Process b) -> Simulation (Activity () a b)
newPreemptibleActivity Bool
preemptible forall a b. (a -> b) -> a -> b
$ \a
a ->
  do Double -> Double -> Process ()
randomLogNormalProcess_ Double
mu Double
nu
     forall (m :: * -> *) a. Monad m => a -> m a
return a
a

-- | Create a new activity that holds the process for a random time interval
-- distributed exponentially with the specified mean (the reciprocal of the rate),
-- when processing every input element.
newPreemptibleRandomExponentialActivity :: Bool
                                           -- ^ whether the activity process can be preempted
                                           -> Double
                                           -- ^ the mean time interval (the reciprocal of the rate)
                                           -> Simulation (Activity () a a)
newPreemptibleRandomExponentialActivity :: forall a. Bool -> Double -> Simulation (Activity () a a)
newPreemptibleRandomExponentialActivity Bool
preemptible Double
mu =
  forall a b.
Bool -> (a -> Process b) -> Simulation (Activity () a b)
newPreemptibleActivity Bool
preemptible forall a b. (a -> b) -> a -> b
$ \a
a ->
  do Double -> Process ()
randomExponentialProcess_ Double
mu
     forall (m :: * -> *) a. Monad m => a -> m a
return a
a
         
-- | Create a new activity that holds the process for a random time interval
-- having the Erlang distribution with the specified scale (the reciprocal of the rate)
-- and shape parameters, when processing every input element.
newPreemptibleRandomErlangActivity :: Bool
                                      -- ^ whether the activity process can be preempted
                                      -> Double
                                      -- ^ the scale (the reciprocal of the rate)
                                      -> Int
                                      -- ^ the shape
                                      -> Simulation (Activity () a a)
newPreemptibleRandomErlangActivity :: forall a. Bool -> Double -> Int -> Simulation (Activity () a a)
newPreemptibleRandomErlangActivity Bool
preemptible Double
beta Int
m =
  forall a b.
Bool -> (a -> Process b) -> Simulation (Activity () a b)
newPreemptibleActivity Bool
preemptible forall a b. (a -> b) -> a -> b
$ \a
a ->
  do Double -> Int -> Process ()
randomErlangProcess_ Double
beta Int
m
     forall (m :: * -> *) a. Monad m => a -> m a
return a
a

-- | Create a new activity that holds the process for a random time interval
-- having the Poisson distribution with the specified mean, when processing
-- every input element.
newPreemptibleRandomPoissonActivity :: Bool
                                       -- ^ whether the activity process can be preempted
                                       -> Double
                                       -- ^ the mean time interval
                                       -> Simulation (Activity () a a)
newPreemptibleRandomPoissonActivity :: forall a. Bool -> Double -> Simulation (Activity () a a)
newPreemptibleRandomPoissonActivity Bool
preemptible Double
mu =
  forall a b.
Bool -> (a -> Process b) -> Simulation (Activity () a b)
newPreemptibleActivity Bool
preemptible forall a b. (a -> b) -> a -> b
$ \a
a ->
  do Double -> Process ()
randomPoissonProcess_ Double
mu
     forall (m :: * -> *) a. Monad m => a -> m a
return a
a

-- | Create a new activity that holds the process for a random time interval
-- having the binomial distribution with the specified probability and trials,
-- when processing every input element.
newPreemptibleRandomBinomialActivity :: Bool
                                        -- ^ whether the activity process can be preempted
                                        -> Double
                                        -- ^ the probability
                                        -> Int
                                        -- ^ the number of trials
                                        -> Simulation (Activity () a a)
newPreemptibleRandomBinomialActivity :: forall a. Bool -> Double -> Int -> Simulation (Activity () a a)
newPreemptibleRandomBinomialActivity Bool
preemptible Double
prob Int
trials =
  forall a b.
Bool -> (a -> Process b) -> Simulation (Activity () a b)
newPreemptibleActivity Bool
preemptible forall a b. (a -> b) -> a -> b
$ \a
a ->
  do Double -> Int -> Process ()
randomBinomialProcess_ Double
prob Int
trials
     forall (m :: * -> *) a. Monad m => a -> m a
return a
a

-- | Create a new activity that holds the process for a random time interval
-- having the Gamma distribution with the specified shape and scale,
-- when processing every input element.
newPreemptibleRandomGammaActivity :: Bool
                                     -- ^ whether the activity process can be preempted
                                     -> Double
                                     -- ^ the shape
                                     -> Double
                                     -- ^ the scale
                                     -> Simulation (Activity () a a)
newPreemptibleRandomGammaActivity :: forall a. Bool -> Double -> Double -> Simulation (Activity () a a)
newPreemptibleRandomGammaActivity Bool
preemptible Double
kappa Double
theta =
  forall a b.
Bool -> (a -> Process b) -> Simulation (Activity () a b)
newPreemptibleActivity Bool
preemptible forall a b. (a -> b) -> a -> b
$ \a
a ->
  do Double -> Double -> Process ()
randomGammaProcess_ Double
kappa Double
theta
     forall (m :: * -> *) a. Monad m => a -> m a
return a
a

-- | Create a new activity that holds the process for a random time interval
-- having the Beta distribution with the specified shape parameters (alpha and beta),
-- when processing every input element.
newPreemptibleRandomBetaActivity :: Bool
                                    -- ^ whether the activity process can be preempted
                                    -> Double
                                    -- ^ shape (alpha)
                                    -> Double
                                    -- ^ shape (beta)
                                    -> Simulation (Activity () a a)
newPreemptibleRandomBetaActivity :: forall a. Bool -> Double -> Double -> Simulation (Activity () a a)
newPreemptibleRandomBetaActivity Bool
preemptible Double
alpha Double
beta =
  forall a b.
Bool -> (a -> Process b) -> Simulation (Activity () a b)
newPreemptibleActivity Bool
preemptible forall a b. (a -> b) -> a -> b
$ \a
a ->
  do Double -> Double -> Process ()
randomBetaProcess_ Double
alpha Double
beta
     forall (m :: * -> *) a. Monad m => a -> m a
return a
a

-- | Create a new activity that holds the process for a random time interval
-- having the Weibull distribution with the specified shape and scale,
-- when processing every input element.
newPreemptibleRandomWeibullActivity :: Bool
                                       -- ^ whether the activity process can be preempted
                                       -> Double
                                       -- ^ shape
                                       -> Double
                                       -- ^ scale
                                       -> Simulation (Activity () a a)
newPreemptibleRandomWeibullActivity :: forall a. Bool -> Double -> Double -> Simulation (Activity () a a)
newPreemptibleRandomWeibullActivity Bool
preemptible Double
alpha Double
beta =
  forall a b.
Bool -> (a -> Process b) -> Simulation (Activity () a b)
newPreemptibleActivity Bool
preemptible forall a b. (a -> b) -> a -> b
$ \a
a ->
  do Double -> Double -> Process ()
randomWeibullProcess_ Double
alpha Double
beta
     forall (m :: * -> *) a. Monad m => a -> m a
return a
a

-- | Create a new activity that holds the process for a random time interval
-- having the specified discrete distribution, when processing every input element.
newPreemptibleRandomDiscreteActivity :: Bool
                                        -- ^ whether the activity process can be preempted
                                        -> DiscretePDF Double
                                        -- ^ the discrete probability density function
                                        -> Simulation (Activity () a a)
newPreemptibleRandomDiscreteActivity :: forall a.
Bool -> DiscretePDF Double -> Simulation (Activity () a a)
newPreemptibleRandomDiscreteActivity Bool
preemptible DiscretePDF Double
dpdf =
  forall a b.
Bool -> (a -> Process b) -> Simulation (Activity () a b)
newPreemptibleActivity Bool
preemptible forall a b. (a -> b) -> a -> b
$ \a
a ->
  do DiscretePDF Double -> Process ()
randomDiscreteProcess_ DiscretePDF Double
dpdf
     forall (m :: * -> *) a. Monad m => a -> m a
return a
a