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

module Simulation.Aivika.Trans.Net.Random
       (randomUniformNet,
        randomUniformIntNet,
        randomTriangularNet,
        randomNormalNet,
        randomLogNormalNet,
        randomExponentialNet,
        randomErlangNet,
        randomPoissonNet,
        randomBinomialNet,
        randomGammaNet,
        randomBetaNet,
        randomWeibullNet,
        randomDiscreteNet) where

import Simulation.Aivika.Trans.DES
import Simulation.Aivika.Trans.Generator
import Simulation.Aivika.Trans.Process
import Simulation.Aivika.Trans.Process.Random
import Simulation.Aivika.Trans.Net

-- | When processing every input element, hold the process
-- for a random time interval distributed uniformly.
randomUniformNet :: MonadDES m
                    => Double
                    -- ^ the minimum time interval
                    -> Double
                    -- ^ the maximum time interval
                    -> Net m a a
{-# INLINABLE randomUniformNet #-}
randomUniformNet :: forall (m :: * -> *) a. MonadDES m => Double -> Double -> Net m a a
randomUniformNet Double
min Double
max =
  Process m () -> Net m a a
forall (m :: * -> *) a. MonadDES m => Process m () -> Net m a a
withinNet (Process m () -> Net m a a) -> Process m () -> Net m a a
forall a b. (a -> b) -> a -> b
$
  Double -> Double -> Process m ()
forall (m :: * -> *).
MonadDES m =>
Double -> Double -> Process m ()
randomUniformProcess_ Double
min Double
max

-- | When processing every input element, hold the process
-- for a random time interval distributed uniformly.
randomUniformIntNet :: MonadDES m
                       => Int
                       -- ^ the minimum time interval
                       -> Int
                       -- ^ the maximum time interval
                       -> Net m a a
{-# INLINABLE randomUniformIntNet #-}
randomUniformIntNet :: forall (m :: * -> *) a. MonadDES m => Int -> Int -> Net m a a
randomUniformIntNet Int
min Int
max =
  Process m () -> Net m a a
forall (m :: * -> *) a. MonadDES m => Process m () -> Net m a a
withinNet (Process m () -> Net m a a) -> Process m () -> Net m a a
forall a b. (a -> b) -> a -> b
$
  Int -> Int -> Process m ()
forall (m :: * -> *). MonadDES m => Int -> Int -> Process m ()
randomUniformIntProcess_ Int
min Int
max

-- | When processing every input element, hold the process
-- for a random time interval having the triangular distribution.
randomTriangularNet :: MonadDES m
                       => Double
                       -- ^ the minimum time interval
                       -> Double
                       -- ^ the median of the time interval
                       -> Double
                       -- ^ the maximum time interval
                       -> Net m a a
{-# INLINABLE randomTriangularNet #-}
randomTriangularNet :: forall (m :: * -> *) a.
MonadDES m =>
Double -> Double -> Double -> Net m a a
randomTriangularNet Double
min Double
median Double
max =
  Process m () -> Net m a a
forall (m :: * -> *) a. MonadDES m => Process m () -> Net m a a
withinNet (Process m () -> Net m a a) -> Process m () -> Net m a a
forall a b. (a -> b) -> a -> b
$
  Double -> Double -> Double -> Process m ()
forall (m :: * -> *).
MonadDES m =>
Double -> Double -> Double -> Process m ()
randomTriangularProcess_ Double
min Double
median Double
max

-- | When processing every input element, hold the process
-- for a random time interval distributed normally.
randomNormalNet :: MonadDES m
                   => Double
                   -- ^ the mean time interval
                   -> Double
                   -- ^ the time interval deviation
                   -> Net m a a
{-# INLINABLE randomNormalNet #-}
randomNormalNet :: forall (m :: * -> *) a. MonadDES m => Double -> Double -> Net m a a
randomNormalNet Double
mu Double
nu =
  Process m () -> Net m a a
forall (m :: * -> *) a. MonadDES m => Process m () -> Net m a a
withinNet (Process m () -> Net m a a) -> Process m () -> Net m a a
forall a b. (a -> b) -> a -> b
$
  Double -> Double -> Process m ()
forall (m :: * -> *).
MonadDES m =>
Double -> Double -> Process m ()
randomNormalProcess_ Double
mu Double
nu
         
-- | When processing every input element, hold the process
-- for a random time interval having the lognormal distribution.
randomLogNormalNet :: 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
                      -> Net m a a
{-# INLINABLE randomLogNormalNet #-}
randomLogNormalNet :: forall (m :: * -> *) a. MonadDES m => Double -> Double -> Net m a a
randomLogNormalNet Double
mu Double
nu =
  Process m () -> Net m a a
forall (m :: * -> *) a. MonadDES m => Process m () -> Net m a a
withinNet (Process m () -> Net m a a) -> Process m () -> Net m a a
forall a b. (a -> b) -> a -> b
$
  Double -> Double -> Process m ()
forall (m :: * -> *).
MonadDES m =>
Double -> Double -> Process m ()
randomLogNormalProcess_ Double
mu Double
nu
         
-- | When processing every input element, hold the process
-- for a random time interval distributed exponentially
-- with the specified mean (the reciprocal of the rate).
randomExponentialNet :: MonadDES m
                        => Double
                        -- ^ the mean time interval (the reciprocal of the rate)
                        -> Net m a a
{-# INLINABLE randomExponentialNet #-}
randomExponentialNet :: forall (m :: * -> *) a. MonadDES m => Double -> Net m a a
randomExponentialNet Double
mu =
  Process m () -> Net m a a
forall (m :: * -> *) a. MonadDES m => Process m () -> Net m a a
withinNet (Process m () -> Net m a a) -> Process m () -> Net m a a
forall a b. (a -> b) -> a -> b
$
  Double -> Process m ()
forall (m :: * -> *). MonadDES m => Double -> Process m ()
randomExponentialProcess_ Double
mu
         
-- | When processing every input element, hold the process
-- for a random time interval having the Erlang distribution with
-- the specified scale (the reciprocal of the rate) and shape parameters.
randomErlangNet :: MonadDES m
                   => Double
                   -- ^ the scale (the reciprocal of the rate)
                   -> Int
                   -- ^ the shape
                   -> Net m a a
{-# INLINABLE randomErlangNet #-}
randomErlangNet :: forall (m :: * -> *) a. MonadDES m => Double -> Int -> Net m a a
randomErlangNet Double
beta Int
m =
  Process m () -> Net m a a
forall (m :: * -> *) a. MonadDES m => Process m () -> Net m a a
withinNet (Process m () -> Net m a a) -> Process m () -> Net m a a
forall a b. (a -> b) -> a -> b
$
  Double -> Int -> Process m ()
forall (m :: * -> *). MonadDES m => Double -> Int -> Process m ()
randomErlangProcess_ Double
beta Int
m

-- | When processing every input element, hold the process
-- for a random time interval having the Poisson distribution
-- with the specified mean.
randomPoissonNet :: MonadDES m
                    => Double
                    -- ^ the mean time interval
                    -> Net m a a
{-# INLINABLE randomPoissonNet #-}
randomPoissonNet :: forall (m :: * -> *) a. MonadDES m => Double -> Net m a a
randomPoissonNet Double
mu =
  Process m () -> Net m a a
forall (m :: * -> *) a. MonadDES m => Process m () -> Net m a a
withinNet (Process m () -> Net m a a) -> Process m () -> Net m a a
forall a b. (a -> b) -> a -> b
$
  Double -> Process m ()
forall (m :: * -> *). MonadDES m => Double -> Process m ()
randomPoissonProcess_ Double
mu

-- | When processing every input element, hold the process
-- for a random time interval having the binomial distribution
-- with the specified probability and trials.
randomBinomialNet :: MonadDES m
                     => Double
                     -- ^ the probability
                     -> Int
                     -- ^ the number of trials
                     -> Net m a a
{-# INLINABLE randomBinomialNet #-}
randomBinomialNet :: forall (m :: * -> *) a. MonadDES m => Double -> Int -> Net m a a
randomBinomialNet Double
prob Int
trials =
  Process m () -> Net m a a
forall (m :: * -> *) a. MonadDES m => Process m () -> Net m a a
withinNet (Process m () -> Net m a a) -> Process m () -> Net m a a
forall a b. (a -> b) -> a -> b
$
  Double -> Int -> Process m ()
forall (m :: * -> *). MonadDES m => Double -> Int -> Process m ()
randomBinomialProcess_ Double
prob Int
trials

-- | When processing every input element, hold the process
-- for a random time interval having the Gamma distribution
-- with the specified shape and scale.
randomGammaNet :: MonadDES m
                  => Double
                  -- ^ the shape
                  -> Double
                  -- ^ the scale (a reciprocal of the rate)
                  -> Net m a a
{-# INLINABLE randomGammaNet #-}
randomGammaNet :: forall (m :: * -> *) a. MonadDES m => Double -> Double -> Net m a a
randomGammaNet Double
kappa Double
theta =
  Process m () -> Net m a a
forall (m :: * -> *) a. MonadDES m => Process m () -> Net m a a
withinNet (Process m () -> Net m a a) -> Process m () -> Net m a a
forall a b. (a -> b) -> a -> b
$
  Double -> Double -> Process m ()
forall (m :: * -> *).
MonadDES m =>
Double -> Double -> Process m ()
randomGammaProcess_ Double
kappa Double
theta

-- | When processing every input element, hold the process
-- for a random time interval having the Beta distribution
-- with the specified shape parameters (alpha and beta).
randomBetaNet :: MonadDES m
                 => Double
                 -- ^ shape (alpha)
                 -> Double
                 -- ^ shape (beta)
                 -> Net m a a
{-# INLINABLE randomBetaNet #-}
randomBetaNet :: forall (m :: * -> *) a. MonadDES m => Double -> Double -> Net m a a
randomBetaNet Double
alpha Double
beta =
  Process m () -> Net m a a
forall (m :: * -> *) a. MonadDES m => Process m () -> Net m a a
withinNet (Process m () -> Net m a a) -> Process m () -> Net m a a
forall a b. (a -> b) -> a -> b
$
  Double -> Double -> Process m ()
forall (m :: * -> *).
MonadDES m =>
Double -> Double -> Process m ()
randomBetaProcess_ Double
alpha Double
beta

-- | When processing every input element, hold the process
-- for a random time interval having the Weibull distribution
-- with the specified shape and scale.
randomWeibullNet :: MonadDES m
                    => Double
                    -- ^ shape
                    -> Double
                    -- ^ scale
                    -> Net m a a
{-# INLINABLE randomWeibullNet #-}
randomWeibullNet :: forall (m :: * -> *) a. MonadDES m => Double -> Double -> Net m a a
randomWeibullNet Double
alpha Double
beta =
  Process m () -> Net m a a
forall (m :: * -> *) a. MonadDES m => Process m () -> Net m a a
withinNet (Process m () -> Net m a a) -> Process m () -> Net m a a
forall a b. (a -> b) -> a -> b
$
  Double -> Double -> Process m ()
forall (m :: * -> *).
MonadDES m =>
Double -> Double -> Process m ()
randomWeibullProcess_ Double
alpha Double
beta

-- | When processing every input element, hold the process
-- for a random time interval having the specified discrete distribution.
randomDiscreteNet :: MonadDES m
                     => DiscretePDF Double
                     -- ^ the discrete probability density function
                     -> Net m a a
{-# INLINABLE randomDiscreteNet #-}
randomDiscreteNet :: forall (m :: * -> *) a.
MonadDES m =>
DiscretePDF Double -> Net m a a
randomDiscreteNet DiscretePDF Double
dpdf =
  Process m () -> Net m a a
forall (m :: * -> *) a. MonadDES m => Process m () -> Net m a a
withinNet (Process m () -> Net m a a) -> Process m () -> Net m a a
forall a b. (a -> b) -> a -> b
$
  DiscretePDF Double -> Process m ()
forall (m :: * -> *).
MonadDES m =>
DiscretePDF Double -> Process m ()
randomDiscreteProcess_ DiscretePDF Double
dpdf