-- |
-- Module     : Simulation.Aivika.Trans.Operation.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 operations that
-- hold the current process for the corresponding random time
-- interval, when processing every input element.
--

module Simulation.Aivika.Trans.Operation.Random
       (newRandomUniformOperation,
        newRandomUniformIntOperation,
        newRandomTriangularOperation,
        newRandomNormalOperation,
        newRandomLogNormalOperation,
        newRandomExponentialOperation,
        newRandomErlangOperation,
        newRandomPoissonOperation,
        newRandomBinomialOperation,
        newRandomGammaOperation,
        newRandomBetaOperation,
        newRandomWeibullOperation,
        newRandomDiscreteOperation,
        newPreemptibleRandomUniformOperation,
        newPreemptibleRandomUniformIntOperation,
        newPreemptibleRandomTriangularOperation,
        newPreemptibleRandomNormalOperation,
        newPreemptibleRandomLogNormalOperation,
        newPreemptibleRandomExponentialOperation,
        newPreemptibleRandomErlangOperation,
        newPreemptibleRandomPoissonOperation,
        newPreemptibleRandomBinomialOperation,
        newPreemptibleRandomGammaOperation,
        newPreemptibleRandomBetaOperation,
        newPreemptibleRandomWeibullOperation,
        newPreemptibleRandomDiscreteOperation) where

import Simulation.Aivika.Trans.DES
import Simulation.Aivika.Trans.Generator
import Simulation.Aivika.Trans.Event
import Simulation.Aivika.Trans.Process
import Simulation.Aivika.Trans.Process.Random
import Simulation.Aivika.Trans.Operation

