
-- |
-- Module     : Simulation.Aivika.Process.Random
  Copyright   : Copyright ( c ) 2009 - 2017 ,   <  >
-- License    : BSD3
  Maintainer :   <  >
-- Stability  : experimental
  Tested with : GHC 8.0.1
--
-- This module defines helper functions, which are useful to hold 
-- the 'Process' computation for a time interval according to some
-- random distribution.
--

module Simulation.Aivika.Process.Random
       (randomUniformProcess,
        randomUniformProcess_,
        randomUniformIntProcess,
        randomUniformIntProcess_,
        randomTriangularProcess,
        randomTriangularProcess_,
        randomNormalProcess,
        randomNormalProcess_,
        randomLogNormalProcess,
        randomLogNormalProcess_,
        randomExponentialProcess,
        randomExponentialProcess_,
        randomErlangProcess,
        randomErlangProcess_,
        randomPoissonProcess,
        randomPoissonProcess_,
        randomBinomialProcess,
        randomBinomialProcess_,
        randomGammaProcess,
        randomGammaProcess_,
        randomBetaProcess,
        randomBetaProcess_,
        randomWeibullProcess,
        randomWeibullProcess_,
        randomDiscreteProcess,
        randomDiscreteProcess_) where

import Control.Monad
import Control.Monad.Trans

import Simulation.Aivika.Generator
import Simulation.Aivika.Parameter
import Simulation.Aivika.Parameter.Random
import Simulation.Aivika.Process

-- | Hold the process for a random time interval distributed uniformly.
randomUniformProcess :: Double
                        -- ^ the minimum time interval
                        -> Double
                        -- ^ the maximum time interval
                        -> Process Double
                        -- ^ a computation of the time interval
                        -- for which the process was actually held
randomUniformProcess min max =
  do t <- liftParameter $ randomUniform min max
     holdProcess t
     return t

-- | Hold the process for a random time interval distributed uniformly.
randomUniformProcess_ :: Double
                         -- ^ the minimum time interval
                         -> Double
                         -- ^ the maximum time interval
                         -> Process ()
randomUniformProcess_ min max =
  do t <- liftParameter $ randomUniform min max
     holdProcess t

-- | Hold the process for a random time interval distributed uniformly.
randomUniformIntProcess :: Int
                           -- ^ the minimum time interval
                           -> Int
                           -- ^ the maximum time interval
                           -> Process Int
                           -- ^ a computation of the time interval
                           -- for which the process was actually held
randomUniformIntProcess min max =
  do t <- liftParameter $ randomUniformInt min max
     holdProcess $ fromIntegral t
     return t

-- | Hold the process for a random time interval distributed uniformly.
randomUniformIntProcess_ :: Int
                            -- ^ the minimum time interval
                            -> Int
                            -- ^ the maximum time interval
                            -> Process ()
randomUniformIntProcess_ min max =
  do t <- liftParameter $ randomUniformInt min max
     holdProcess $ fromIntegral t

-- | Hold the process for a random time interval having the triangular distribution.
randomTriangularProcess :: Double
                           -- ^ the minimum time interval
                           -> Double
                           -- ^ a median of the time interval
                           -> Double
                           -- ^ the maximum time interval
                           -> Process Double
                           -- ^ a computation of the time interval
                           -- for which the process was actually held
randomTriangularProcess min median max =
  do t <- liftParameter $ randomTriangular min median max
     holdProcess t
     return t

-- | Hold the process for a random time interval having the triangular distribution.
randomTriangularProcess_ :: Double
                            -- ^ the minimum time interval
                            -> Double
                            -- ^ a median of the time interval
                            -> Double
                            -- ^ the maximum time interval
                            -> Process ()
randomTriangularProcess_ min median max =
  do t <- liftParameter $ randomTriangular min median max
     holdProcess t

-- | Hold the process for a random time interval distributed normally.
randomNormalProcess :: Double
                       -- ^ the mean time interval
                       -> Double
                       -- ^ the time interval deviation
                       -> Process Double
                       -- ^ a computation of the time interval
                       -- for which the process was actually held
randomNormalProcess mu nu =
  do t <- liftParameter $ randomNormal mu nu
     when (t > 0) $
       holdProcess t
     return t
         
-- | Hold the process for a random time interval distributed normally.
randomNormalProcess_ :: Double
                        -- ^ the mean time interval
                        -> Double
                        -- ^ the time interval deviation
                        -> Process ()
randomNormalProcess_ mu nu =
  do t <- liftParameter $ randomNormal mu nu
     when (t > 0) $
       holdProcess t

