{-# LANGUAGE FlexibleContexts, MonoLocalBinds #-}

-- |
-- Module     : Simulation.Aivika.Trans.Results.IO
-- 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
--
-- The module allows printing and converting the 'Simulation' 'Results' to a 'String'.
--
module Simulation.Aivika.Trans.Results.IO
       (-- * Basic Types
        ResultSourcePrint,
        ResultSourceShowS,
        -- * Printing the Results
        printResultsWithTime,
        printResultsInStartTime,
        printResultsInStopTime,
        printResultsInIntegTimes,
        printResultsInTime,
        printResultsInTimes,
        -- * Simulating and Printing the Results
        printSimulationResultsInStartTime,
        printSimulationResultsInStopTime,
        printSimulationResultsInIntegTimes,
        printSimulationResultsInTime,
        printSimulationResultsInTimes,
        -- * Showing the Results
        showResultsWithTime,
        showResultsInStartTime,
        showResultsInStopTime,
        showResultsInIntegTimes,
        showResultsInTime,
        showResultsInTimes,
        -- * Simulating and Showing the Results
        showSimulationResultsInStartTime,
        showSimulationResultsInStopTime,
        showSimulationResultsInIntegTimes,
        showSimulationResultsInTime,
        showSimulationResultsInTimes,
        -- * Printing the Result Source
        hPrintResultSourceIndented,
        hPrintResultSource,
        hPrintResultSourceInRussian,
        hPrintResultSourceInEnglish,
        printResultSourceIndented,
        printResultSource,
        printResultSourceInRussian,
        printResultSourceInEnglish,
        -- * Enqueue Printing of the Result Source
        hEnqueuePrintingResultSourceIndented,
        hEnqueuePrintingResultSource,
        hEnqueuePrintingResultSourceInRussian,
        hEnqueuePrintingResultSourceInEnglish,
        enqueuePrintingResultSourceIndented,
        enqueuePrintingResultSource,
        enqueuePrintingResultSourceInRussian,
        enqueuePrintingResultSourceInEnglish,
        -- * Showing the Result Source
        showResultSourceIndented,
        showResultSource,
        showResultSourceInRussian,
        showResultSourceInEnglish) where

import Control.Monad
import Control.Monad.Trans

import qualified Data.Map as M
import qualified Data.Array as A

import System.IO

import Simulation.Aivika.Trans.Comp
import Simulation.Aivika.Trans.DES
import Simulation.Aivika.Trans.Specs
import Simulation.Aivika.Trans.Simulation
import Simulation.Aivika.Trans.Dynamics
import Simulation.Aivika.Trans.Event
import Simulation.Aivika.Trans.Ref
import Simulation.Aivika.Trans.Results
import Simulation.Aivika.Trans.Results.Locale

-- | This is a function that shows the simulation results within
-- the 'Event' computation synchronized with the event queue.
type ResultSourceShowS m = ResultSource m -> Event m ShowS

-- | This is a function that prints the simulation results within
-- the 'Event' computation synchronized with the event queue.
type ResultSourcePrint m = ResultSource m -> Event m ()

-- | Print a localised text representation of the results by the specified source
-- and with the given indent.
hPrintResultSourceIndented :: (MonadDES m, MonadIO (Event m))
                              => Handle
                              -- ^ a handle
                              -> Int
                              -- ^ an indent
                              -> ResultLocalisation
                              -- ^ a localisation
                              -> ResultSourcePrint m
{-# INLINABLE hPrintResultSourceIndented #-}
hPrintResultSourceIndented :: forall (m :: * -> *).
(MonadDES m, MonadIO (Event m)) =>
Handle -> Int -> ResultLocalisation -> ResultSourcePrint m
hPrintResultSourceIndented Handle
h Int
indent ResultLocalisation
loc source :: ResultSource m
source@(ResultItemSource (ResultItem a m
x)) =
  Handle
-> Int -> ResultName -> ResultLocalisation -> ResultSourcePrint m
forall (m :: * -> *).
(MonadDES m, MonadIO (Event m)) =>
Handle
-> Int -> ResultName -> ResultLocalisation -> ResultSourcePrint m
hPrintResultSourceIndentedLabelled Handle
h Int
indent (a m -> ResultName
forall (m :: * -> *). a m -> ResultName
forall (a :: (* -> *) -> *) (m :: * -> *).
ResultItemable a =>
a m -> ResultName
resultItemName a m
x) ResultLocalisation
loc ResultSource m
source
hPrintResultSourceIndented Handle
h Int
indent ResultLocalisation
loc source :: ResultSource m
source@(ResultVectorSource ResultVector m
x) =
  Handle
-> Int -> ResultName -> ResultLocalisation -> ResultSourcePrint m
forall (m :: * -> *).
(MonadDES m, MonadIO (Event m)) =>
Handle
-> Int -> ResultName -> ResultLocalisation -> ResultSourcePrint m
hPrintResultSourceIndentedLabelled Handle
h Int
indent (ResultVector m -> ResultName
forall (m :: * -> *). ResultVector m -> ResultName
resultVectorName ResultVector m
x) ResultLocalisation
loc ResultSource m
source
hPrintResultSourceIndented Handle
h Int
indent ResultLocalisation
loc source :: ResultSource m
source@(ResultObjectSource ResultObject m
x) =
  Handle
-> Int -> ResultName -> ResultLocalisation -> ResultSourcePrint m
forall (m :: * -> *).
(MonadDES m, MonadIO (Event m)) =>
Handle
-> Int -> ResultName -> ResultLocalisation -> ResultSourcePrint m
hPrintResultSourceIndentedLabelled Handle
h Int
indent (ResultObject m -> ResultName
forall (m :: * -> *). ResultObject m -> ResultName
resultObjectName ResultObject m
x) ResultLocalisation
loc ResultSource m
source
hPrintResultSourceIndented Handle
h Int
indent ResultLocalisation
loc source :: ResultSource m
source@(ResultSeparatorSource ResultSeparator
x) =
  Handle
-> Int -> ResultName -> ResultLocalisation -> ResultSourcePrint m
forall (m :: * -> *).
(MonadDES m, MonadIO (Event m)) =>
Handle
-> Int -> ResultName -> ResultLocalisation -> ResultSourcePrint m
hPrintResultSourceIndentedLabelled Handle
h Int
indent (ResultSeparator -> ResultName
resultSeparatorText ResultSeparator
x) ResultLocalisation
loc ResultSource m
source

-- | Print an indented and labelled text representation of the results by
-- the specified source.
hPrintResultSourceIndentedLabelled :: (MonadDES m, MonadIO (Event m))
                                      => Handle
                                      -- ^ a handle
                                      -> Int
                                      -- ^ an indent
                                      -> ResultName
                                      -- ^ a label
                                      -> ResultLocalisation
                                      -- ^ a localisation
                                      -> ResultSourcePrint m
{-# INLINABLE hPrintResultSourceIndentedLabelled #-}
hPrintResultSourceIndentedLabelled :: forall (m :: * -> *).
(MonadDES m, MonadIO (Event m)) =>
Handle
-> Int -> ResultName -> ResultLocalisation -> ResultSourcePrint m
hPrintResultSourceIndentedLabelled Handle
h Int
indent ResultName
label ResultLocalisation
loc (ResultItemSource (ResultItem a m
x)) =
  do ResultName
a <- ResultValue ResultName m -> ResultData ResultName m
forall e (m :: * -> *). ResultValue e m -> ResultData e m
resultValueData (ResultValue ResultName m -> ResultData ResultName m)
-> ResultValue ResultName m -> ResultData ResultName m
forall a b. (a -> b) -> a -> b
$ a m -> ResultValue ResultName m
forall (m :: * -> *) (a :: (* -> *) -> *).
(MonadDES m, ResultItemable a) =>
a m -> ResultValue ResultName m
resultItemToStringValue a m
x
     let tab :: ResultName
tab = Int -> Char -> ResultName
forall a. Int -> a -> [a]
replicate Int
indent Char
' '
     IO () -> Event m ()
forall a. IO a -> Event m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> Event m ()) -> IO () -> Event m ()
forall a b. (a -> b) -> a -> b
$
       do Handle -> ResultName -> IO ()
hPutStr Handle
h ResultName
tab
          Handle -> ResultName -> IO ()
hPutStr Handle
h ResultName
"-- "
          Handle -> ResultName -> IO ()
hPutStr Handle
h (ResultLocalisation -> ResultId -> ResultName
localiseResultDescription ResultLocalisation
loc (ResultId -> ResultName) -> ResultId -> ResultName
forall a b. (a -> b) -> a -> b
$ a m -> ResultId
forall (m :: * -> *). a m -> ResultId
forall (a :: (* -> *) -> *) (m :: * -> *).
ResultItemable a =>
a m -> ResultId
resultItemId a m
x)
          Handle -> ResultName -> IO ()
hPutStrLn Handle
h ResultName
""
          Handle -> ResultName -> IO ()
hPutStr Handle
h ResultName
tab
          Handle -> ResultName -> IO ()
hPutStr Handle
h ResultName
label
          Handle -> ResultName -> IO ()
hPutStr Handle
h ResultName
" = "
          Handle -> ResultName -> IO ()
hPutStrLn Handle
h ResultName
a
          Handle -> ResultName -> IO ()
hPutStrLn Handle
h ResultName
""
hPrintResultSourceIndentedLabelled Handle
h Int
indent ResultName
label ResultLocalisation
loc (ResultVectorSource ResultVector m
x) =
  do let tab :: ResultName
tab = Int -> Char -> ResultName
forall a. Int -> a -> [a]
replicate Int
indent Char
' '
     IO () -> Event m ()
forall a. IO a -> Event m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> Event m ()) -> IO () -> Event m ()
forall a b. (a -> b) -> a -> b
$
       do Handle -> ResultName -> IO ()
hPutStr Handle
h ResultName
tab
          Handle -> ResultName -> IO ()
hPutStr Handle
h ResultName
"-- "
          Handle -> ResultName -> IO ()
hPutStr Handle
h (ResultLocalisation -> ResultId -> ResultName
localiseResultDescription ResultLocalisation
loc (ResultId -> ResultName) -> ResultId -> ResultName
forall a b. (a -> b) -> a -> b
$ ResultVector m -> ResultId
forall (m :: * -> *). ResultVector m -> ResultId
resultVectorId ResultVector m
x)
          Handle -> ResultName -> IO ()
hPutStrLn Handle
h ResultName
""
          Handle -> ResultName -> IO ()
hPutStr Handle
h ResultName
tab
          Handle -> ResultName -> IO ()
hPutStr Handle
h ResultName
label
          Handle -> ResultName -> IO ()
hPutStrLn Handle
h ResultName
":"
          Handle -> ResultName -> IO ()
hPutStrLn Handle
h ResultName
""
     let items :: [ResultSource m]
items = Array Int (ResultSource m) -> [ResultSource m]
forall i e. Array i e -> [e]
A.elems (ResultVector m -> Array Int (ResultSource m)
forall (m :: * -> *). ResultVector m -> Array Int (ResultSource m)
resultVectorItems ResultVector m
x)
         subscript :: [ResultName]
subscript = Array Int ResultName -> [ResultName]
forall i e. Array i e -> [e]
A.elems (ResultVector m -> Array Int ResultName
forall (m :: * -> *). ResultVector m -> Array Int ResultName
resultVectorSubscript ResultVector m
x)
     [(ResultSource m, ResultName)]
-> ((ResultSource m, ResultName) -> Event m ()) -> Event m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ ([ResultSource m] -> [ResultName] -> [(ResultSource m, ResultName)]
forall a b. [a] -> [b] -> [(a, b)]
zip [ResultSource m]
items [ResultName]
subscript) (((ResultSource m, ResultName) -> Event m ()) -> Event m ())
-> ((ResultSource m, ResultName) -> Event m ()) -> Event m ()
forall a b. (a -> b) -> a -> b
$ \(ResultSource m
i, ResultName
s) ->
       Handle
-> Int -> ResultName -> ResultLocalisation -> ResultSourcePrint m
forall (m :: * -> *).
(MonadDES m, MonadIO (Event m)) =>
Handle
-> Int -> ResultName -> ResultLocalisation -> ResultSourcePrint m
hPrintResultSourceIndentedLabelled Handle
h (Int
indent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
2) (ResultName
label ResultName -> ResultName -> ResultName
forall a. [a] -> [a] -> [a]
++ ResultName
s) ResultLocalisation
loc ResultSource m
i
hPrintResultSourceIndentedLabelled Handle
h Int
indent ResultName
label ResultLocalisation
loc (ResultObjectSource ResultObject m
x) =
  do let tab :: ResultName
tab = Int -> Char -> ResultName
forall a. Int -> a -> [a]
replicate Int
indent Char
' '
     IO () -> Event m ()
forall a. IO a -> Event m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> Event m ()) -> IO () -> Event m ()
forall a b. (a -> b) -> a -> b
$
       do Handle -> ResultName -> IO ()