-- | Create a new operation that holds the process for a random time interval
-- distributed uniformly, when processing every input element.
--
-- By default, it is assumed that the operation process cannot be preempted,
-- because the handling of possible task preemption is rather costly.
newRandomUniformOperation :: MonadDES m
                             => Double
                             -- ^ the minimum time interval
                             -> Double
                             -- ^ the maximum time interval
                             -> Event m (Operation m a a)
{-# INLINABLE newRandomUniformOperation #-}
newRandomUniformOperation :: forall (m :: * -> *) a.
MonadDES m =>
Double -> Double -> Event m (Operation m a a)
newRandomUniformOperation =
  Bool -> Double -> Double -> Event m (Operation m a a)
forall (m :: * -> *) a.
MonadDES m =>
Bool -> Double -> Double -> Event m (Operation m a a)
newPreemptibleRandomUniformOperation Bool
False

-- | Create a new operation that holds the process for a random time interval
-- distributed uniformly, when processing every input element.
--
-- By default, it is assumed that the operation process cannot be preempted,
-- because the handling of possible task preemption is rather costly.
newRandomUniformIntOperation :: MonadDES m
                                => Int
                                -- ^ the minimum time interval
                                -> Int
                                -- ^ the maximum time interval
                                -> Event m (Operation m a a)
{-# INLINABLE newRandomUniformIntOperation #-}
newRandomUniformIntOperation :: forall (m :: * -> *) a.
MonadDES m =>
Int -> Int -> Event m (Operation m a a)
newRandomUniformIntOperation =
  Bool -> Int -> Int -> Event m (Operation m a a)
forall (m :: * -> *) a.
MonadDES m =>
Bool -> Int -> Int -> Event m (Operation m a a)
newPreemptibleRandomUniformIntOperation Bool
False

-- | Create a new operation 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 operation process cannot be preempted,
-- because the handling of possible task preemption is rather costly.
newRandomTriangularOperation :: MonadDES m
                                => Double
                                -- ^ the minimum time interval
                                -> Double
                                -- ^ the median of the time interval
                                -> Double
                                -- ^ the maximum time interval
                                -> Event m (Operation m a a)
{-# INLINABLE newRandomTriangularOperation #-}
newRandomTriangularOperation :: forall (m :: * -> *) a.
MonadDES m =>
Double -> Double -> Double -> Event m (Operation m a a)
newRandomTriangularOperation =
  Bool -> Double -> Double -> Double -> Event m (Operation m a a)
forall (m :: * -> *) a.
MonadDES m =>
Bool -> Double -> Double -> Double -> Event m (Operation m a a)
newPreemptibleRandomTriangularOperation Bool
False

-- | Create a new operation that holds the process for a random time interval
-- distributed normally, when processing every input element.
--
-- By default, it is assumed that the operation process cannot be preempted,
-- because the handling of possible task preemption is rather costly.
newRandomNormalOperation :: MonadDES m
                            => Double
                            -- ^ the mean time interval
                            -> Double
                            -- ^ the time interval deviation
                            -> Event m (Operation m a a)
{-# INLINABLE newRandomNormalOperation #-}
newRandomNormalOperation :: forall (m :: * -> *) a.
MonadDES m =>
Double -> Double -> Event m (Operation m a a)
newRandomNormalOperation =
  Bool -> Double -> Double -> Event m (Operation m a a)
forall (m :: * -> *) a.
MonadDES m =>
Bool -> Double -> Double -> Event m (Operation m a a)
newPreemptibleRandomNormalOperation Bool
False
         
-- | Create a new operation 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 operation process cannot be preempted,
-- because the handling of possible task preemption is rather costly.
newRandomLogNormalOperation :: MonadDES m
                               => 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
                               -> Event m (Operation m a a)
{-# INLINABLE newRandomLogNormalOperation #-}
newRandomLogNormalOperation :: forall (m :: * -> *) a.
MonadDES m =>
Double -> Double -> Event m (Operation m a a)
newRandomLogNormalOperation =
  Bool -> Double -> Double -> Event m (Operation m a a)
forall (m :: * -> *) a.
MonadDES m =>
Bool -> Double -> Double -> Event m (Operation m a a)
newPreemptibleRandomLogNormalOperation Bool
False
         
-- | Create a new operation 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 operation process cannot be preempted,
-- because the handling of possible task preemption is rather costly.
newRandomExponentialOperation :: MonadDES m
                                 => Double
                                 -- ^ the mean time interval (the reciprocal of the rate)
                                 -> Event m (Operation m a a)
{-# INLINABLE newRandomExponentialOperation #-}
newRandomExponentialOperation :: forall (m :: * -> *) a.
MonadDES m =>
Double -> Event m (Operation m a a)
newRandomExponentialOperation =
  Bool -> Double -> Event m (Operation m a a)
forall (m :: * -> *) a.
MonadDES m =>
Bool -> Double -> Event m (Operation m a a)
newPreemptibleRandomExponentialOperation Bool
False
         
-- | Create a new operation 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 operation process cannot be preempted,
-- because the handling of possible task preemption is rather costly.
newRandomErlangOperation :: MonadDES m
                            => Double
                            -- ^ the scale (the reciprocal of the rate)
                            -> Int
                            -- ^ the shape
                            -> Event m (Operation m a a)
{-# INLINABLE newRandomErlangOperation #-}
newRandomErlangOperation :: forall (m :: * -> *) a.
MonadDES m =>
Double -> Int -> Event m (Operation m a a)
newRandomErlangOperation =
  Bool -> Double -> Int -> Event m (Operation m a a)
forall (m :: * -> *) a.
MonadDES m =>
Bool -> Double -> Int -> Event m (Operation m a a)
newPreemptibleRandomErlangOperation Bool
False

-- | Create a new operation 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 operation process cannot be preempted,
-- because the handling of possible task preemption is rather costly.
newRandomPoissonOperation :: MonadDES m
                             => Double
                             -- ^ the mean time interval
                             -> Event m (Operation m a a)
{-# INLINABLE newRandomPoissonOperation #-}
newRandomPoissonOperation :: forall (m :: * -> *) a.
MonadDES m =>
Double -> Event m (Operation m a a)
newRandomPoissonOperation =
  Bool -> Double -> Event m (Operation m a a)
forall (m :: * -> *) a.
MonadDES m =>
Bool -> Double -> Event m (Operation m a a)
newPreemptibleRandomPoissonOperation Bool
False

-- | Create a new operation 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 operation process cannot be preempted,
-- because the handling of possible task preemption is rather costly.
newRandomBinomialOperation :: MonadDES m
                              => Double
                              -- ^ the probability
                              -> Int
                              -- ^ the number of trials
                              -> Event m (Operation m a a)
{-# INLINABLE newRandomBinomialOperation #-}
newRandomBinomialOperation :: forall (m :: * -> *) a.
MonadDES m =>
Double -> Int -> Event m (Operation m a a)
newRandomBinomialOperation =
  Bool -> Double -> Int -> Event m (Operation m a a)
forall (m :: * -> *) a.
MonadDES m =>
Bool -> Double -> Int -> Event m (Operation m a a)
newPreemptibleRandomBinomialOperation Bool
False

-- | Create a new operation 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 operation process cannot be preempted,
-- because the handling of possible task preemption is rather costly.
newRandomGammaOperation :: MonadDES m
                           => Double
                           -- ^ the shape
                           -> Double
                           -- ^ the scale (a reciprocal of the rate)
                           -> Event m (Operation m a a)
{-# INLINABLE newRandomGammaOperation #-}
newRandomGammaOperation :: forall (m :: * -> *) a.
MonadDES m =>
Double -> Double -> Event m (Operation m a a)
newRandomGammaOperation =
  Bool -> Double -> Double -> Event m (Operation m a a)
forall (m :: * -> *) a.
MonadDES m =>
Bool -> Double -> Double -> Event m (Operation m a a)
newPreemptibleRandomGammaOperation Bool
False

-- | Create a new operation 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 operation process cannot be preempted,
-- because the handling of possible task preemption is rather costly.
newRandomBetaOperation :: MonadDES m
                          => Double
                          -- ^ shape (alpha)
                          -> Double
                          -- ^ shape (beta)
                          -> Event m (Operation m a a)
{-# INLINABLE newRandomBetaOperation #-}
newRandomBetaOperation :: forall (m :: * -> *) a.
MonadDES m =>
Double -> Double -> Event m (Operation m a a)
newRandomBetaOperation =
  Bool -> Double -> Double -> Event m (Operation m a a)
forall (m :: * -> *) a.
MonadDES m =>
Bool -> Double -> Double -> Event m (Operation m a a)
newPreemptibleRandomBetaOperation Bool
False

-- | Create a new operation 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 operation process cannot be preempted,
-- because the handling of possible task preemption is rather costly.
newRandomWeibullOperation :: MonadDES m
                             => Double
                             -- ^ shape
                             -> Double
                             -- ^ scale
                             -> Event m (Operation m a a)
{-# INLINABLE newRandomWeibullOperation #-}
newRandomWeibullOperation :: forall (m :: * -> *) a.
MonadDES m =>
Double -> Double -> Event m (Operation m a a)
newRandomWeibullOperation =
  Bool -> Double -> Double -> Event m (Operation m a a)
forall (m :: * -> *) a.
MonadDES m =>
Bool -> Double -> Double -> Event m (Operation m a a)
newPreemptibleRandomWeibullOperation Bool
False

-- | Create a new operation 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 operation process cannot be preempted,
-- because the handling of possible task preemption is rather costly.
newRandomDiscreteOperation :: MonadDES m
                              => DiscretePDF Double
                              -- ^ the discrete probability density function
                              -> Event m (Operation m a a)
{-# INLINABLE newRandomDiscreteOperation #-}
newRandomDiscreteOperation :: forall (m :: * -> *) a.
MonadDES m =>
DiscretePDF Double -> Event m (Operation m a a)
newRandomDiscreteOperation =
  Bool -> DiscretePDF Double -> Event m (Operation m a a)
forall (m :: * -> *) a.
MonadDES m =>
Bool -> DiscretePDF Double -> Event m (Operation m a a)
newPreemptibleRandomDiscreteOperation Bool
False

-- | Create a new operation that holds the process for a random time interval
-- distributed uniformly, when processing every input element.
newPreemptibleRandomUniformOperation :: MonadDES m
                                        => Bool
                                        -- ^ whether the operation process can be preempted
                                        -> Double
                                        -- ^ the minimum time interval
                                        -> Double
                                        -- ^ the maximum time interval
                                        -> Event m (Operation m a a)
{-# INLINABLE newPreemptibleRandomUniformOperation #-}
newPreemptibleRandomUniformOperation :: forall (m :: * -> *) a.
MonadDES m =>
Bool -> Double -> Double -> Event m (Operation m a a)
newPreemptibleRandomUniformOperation Bool
preemptible Double
min Double
max =
  Bool -> (a -> Process m a) -> Event m (Operation m a a)
forall (m :: * -> *) a b.
MonadDES m =>
Bool -> (a -> Process m b) -> Event m (Operation m a b)
newPreemptibleOperation Bool
preemptible ((a -> Process m a) -> Event m (Operation m a a))
-> (a -> Process m a) -> Event m (Operation m a a)
forall a b. (a -> b) -> a -> b
$ \a
a ->
  do Double -> Double -> Process m ()
forall (m :: * -> *).
MonadDES m =>
Double -> Double -> Process m ()
randomUniformProcess_ Double
min Double
max
     a -> Process m a
forall a. a -> Process m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
a

-- | Create a new operation that holds the process for a random time interval
-- distributed uniformly, when processing every input element.
newPreemptibleRandomUniformIntOperation :: MonadDES m
                                           => Bool
                                           -- ^ whether the operation process can be preempted
                                           -> Int
                                           -- ^ the minimum time interval
                                           -> Int
                                           -- ^ the maximum time interval
                                           -> Event m (Operation m a a)
{-# INLINABLE newPreemptibleRandomUniformIntOperation #-}
newPreemptibleRandomUniformIntOperation :: forall (m :: * -> *) a.
MonadDES m =>
Bool -> Int -> Int -> Event m (Operation m a a)
newPreemptibleRandomUniformIntOperation Bool
preemptible Int
min Int
max =
  Bool -> (a -> Process m a) -> Event m (Operation m a a)
forall (m :: * -> *) a b.
MonadDES m =>
Bool -> (a -> Process m b) -> Event m (Operation m a b)
newPreemptibleOperation Bool
preemptible ((a -> Process m a) -> Event m (Operation m a a))
-> (a -> Process m a) -> Event m (Operation m a a)
forall a b. (a -> b) -> a -> b
$ \a
a ->
  do Int -> Int -> Process m ()
forall (m :: * -> *). MonadDES m => Int -> Int -> Process m ()
randomUniformIntProcess_ Int
min Int
max
     a -> Process m a
forall a. a -> Process m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
a

-- | Create a new operation that holds the process for a random time interval
-- having the triangular distribution, when processing every input element.
newPreemptibleRandomTriangularOperation :: MonadDES m
                                           => Bool
                                           -- ^ whether the operation process can be preempted
                                           -> Double
                                           -- ^ the minimum time interval
                                           -> Double
                                           -- ^ the median of the time interval
                                           -> Double
                                           -- ^ the maximum time interval
                                           -> Event m (Operation m a a)
{-# INLINABLE newPreemptibleRandomTriangularOperation #-}
newPreemptibleRandomTriangularOperation :: forall (m :: * -> *) a.
MonadDES m =>
Bool -> Double -> Double -> Double -> Event m (Operation m a a)
newPreemptibleRandomTriangularOperation Bool
preemptible Double
min Double
median Double
max =
  Bool -> (a -> Process m a) -> Event m (Operation m a a)
forall (m :: * -> *) a b.
MonadDES m =>
Bool -> (a -> Process m b) -> Event m (Operation m a b)
newPreemptibleOperation Bool
preemptible ((a -> Process m a) -> Event m (Operation m a a))
-> (a -> Process m a) -> Event m (Operation m a a)
forall a b. (a -> b) -> a -> b
$ \a
a ->
  do Double -> Double -> Double -> Process m ()
forall (m :: * -> *).
MonadDES m =>
Double -> Double -> Double -> Process m ()
randomTriangularProcess_ Double
min Double
median Double
max
     a -> Process m a
forall a. a -> Process m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
a

-- | Create a new operation that holds the process for a random time interval
-- distributed normally, when processing every input element.
newPreemptibleRandomNormalOperation :: MonadDES m
                                       => Bool
                                       -- ^ whether the operation process can be preempted
                                       -> Double
                                       -- ^ the mean time interval
                                       -> Double
                                       -- ^ the time interval deviation
                                       -> Event m (Operation m a a)
{-# INLINABLE newPreemptibleRandomNormalOperation #-}
newPreemptibleRandomNormalOperation :: forall (m :: * -> *) a.
MonadDES m =>
Bool -> Double -> Double -> Event m (Operation m a a)
newPreemptibleRandomNormalOperation Bool
preemptible Double
mu Double
nu =
  Bool -> (a -> Process m a) -> Event m (Operation m a a)
forall (m :: * -> *) a b.
MonadDES m =>
Bool -> (a -> Process m b) -> Event m (Operation m a b)
newPreemptibleOperation Bool
preemptible ((a -> Process m a) -> Event m (Operation m a a))
-> (a -> Process m a) -> Event m (Operation m a a)
forall a b. (a -> b) -> a -> b
$ \a
a ->
  do Double -> Double -> Process m ()
forall (m :: * -> *).
MonadDES m =>
Double -> Double -> Process m ()
randomNormalProcess_ Double
mu Double
nu
     a -> Process m a
forall a. a -> Process m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
a

-- | Create a new operation that holds the process for a random time interval
-- having the lognormal distribution, when processing every input element.
newPreemptibleRandomLogNormalOperation :: MonadDES m
                                          => Bool
                                          -- ^ whether the operation 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
                                          -> Event m (Operation m a a)
{-# INLINABLE newPreemptibleRandomLogNormalOperation #-}
newPreemptibleRandomLogNormalOperation :: forall (m :: * -> *) a.
MonadDES m =>
Bool -> Double -> Double -> Event m (Operation m a a)
newPreemptibleRandomLogNormalOperation Bool
preemptible Double
mu Double
nu =
  Bool -> (a -> Process m a) -> Event m (Operation m a a)
forall (m :: * -> *) a b.
MonadDES m =>
Bool -> (a -> Process m b) -> Event m (Operation m a b)
newPreemptibleOperation Bool
preemptible ((a -> Process m a) -> Event m (Operation m a a))
-> (a -> Process m a) -> Event m (Operation m a a)
forall a b. (a -> b) -> a -> b
$ \a
a ->
  do Double -> Double -> Process m ()
forall (m :: * -> *).
MonadDES m =>
Double -> Double -> Process m ()
randomLogNormalProcess_ Double
mu Double
nu
     a -> Process m a
forall a. a -> Process m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
a

-- | Create a new operation 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.
newPreemptibleRandomExponentialOperation :: MonadDES m
                                            => Bool
                                            -- ^ whether the operation process can be preempted
                                            -> Double
                                            -- ^ the mean time interval (the reciprocal of the rate)
                                            -> Event m (Operation m a a)
{-# INLINABLE newPreemptibleRandomExponentialOperation #-}
newPreemptibleRandomExponentialOperation :: forall (m :: * -> *) a.
MonadDES m =>
Bool -> Double -> Event m (Operation m a a)
newPreemptibleRandomExponentialOperation Bool
preemptible Double
mu =
  Bool -> (a -> Process m a) -> Event m (Operation m a a)
forall (m :: * -> *) a b.
MonadDES m =>
Bool -> (a -> Process m b) -> Event m (Operation m a b)
newPreemptibleOperation Bool
preemptible ((a -> Process m a) -> Event m (Operation m a a))
-> (a -> Process m a) -> Event m (Operation m a a)
forall a b. (a -> b) -> a -> b
$ \a
a ->
  do Double -> Process m ()
forall (m :: * -> *). MonadDES m => Double -> Process m ()
randomExponentialProcess_ Double
mu
     a -> Process m a
forall a. a -> Process m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
a
         
-- | Create a new operation 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.
newPreemptibleRandomErlangOperation :: MonadDES m
                                       => Bool
                                       -- ^ whether the operation process can be preempted
                                       -> Double
                                       -- ^ the scale (the reciprocal of the rate)
                                       -> Int
                                       -- ^ the shape
                                       -> Event m (Operation m a a)
{-# INLINABLE newPreemptibleRandomErlangOperation #-}
newPreemptibleRandomErlangOperation :: forall (m :: * -> *) a.
MonadDES m =>
Bool -> Double -> Int -> Event m (Operation m a a)
newPreemptibleRandomErlangOperation Bool
preemptible Double
beta Int
m =
  Bool -> (a -> Process m a) -> Event m (Operation m a a)
forall (m :: * -> *) a b.
MonadDES m =>
Bool -> (a -> Process m b) -> Event m (Operation m a b)
newPreemptibleOperation Bool
preemptible ((a -> Process m a) -> Event m (Operation m a a))
-> (a -> Process m a) -> Event m (Operation m a a)
forall a b. (a -> b) -> a -> b
$ \a
a ->
  do Double -> Int -> Process m ()
forall (m :: * -> *). MonadDES m => Double -> Int -> Process m ()
randomErlangProcess_ Double
beta Int
m
     a -> Process m a
forall a. a -> Process m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
a

-- | Create a new operation that holds the process for a random time interval
-- having the Poisson distribution with the specified mean, when processing
-- every input element.
newPreemptibleRandomPoissonOperation :: MonadDES m
                                        => Bool
                                        -- ^ whether the operation process can be preempted
                                        -> Double
                                        -- ^ the mean time interval
                                        -> Event m (Operation m a a)
{-# INLINABLE newPreemptibleRandomPoissonOperation #-}
newPreemptibleRandomPoissonOperation :: forall (m :: * -> *) a.
MonadDES m =>
Bool -> Double -> Event m (Operation m a a)
newPreemptibleRandomPoissonOperation Bool
preemptible Double
mu =
  Bool -> (a -> Process m a) -> Event m (Operation m a a)
forall (m :: * -> *) a b.
MonadDES m =>
Bool -> (a -> Process m b) -> Event m (Operation m a b)
newPreemptibleOperation Bool
preemptible ((a -> Process m a) -> Event m (Operation m a a))
-> (a -> Process m a) -> Event m (Operation m a a)
forall a b. (a -> b) -> a -> b
$ \a
a ->
  do Double -> Process m ()
forall (m :: * -> *). MonadDES m => Double -> Process m ()
randomPoissonProcess_ Double
mu
     a -> Process m a
forall a. a -> Process m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
a

-- | Create a new operation that holds the process for a random time interval
-- having the binomial distribution with the specified probability and trials,
-- when processing every input element.
newPreemptibleRandomBinomialOperation :: MonadDES m
                                         => Bool
                                         -- ^ whether the operation process can be preempted
                                         -> Double
                                         -- ^ the probability
                                         -> Int
                                         -- ^ the number of trials
                                         -> Event m (Operation m a a)
{-# INLINABLE newPreemptibleRandomBinomialOperation #-}
newPreemptibleRandomBinomialOperation :: forall (m :: * -> *) a.
MonadDES m =>
Bool -> Double -> Int -> Event m (Operation m a a)
newPreemptibleRandomBinomialOperation Bool
preemptible Double
prob Int
trials =
  Bool -> (a -> Process m a) -> Event m (Operation m a a)
forall (m :: * -> *) a b.
MonadDES m =>
Bool -> (a -> Process m b) -> Event m (Operation m a b)
newPreemptibleOperation Bool
preemptible ((a -> Process m a) -> Event m (Operation m a a))
-> (a -> Process m a) -> Event m (Operation m a a)
forall a b. (a -> b) -> a -> b
$ \a
a ->
  do Double -> Int -> Process m ()
forall (m :: * -> *). MonadDES m => Double -> Int -> Process m ()
randomBinomialProcess_ Double
prob Int
trials
     a -> Process m a
forall a. a -> Process m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
a

-- | Create a new operation that holds the process for a random time interval
-- having the Gamma distribution with the specified shape and scale,
-- when processing every input element.
newPreemptibleRandomGammaOperation :: MonadDES m
                                      => Bool
                                      -- ^ whether the operation process can be preempted
                                      -> Double
                                      -- ^ the shape
                                      -> Double
                                      -- ^ the scale
                                      -> Event m (Operation m a a)
{-# INLINABLE newPreemptibleRandomGammaOperation #-}
newPreemptibleRandomGammaOperation :: forall (m :: * -> *) a.
MonadDES m =>
Bool -> Double -> Double -> Event m (Operation m a a)
newPreemptibleRandomGammaOperation Bool
preemptible Double
kappa Double
theta =
  Bool -> (a -> Process m a) -> Event m (Operation m a a)
forall (m :: * -> *) a b.
MonadDES m =>
Bool -> (a -> Process m b) -> Event m (Operation m a b)
newPreemptibleOperation Bool
preemptible ((a -> Process m a) -> Event m (Operation m a a))
-> (a -> Process m a) -> Event m (Operation m a a)
forall a b. (a -> b) -> a -> b
$ \a
a ->
  do Double -> Double -> Process m ()
forall (m :: * -> *).
MonadDES m =>
Double -> Double -> Process m ()
randomGammaProcess_ Double
kappa Double
theta
     a -> Process m a
forall a. a -> Process m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
a

-- | Create a new operation 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.
newPreemptibleRandomBetaOperation :: MonadDES m
                                     => Bool
                                     -- ^ whether the operation process can be preempted
                                     -> Double
                                     -- ^ shape (alpha)
                                     -> Double
                                     -- ^ shape (beta)
                                     -> Event m (Operation m a a)
{-# INLINABLE newPreemptibleRandomBetaOperation #-}
newPreemptibleRandomBetaOperation :: forall (m :: * -> *) a.
MonadDES m =>
Bool -> Double -> Double -> Event m (Operation m a a)
newPreemptibleRandomBetaOperation Bool
preemptible Double
alpha Double
beta =
  Bool -> (a -> Process m a) -> Event m (Operation m a a)
forall (m :: * -> *) a b.
MonadDES m =>
Bool -> (a -> Process m b) -> Event m (Operation m a b)
newPreemptibleOperation Bool
preemptible ((a -> Process m a) -> Event m (Operation m a a))
-> (a -> Process m a) -> Event m (Operation m a a)
forall a b. (a -> b) -> a -> b
$ \a
a ->
  do Double -> Double -> Process m ()
forall (m :: * -> *).
MonadDES m =>
Double -> Double -> Process m ()
randomBetaProcess_ Double
alpha Double
beta
     a -> Process m a
forall a. a -> Process m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
a

-- | Create a new operation that holds the process for a random time interval
-- having the Weibull distribution with the specified shape and scale,
-- when processing every input element.
newPreemptibleRandomWeibullOperation :: MonadDES m
                                        => Bool
                                        -- ^ whether the operation process can be preempted
                                        -> Double
                                        -- ^ shape
                                        -> Double
                                        -- ^ scale
                                        -> Event m (Operation m a a)
{-# INLINABLE newPreemptibleRandomWeibullOperation #-}
newPreemptibleRandomWeibullOperation :: forall (m :: * -> *) a.
MonadDES m =>
Bool -> Double -> Double -> Event m (Operation m a a)
newPreemptibleRandomWeibullOperation Bool
preemptible Double
alpha Double
beta =
  Bool -> (a -> Process m a) -> Event m (Operation m a a)
forall (m :: * -> *) a b.
MonadDES m =>
Bool -> (a -> Process m b) -> Event m (Operation m a b)
newPreemptibleOperation Bool
preemptible ((a -> Process m a) -> Event m (Operation m a a))
-> (a -> Process m a) -> Event m (Operation m a a)
forall a b. (a -> b) -> a -> b
$ \a
a ->
  do Double -> Double -> Process m ()
forall (m :: * -> *).
MonadDES m =>
Double -> Double -> Process m ()
randomWeibullProcess_ Double
alpha Double
beta
     a -> Process m a
forall a. a -> Process m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
a

-- | Create a new operation that holds the process for a random time interval
-- having the specified discrete distribution, when processing every input element.
newPreemptibleRandomDiscreteOperation :: MonadDES m
                                         => Bool
                                         -- ^ whether the operation process can be preempted
                                         -> DiscretePDF Double
                                         -- ^ the discrete probability density function
                                         -> Event m (Operation m a a)
{-# INLINABLE newPreemptibleRandomDiscreteOperation #-}
newPreemptibleRandomDiscreteOperation :: forall (m :: * -> *) a.
MonadDES m =>
Bool -> DiscretePDF Double -> Event m (Operation m a a)
newPreemptibleRandomDiscreteOperation Bool
preemptible DiscretePDF Double
dpdf =
  Bool -> (a -> Process m a) -> Event m (Operation m a a)
forall (m :: * -> *) a b.
MonadDES m =>
Bool -> (a -> Process m b) -> Event m (Operation m a b)
newPreemptibleOperation Bool
preemptible ((a -> Process m a) -> Event m (Operation m a a))
-> (a -> Process m a) -> Event m (Operation m a a)
forall a b. (a -> b) -> a -> b
$ \a
a ->
  do DiscretePDF Double -> Process m ()
forall (m :: * -> *).
MonadDES m =>
DiscretePDF Double -> Process m ()
randomDiscreteProcess_ DiscretePDF Double
dpdf
     a -> Process m a
forall a. a -> Process m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
a