-- | Hold the process for a random time interval having the lognormal distribution.
randomLogNormalProcess :: Double
                          -- ^ the mean for a normal distribution
                          -- which this distribution is derived from
                          -> Double
                          -- ^ the deviation for a normal distribution
                          -- which this distribution is derived from
                          -> Process Double
                          -- ^ a computation of the time interval
                          -- for which the process was actually held
randomLogNormalProcess mu nu =
  do t <- liftParameter $ randomLogNormal mu nu
     holdProcess t
     return t

-- | Hold the process for a random time interval having the lognormal distribution.
randomLogNormalProcess_ :: Double
                           -- ^ the mean for a normal distribution
                           -- which this distribution is derived from
                           -> Double
                           -- ^ the deviation for a normal distribution
                           -- which this distribution is derived from
                           -> Process ()
randomLogNormalProcess_ mu nu =
  do t <- liftParameter $ randomLogNormal mu nu
     holdProcess t

-- | Hold the process for a random time interval distributed exponentially
-- with the specified mean (the reciprocal of the rate).
randomExponentialProcess :: Double
                            -- ^ the mean time interval (the reciprocal of the rate)
                            -> Process Double
                            -- ^ a computation of the time interval
                            -- for which the process was actually held
randomExponentialProcess mu =
  do t <- liftParameter $ randomExponential mu
     holdProcess t
     return t
         
-- | Hold the process for a random time interval distributed exponentially
-- with the specified mean (the reciprocal of the rate).
randomExponentialProcess_ :: Double
                             -- ^ the mean time interval (the reciprocal of the rate)
                             -> Process ()
randomExponentialProcess_ mu =
  do t <- liftParameter $ randomExponential mu
     holdProcess t
         
  | Hold the process for a random time interval having the Erlang distribution with
-- the specified scale (the reciprocal of the rate) and shape parameters.
randomErlangProcess :: Double
                       -- ^ the scale (the reciprocal of the rate)
                       -> Int
                       -- ^ the shape
                       -> Process Double
                       -- ^ a computation of the time interval
                       -- for which the process was actually held
randomErlangProcess beta m =
  do t <- liftParameter $ randomErlang beta m
     holdProcess t
     return t

  | Hold the process for a random time interval having the Erlang distribution with
-- the specified scale (the reciprocal of the rate) and shape parameters.
randomErlangProcess_ :: Double
                        -- ^ the scale (the reciprocal of the rate)
                        -> Int
                        -- ^ the shape
                        -> Process ()
randomErlangProcess_ beta m =
  do t <- liftParameter $ randomErlang beta m
     holdProcess t

  | Hold the process for a random time interval having the  distribution with
-- the specified mean.
randomPoissonProcess :: Double
                        -- ^ the mean time interval
                        -> Process Int
                        -- ^ a computation of the time interval
                        -- for which the process was actually held
randomPoissonProcess mu =
  do t <- liftParameter $ randomPoisson mu
     holdProcess $ fromIntegral t
     return t

  | Hold the process for a random time interval having the  distribution with
-- the specified mean.
randomPoissonProcess_ :: Double
                         -- ^ the mean time interval
                         -> Process ()
randomPoissonProcess_ mu =
  do t <- liftParameter $ randomPoisson mu
     holdProcess $ fromIntegral t

-- | Hold the process for a random time interval having the binomial distribution
-- with the specified probability and trials.
randomBinomialProcess :: Double
                         -- ^ the probability
                         -> Int
                         -- ^ the number of trials
                         -> Process Int
                         -- ^ a computation of the time interval
                         -- for which the process was actually held
randomBinomialProcess prob trials =
  do t <- liftParameter $ randomBinomial prob trials
     holdProcess $ fromIntegral t
     return t

-- | Hold the process for a random time interval having the binomial distribution
-- with the specified probability and trials.
randomBinomialProcess_ :: Double
                         -- ^ the probability
                         -> Int
                         -- ^ the number of trials
                         -> Process ()
randomBinomialProcess_ prob trials =
  do t <- liftParameter $ randomBinomial prob trials
     holdProcess $ fromIntegral t

  | Hold the process for a random time interval having the Gamma distribution
-- with the specified shape and scale.
randomGammaProcess :: Double
                      -- ^ the shape
                      -> Double
                      -- ^ the scale (a reciprocal of the rate)
                      -> Process Double
                      -- ^ a computation of the time interval
                      -- for which the process was actually held
randomGammaProcess kappa theta =
  do t <- liftParameter $ randomGamma kappa theta
     holdProcess t
     return t

  | Hold the process for a random time interval having the Gamma distribution
