{-# LANGUAGE GADTs #-}
module Epidemic.Types.Simulation
( SimulationConfiguration(..)
, SimulationState(..)
, SimulationRandEvent(..)
, TerminationHandler(..)
, genIOFromFixed
, genIOFromWord32
, genIOFromSystem
) where
import qualified Data.Vector.Unboxed as Unboxed
import Epidemic.Types.Events
import Epidemic.Types.Parameter
import Epidemic.Types.Population
import Epidemic.Types.Time (AbsoluteTime (..), TimeDelta (..))
import GHC.Word (Word32)
import System.Random.MWC (GenIO, create, createSystemRandom,
initialize)
data SimulationConfiguration r p s =
SimulationConfiguration
{
SimulationConfiguration r p s -> r
scRates :: r
, SimulationConfiguration r p s -> p
scPopulation :: p
, SimulationConfiguration r p s -> Identifier
scNewIdentifier :: Identifier
, SimulationConfiguration r p s -> AbsoluteTime
scStartTime :: AbsoluteTime
, SimulationConfiguration r p s -> TimeDelta
scSimDuration :: TimeDelta
, SimulationConfiguration r p s -> Maybe (TerminationHandler p s)
scTerminationHandler :: Maybe (TerminationHandler p s)
, SimulationConfiguration r p s -> Bool
scRequireCherry :: Bool
}
data SimulationState b c
= SimulationState (AbsoluteTime, [EpidemicEvent], b, Identifier)
| TerminatedSimulation (Maybe c)
deriving (SimulationState b c -> SimulationState b c -> Bool
(SimulationState b c -> SimulationState b c -> Bool)
-> (SimulationState b c -> SimulationState b c -> Bool)
-> Eq (SimulationState b c)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall b c.
(Eq b, Eq c) =>
SimulationState b c -> SimulationState b c -> Bool
/= :: SimulationState b c -> SimulationState b c -> Bool
$c/= :: forall b c.
(Eq b, Eq c) =>
SimulationState b c -> SimulationState b c -> Bool
== :: SimulationState b c -> SimulationState b c -> Bool
$c== :: forall b c.
(Eq b, Eq c) =>
SimulationState b c -> SimulationState b c -> Bool
Eq, Int -> SimulationState b c -> ShowS
[SimulationState b c] -> ShowS
SimulationState b c -> String
(Int -> SimulationState b c -> ShowS)
-> (SimulationState b c -> String)
-> ([SimulationState b c] -> ShowS)
-> Show (SimulationState b c)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall b c. (Show b, Show c) => Int -> SimulationState b c -> ShowS
forall b c. (Show b, Show c) => [SimulationState b c] -> ShowS
forall b c. (Show b, Show c) => SimulationState b c -> String
showList :: [SimulationState b c] -> ShowS
$cshowList :: forall b c. (Show b, Show c) => [SimulationState b c] -> ShowS
show :: SimulationState b c -> String
$cshow :: forall b c. (Show b, Show c) => SimulationState b c -> String
showsPrec :: Int -> SimulationState b c -> ShowS
$cshowsPrec :: forall b c. (Show b, Show c) => Int -> SimulationState b c -> ShowS
Show)
data SimulationRandEvent a b where
SimulationRandEvent
:: (ModelParameters a b, Population b)
=> (a
-> AbsoluteTime
-> b
-> Identifier
-> GenIO
-> IO (AbsoluteTime, EpidemicEvent, b, Identifier))
-> SimulationRandEvent a b
data TerminationHandler b c where
TerminationHandler
:: Population b
=> (b -> Bool)
-> ([EpidemicEvent] -> c)
-> TerminationHandler b c
genIOFromWord32 :: Word32 -> IO GenIO
genIOFromWord32 :: Word32 -> IO GenIO
genIOFromWord32 Word32
seed = Vector Word32 -> IO GenIO
forall (m :: * -> *) (v :: * -> *).
(PrimMonad m, Vector v Word32) =>
v Word32 -> m (Gen (PrimState m))
initialize ([Word32] -> Vector Word32
forall a. Unbox a => [a] -> Vector a
Unboxed.fromList [Word32
seed])
genIOFromSystem :: IO GenIO
genIOFromSystem :: IO GenIO
genIOFromSystem = IO GenIO
createSystemRandom
genIOFromFixed :: IO GenIO
genIOFromFixed :: IO GenIO
genIOFromFixed = IO GenIO
forall (m :: * -> *). PrimMonad m => m (Gen (PrimState m))
create