hPutStr Handle
h ResultName
tab
          Handle -> ResultName -> IO ()
hPutStr Handle
h ResultName
"-- "
          Handle -> ResultName -> IO ()
hPutStr Handle
h (ResultLocalisation -> ResultId -> ResultName
localiseResultDescription ResultLocalisation
loc (ResultId -> ResultName) -> ResultId -> ResultName
forall a b. (a -> b) -> a -> b
$ ResultObject m -> ResultId
forall (m :: * -> *). ResultObject m -> ResultId
resultObjectId ResultObject m
x)
          Handle -> ResultName -> IO ()
hPutStrLn Handle
h ResultName
""
          Handle -> ResultName -> IO ()
hPutStr Handle
h ResultName
tab
          Handle -> ResultName -> IO ()
hPutStr Handle
h ResultName
label
          Handle -> ResultName -> IO ()
hPutStrLn Handle
h ResultName
":"
          Handle -> ResultName -> IO ()
hPutStrLn Handle
h ResultName
""
     [ResultProperty m]
-> (ResultProperty m -> Event m ()) -> Event m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (ResultObject m -> [ResultProperty m]
forall (m :: * -> *). ResultObject m -> [ResultProperty m]
resultObjectProperties ResultObject m
x) ((ResultProperty m -> Event m ()) -> Event m ())
-> (ResultProperty m -> Event m ()) -> Event m ()
forall a b. (a -> b) -> a -> b
$ \ResultProperty m
p ->
       do let indent' :: Int
indent' = Int
2 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
indent
              tab' :: ResultName
tab'    = ResultName
"  " ResultName -> ResultName -> ResultName
forall a. [a] -> [a] -> [a]
++ ResultName
tab
              label' :: ResultName
label'  = ResultProperty m -> ResultName
forall (m :: * -> *). ResultProperty m -> ResultName
resultPropertyLabel ResultProperty m
p
              source' :: ResultSource m
source' = ResultProperty m -> ResultSource m
forall (m :: * -> *). ResultProperty m -> ResultSource m
resultPropertySource ResultProperty m
p
          Handle
-> Int -> ResultName -> ResultLocalisation -> ResultSourcePrint m
forall (m :: * -> *).
(MonadDES m, MonadIO (Event m)) =>
Handle
-> Int -> ResultName -> ResultLocalisation -> ResultSourcePrint m
hPrintResultSourceIndentedLabelled Handle
h Int
indent' ResultName
label' ResultLocalisation
loc ResultSource m
source'
hPrintResultSourceIndentedLabelled Handle
h Int
indent ResultName
label ResultLocalisation
loc (ResultSeparatorSource ResultSeparator
x) =
  do let tab :: ResultName
tab = Int -> Char -> ResultName
forall a. Int -> a -> [a]
replicate Int
indent Char
' '
     IO () -> Event m ()
forall a. IO a -> Event m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> Event m ()) -> IO () -> Event m ()
forall a b. (a -> b) -> a -> b
$
       do Handle -> ResultName -> IO ()
hPutStr Handle
h ResultName
tab
          Handle -> ResultName -> IO ()
hPutStr Handle
h ResultName
label
          Handle -> ResultName -> IO ()
hPutStrLn Handle
h ResultName
""
          Handle -> ResultName -> IO ()
hPutStrLn Handle
h ResultName
""