-- with the specified shape and scale.
randomGammaProcess_ :: Double
                       -- ^ the shape
                       -> Double
                       -- ^ the scale (a reciprocal of the rate)
                       -> Process ()
randomGammaProcess_ kappa theta =
  do t <- liftParameter $ randomGamma kappa theta
     holdProcess t

-- | Hold the process for a random time interval having the Beta distribution
-- with the specified shape parameters (alpha and beta).
randomBetaProcess :: Double
                     -- ^ the shape (alpha)
                     -> Double
                     -- ^ the shape (beta)
                     -> Process Double
                     -- ^ a computation of the time interval
                     -- for which the process was actually held
randomBetaProcess alpha beta =
  do t <- liftParameter $ randomBeta alpha beta
     holdProcess t
     return t

-- | Hold the process for a random time interval having the Beta distribution
-- with the specified shape parameters (alpha and beta).
randomBetaProcess_ :: Double
                      -- ^ the shape (alpha)
                      -> Double
                      -- ^ the shape (beta)
                      -> Process ()
randomBetaProcess_ alpha beta =
  do t <- liftParameter $ randomBeta alpha beta
     holdProcess t

  | Hold the process for a random time interval having the Weibull distribution
-- with the specified shape and scale.
randomWeibullProcess :: Double
                        -- ^ the shape
                        -> Double
                        -- ^ the scale
                        -> Process Double
                        -- ^ a computation of the time interval
                        -- for which the process was actually held
randomWeibullProcess alpha beta =
  do t <- liftParameter $ randomWeibull alpha beta
     holdProcess t
     return t

  | Hold the process for a random time interval having the Weibull distribution
-- with the specified shape and scale.
randomWeibullProcess_ :: Double
                         -- ^ the shape
                         -> Double
                         -- ^ the scale
                         -> Process ()
randomWeibullProcess_ alpha beta =
  do t <- liftParameter $ randomWeibull alpha beta
     holdProcess t

-- | Hold the process for a random time interval having the specified discrete distribution.
randomDiscreteProcess :: DiscretePDF Double
                         -- ^ the discrete probability density function
                         -> Process Double
                         -- ^ a computation of the time interval
                         -- for which the process was actually held
randomDiscreteProcess dpdf =
  do t <- liftParameter $ randomDiscrete dpdf
     holdProcess t
     return t

-- | Hold the process for a random time interval having the specified discrete distribution.
randomDiscreteProcess_ :: DiscretePDF Double
                          -- ^ the discrete probability density function
                          -> Process ()
randomDiscreteProcess_ dpdf =
  do t <- liftParameter $ randomDiscrete dpdf
     holdProcess t

 |
 Module     : Simulation.Aivika.Process.Random
 License    : BSD3
 Stability  : experimental

 This module defines helper functions, which are useful to hold 
 the 'Process' computation for a time interval according to some
 random distribution.

 | Hold the process for a random time interval distributed uniformly.
 ^ the minimum time interval
 ^ the maximum time interval
 ^ a computation of the time interval
 for which the process was actually held
 | Hold the process for a random time interval distributed uniformly.
 ^ the minimum time interval
 ^ the maximum time interval
 | Hold the process for a random time interval distributed uniformly.
 ^ the minimum time interval
 ^ the maximum time interval
 ^ a computation of the time interval
 for which the process was actually held
 | Hold the process for a random time interval distributed uniformly.
 ^ the minimum time interval
 ^ the maximum time interval
 | Hold the process for a random time interval having the triangular distribution.
 ^ the minimum time interval
 ^ a median of the time interval
 ^ the maximum time interval
 ^ a computation of the time interval
 for which the process was actually held
 | Hold the process for a random time interval having the triangular distribution.
 ^ the minimum time interval
 ^ a median of the time interval
 ^ the maximum time interval
 | Hold the process for a random time interval distributed normally.
 ^ the mean time interval
 ^ the time interval deviation
 ^ a computation of the time interval
 for which the process was actually held
 | Hold the process for a random time interval distributed normally.
 ^ the mean time interval
 ^ the time interval deviation
 | Hold the process for a random time interval having the lognormal distribution.
 ^ the mean for a normal distribution
 which this distribution is derived from
 ^ the deviation for a normal distribution
 which this distribution is derived from
 ^ a computation of the time interval
 for which the process was actually held
 | Hold the process for a random time interval having the lognormal distribution.
 ^ the mean for a normal distribution
 which this distribution is derived from
 ^ the deviation for a normal distribution
 which this distribution is derived from
 | Hold the process for a random time interval distributed exponentially
 with the specified mean (the reciprocal of the rate).
 ^ the mean time interval (the reciprocal of the rate)
 ^ a computation of the time interval
 for which the process was actually held
 | Hold the process for a random time interval distributed exponentially
 with the specified mean (the reciprocal of the rate).
 ^ the mean time interval (the reciprocal of the rate)
 the specified scale (the reciprocal of the rate) and shape parameters.
 ^ the scale (the reciprocal of the rate)
 ^ the shape
 ^ a computation of the time interval
 for which the process was actually held
 the specified scale (the reciprocal of the rate) and shape parameters.
 ^ the scale (the reciprocal of the rate)
 ^ the shape
 the specified mean.
 ^ the mean time interval
 ^ a computation of the time interval
 for which the process was actually held
 the specified mean.
 ^ the mean time interval
 | Hold the process for a random time interval having the binomial distribution
 with the specified probability and trials.
 ^ the probability
 ^ the number of trials
 ^ a computation of the time interval
 for which the process was actually held
 | Hold the process for a random time interval having the binomial distribution
 with the specified probability and trials.
 ^ the probability
 ^ the number of trials
 with the specified shape and scale.
 ^ the shape
 ^ the scale (a reciprocal of the rate)
 ^ a computation of the time interval
 for which the process was actually held
 with the specified shape and scale.
 ^ the shape
 ^ the scale (a reciprocal of the rate)
 | Hold the process for a random time interval having the Beta distribution
 with the specified shape parameters (alpha and beta).
 ^ the shape (alpha)
 ^ the shape (beta)
 ^ a computation of the time interval
 for which the process was actually held
 | Hold the process for a random time interval having the Beta distribution
 with the specified shape parameters (alpha and beta).
 ^ the shape (alpha)
 ^ the shape (beta)
 with the specified shape and scale.
 ^ the shape
 ^ the scale
 ^ a computation of the time interval
 for which the process was actually held
 with the specified shape and scale.
 ^ the shape
 ^ the scale
 | Hold the process for a random time interval having the specified discrete distribution.
 ^ the discrete probability density function
 ^ a computation of the time interval
 for which the process was actually held
 | Hold the process for a random time interval having the specified discrete distribution.
 ^ the discrete probability density function

  Copyright   : Copyright ( c ) 2009 - 2017 ,   <  >
  Maintainer :   <  >
  Tested with : GHC 8.0.1

module Simulation.Aivika.Process.Random
       (randomUniformProcess,
        randomUniformProcess_,
        randomUniformIntProcess,
        randomUniformIntProcess_,
        randomTriangularProcess,
        randomTriangularProcess_,
        randomNormalProcess,
        randomNormalProcess_,
        randomLogNormalProcess,
        randomLogNormalProcess_,
        randomExponentialProcess,
        randomExponentialProcess_,
        randomErlangProcess,
        randomErlangProcess_,
        randomPoissonProcess,
        randomPoissonProcess_,
        randomBinomialProcess,
        randomBinomialProcess_,
        randomGammaProcess,
        randomGammaProcess_,
        randomBetaProcess,
        randomBetaProcess_,
        randomWeibullProcess,
        randomWeibullProcess_,
        randomDiscreteProcess,
        randomDiscreteProcess_) where

import Control.Monad
import Control.Monad.Trans

import Simulation.Aivika.Generator
import Simulation.Aivika.Parameter
import Simulation.Aivika.Parameter.Random
import Simulation.Aivika.Process

randomUniformProcess :: Double
                        -> Double
                        -> Process Double
randomUniformProcess min max =
  do t <- liftParameter $ randomUniform min max
     holdProcess t
     return t

randomUniformProcess_ :: Double
                         -> Double
                         -> Process ()
randomUniformProcess_ min max =
  do t <- liftParameter $ randomUniform min max
     holdProcess t

randomUniformIntProcess :: Int
                           -> Int
                           -> Process Int
randomUniformIntProcess min max =
  do t <- liftParameter $ randomUniformInt min max
     holdProcess $ fromIntegral t
     return t

randomUniformIntProcess_ :: Int
                            -> Int
                            -> Process ()
randomUniformIntProcess_ min max =
  do t <- liftParameter $ randomUniformInt min max
     holdProcess $ fromIntegral t

randomTriangularProcess :: Double
                           -> Double
                           -> Double
                           -> Process Double
randomTriangularProcess min median max =
  do t <- liftParameter $ randomTriangular min median max
     holdProcess t
     return t

randomTriangularProcess_ :: Double
                            -> Double
                            -> Double
                            -> Process ()