-- | Print a localised text representation of the results by the specified source
-- and with the given indent.
printResultSourceIndented :: (MonadDES m, MonadIO (Event m))
                             => Int
                             -- ^ an indent
                             -> ResultLocalisation
                             -- ^ a localisation
                             -> ResultSourcePrint m
{-# INLINABLE printResultSourceIndented #-}
printResultSourceIndented :: forall (m :: * -> *).
(MonadDES m, MonadIO (Event m)) =>
Int -> ResultLocalisation -> ResultSourcePrint m
printResultSourceIndented = Handle -> Int -> ResultLocalisation -> ResultSourcePrint m
forall (m :: * -> *).
(MonadDES m, MonadIO (Event m)) =>
Handle -> Int -> ResultLocalisation -> ResultSourcePrint m
hPrintResultSourceIndented Handle
stdout

-- | Print a localised text representation of the results by the specified source.
hPrintResultSource :: (MonadDES m, MonadIO (Event m))
                      => Handle
                      -- ^ a handle
                      -> ResultLocalisation
                      -- ^ a localisation
                      -> ResultSourcePrint m
{-# INLINABLE hPrintResultSource #-}
hPrintResultSource :: forall (m :: * -> *).
(MonadDES m, MonadIO (Event m)) =>
Handle -> ResultLocalisation -> ResultSourcePrint m
hPrintResultSource Handle
h = Handle -> Int -> ResultLocalisation -> ResultSourcePrint m
forall (m :: * -> *).
(MonadDES m, MonadIO (Event m)) =>
Handle -> Int -> ResultLocalisation -> ResultSourcePrint m
hPrintResultSourceIndented Handle
h Int
0

-- | Print a localised text representation of the results by the specified source.
printResultSource :: (MonadDES m, MonadIO (Event m))
                     => ResultLocalisation
                     -- ^ a localisation
                     -> ResultSourcePrint m
{-# INLINABLE printResultSource #-}
printResultSource :: forall (m :: * -> *).
(MonadDES m, MonadIO (Event m)) =>
ResultLocalisation -> ResultSourcePrint m
printResultSource = Handle -> ResultLocalisation -> ResultSourcePrint m
forall (m :: * -> *).
(MonadDES m, MonadIO (Event m)) =>
Handle -> ResultLocalisation -> ResultSourcePrint m
hPrintResultSource Handle
stdout

-- | Print in Russian a text representation of the results by the specified source.
hPrintResultSourceInRussian :: (MonadDES m, MonadIO (Event m)) => Handle -> ResultSourcePrint m
{-# INLINABLE hPrintResultSourceInRussian #-}
hPrintResultSourceInRussian :: forall (m :: * -> *).
(MonadDES m, MonadIO (Event m)) =>
Handle -> ResultSourcePrint m
hPrintResultSourceInRussian Handle
h = Handle -> ResultLocalisation -> ResultSourcePrint m
forall (m :: * -> *).
(MonadDES m, MonadIO (Event m)) =>
Handle -> ResultLocalisation -> ResultSourcePrint m
hPrintResultSource Handle
h ResultLocalisation
russianResultLocalisation

-- | Print in English a text representation of the results by the specified source.
hPrintResultSourceInEnglish :: (MonadDES m, MonadIO (Event m)) => Handle -> ResultSourcePrint m
{-# INLINABLE hPrintResultSourceInEnglish #-}
hPrintResultSourceInEnglish :: forall (m :: * -> *).
(MonadDES m, MonadIO (Event m)) =>
Handle -> ResultSourcePrint m
hPrintResultSourceInEnglish Handle
h = Handle -> ResultLocalisation -> ResultSourcePrint m
forall (m :: * -> *).
(MonadDES m, MonadIO (Event m)) =>
Handle -> ResultLocalisation -> ResultSourcePrint m
hPrintResultSource Handle
h ResultLocalisation
englishResultLocalisation

-- | Print in Russian a text representation of the results by the specified source.
printResultSourceInRussian :: (MonadDES m, MonadIO (Event m)) => ResultSourcePrint m
{-# INLINABLE printResultSourceInRussian #-}
printResultSourceInRussian :: forall (m :: * -> *).
(MonadDES m, MonadIO (Event m)) =>
ResultSourcePrint m
printResultSourceInRussian = Handle -> ResultSourcePrint m
forall (m :: * -> *).
(MonadDES m, MonadIO (Event m)) =>
Handle -> ResultSourcePrint m
hPrintResultSourceInRussian Handle
stdout

-- | Print in English a text representation of the results by the specified source.
printResultSourceInEnglish :: (MonadDES m, MonadIO (Event m)) => ResultSourcePrint m
{-# INLINABLE printResultSourceInEnglish #-}
printResultSourceInEnglish :: forall (m :: * -> *).
(MonadDES m, MonadIO (Event m)) =>
ResultSourcePrint m
printResultSourceInEnglish = Handle -> ResultSourcePrint m
forall (m :: * -> *).
(MonadDES m, MonadIO (Event m)) =>
Handle -> ResultSourcePrint m
hPrintResultSourceInEnglish Handle
stdout

-- | Enqueue printing of a localised text representation of the results by the specified source
-- and with the given indent.
hEnqueuePrintingResultSourceIndented :: (MonadDES m, EventIOQueueing m)
                                        => Handle
                                        -- ^ a handle
                                        -> Int
                                        -- ^ an indent
                                        -> ResultLocalisation
                                        -- ^ a localisation
                                        -> ResultSourcePrint m
{-# INLINABLE hEnqueuePrintingResultSourceIndented #-}
hEnqueuePrintingResultSourceIndented :: forall (m :: * -> *).
(MonadDES m, EventIOQueueing m) =>
Handle -> Int -> ResultLocalisation -> ResultSourcePrint m
hEnqueuePrintingResultSourceIndented Handle
h Int
indent ResultLocalisation
loc ResultSource m
source =
  do Double
t <- Dynamics m Double -> Event m Double
forall a. Dynamics m a -> Event m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
DynamicsLift t m =>
Dynamics m a -> t m a
liftDynamics Dynamics m Double
forall (m :: * -> *). Monad m => Dynamics m Double
time
     Double -> Event m () -> Event m ()
forall (m :: * -> *).
EventIOQueueing m =>
Double -> Event m () -> Event m ()
enqueueEventIO Double
t (Event m () -> Event m ()) -> Event m () -> Event m ()
forall a b. (a -> b) -> a -> b
$
       Handle -> Int -> ResultLocalisation -> ResultSourcePrint m
forall (m :: * -> *).
(MonadDES m, MonadIO (Event m)) =>
Handle -> Int -> ResultLocalisation -> ResultSourcePrint m
hPrintResultSourceIndented Handle
h Int
indent ResultLocalisation
loc ResultSource m
source

-- | Enqueue printing of a localised text representation of the results by the specified source
-- and with the given indent.
enqueuePrintingResultSourceIndented :: (MonadDES m, EventIOQueueing m)
                                       => Int
                                       -- ^ an indent
                                       -> ResultLocalisation
                                       -- ^ a localisation
                                       -> ResultSourcePrint m
{-# INLINABLE enqueuePrintingResultSourceIndented #-}
enqueuePrintingResultSourceIndented :: forall (m :: * -> *).
(MonadDES m, EventIOQueueing m) =>
Int -> ResultLocalisation -> ResultSourcePrint m
enqueuePrintingResultSourceIndented = Handle -> Int -> ResultLocalisation -> ResultSourcePrint m
forall (m :: * -> *).
(MonadDES m, EventIOQueueing m) =>
Handle -> Int -> ResultLocalisation -> ResultSourcePrint m
hEnqueuePrintingResultSourceIndented Handle
stdout

-- | Enqueue printing of a localised text representation of the results by the specified source.
hEnqueuePrintingResultSource :: (MonadDES m, EventIOQueueing m)
                                => Handle
                                -- ^ a handle
                                -> ResultLocalisation
                                -- ^ a localisation
                                -> ResultSourcePrint m
{-# INLINABLE hEnqueuePrintingResultSource #-}
hEnqueuePrintingResultSource :: forall (m :: * -> *).
(MonadDES m, EventIOQueueing m) =>
Handle -> ResultLocalisation -> ResultSourcePrint m
hEnqueuePrintingResultSource Handle
h = Handle -> Int -> ResultLocalisation -> ResultSourcePrint m
forall (m :: * -> *).
(MonadDES m, EventIOQueueing m) =>
Handle -> Int -> ResultLocalisation -> ResultSourcePrint m
hEnqueuePrintingResultSourceIndented Handle
h Int
0

-- | Enqueue printing of a localised text representation of the results by the specified source.
enqueuePrintingResultSource :: (MonadDES m, EventIOQueueing m)
                               => ResultLocalisation
                               -- ^ a localisation
                               -> ResultSourcePrint m
{-# INLINABLE enqueuePrintingResultSource #-}
enqueuePrintingResultSource :: forall (m :: * -> *).
(MonadDES m, EventIOQueueing m) =>
ResultLocalisation -> ResultSourcePrint m
enqueuePrintingResultSource = Handle -> ResultLocalisation -> ResultSourcePrint m
forall (m :: * -> *).
(MonadDES m, EventIOQueueing m) =>
Handle -> ResultLocalisation -> ResultSourcePrint m
hEnqueuePrintingResultSource Handle
stdout

-- | Enqueue printing in Russian of a text representation of the results by the specified source.
hEnqueuePrintingResultSourceInRussian :: (MonadDES m, EventIOQueueing m) => Handle -> ResultSourcePrint m
{-# INLINABLE hEnqueuePrintingResultSourceInRussian #-}
hEnqueuePrintingResultSourceInRussian :: forall (m :: * -> *).
(MonadDES m, EventIOQueueing m) =>
Handle -> ResultSourcePrint m
hEnqueuePrintingResultSourceInRussian Handle
h = Handle -> ResultLocalisation -> ResultSourcePrint m
forall (m :: * -> *).
(MonadDES m, EventIOQueueing m) =>
Handle -> ResultLocalisation -> ResultSourcePrint m
hEnqueuePrintingResultSource Handle
h ResultLocalisation
russianResultLocalisation

-- | Enqueue printing in English of a text representation of the results by the specified source.
hEnqueuePrintingResultSourceInEnglish :: (MonadDES m, EventIOQueueing m) => Handle -> ResultSourcePrint m
{-# INLINABLE hEnqueuePrintingResultSourceInEnglish #-}
hEnqueuePrintingResultSourceInEnglish :: forall (m :: * -> *).
(MonadDES m, EventIOQueueing m) =>
Handle -> ResultSourcePrint m
hEnqueuePrintingResultSourceInEnglish Handle
h = Handle -> ResultLocalisation -> ResultSourcePrint m
forall (m :: * -> *).
(MonadDES m, EventIOQueueing m) =>
Handle -> ResultLocalisation -> ResultSourcePrint m
hEnqueuePrintingResultSource Handle
h ResultLocalisation
englishResultLocalisation

-- | Enqueue printing in Russian of a text representation of the results by the specified source.
enqueuePrintingResultSourceInRussian :: (MonadDES m, EventIOQueueing m) => ResultSourcePrint m
{-# INLINABLE enqueuePrintingResultSourceInRussian #-}
enqueuePrintingResultSourceInRussian :: forall (m :: * -> *).
(MonadDES m, EventIOQueueing m) =>
ResultSourcePrint m
enqueuePrintingResultSourceInRussian = Handle -> ResultSourcePrint m
forall (m :: * -> *).
(MonadDES m, EventIOQueueing m) =>
Handle -> ResultSourcePrint m
hEnqueuePrintingResultSourceInRussian Handle
stdout

-- | Enqueue printing in English of a text representation of the results by the specified source.
enqueuePrintingResultSourceInEnglish :: (MonadDES m, EventIOQueueing m) => ResultSourcePrint m
{-# INLINABLE enqueuePrintingResultSourceInEnglish #-}
enqueuePrintingResultSourceInEnglish :: forall (m :: * -> *).
(MonadDES m, EventIOQueueing m) =>
ResultSourcePrint m
enqueuePrintingResultSourceInEnglish = Handle -> ResultSourcePrint m
forall (m :: * -> *).
(MonadDES m, EventIOQueueing m) =>
Handle -> ResultSourcePrint m
hEnqueuePrintingResultSourceInEnglish Handle
stdout

-- | Show a localised text representation of the results by the specified source
-- and with the given indent.
showResultSourceIndented :: MonadDES m
                            => Int
                            -- ^ an indent
                            -> ResultLocalisation
                            -- ^ a localisation
                            -> ResultSourceShowS m
{-# INLINABLE showResultSourceIndented #-}
showResultSourceIndented :: forall (m :: * -> *).
MonadDES m =>
Int -> ResultLocalisation -> ResultSourceShowS m
showResultSourceIndented Int
indent ResultLocalisation
loc source :: ResultSource m
source@(ResultItemSource (ResultItem a m
x)) =
  Int -> ResultName -> ResultLocalisation -> ResultSourceShowS m
forall (m :: * -> *).
MonadDES m =>
Int -> ResultName -> ResultLocalisation -> ResultSourceShowS m
showResultSourceIndentedLabelled Int
indent (a m -> ResultName
forall (m :: * -> *). a m -> ResultName
forall (a :: (* -> *) -> *) (m :: * -> *).
ResultItemable a =>
a m -> ResultName
resultItemName a m
x) ResultLocalisation
loc ResultSource m
source
showResultSourceIndented Int
indent ResultLocalisation
loc source :: ResultSource m
source@(ResultVectorSource ResultVector m
x) =
  Int -> ResultName -> ResultLocalisation -> ResultSourceShowS m
forall (m :: * -> *).
MonadDES m =>
Int -> ResultName -> ResultLocalisation -> ResultSourceShowS m
showResultSourceIndentedLabelled Int
indent (ResultVector m -> ResultName
forall (m :: * -> *). ResultVector m -> ResultName
resultVectorName ResultVector m
x) ResultLocalisation
loc ResultSource m
source
showResultSourceIndented Int
indent ResultLocalisation
loc source :: ResultSource m
source@(ResultObjectSource ResultObject m
x) =
  Int -> ResultName -> ResultLocalisation -> ResultSourceShowS m
forall (m :: * -> *).
MonadDES m =>
Int -> ResultName -> ResultLocalisation -> ResultSourceShowS m
showResultSourceIndentedLabelled Int
indent (ResultObject m -> ResultName
forall (m :: * -> *). ResultObject m -> ResultName
resultObjectName ResultObject m
x) ResultLocalisation
loc ResultSource m
source
showResultSourceIndented Int
indent ResultLocalisation
loc source :: ResultSource m
source@(ResultSeparatorSource ResultSeparator
x) =
  Int -> ResultName -> ResultLocalisation -> ResultSourceShowS m
forall (m :: * -> *).
MonadDES m =>
Int -> ResultName -> ResultLocalisation -> ResultSourceShowS m
showResultSourceIndentedLabelled Int
indent (ResultSeparator -> ResultName
resultSeparatorText ResultSeparator
x) ResultLocalisation
loc ResultSource m
source

-- | Show an indented and labelled text representation of the results by the specified source.
showResultSourceIndentedLabelled :: MonadDES m
                                    => Int
                                    -- ^ an indent
                                    -> String
                                    -- ^ a label
                                    -> ResultLocalisation
                                    -- ^ a localisation
                                    -> ResultSourceShowS m
{-# INLINABLE showResultSourceIndentedLabelled #-}
showResultSourceIndentedLabelled :: forall (m :: * -> *).
MonadDES m =>
Int -> ResultName -> ResultLocalisation -> ResultSourceShowS m
showResultSourceIndentedLabelled Int
indent ResultName
label ResultLocalisation
loc (ResultItemSource (ResultItem a m
x)) =
  do ResultName
a <- ResultValue ResultName m -> ResultData ResultName m
forall e (m :: * -> *). ResultValue e m -> ResultData e m
resultValueData (ResultValue ResultName m -> ResultData ResultName m)
-> ResultValue ResultName m -> ResultData ResultName m
forall a b. (a -> b) -> a -> b
$ a m -> ResultValue ResultName m
forall (m :: * -> *) (a :: (* -> *) -> *).
(MonadDES m, ResultItemable a) =>
a m -> ResultValue ResultName m
resultItemToStringValue a m
x
     let tab :: ResultName
tab = Int -> Char -> ResultName
forall a. Int -> a -> [a]
replicate Int
indent Char
' '
     (ResultName -> ResultName) -> Event m (ResultName -> ResultName)
forall a. a -> Event m a
forall (m :: * -> *) a. Monad m => a -> m a
return ((ResultName -> ResultName) -> Event m (ResultName -> ResultName))
-> (ResultName -> ResultName) -> Event m (ResultName -> ResultName)
forall a b. (a -> b) -> a -> b
$
       ResultName -> ResultName -> ResultName
showString ResultName
tab (ResultName -> ResultName)
-> (ResultName -> ResultName) -> ResultName -> ResultName
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       ResultName -> ResultName -> ResultName
showString ResultName
"-- " (ResultName -> ResultName)
-> (ResultName -> ResultName) -> ResultName -> ResultName
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       ResultName -> ResultName -> ResultName
showString (ResultLocalisation -> ResultId -> ResultName
localiseResultDescription ResultLocalisation
loc (ResultId -> ResultName) -> ResultId -> ResultName
forall a b. (a -> b) -> a -> b
$ a m -> ResultId
forall (m :: * -> *). a m -> ResultId
forall (a :: (* -> *) -> *) (m :: * -> *).
ResultItemable a =>
a m -> ResultId
resultItemId a m
x) (ResultName -> ResultName)
-> (ResultName -> ResultName) -> ResultName -> ResultName
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       ResultName -> ResultName -> ResultName
showString ResultName
"\n" (ResultName -> ResultName)
-> (ResultName -> ResultName) -> ResultName -> ResultName
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       ResultName -> ResultName -> ResultName
showString ResultName
tab (ResultName -> ResultName)
-> (ResultName -> ResultName) -> ResultName -> ResultName
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       ResultName -> ResultName -> ResultName
showString ResultName
label (ResultName -> ResultName)
-> (ResultName -> ResultName) -> ResultName -> ResultName
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       ResultName -> ResultName -> ResultName
showString ResultName
" = " (ResultName -> ResultName)
-> (ResultName -> ResultName) -> ResultName -> ResultName
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       ResultName -> ResultName -> ResultName
showString ResultName
a (ResultName -> ResultName)
-> (ResultName -> ResultName) -> ResultName -> ResultName
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       ResultName -> ResultName -> ResultName
showString ResultName
"\n\n"
showResultSourceIndentedLabelled Int
indent ResultName
label ResultLocalisation
loc (ResultVectorSource ResultVector m
x) =
  do let tab :: ResultName
tab = Int -> Char -> ResultName
forall a. Int -> a -> [a]
replicate Int
indent Char
' '
         items :: [ResultSource m]
items = Array Int (ResultSource m) -> [ResultSource m]
forall i e. Array i e -> [e]
A.elems (ResultVector m -> Array Int (ResultSource m)
forall (m :: * -> *). ResultVector m -> Array Int (ResultSource m)
resultVectorItems ResultVector m
x)
         subscript :: [ResultName]
subscript = Array Int ResultName -> [ResultName]
forall i e. Array i e -> [e]
A.elems (ResultVector m -> Array Int ResultName
forall (m :: * -> *). ResultVector m -> Array Int ResultName
resultVectorSubscript ResultVector m
x)
     [ResultName -> ResultName]
contents <-
       [(ResultSource m, ResultName)]
-> ((ResultSource m, ResultName)
    -> Event m (ResultName -> ResultName))
-> Event m [ResultName -> ResultName]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM ([ResultSource m] -> [ResultName] -> [(ResultSource m, ResultName)]
forall a b. [a] -> [b] -> [(a, b)]
zip [ResultSource m]
items [ResultName]
subscript) (((ResultSource m, ResultName)
  -> Event m (ResultName -> ResultName))
 -> Event m [ResultName -> ResultName])
-> ((ResultSource m, ResultName)
    -> Event m (ResultName -> ResultName))
-> Event m [ResultName -> ResultName]
forall a b. (a -> b) -> a -> b
$ \(ResultSource m
i, ResultName
s) ->
       Int -> ResultName -> ResultLocalisation -> ResultSourceShowS m
forall (m :: * -> *).
MonadDES m =>
Int -> ResultName -> ResultLocalisation -> ResultSourceShowS m
showResultSourceIndentedLabelled (Int
indent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
2) (ResultName
label ResultName -> ResultName -> ResultName
forall a. [a] -> [a] -> [a]
++ ResultName
s) ResultLocalisation
loc ResultSource m
i
     let showContents :: ResultName -> ResultName
showContents = ((ResultName -> ResultName)
 -> (ResultName -> ResultName) -> ResultName -> ResultName)
-> (ResultName -> ResultName)
-> [ResultName -> ResultName]
-> ResultName
-> ResultName
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (ResultName -> ResultName)
-> (ResultName -> ResultName) -> ResultName -> ResultName
forall b c a. (b -> c) -> (a -> b) -> a -> c
(.) ResultName -> ResultName
forall a. a -> a
id [ResultName -> ResultName]
contents
     (ResultName -> ResultName) -> Event m (ResultName -> ResultName)
forall a. a -> Event m a
forall (m :: * -> *) a. Monad m => a -> m a
return ((ResultName -> ResultName) -> Event m (ResultName -> ResultName))
-> (ResultName -> ResultName) -> Event m (ResultName -> ResultName)
forall a b. (a -> b) -> a -> b
$
       ResultName -> ResultName -> ResultName
showString ResultName
tab (ResultName -> ResultName)
-> (ResultName -> ResultName) -> ResultName -> ResultName
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       ResultName -> ResultName -> ResultName
showString ResultName
"-- " (ResultName -> ResultName)
-> (ResultName -> ResultName) -> ResultName -> ResultName
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       ResultName -> ResultName -> ResultName
showString (ResultLocalisation -> ResultId -> ResultName
localiseResultDescription ResultLocalisation
loc (ResultId -> ResultName) -> ResultId -> ResultName
forall a b. (a -> b) -> a -> b
$ ResultVector m -> ResultId
forall (m :: * -> *). ResultVector m -> ResultId
resultVectorId ResultVector m
x) (ResultName -> ResultName)
-> (ResultName -> ResultName) -> ResultName -> ResultName
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       ResultName -> ResultName -> ResultName
showString ResultName
"\n" (ResultName -> ResultName)
-> (ResultName -> ResultName) -> ResultName -> ResultName
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       ResultName -> ResultName -> ResultName
showString ResultName
tab (ResultName -> ResultName)
-> (ResultName -> ResultName) -> ResultName -> ResultName
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       ResultName -> ResultName -> ResultName
showString ResultName
label (ResultName -> ResultName)
-> (ResultName -> ResultName) -> ResultName -> ResultName
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       ResultName -> ResultName -> ResultName
showString ResultName
":\n\n" (ResultName -> ResultName)
-> (ResultName -> ResultName) -> ResultName -> ResultName
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       ResultName -> ResultName
showContents
showResultSourceIndentedLabelled Int
indent ResultName
label ResultLocalisation
loc (ResultObjectSource ResultObject m
x) =
  do let tab :: ResultName
tab = Int -> Char -> ResultName
forall a. Int -> a -> [a]
replicate Int
indent Char
' '
     [ResultName -> ResultName]
contents <-
       [ResultProperty m]
-> (ResultProperty m -> Event m (ResultName -> ResultName))
-> Event m [ResultName -> ResultName]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM (ResultObject m -> [ResultProperty m]
forall (m :: * -> *). ResultObject m -> [ResultProperty m]
resultObjectProperties ResultObject m
x) ((ResultProperty m -> Event m (ResultName -> ResultName))
 -> Event m [ResultName -> ResultName])
-> (ResultProperty m -> Event m (ResultName -> ResultName))
-> Event m [ResultName -> ResultName]
forall a b. (a -> b) -> a -> b
$ \ResultProperty m
p ->
       do let indent' :: Int
indent' = Int
2 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
indent
              tab' :: ResultName
tab'    = ResultName
"  " ResultName -> ResultName -> ResultName
forall a. [a] -> [a] -> [a]
++ ResultName
tab
              label' :: ResultName
label'  = ResultProperty m -> ResultName
forall (m :: * -> *). ResultProperty m -> ResultName
resultPropertyLabel ResultProperty m
p
              output' :: ResultSource m
output' = ResultProperty m -> ResultSource m
forall (m :: * -> *). ResultProperty m -> ResultSource m
resultPropertySource ResultProperty m
p
          Int -> ResultName -> ResultLocalisation -> ResultSourceShowS m
forall (m :: * -> *).
MonadDES m =>
Int -> ResultName -> ResultLocalisation -> ResultSourceShowS m
showResultSourceIndentedLabelled Int
indent' ResultName
label' ResultLocalisation
loc ResultSource m
output'
     let showContents :: ResultName -> ResultName
showContents = ((ResultName -> ResultName)
 -> (ResultName -> ResultName) -> ResultName -> ResultName)
-> (ResultName -> ResultName)
-> [ResultName -> ResultName]
-> ResultName
-> ResultName
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (ResultName -> ResultName)
-> (ResultName -> ResultName) -> ResultName -> ResultName
forall b c a. (b -> c) -> (a -> b) -> a -> c
(.) ResultName -> ResultName
forall a. a -> a
id [ResultName -> ResultName]
contents
     (ResultName -> ResultName) -> Event m (ResultName -> ResultName)
forall a. a -> Event m a
forall (m :: * -> *) a. Monad m => a -> m a
return ((ResultName -> ResultName) -> Event m (ResultName -> ResultName))
-> (ResultName -> ResultName) -> Event m (ResultName -> ResultName)
forall a b. (a -> b) -> a -> b
$
       ResultName -> ResultName -> ResultName
showString ResultName
tab (ResultName -> ResultName)
-> (ResultName -> ResultName) -> ResultName -> ResultName
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       ResultName -> ResultName -> ResultName
showString ResultName
"-- " (ResultName -> ResultName)
-> (ResultName -> ResultName) -> ResultName -> ResultName
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       ResultName -> ResultName -> ResultName
showString (ResultLocalisation -> ResultId -> ResultName
localiseResultDescription ResultLocalisation
loc (ResultId -> ResultName) -> ResultId -> ResultName
forall a b. (a -> b) -> a -> b
$ ResultObject m -> ResultId
forall (m :: * -> *). ResultObject m -> ResultId
resultObjectId ResultObject m
x) (ResultName -> ResultName)
-> (ResultName -> ResultName) -> ResultName -> ResultName
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       ResultName -> ResultName -> ResultName
showString ResultName
"\n" (ResultName -> ResultName)
-> (ResultName -> ResultName) -> ResultName -> ResultName
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       ResultName -> ResultName -> ResultName
showString ResultName
tab (ResultName -> ResultName)
-> (ResultName -> ResultName) -> ResultName -> ResultName
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       ResultName -> ResultName -> ResultName
showString ResultName
label (ResultName -> ResultName)
-> (ResultName -> ResultName) -> ResultName -> ResultName
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       ResultName -> ResultName -> ResultName
showString ResultName
":\n\n" (ResultName -> ResultName)
-> (ResultName -> ResultName) -> ResultName -> ResultName
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       ResultName -> ResultName
showContents
showResultSourceIndentedLabelled Int
indent ResultName
label ResultLocalisation
loc (ResultSeparatorSource ResultSeparator
x) =
  do let tab :: ResultName
tab = Int -> Char -> ResultName
forall a. Int -> a -> [a]
replicate Int
indent Char
' '
     (ResultName -> ResultName) -> Event m (ResultName -> ResultName)
forall a. a -> Event m a
forall (m :: * -> *) a. Monad m => a -> m a
return ((ResultName -> ResultName) -> Event m (ResultName -> ResultName))
-> (ResultName -> ResultName) -> Event m (ResultName -> ResultName)
forall a b. (a -> b) -> a -> b
$
       ResultName -> ResultName -> ResultName
showString ResultName
tab (ResultName -> ResultName)
-> (ResultName -> ResultName) -> ResultName -> ResultName
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       ResultName -> ResultName -> ResultName
showString ResultName
label (ResultName -> ResultName)
-> (ResultName -> ResultName) -> ResultName -> ResultName
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       ResultName -> ResultName -> ResultName
showString ResultName
"\n\n"

-- | Show a localised text representation of the results by the specified source.
showResultSource :: MonadDES m
                    => ResultLocalisation
                    -- ^ a localisation
                    -> ResultSourceShowS m
{-# INLINABLE showResultSource #-}
showResultSource :: forall (m :: * -> *).
MonadDES m =>
ResultLocalisation -> ResultSourceShowS m
showResultSource = Int -> ResultLocalisation -> ResultSourceShowS m
forall (m :: * -> *).
MonadDES m =>
Int -> ResultLocalisation -> ResultSourceShowS m
showResultSourceIndented Int
0

-- | Show in Russian a text representation of the results by the specified source.
showResultSourceInRussian :: MonadDES m => ResultSourceShowS m
{-# INLINABLE showResultSourceInRussian #-}
showResultSourceInRussian :: forall (m :: * -> *). MonadDES m => ResultSourceShowS m
showResultSourceInRussian = ResultLocalisation -> ResultSourceShowS m
forall (m :: * -> *).
MonadDES m =>
ResultLocalisation -> ResultSourceShowS m
showResultSource ResultLocalisation
russianResultLocalisation

-- | Show in English a text representation of the results by the specified source.
showResultSourceInEnglish :: MonadDES m => ResultSourceShowS m
{-# INLINABLE showResultSourceInEnglish #-}
showResultSourceInEnglish :: forall (m :: * -> *). MonadDES m => ResultSourceShowS m
showResultSourceInEnglish = ResultLocalisation -> ResultSourceShowS m
forall (m :: * -> *).
MonadDES m =>
ResultLocalisation -> ResultSourceShowS m
showResultSource ResultLocalisation
englishResultLocalisation

-- | Print the results with the information about the modeling time.
printResultsWithTime :: (MonadDES m, MonadIO (Event m)) => ResultSourcePrint m -> Results m -> Event m ()
{-# INLINABLE printResultsWithTime #-}
printResultsWithTime :: forall (m :: * -> *).
(MonadDES m, MonadIO (Event m)) =>
ResultSourcePrint m -> Results m -> Event m ()
printResultsWithTime ResultSourcePrint m
print Results m
results =
  do let x1 :: ResultSource m
x1 = ResultName -> ResultSource m
forall (m :: * -> *). ResultName -> ResultSource m
textResultSource ResultName
"----------"
         x2 :: ResultSource m
x2 = ResultSource m
forall (m :: * -> *). MonadDES m => ResultSource m
timeResultSource
         x3 :: ResultSource m
x3 = ResultName -> ResultSource m
forall (m :: * -> *). ResultName -> ResultSource m
textResultSource ResultName
""
         xs :: [ResultSource m]
xs = Results m -> [ResultSource m]
forall (m :: * -> *). Results m -> [ResultSource m]
resultSourceList Results m
results
     ResultSourcePrint m
print ResultSource m
forall {m :: * -> *}. ResultSource m
x1
     ResultSourcePrint m
print ResultSource m
x2
     -- print x3
     ResultSourcePrint m -> [ResultSource m] -> Event m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ ResultSourcePrint m
print [ResultSource m]
xs
     -- print x3

-- | Print the simulation results in start time.
printResultsInStartTime :: (MonadDES m, EventIOQueueing m) => ResultSourcePrint m -> Results m -> Simulation m ()
{-# INLINABLE printResultsInStartTime #-}
printResultsInStartTime :: forall (m :: * -> *).
(MonadDES m, EventIOQueueing m) =>
ResultSourcePrint m -> Results m -> Simulation m ()
printResultsInStartTime ResultSourcePrint m
print Results m
results =
  do Event m () -> Simulation m ()
forall (m :: * -> *) a. MonadDES m => Event m a -> Simulation m a
runEventInStartTime (Event m () -> Simulation m ()) -> Event m () -> Simulation m ()
forall a b. (a -> b) -> a -> b
$
       Event m () -> Event m ()
forall (m :: * -> *).
(MonadDES m, EventIOQueueing m) =>
Event m () -> Event m ()
enqueueEventIOWithStartTime (Event m () -> Event m ()) -> Event m () -> Event m ()
forall a b. (a -> b) -> a -> b
$
       ResultSourcePrint m -> Results m -> Event m ()
forall (m :: * -> *).
(MonadDES m, MonadIO (Event m)) =>
ResultSourcePrint m -> Results m -> Event m ()
printResultsWithTime ResultSourcePrint m
print Results m
results
     Event m () -> Simulation m ()
forall (m :: * -> *) a. MonadDES m => Event m a -> Simulation m a
runEventInStopTime (Event m () -> Simulation m ()) -> Event m () -> Simulation m ()
forall a b. (a -> b) -> a -> b
$
       () -> Event m ()
forall a. a -> Event m a
forall (m :: * -> *) a. Monad m => a -> m a
return ()

-- | Print the simulation results in stop time.
printResultsInStopTime :: (MonadDES m, EventIOQueueing m) => ResultSourcePrint m -> Results m -> Simulation m ()
{-# INLINABLE printResultsInStopTime #-}
printResultsInStopTime :: forall (m :: * -> *).
(MonadDES m, EventIOQueueing m) =>
ResultSourcePrint m -> Results m -> Simulation m ()
printResultsInStopTime ResultSourcePrint m
print Results m
results =
  do Event m () -> Simulation m ()
forall (m :: * -> *) a. MonadDES m => Event m a -> Simulation m a
runEventInStartTime (Event m () -> Simulation m ()) -> Event m () -> Simulation m ()
forall a b. (a -> b) -> a -> b
$
       Event m () -> Event m ()
forall (m :: * -> *).
(MonadDES m, EventIOQueueing m) =>
Event m () -> Event m ()
enqueueEventIOWithStopTime (Event m () -> Event m ()) -> Event m () -> Event m ()
forall a b. (a -> b) -> a -> b
$
       ResultSourcePrint m -> Results m -> Event m ()
forall (m :: * -> *).
(MonadDES m, MonadIO (Event m)) =>
ResultSourcePrint m -> Results m -> Event m ()
printResultsWithTime ResultSourcePrint m
print Results m
results
     Event m () -> Simulation m ()
forall (m :: * -> *) a. MonadDES m => Event m a -> Simulation m a
runEventInStopTime (Event m () -> Simulation m ()) -> Event m () -> Simulation m ()
forall a b. (a -> b) -> a -> b
$
       () -> Event m ()
forall a. a -> Event m a
forall (m :: * -> *) a. Monad m => a -> m a
return ()

-- | Print the simulation results in the integration time points.
printResultsInIntegTimes :: (MonadDES m, EventIOQueueing m) => ResultSourcePrint m -> Results m -> Simulation m ()
{-# INLINABLE printResultsInIntegTimes #-}
printResultsInIntegTimes :: forall (m :: * -> *).
(MonadDES m, EventIOQueueing m) =>
ResultSourcePrint m -> Results m -> Simulation m ()
printResultsInIntegTimes ResultSourcePrint m
print Results m
results =
  do Event m () -> Simulation m ()
forall (m :: * -> *) a. MonadDES m => Event m a -> Simulation m a
runEventInStartTime (Event m () -> Simulation m ()) -> Event m () -> Simulation m ()
forall a b. (a -> b) -> a -> b
$
       Event m () -> Event m ()
forall (m :: * -> *).
(MonadDES m, EventIOQueueing m) =>
Event m () -> Event m ()
enqueueEventIOWithIntegTimes (Event m () -> Event m ()) -> Event m () -> Event m ()
forall a b. (a -> b) -> a -> b
$
       ResultSourcePrint m -> Results m -> Event m ()
forall (m :: * -> *).
(MonadDES m, MonadIO (Event m)) =>
ResultSourcePrint m -> Results m -> Event m ()
printResultsWithTime ResultSourcePrint m
print Results m
results
     Event m () -> Simulation m ()
forall (m :: * -> *) a. MonadDES m => Event m a -> Simulation m a
runEventInStopTime (Event m () -> Simulation m ()) -> Event m () -> Simulation m ()
forall a b. (a -> b) -> a -> b
$
       () -> Event m ()
forall a. a -> Event m a
forall (m :: * -> *) a. Monad m => a -> m a
return ()

-- | Print the simulation results in the specified time.
printResultsInTime :: (MonadDES m, EventIOQueueing m) => Double -> ResultSourcePrint m -> Results m -> Simulation m ()
{-# INLINABLE printResultsInTime #-}
printResultsInTime :: forall (m :: * -> *).
(MonadDES m, EventIOQueueing m) =>
Double -> ResultSourcePrint m -> Results m -> Simulation m ()
printResultsInTime Double
t ResultSourcePrint m
print Results m
results =
  do Event m () -> Simulation m ()
forall (m :: * -> *) a. MonadDES m => Event m a -> Simulation m a
runEventInStartTime (Event m () -> Simulation m ()) -> Event m () -> Simulation m ()
forall a b. (a -> b) -> a -> b
$
       Double -> Event m () -> Event m ()
forall (m :: * -> *).
EventIOQueueing m =>
Double -> Event m () -> Event m ()
enqueueEventIO Double
t (Event m () -> Event m ()) -> Event m () -> Event m ()
forall a b. (a -> b) -> a -> b
$
       ResultSourcePrint m -> Results m -> Event m ()
forall (m :: * -> *).
(MonadDES m, MonadIO (Event m)) =>
ResultSourcePrint m -> Results m -> Event m ()
printResultsWithTime ResultSourcePrint m
print Results m
results
     Event m () -> Simulation m ()
forall (m :: * -> *) a. MonadDES m => Event m a -> Simulation m a
runEventInStopTime (Event m () -> Simulation m ()) -> Event m () -> Simulation m ()
forall a b. (a -> b) -> a -> b
$
       () -> Event m ()
forall a. a -> Event m a
forall (m :: * -> *) a. Monad m => a -> m a
return ()

-- | Print the simulation results in the specified time points.
printResultsInTimes :: (MonadDES m, EventIOQueueing m) => [Double] -> ResultSourcePrint m -> Results m -> Simulation m ()
{-# INLINABLE printResultsInTimes #-}
printResultsInTimes :: forall (m :: * -> *).
(MonadDES m, EventIOQueueing m) =>
[Double] -> ResultSourcePrint m -> Results m -> Simulation m ()
printResultsInTimes [Double]
ts ResultSourcePrint m
print Results m
results =
  do Event m () -> Simulation m ()
forall (m :: * -> *) a. MonadDES m => Event m a -> Simulation m a
runEventInStartTime (Event m () -> Simulation m ()) -> Event m () -> Simulation m ()
forall a b. (a -> b) -> a -> b
$
       [Double] -> Event m () -> Event m ()
forall (m :: * -> *).
(MonadDES m, EventIOQueueing m) =>
[Double] -> Event m () -> Event m ()
enqueueEventIOWithTimes [Double]
ts (Event m () -> Event m ()) -> Event m () -> Event m ()
forall a b. (a -> b) -> a -> b
$
       ResultSourcePrint m -> Results m -> Event m ()
forall (m :: * -> *).
(MonadDES m, MonadIO (Event m)) =>
ResultSourcePrint m -> Results m -> Event m ()
printResultsWithTime ResultSourcePrint m
print Results m
results
     Event m () -> Simulation m ()
forall (m :: * -> *) a. MonadDES m => Event m a -> Simulation m a
runEventInStopTime (Event m () -> Simulation m ()) -> Event m () -> Simulation m ()
forall a b. (a -> b) -> a -> b
$
       () -> Event m ()
forall a. a -> Event m a
forall (m :: * -> *) a. Monad m => a -> m a
return ()

-- | Show the results with the information about the modeling time.
showResultsWithTime :: MonadDES m => ResultSourceShowS m -> Results m -> Event m ShowS
{-# INLINABLE showResultsWithTime #-}
showResultsWithTime :: forall (m :: * -> *).
MonadDES m =>
ResultSourceShowS m
-> Results m -> Event m (ResultName -> ResultName)
showResultsWithTime ResultSourceShowS m
f Results m
results =
  do let x1 :: ResultSource m
x1 = ResultName -> ResultSource m
forall (m :: * -> *). ResultName -> ResultSource m
textResultSource ResultName
"----------"
         x2 :: ResultSource m
x2 = ResultSource m
forall (m :: * -> *). MonadDES m => ResultSource m
timeResultSource
         x3 :: ResultSource m
x3 = ResultName -> ResultSource m
forall (m :: * -> *). ResultName -> ResultSource m
textResultSource ResultName
""
         xs :: [ResultSource m]
xs = Results m -> [ResultSource m]
forall (m :: * -> *). Results m -> [ResultSource m]
resultSourceList Results m
results
     ResultName -> ResultName
y1 <- ResultSourceShowS m
f ResultSource m
forall {m :: * -> *}. ResultSource m
x1
     ResultName -> ResultName
y2 <- ResultSourceShowS m
f ResultSource m
x2
     ResultName -> ResultName
y3 <- ResultSourceShowS m
f ResultSource m
forall {m :: * -> *}. ResultSource m
x3
     [ResultName -> ResultName]
ys <- [ResultSource m]
-> ResultSourceShowS m -> Event m [ResultName -> ResultName]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM [ResultSource m]
xs ResultSourceShowS m
f
     (ResultName -> ResultName) -> Event m (ResultName -> ResultName)
forall a. a -> Event m a
forall (m :: * -> *) a. Monad m => a -> m a
return ((ResultName -> ResultName) -> Event m (ResultName -> ResultName))
-> (ResultName -> ResultName) -> Event m (ResultName -> ResultName)
forall a b. (a -> b) -> a -> b
$
       ResultName -> ResultName
y1 (ResultName -> ResultName)
-> (ResultName -> ResultName) -> ResultName -> ResultName
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       ResultName -> ResultName
y2 (ResultName -> ResultName)
-> (ResultName -> ResultName) -> ResultName -> ResultName
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       -- y3 .
       ((ResultName -> ResultName)
 -> (ResultName -> ResultName) -> ResultName -> ResultName)
-> (ResultName -> ResultName)
-> [ResultName -> ResultName]
-> ResultName
-> ResultName
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (ResultName -> ResultName)
-> (ResultName -> ResultName) -> ResultName -> ResultName
forall b c a. (b -> c) -> (a -> b) -> a -> c
(.) ResultName -> ResultName
forall a. a -> a
id [ResultName -> ResultName]
ys
       -- y3

-- | Show the simulation results in start time.
showResultsInStartTime :: MonadDES m => ResultSourceShowS m -> Results m -> Simulation m ShowS
{-# INLINABLE showResultsInStartTime #-}
showResultsInStartTime :: forall (m :: * -> *).
MonadDES m =>
ResultSourceShowS m
-> Results m -> Simulation m (ResultName -> ResultName)
showResultsInStartTime ResultSourceShowS m
f Results m
results =
  do ResultName -> ResultName
g <- Event m (ResultName -> ResultName)
-> Simulation m (ResultName -> ResultName)
forall (m :: * -> *) a. MonadDES m => Event m a -> Simulation m a
runEventInStartTime (Event m (ResultName -> ResultName)
 -> Simulation m (ResultName -> ResultName))
-> Event m (ResultName -> ResultName)
-> Simulation m (ResultName -> ResultName)
forall a b. (a -> b) -> a -> b
$ ResultSourceShowS m
-> Results m -> Event m (ResultName -> ResultName)
forall (m :: * -> *).
MonadDES m =>
ResultSourceShowS m
-> Results m -> Event m (ResultName -> ResultName)
showResultsWithTime ResultSourceShowS m
f Results m
results
     Event m (ResultName -> ResultName)
-> Simulation m (ResultName -> ResultName)
forall (m :: * -> *) a. MonadDES m => Event m a -> Simulation m a
runEventInStopTime (Event m (ResultName -> ResultName)
 -> Simulation m (ResultName -> ResultName))
-> Event m (ResultName -> ResultName)
-> Simulation m (ResultName -> ResultName)
forall a b. (a -> b) -> a -> b
$ (ResultName -> ResultName) -> Event m (ResultName -> ResultName)
forall a. a -> Event m a
forall (m :: * -> *) a. Monad m => a -> m a
return ResultName -> ResultName
g

-- | Show the simulation results in stop time.
showResultsInStopTime :: MonadDES m => ResultSourceShowS m -> Results m -> Simulation m ShowS
{-# INLINABLE showResultsInStopTime #-}
showResultsInStopTime :: forall (m :: * -> *).
MonadDES m =>
ResultSourceShowS m
-> Results m -> Simulation m (ResultName -> ResultName)
showResultsInStopTime ResultSourceShowS m
f Results m
results =
  Event m (ResultName -> ResultName)
-> Simulation m (ResultName -> ResultName)
forall (m :: * -> *) a. MonadDES m => Event m a -> Simulation m a
runEventInStopTime (Event m (ResultName -> ResultName)
 -> Simulation m (ResultName -> ResultName))
-> Event m (ResultName -> ResultName)
-> Simulation m (ResultName -> ResultName)
forall a b. (a -> b) -> a -> b
$ ResultSourceShowS m
-> Results m -> Event m (ResultName -> ResultName)
forall (m :: * -> *).
MonadDES m =>
ResultSourceShowS m
-> Results m -> Event m (ResultName -> ResultName)
showResultsWithTime ResultSourceShowS m
f Results m
results

-- | Show the simulation results in the integration time points.
--
-- It may consume much memory, for we have to traverse all the integration
-- points to create the resulting function within the 'Simulation' computation.
showResultsInIntegTimes :: MonadDES m => ResultSourceShowS m -> Results m -> Simulation m ShowS
{-# INLINABLE showResultsInIntegTimes #-}
showResultsInIntegTimes :: forall (m :: * -> *).
MonadDES m =>
ResultSourceShowS m
-> Results m -> Simulation m (ResultName -> ResultName)
showResultsInIntegTimes ResultSourceShowS m
f Results m
results =
  do Ref m (ResultName -> ResultName)
r <- (ResultName -> ResultName)
-> Simulation m (Ref m (ResultName -> ResultName))
forall (m :: * -> *) a. MonadDES m => a -> Simulation m (Ref m a)
newRef ResultName -> ResultName
forall a. a -> a
id
     Event m () -> Simulation m ()
forall (m :: * -> *) a. MonadDES m => Event m a -> Simulation m a
runEventInStartTime (Event m () -> Simulation m ()) -> Event m () -> Simulation m ()
forall a b. (a -> b) -> a -> b
$
       Event m () -> Event m ()
forall (m :: * -> *). MonadDES m => Event m () -> Event m ()
enqueueEventWithIntegTimes (Event m () -> Event m ()) -> Event m () -> Event m ()
forall a b. (a -> b) -> a -> b
$
       do ResultName -> ResultName
g <- ResultSourceShowS m
-> Results m -> Event m (ResultName -> ResultName)
forall (m :: * -> *).
MonadDES m =>
ResultSourceShowS m
-> Results m -> Event m (ResultName -> ResultName)
showResultsWithTime ResultSourceShowS m
f Results m
results
          Ref m (ResultName -> ResultName)
-> ((ResultName -> ResultName) -> ResultName -> ResultName)
-> Event m ()
forall (m :: * -> *) a.
MonadDES m =>
Ref m a -> (a -> a) -> Event m ()
modifyRef Ref m (ResultName -> ResultName)
r ((ResultName -> ResultName)
-> (ResultName -> ResultName) -> ResultName -> ResultName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ResultName -> ResultName
g)
     Event m (ResultName -> ResultName)
-> Simulation m (ResultName -> ResultName)
forall (m :: * -> *) a. MonadDES m => Event m a -> Simulation m a
runEventInStopTime (Event m (ResultName -> ResultName)
 -> Simulation m (ResultName -> ResultName))
-> Event m (ResultName -> ResultName)
-> Simulation m (ResultName -> ResultName)
forall a b. (a -> b) -> a -> b
$
       Ref m (ResultName -> ResultName)
-> Event m (ResultName -> ResultName)
forall (m :: * -> *) a. MonadDES m => Ref m a -> Event m a
readRef Ref m (ResultName -> ResultName)
r

-- | Show the simulation results in the specified time point.
showResultsInTime :: MonadDES m => Double -> ResultSourceShowS m -> Results m -> Simulation m ShowS
{-# INLINABLE showResultsInTime #-}
showResultsInTime :: forall (m :: * -> *).
MonadDES m =>
Double
-> ResultSourceShowS m
-> Results m
-> Simulation m (ResultName -> ResultName)
showResultsInTime Double
t ResultSourceShowS m
f Results m
results =
  do Ref m (ResultName -> ResultName)
r <- (ResultName -> ResultName)
-> Simulation m (Ref m (ResultName -> ResultName))
forall (m :: * -> *) a. MonadDES m => a -> Simulation m (Ref m a)
newRef ResultName -> ResultName
forall a. a -> a
id
     Event m () -> Simulation m ()
forall (m :: * -> *) a. MonadDES m => Event m a -> Simulation m a
runEventInStartTime (Event m () -> Simulation m ()) -> Event m () -> Simulation m ()
forall a b. (a -> b) -> a -> b
$
       Double -> Event m () -> Event m ()
forall (m :: * -> *).
EventQueueing m =>
Double -> Event m () -> Event m ()
enqueueEvent Double
t (Event m () -> Event m ()) -> Event m () -> Event m ()
forall a b. (a -> b) -> a -> b
$
       do ResultName -> ResultName
g <- ResultSourceShowS m
-> Results m -> Event m (ResultName -> ResultName)
forall (m :: * -> *).
MonadDES m =>
ResultSourceShowS m
-> Results m -> Event m (ResultName -> ResultName)
showResultsWithTime ResultSourceShowS m
f Results m
results
          Ref m (ResultName -> ResultName)
-> (ResultName -> ResultName) -> Event m ()
forall (m :: * -> *) a. MonadDES m => Ref m a -> a -> Event m ()
writeRef Ref m (ResultName -> ResultName)
r ResultName -> ResultName
g
     Event m (ResultName -> ResultName)
-> Simulation m (ResultName -> ResultName)
forall (m :: * -> *) a. MonadDES m => Event m a -> Simulation m a
runEventInStopTime (Event m (ResultName -> ResultName)
 -> Simulation m (ResultName -> ResultName))
-> Event m (ResultName -> ResultName)
-> Simulation m (ResultName -> ResultName)
forall a b. (a -> b) -> a -> b
$
       Ref m (ResultName -> ResultName)
-> Event m (ResultName -> ResultName)
forall (m :: * -> *) a. MonadDES m => Ref m a -> Event m a
readRef Ref m (ResultName -> ResultName)
r

-- | Show the simulation results in the specified time points.
--
-- It may consume much memory, for we have to traverse all the specified
-- points to create the resulting function within the 'Simulation' computation.
showResultsInTimes :: MonadDES m => [Double] -> ResultSourceShowS m -> Results m -> Simulation m ShowS
{-# INLINABLE showResultsInTimes #-}
showResultsInTimes :: forall (m :: * -> *).
MonadDES m =>
[Double]
-> ResultSourceShowS m
-> Results m
-> Simulation m (ResultName -> ResultName)
showResultsInTimes [Double]
ts ResultSourceShowS m
f Results m
results =
  do Ref m (ResultName -> ResultName)
r <- (ResultName -> ResultName)
-> Simulation m (Ref m (ResultName -> ResultName))
forall (m :: * -> *) a. MonadDES m => a -> Simulation m (Ref m a)
newRef ResultName -> ResultName
forall a. a -> a
id
     Event m () -> Simulation m ()
forall (m :: * -> *) a. MonadDES m => Event m a -> Simulation m a
runEventInStartTime (Event m () -> Simulation m ()) -> Event m () -> Simulation m ()
forall a b. (a -> b) -> a -> b
$
       [Double] -> Event m () -> Event m ()
forall (m :: * -> *).
MonadDES m =>
[Double] -> Event m () -> Event m ()
enqueueEventWithTimes [Double]
ts (Event m () -> Event m ()) -> Event m () -> Event m ()
forall a b. (a -> b) -> a -> b
$
       do ResultName -> ResultName
g <- ResultSourceShowS m
-> Results m -> Event m (ResultName -> ResultName)
forall (m :: * -> *).
MonadDES m =>
ResultSourceShowS m
-> Results m -> Event m (ResultName -> ResultName)
showResultsWithTime ResultSourceShowS m
f Results m
results
          Ref m (ResultName -> ResultName)
-> ((ResultName -> ResultName) -> ResultName -> ResultName)
-> Event m ()
forall (m :: * -> *) a.
MonadDES m =>
Ref m a -> (a -> a) -> Event m ()
modifyRef Ref m (ResultName -> ResultName)
r ((ResultName -> ResultName)
-> (ResultName -> ResultName) -> ResultName -> ResultName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ResultName -> ResultName
g)
     Event m (ResultName -> ResultName)
-> Simulation m (ResultName -> ResultName)
forall (m :: * -> *) a. MonadDES m => Event m a -> Simulation m a
runEventInStopTime (Event m (ResultName -> ResultName)
 -> Simulation m (ResultName -> ResultName))
-> Event m (ResultName -> ResultName)
-> Simulation m (ResultName -> ResultName)
forall a b. (a -> b) -> a -> b
$
       Ref m (ResultName -> ResultName)
-> Event m (ResultName -> ResultName)
forall (m :: * -> *) a. MonadDES m => Ref m a -> Event m a
readRef Ref m (ResultName -> ResultName)
r

-- | Run the simulation and then print the results in the start time.
printSimulationResultsInStartTime :: (MonadDES m, EventIOQueueing m) => ResultSourcePrint m -> Simulation m (Results m) -> Specs m -> m ()
{-# INLINABLE printSimulationResultsInStartTime #-}
printSimulationResultsInStartTime :: forall (m :: * -> *).
(MonadDES m, EventIOQueueing m) =>
ResultSourcePrint m -> Simulation m (Results m) -> Specs m -> m ()
printSimulationResultsInStartTime ResultSourcePrint m
print Simulation m (Results m)
model Specs m
specs =
  (Simulation m () -> Specs m -> m ())
-> Specs m -> Simulation m () -> m ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip Simulation m () -> Specs m -> m ()
forall (m :: * -> *) a.
MonadDES m =>
Simulation m a -> Specs m -> m a
runSimulation Specs m
specs (Simulation m () -> m ()) -> Simulation m () -> m ()
forall a b. (a -> b) -> a -> b
$
  Simulation m (Results m)
model Simulation m (Results m)
-> (Results m -> Simulation m ()) -> Simulation m ()
forall a b.
Simulation m a -> (a -> Simulation m b) -> Simulation m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ResultSourcePrint m -> Results m -> Simulation m ()
forall (m :: * -> *).
(MonadDES m, EventIOQueueing m) =>
ResultSourcePrint m -> Results m -> Simulation m ()
printResultsInStartTime ResultSourcePrint m
print

-- | Run the simulation and then print the results in the final time.
printSimulationResultsInStopTime :: (MonadDES m, EventIOQueueing m) => ResultSourcePrint m -> Simulation m (Results m) -> Specs m -> m ()
{-# INLINABLE printSimulationResultsInStopTime #-}
printSimulationResultsInStopTime :: forall (m :: * -> *).
(MonadDES m, EventIOQueueing m) =>
ResultSourcePrint m -> Simulation m (Results m) -> Specs m -> m ()
printSimulationResultsInStopTime ResultSourcePrint m
print Simulation m (Results m)
model Specs m
specs =
  (Simulation m () -> Specs m -> m ())
-> Specs m -> Simulation m () -> m ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip Simulation m () -> Specs m -> m ()
forall (m :: * -> *) a.
MonadDES m =>
Simulation m a -> Specs m -> m a
runSimulation Specs m
specs (Simulation m () -> m ()) -> Simulation m () -> m ()
forall a b. (a -> b) -> a -> b
$
  Simulation m (Results m)
model Simulation m (Results m)
-> (Results m -> Simulation m ()) -> Simulation m ()
forall a b.
Simulation m a -> (a -> Simulation m b) -> Simulation m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ResultSourcePrint m -> Results m -> Simulation m ()
forall (m :: * -> *).
(MonadDES m, EventIOQueueing m) =>
ResultSourcePrint m -> Results m -> Simulation m ()
printResultsInStopTime ResultSourcePrint m
print

-- | Run the simulation and then print the results in the integration time points.
printSimulationResultsInIntegTimes :: (MonadDES m, EventIOQueueing m) => ResultSourcePrint m -> Simulation m (Results m) -> Specs m -> m ()
{-# INLINABLE printSimulationResultsInIntegTimes #-}
printSimulationResultsInIntegTimes :: forall (m :: * -> *).
(MonadDES m, EventIOQueueing m) =>
ResultSourcePrint m -> Simulation m (Results m) -> Specs m -> m ()
printSimulationResultsInIntegTimes ResultSourcePrint m
print Simulation m (Results m)
model Specs m
specs =
  (Simulation m () -> Specs m -> m ())
-> Specs m -> Simulation m () -> m ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip Simulation m () -> Specs m -> m ()
forall (m :: * -> *) a.
MonadDES m =>
Simulation m a -> Specs m -> m a
runSimulation Specs m
specs (Simulation m () -> m ()) -> Simulation m () -> m ()
forall a b. (a -> b) -> a -> b
$
  Simulation m (Results m)
model Simulation m (Results m)
-> (Results m -> Simulation m ()) -> Simulation m ()
forall a b.
Simulation m a -> (a -> Simulation m b) -> Simulation m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ResultSourcePrint m -> Results m -> Simulation m ()
forall (m :: * -> *).
(MonadDES m, EventIOQueueing m) =>
ResultSourcePrint m -> Results m -> Simulation m ()
printResultsInIntegTimes ResultSourcePrint m
print

-- | Run the simulation and then print the results in the specified time point.
printSimulationResultsInTime :: (MonadDES m, EventIOQueueing m) => Double -> ResultSourcePrint m -> Simulation m (Results m) -> Specs m -> m ()
{-# INLINABLE printSimulationResultsInTime #-}
printSimulationResultsInTime :: forall (m :: * -> *).
(MonadDES m, EventIOQueueing m) =>
Double
-> ResultSourcePrint m
-> Simulation m (Results m)
-> Specs m
-> m ()
printSimulationResultsInTime Double
t ResultSourcePrint m
print Simulation m (Results m)
model Specs m
specs =
  (Simulation m () -> Specs m -> m ())
-> Specs m -> Simulation m () -> m ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip Simulation m () -> Specs m -> m ()
forall (m :: * -> *) a.
MonadDES m =>
Simulation m a -> Specs m -> m a
runSimulation Specs m
specs (Simulation m () -> m ()) -> Simulation m () -> m ()
forall a b. (a -> b) -> a -> b
$
  Simulation m (Results m)
model Simulation m (Results m)
-> (Results m -> Simulation m ()) -> Simulation m ()
forall a b.
Simulation m a -> (a -> Simulation m b) -> Simulation m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Double -> ResultSourcePrint m -> Results m -> Simulation m ()
forall (m :: * -> *).
(MonadDES m, EventIOQueueing m) =>
Double -> ResultSourcePrint m -> Results m -> Simulation m ()
printResultsInTime Double
t ResultSourcePrint m
print

-- | Run the simulation and then print the results in the specified time points.
printSimulationResultsInTimes :: (MonadDES m, EventIOQueueing m) => [Double] -> ResultSourcePrint m -> Simulation m (Results m) -> Specs m -> m ()
{-# INLINABLE printSimulationResultsInTimes #-}
printSimulationResultsInTimes :: forall (m :: * -> *).
(MonadDES m, EventIOQueueing m) =>
[Double]
-> ResultSourcePrint m
-> Simulation m (Results m)
-> Specs m
-> m ()
printSimulationResultsInTimes [Double]
ts ResultSourcePrint m
print Simulation m (Results m)
model Specs m
specs =
  (Simulation m () -> Specs m -> m ())
-> Specs m -> Simulation m () -> m ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip Simulation m () -> Specs m -> m ()
forall (m :: * -> *) a.
MonadDES m =>
Simulation m a -> Specs m -> m a
runSimulation Specs m
specs (Simulation m () -> m ()) -> Simulation m () -> m ()
forall a b. (a -> b) -> a -> b
$
  Simulation m (Results m)
model Simulation m (Results m)
-> (Results m -> Simulation m ()) -> Simulation m ()
forall a b.
Simulation m a -> (a -> Simulation m b) -> Simulation m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= [Double] -> ResultSourcePrint m -> Results m -> Simulation m ()
forall (m :: * -> *).
(MonadDES m, EventIOQueueing m) =>
[Double] -> ResultSourcePrint m -> Results m -> Simulation m ()
printResultsInTimes [Double]
ts ResultSourcePrint m
print

-- | Run the simulation and then show the results in the start time.
showSimulationResultsInStartTime :: MonadDES m => ResultSourceShowS m -> Simulation m (Results m) -> Specs m -> m ShowS
{-# INLINABLE showSimulationResultsInStartTime #-}
showSimulationResultsInStartTime :: forall (m :: * -> *).
MonadDES m =>
ResultSourceShowS m
-> Simulation m (Results m)
-> Specs m
-> m (ResultName -> ResultName)
showSimulationResultsInStartTime ResultSourceShowS m
f Simulation m (Results m)
model Specs m
specs =
  (Simulation m (ResultName -> ResultName)
 -> Specs m -> m (ResultName -> ResultName))
-> Specs m
-> Simulation m (ResultName -> ResultName)
-> m (ResultName -> ResultName)
forall a b c. (a -> b -> c) -> b -> a -> c
flip Simulation m (ResultName -> ResultName)
-> Specs m -> m (ResultName -> ResultName)
forall (m :: * -> *) a.
MonadDES m =>
Simulation m a -> Specs m -> m a
runSimulation Specs m
specs (Simulation m (ResultName -> ResultName)
 -> m (ResultName -> ResultName))
-> Simulation m (ResultName -> ResultName)
-> m (ResultName -> ResultName)
forall a b. (a -> b) -> a -> b
$
  Simulation m (Results m)
model Simulation m (Results m)
-> (Results m -> Simulation m (ResultName -> ResultName))
-> Simulation m (ResultName -> ResultName)
forall a b.
Simulation m a -> (a -> Simulation m b) -> Simulation m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ResultSourceShowS m
-> Results m -> Simulation m (ResultName -> ResultName)
forall (m :: * -> *).
MonadDES m =>
ResultSourceShowS m
-> Results m -> Simulation m (ResultName -> ResultName)
showResultsInStartTime ResultSourceShowS m
f

-- | Run the simulation and then show the results in the final time.
showSimulationResultsInStopTime :: MonadDES m => ResultSourceShowS m -> Simulation m (Results m) -> Specs m -> m ShowS
{-# INLINABLE showSimulationResultsInStopTime #-}
showSimulationResultsInStopTime :: forall (m :: * -> *).
MonadDES m =>
ResultSourceShowS m
-> Simulation m (Results m)
-> Specs m
-> m (ResultName -> ResultName)
showSimulationResultsInStopTime ResultSourceShowS m
f Simulation m (Results m)
model Specs m
specs =
  (Simulation m (ResultName -> ResultName)
 -> Specs m -> m (ResultName -> ResultName))
-> Specs m
-> Simulation m (ResultName -> ResultName)
-> m (ResultName -> ResultName)
forall a b c. (a -> b -> c) -> b -> a -> c
flip Simulation m (ResultName -> ResultName)
-> Specs m -> m (ResultName -> ResultName)
forall (m :: * -> *) a.
MonadDES m =>
Simulation m a -> Specs m -> m a
runSimulation Specs m
specs (Simulation m (ResultName -> ResultName)
 -> m (ResultName -> ResultName))
-> Simulation m (ResultName -> ResultName)
-> m (ResultName -> ResultName)
forall a b. (a -> b) -> a -> b
$
  Simulation m (Results m)
model Simulation m (Results m)
-> (Results m -> Simulation m (ResultName -> ResultName))
-> Simulation m (ResultName -> ResultName)
forall a b.
Simulation m a -> (a -> Simulation m b) -> Simulation m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ResultSourceShowS m
-> Results m -> Simulation m (ResultName -> ResultName)
forall (m :: * -> *).
MonadDES m =>
ResultSourceShowS m
-> Results m -> Simulation m (ResultName -> ResultName)
showResultsInStopTime ResultSourceShowS m
f

-- | Run the simulation and then show the results in the integration time points.
--
-- It may consume much memory, for we have to traverse all the integration
-- points to create the resulting function within the 'IO' computation.
showSimulationResultsInIntegTimes :: MonadDES m => ResultSourceShowS m -> Simulation m (Results m) -> Specs m -> m ShowS
{-# INLINABLE showSimulationResultsInIntegTimes #-}
showSimulationResultsInIntegTimes :: forall (m :: * -> *).
MonadDES m =>
ResultSourceShowS m
-> Simulation m (Results m)
-> Specs m
-> m (ResultName -> ResultName)
showSimulationResultsInIntegTimes ResultSourceShowS m
f Simulation m (Results m)
model Specs m
specs =
  (Simulation m (ResultName -> ResultName)
 -> Specs m -> m (ResultName -> ResultName))
-> Specs m
-> Simulation m (ResultName -> ResultName)
-> m (ResultName -> ResultName)
forall a b c. (a -> b -> c) -> b -> a -> c
flip Simulation m (ResultName -> ResultName)
-> Specs m -> m (ResultName -> ResultName)
forall (m :: * -> *) a.
MonadDES m =>
Simulation m a -> Specs m -> m a
runSimulation Specs m
specs (Simulation m (ResultName -> ResultName)
 -> m (ResultName -> ResultName))
-> Simulation m (ResultName -> ResultName)
-> m (ResultName -> ResultName)
forall a b. (a -> b) -> a -> b
$
  Simulation m (Results m)
model Simulation m (Results m)
-> (Results m -> Simulation m (ResultName -> ResultName))
-> Simulation m (ResultName -> ResultName)
forall a b.
Simulation m a -> (a -> Simulation m b) -> Simulation m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ResultSourceShowS m
-> Results m -> Simulation m (ResultName -> ResultName)
forall (m :: * -> *).
MonadDES m =>
ResultSourceShowS m
-> Results m -> Simulation m (ResultName -> ResultName)
showResultsInIntegTimes ResultSourceShowS m
f

-- | Run the simulation and then show the results in the integration time point.
showSimulationResultsInTime :: MonadDES m => Double -> ResultSourceShowS m -> Simulation m (Results m) -> Specs m -> m ShowS
{-# INLINABLE showSimulationResultsInTime #-}
showSimulationResultsInTime :: forall (m :: * -> *).
MonadDES m =>
Double
-> ResultSourceShowS m
-> Simulation m (Results m)
-> Specs m
-> m (ResultName -> ResultName)
showSimulationResultsInTime Double
t ResultSourceShowS m
f Simulation m (Results m)
model Specs m
specs =
  (Simulation m (ResultName -> ResultName)
 -> Specs m -> m (ResultName -> ResultName))
-> Specs m
-> Simulation m (ResultName -> ResultName)
-> m (ResultName -> ResultName)
forall a b c. (a -> b -> c) -> b -> a -> c
flip Simulation m (ResultName -> ResultName)
-> Specs m -> m (ResultName -> ResultName)
forall (m :: * -> *) a.
MonadDES m =>
Simulation m a -> Specs m -> m a
runSimulation Specs m
specs (Simulation m (ResultName -> ResultName)
 -> m (ResultName -> ResultName))
-> Simulation m (ResultName -> ResultName)
-> m (ResultName -> ResultName)
forall a b. (a -> b) -> a -> b
$
  Simulation m (Results m)
model Simulation m (Results m)
-> (Results m -> Simulation m (ResultName -> ResultName))
-> Simulation m (ResultName -> ResultName)
forall a b.
Simulation m a -> (a -> Simulation m b) -> Simulation m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Double
-> ResultSourceShowS m
-> Results m
-> Simulation m (ResultName -> ResultName)
forall (m :: * -> *).
MonadDES m =>
Double
-> ResultSourceShowS m
-> Results m
-> Simulation m (ResultName -> ResultName)
showResultsInTime Double
t ResultSourceShowS m
f

-- | Run the simulation and then show the results in the specified time points.
--
-- It may consume much memory, for we have to traverse all the specified
-- points to create the resulting function within the 'IO' computation.
showSimulationResultsInTimes :: MonadDES m => [Double] -> ResultSourceShowS m -> Simulation m (Results m) -> Specs m -> m ShowS
{-# INLINABLE showSimulationResultsInTimes #-}
showSimulationResultsInTimes :: forall (m :: * -> *).
MonadDES m =>
[Double]
-> ResultSourceShowS m
-> Simulation m (Results m)
-> Specs m
-> m (ResultName -> ResultName)
showSimulationResultsInTimes [Double]
ts ResultSourceShowS m
f Simulation m (Results m)
model Specs m
specs =
  (Simulation m (ResultName -> ResultName)
 -> Specs m -> m (ResultName -> ResultName))
-> Specs m
-> Simulation m (ResultName -> ResultName)
-> m (ResultName -> ResultName)
forall a b c. (a -> b -> c) -> b -> a -> c
flip Simulation m (ResultName -> ResultName)
-> Specs m -> m (ResultName -> ResultName)
forall (m :: * -> *) a.
MonadDES m =>
Simulation m a -> Specs m -> m a
runSimulation Specs m
specs (Simulation m (ResultName -> ResultName)
 -> m (ResultName -> ResultName))
-> Simulation m (ResultName -> ResultName)
-> m (ResultName -> ResultName)
forall a b. (a -> b) -> a -> b
$
  Simulation m (Results m)
model Simulation m (Results m)
-> (Results m -> Simulation m (ResultName -> ResultName))
-> Simulation m (ResultName -> ResultName)
forall a b.
Simulation m a -> (a -> Simulation m b) -> Simulation m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= [Double]
-> ResultSourceShowS m
-> Results m
-> Simulation m (ResultName -> ResultName)
forall (m :: * -> *).
MonadDES m =>
[Double]
-> ResultSourceShowS m
-> Results m
-> Simulation m (ResultName -> ResultName)
showResultsInTimes [Double]
ts ResultSourceShowS m
f