randomTriangularProcess_ min median max =
  do t <- liftParameter $ randomTriangular min median max
     holdProcess t

randomNormalProcess :: Double
                       -> Double
                       -> Process Double
randomNormalProcess mu nu =
  do t <- liftParameter $ randomNormal mu nu
     when (t > 0) $
       holdProcess t
     return t
         
randomNormalProcess_ :: Double
                        -> Double
                        -> Process ()
randomNormalProcess_ mu nu =
  do t <- liftParameter $ randomNormal mu nu
     when (t > 0) $
       holdProcess t

randomLogNormalProcess :: Double
                          -> Double
                          -> Process Double
randomLogNormalProcess mu nu =
  do t <- liftParameter $ randomLogNormal mu nu
     holdProcess t
     return t

randomLogNormalProcess_ :: Double
                           -> Double
                           -> Process ()
randomLogNormalProcess_ mu nu =
  do t <- liftParameter $ randomLogNormal mu nu
     holdProcess t

randomExponentialProcess :: Double
                            -> Process Double
randomExponentialProcess mu =
  do t <- liftParameter $ randomExponential mu
     holdProcess t
     return t
         
randomExponentialProcess_ :: Double
                             -> Process ()
randomExponentialProcess_ mu =
  do t <- liftParameter $ randomExponential mu
     holdProcess t
         
  | Hold the process for a random time interval having the Erlang distribution with
randomErlangProcess :: Double
                       -> Int
                       -> Process Double
randomErlangProcess beta m =
  do t <- liftParameter $ randomErlang beta m
     holdProcess t
     return t

  | Hold the process for a random time interval having the Erlang distribution with
randomErlangProcess_ :: Double
                        -> Int
                        -> Process ()
randomErlangProcess_ beta m =
  do t <- liftParameter $ randomErlang beta m
     holdProcess t

  | Hold the process for a random time interval having the  distribution with
randomPoissonProcess :: Double
                        -> Process Int
randomPoissonProcess mu =
  do t <- liftParameter $ randomPoisson mu
     holdProcess $ fromIntegral t
     return t

  | Hold the process for a random time interval having the  distribution with
randomPoissonProcess_ :: Double
                         -> Process ()
randomPoissonProcess_ mu =
  do t <- liftParameter $ randomPoisson mu
     holdProcess $ fromIntegral t

randomBinomialProcess :: Double
                         -> Int
                         -> Process Int
randomBinomialProcess prob trials =
  do t <- liftParameter $ randomBinomial prob trials
     holdProcess $ fromIntegral t
     return t

randomBinomialProcess_ :: Double
                         -> Int
                         -> Process ()
randomBinomialProcess_ prob trials =
  do t <- liftParameter $ randomBinomial prob trials
     holdProcess $ fromIntegral t

  | Hold the process for a random time interval having the Gamma distribution
randomGammaProcess :: Double
                      -> Double
                      -> Process Double
randomGammaProcess kappa theta =
  do t <- liftParameter $ randomGamma kappa theta
     holdProcess t
     return t

  | Hold the process for a random time interval having the Gamma distribution
randomGammaProcess_ :: Double
                       -> Double
                       -> Process ()
randomGammaProcess_ kappa theta =
  do t <- liftParameter $ randomGamma kappa theta
     holdProcess t

randomBetaProcess :: Double
                     -> Double
                     -> Process Double
randomBetaProcess alpha beta =
  do t <- liftParameter $ randomBeta alpha beta
     holdProcess t
     return t

randomBetaProcess_ :: Double
                      -> Double
                      -> Process ()
randomBetaProcess_ alpha beta =
  do t <- liftParameter $ randomBeta alpha beta
     holdProcess t

  | Hold the process for a random time interval having the Weibull distribution
randomWeibullProcess :: Double
                        -> Double
                        -> Process Double
randomWeibullProcess alpha beta =
  do t <- liftParameter $ randomWeibull alpha beta
     holdProcess t
     return t

  | Hold the process for a random time interval having the Weibull distribution
randomWeibullProcess_ :: Double
                         -> Double
                         -> Process ()
randomWeibullProcess_ alpha beta =
  do t <- liftParameter $ randomWeibull alpha beta
     holdProcess t

randomDiscreteProcess :: DiscretePDF Double
                         -> Process Double
randomDiscreteProcess dpdf =
  do t <- liftParameter $ randomDiscrete dpdf
     holdProcess t
     return t

randomDiscreteProcess_ :: DiscretePDF Double
                          -> Process ()
randomDiscreteProcess_ dpdf =
  do t <- liftParameter $ randomDiscrete dpdf
     holdProcess t
