packages feed

aivika-experiment-chart 4.2 → 4.3

raw patch · 13 files changed

+580/−4 lines, 13 filesdep ~aivikaPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: aivika

API changes (from Hackage documentation)

Files

+ CHANGELOG.md view
@@ -0,0 +1,5 @@++Version 4.3+-----++* Updated examples.
aivika-experiment-chart.cabal view
@@ -1,5 +1,5 @@ name:            aivika-experiment-chart-version:         4.2+version:         4.3 synopsis:        Simulation experiments with charting for the Aivika library description:     This package complements the Aivika and Aivika Experiment packages with@@ -93,6 +93,17 @@                      examples/SingleLaneTraffic/MainUsingCairo.hs                      examples/SingleLaneTraffic/MainUsingDiagrams.hs                      examples/SingleLaneTraffic/README+                     examples/PERT/Model.hs+                     examples/PERT/Experiment.hs+                     examples/PERT/MainUsingCairo.hs+                     examples/PERT/MainUsingDiagrams.hs+                     examples/PERT/README+                     examples/TruckHaulingSituation/Model.hs+                     examples/TruckHaulingSituation/Experiment.hs+                     examples/TruckHaulingSituation/MainUsingCairo.hs+                     examples/TruckHaulingSituation/MainUsingDiagrams.hs+                     examples/TruckHaulingSituation/README+                     CHANGELOG.md  library @@ -116,7 +127,7 @@                      lens >= 3.9,                      data-default-class < 0.1,                      colour >= 2.3.3,-                     aivika >= 4.2,+                     aivika >= 4.3,                      aivika-experiment >= 4.0.3      extensions:      MultiParamTypeClasses
examples/MachineBreakdowns/README view
@@ -1,6 +1,4 @@ -CAUTION: THE MODEL IS NOT COMPLETE YET!- Example: Machine Tool with Breakdowns  It is described in different sources [1, 2]. So, this is chapter 13 of [2] and section 6.12 of [1].
+ examples/PERT/Experiment.hs view
@@ -0,0 +1,65 @@++module Experiment (experiment, generators) where++import Data.Monoid++import Control.Arrow++import Simulation.Aivika+import Simulation.Aivika.Experiment+import Simulation.Aivika.Experiment.Chart++import qualified Simulation.Aivika.Results.Transform as T++-- | The simulation specs.+specs = Specs { spcStartTime = 0.0,+                spcStopTime = 1000.0,+                spcDT = 0.1,+                spcMethod = RungeKutta4,+                spcGeneratorType = SimpleGenerator }++-- | The experiment.+experiment :: Experiment+experiment =+  defaultExperiment {+    experimentSpecs = specs,+    experimentRunCount = 10000,+    -- experimentRunCount = 10,+    experimentTitle = "Analysis of a PERT-type Network" }++timers = resultByName "timers"++timer2 = timers >>> resultByIndex 0+timer3 = timers >>> resultByIndex 1+timer4 = timers >>> resultByIndex 2+timer5 = timers >>> resultByIndex 3++projCompletion = resultByName "projCompletion"++completionTime series = +  T.tr $ +  T.samplingStatsMean $+  T.arrivalProcessingTime $+  T.ArrivalTimer series++histogramView title series = +  defaultFinalHistogramView {+    finalHistogramTitle  = title,+    finalHistogramSeries = series+  }++generators :: ChartRendering r => [WebPageGenerator r]+generators =+  [outputView defaultExperimentSpecsView,+   outputView defaultInfoView,+   outputView $ defaultFinalStatsView {+     finalStatsTitle = "The Completion Time",+     finalStatsSeries = +       completionTime timers <> +       completionTime projCompletion },+   outputView $ histogramView "Node 2" $ completionTime timer2,+   outputView $ histogramView "Node 3" $ completionTime timer3,+   outputView $ histogramView "Node 4" $ completionTime timer3,+   outputView $ histogramView "Node 5" $ completionTime timer5,+   outputView $ histogramView "The Project Completion" $ +     completionTime projCompletion]
+ examples/PERT/MainUsingCairo.hs view
@@ -0,0 +1,12 @@++-- To run, package aivika-experiment-cairo must be installed.++import Simulation.Aivika.Experiment+import Simulation.Aivika.Experiment.Chart.Backend.Cairo++import Graphics.Rendering.Chart.Backend.Cairo++import Model+import Experiment++main = runExperiment experiment generators (WebPageRenderer $ CairoRenderer PNG) model
+ examples/PERT/MainUsingDiagrams.hs view
@@ -0,0 +1,14 @@++-- To run, package aivika-experiment-diagrams must be installed.++import Simulation.Aivika.Experiment+import Simulation.Aivika.Experiment.Chart.Backend.Diagrams++import Graphics.Rendering.Chart.Backend.Diagrams++import qualified Data.Map as M++import Model+import Experiment++main = runExperiment experiment generators (WebPageRenderer $ DiagramsRenderer SVG M.empty) model
+ examples/PERT/Model.hs view
@@ -0,0 +1,137 @@++{-# LANGUAGE RecursiveDo #-}++-- Example: Analysis of a PERT-type Network +--+-- It is described in different sources [1, 2]. So, this is chapter 14 of [2] and section 7.11 of [1].+--+-- PERT is a technique for evaluating and reviewing a project consisting of+-- interdependent activities. A number of books have been written that describe+-- PERT modeling and analysis procedures. A PERT network activity descriptions+-- are given in a table stated below. All activity times will be assumed to be+-- triangularly distributed. For ease of description, activities have been+-- aggregated. The activities relate to power units, instrumentation, and+-- a new assembly and involve standard types of operations.+-- +-- In the following description of the project, activity numbers are given+-- in parentheses. At the beginning of the project, three parallel activities+-- can be performed that involve: the disassembly of power units and+-- instrumentation (1); the installation of a new assembly (2); and+-- the preparation for a retrofit check (3). Cleaning, inspecting, and+-- repairing the power units (4) and calibrating the instrumentation (5)+-- can be done only after the power units and instrumentation have been+-- disassembled. Thus, activities 4 and 5 must follow activity 1 in the network.+-- Following the installation of the new assembly (2) and after the instrumentation+-- have been calibrated (5), a check of interfaces (6) and a check of+-- the new assembly (7) can be made. The retrofit check (9) can be made+-- after the assembly is checked (7) and the preparation for the retrofit+-- check (3) has been completed. The assembly and test of power units (8)+-- can be performed following the cleaning and maintenance of power units (4).+-- The project is considered completed when all nine activities are completed.+-- Since activities 6, 8, and 9 require the other activities to precede them,+-- their completion signifies the end of the project. This is indicated on+-- the network by having activities 6, 8, and 9 incident to node 6, the sink+-- node for the project. The objective of this example is to illustrate+-- the procedures for using Aivika to model and simulate project planning network.+-- +-- Activity    Description                                  Mode Minimum Maximum Average+-- +--  1          Disassemble power units and instrumentation    3      1       5       3+--  2          Install new assembly                           6      3       9       6+--  3          Prepare for retrofit check                    13     10      19      14+--  4          Clean, inspect, and repair power units         9      3      12       8+--  5          Calibrate instrumentation                      3      1       8       4+--  6          Check interfaces                               9      8      16      11+--  7          Check assembly                                 7      4      13       8+--  8          Assemble and test power units                  6      3       9       6+--  9          Retrofit check                                 3      1       8       4+-- +-- Node 	Depends of Activities+-- +--  1              -+--  2              1+--  3              2, 5+--  4              3, 7+--  5              4+--  6              6, 8, 9 +-- +-- Activity    Depends on Node+-- +--  1              1+--  2              1+--  3              1+--  4              2+--  5              2+--  6              3+--  7              3+--  8              5+--  9              4+-- +-- [1] A. Alan B. Pritsker, Simulation with Visual SLAM and AweSim, 2nd ed.+-- [2] Труб И.И., Объектно-ориентированное моделирование на C++: Учебный курс. - СПб.: Питер, 2006++module Model (model) where++import Control.Monad+import Control.Monad.Trans+import Control.Arrow++import Data.Array+import Data.Maybe+import Data.Monoid++import Simulation.Aivika++model :: Simulation Results+model = mdo+  timers' <- forM [2..5] $ \i -> newArrivalTimer+  projCompletionTimer <- newArrivalTimer+  let timers = array (2, 5) $ zip [2..] timers'+      p1 = randomTriangularProcessor 1 3 5+      p2 = randomTriangularProcessor 3 6 9+      p3 = randomTriangularProcessor 10 13 19+      p4 = randomTriangularProcessor 3 9 12+      p5 = randomTriangularProcessor 1 3 8+      p6 = randomTriangularProcessor 8 9 16+      p7 = randomTriangularProcessor 4 7 13+      p8 = randomTriangularProcessor 3 6 9+      p9 = randomTriangularProcessor 1 3 8+  let c2 = arrivalTimerProcessor (timers ! 2)+      c3 = arrivalTimerProcessor (timers ! 3)+      c4 = arrivalTimerProcessor (timers ! 4)+      c5 = arrivalTimerProcessor (timers ! 5)+      c6 = arrivalTimerProcessor projCompletionTimer+  [i1, i2, i3] <- cloneStream 3 n1+  [i4, i5] <- cloneStream 2 n2+  [i6, i7] <- cloneStream 2 n3+  let i9 = n4+      i8 = n5+  let s1 = runProcessor p1 i1+      s2 = runProcessor p2 i2+      s3 = runProcessor p3 i3+      s4 = runProcessor p4 i4+      s5 = runProcessor p5 i5+      s6 = runProcessor p6 i6+      s7 = runProcessor p7 i7+      s8 = runProcessor p8 i8+      s9 = runProcessor p9 i9+  let n1 = takeStream 1 $ randomStream $ return (0, 0)+      n2 = runProcessor c2 s1+      n3 = runProcessor c3 $ firstArrivalStream 2 (s2 <> s5)+      n4 = runProcessor c4 $ firstArrivalStream 2 (s3 <> s7)+      n5 = runProcessor c5 s4+      n6 = runProcessor c6 $ firstArrivalStream 3 (s6 <> s8 <> s9)+  runProcessInStartTime $ sinkStream n6+  return $+    results+    [resultSource+     "timers" "Timers"+     timers,+     --+     resultSource+     "projCompletion" "Project Completion Timer"+     projCompletionTimer]++modelSummary :: Simulation Results+modelSummary =+  fmap resultSummary model
+ examples/PERT/README view
@@ -0,0 +1,69 @@++Example: Analysis of a PERT-Type Network.++It is described in different sources [1, 2]. So, this is chapter 14 of [2] and section 7.11 of [1].++PERT is a technique for evaluating and reviewing a project consisting of+interdependent activities. A number of books have been written that describe+PERT modeling and analysis procedures. A PERT network activity descriptions+are given in a table stated below. All activity times will be assumed to be+triangularly distributed. For ease of description, activities have been+aggregated. The activities relate to power units, instrumentation, and+a new assembly and involve standard types of operations.++In the following description of the project, activity numbers are given+in parentheses. At the beginning of the project, three parallel activities+can be performed that involve: the disassembly of power units and+instrumentation (1); the installation of a new assembly (2); and+the preparation for a retrofit check (3). Cleaning, inspecting, and+repairing the power units (4) and calibrating the instrumentation (5)+can be done only after the power units and instrumentation have been+disassembled. Thus, activities 4 and 5 must follow activity 1 in the network.+Following the installation of the new assembly (2) and after the instrumentation+have been calibrated (5), a check of interfaces (6) and a check of+the new assembly (7) can be made. The retrofit check (9) can be made+after the assembly is checked (7) and the preparation for the retrofit+check (3) has been completed. The assembly and test of power units (8)+can be performed following the cleaning and maintenance of power units (4).+The project is considered completed when all nine activities are completed.+Since activities 6, 8, and 9 require the other activities to precede them,+their completion signifies the end of the project. This is indicated on+the network by having activities 6, 8, and 9 incident to node 6, the sink+node for the project. The objective of this example is to illustrate+the procedures for using Aivika to model and simulate project planning network.++Activity    Description                                  Mode Minimum Maximum Average++ 1          Disassemble power units and instrumentation    3      1       5       3+ 2          Install new assembly                           6      3       9       6+ 3          Prepare for retrofit check                    13     10      19      14+ 4          Clean, inspect, and repair power units         9      3      12       8+ 5          Calibrate instrumentation                      3      1       8       4+ 6          Check interfaces                               9      8      16      11+ 7          Check assembly                                 7      4      13       8+ 8          Assemble and test power units                  6      3       9       6+ 9          Retrofit check                                 3      1       8       4++Node 	Depends of Activities++ 1              -+ 2              1+ 3              2, 5+ 4              3, 7+ 5              4+ 6              6, 8, 9++Activity    Depends on Node++ 1              1+ 2              1+ 3              1+ 4              2+ 5              2+ 6              3+ 7              3+ 8              5+ 9              4++[1] A. Alan B. Pritsker, Simulation with Visual SLAM and AweSim, 2nd ed.+[2] Труб И.И., Объектно-ориентированное моделирование на C++: Учебный курс. - СПб.: Питер, 2006
+ examples/TruckHaulingSituation/Experiment.hs view
@@ -0,0 +1,85 @@++{-# LANGUAGE FlexibleContexts #-}++module Experiment (experiment, generators) where++import Data.Monoid++import Control.Arrow++import Simulation.Aivika+import Simulation.Aivika.Experiment+import Simulation.Aivika.Experiment.Chart++import qualified Simulation.Aivika.Results.Transform as T++-- | The simulation specs.+specs = Specs { spcStartTime = 0.0,+                spcStopTime = 1000.0,+                spcDT = 0.1,+                spcMethod = RungeKutta4,+                spcGeneratorType = SimpleGenerator }++-- | The experiment.+experiment :: Experiment+experiment =+  defaultExperiment {+    experimentSpecs = specs,+    experimentRunCount = 1000,+    -- experimentRunCount = 10,+    experimentTitle = "A Truck Hauling Situation" }++loadQueue           = T.Queue $ resultByName "loadQueue"+loadQueueCount      = T.tr $ T.queueCount loadQueue+loadQueueCountStats = T.tr $ T.queueCountStats loadQueue+loadWaitTime        = T.tr $ T.queueWaitTime loadQueue++truckQueue           = T.Queue $ resultByName "truckQueue"+truckQueueCount      = T.tr $ T.queueCount truckQueue+truckQueueCountStats = T.tr $ T.queueCountStats truckQueue+truckWaitTime        = T.tr $ T.queueWaitTime truckQueue++loaderQueue           = T.Queue $ resultByName "loaderQueue"+loaderQueueCount      = T.tr $ T.queueCount loaderQueue+loaderQueueCountStats = T.tr $ T.queueCountStats loaderQueue+loaderWaitTime        = T.tr $ T.queueWaitTime loaderQueue++loaderOps               = T.Operation $ resultByName "loaderOps"+loaderUtilisationTime   = T.tr $ T.operationUtilisationTime loaderOps+loaderUtilisationFactor = T.tr $ T.operationUtilisationFactor loaderOps++statsView title series =+  defaultFinalStatsView {+    finalStatsTitle = title,+    finalStatsSeries = series +  }++chartView title series = +  defaultDeviationChartView {+    deviationChartTitle = title,+    deviationChartRightYSeries = series+  }++generators :: ChartRendering r => [WebPageGenerator r]+generators =+  [outputView defaultExperimentSpecsView,+   outputView defaultInfoView,+   outputView $ statsView "Queue Length" $+     loadQueueCountStats <>+     truckQueueCountStats <>+     loaderQueueCountStats,+   outputView $ chartView "Queue Load" $+     loadQueueCount <> loadQueueCountStats,+   outputView $ chartView "Queue Trucks" $+     truckQueueCount <> truckQueueCountStats,+   outputView $ chartView "Queue Loader" $+     loaderQueueCount <> loaderQueueCountStats,+   outputView $ statsView "Queue Waiting Time" $+     loadWaitTime <>+     truckWaitTime <>+     loaderWaitTime,+   outputView $ chartView "Loader Utilisation Chart"+     loaderUtilisationFactor,+   outputView $ statsView "Loader Utilisation Summary" $+     loaderUtilisationFactor <>+     loaderUtilisationTime]
+ examples/TruckHaulingSituation/MainUsingCairo.hs view
@@ -0,0 +1,12 @@++-- To run, package aivika-experiment-cairo must be installed.++import Simulation.Aivika.Experiment+import Simulation.Aivika.Experiment.Chart.Backend.Cairo++import Graphics.Rendering.Chart.Backend.Cairo++import Model+import Experiment++main = runExperiment experiment generators (WebPageRenderer $ CairoRenderer PNG) model
+ examples/TruckHaulingSituation/MainUsingDiagrams.hs view
@@ -0,0 +1,14 @@++-- To run, package aivika-experiment-diagrams must be installed.++import Simulation.Aivika.Experiment+import Simulation.Aivika.Experiment.Chart.Backend.Diagrams++import Graphics.Rendering.Chart.Backend.Diagrams++import qualified Data.Map as M++import Model+import Experiment++main = runExperiment experiment generators (WebPageRenderer $ DiagramsRenderer SVG M.empty) model
+ examples/TruckHaulingSituation/Model.hs view
@@ -0,0 +1,127 @@++-- Example: A Truck Hauling Situation+--+-- It is described in different sources [1, 2]. So, this is chapter 9 of [2] and section 7.16 of [1].+--+-- The system to be modeled in this example consists of one bulldozer, four trucks,+-- and two man-machine loaders. The bulldozer stockpiles material for the loaders.+-- Two piles of material must be stocked prior to the initiation of any load operation.+-- The time for the bulldozer to stockpile material is Erlang distributed and consists+-- of the sum of two exponential variables each with a men of 4. (This corresponds to+-- an Erlang variable with a mean of 8 and a variance of 32.) In addition to this+-- material, a loader and an unloaded truck must be available before the loading+-- operations can begin. Loading time is exponentially distributed with a mean time of+-- 14 minutes for server 1 and 12 minutes for server 2.+-- +-- After a truck is loaded, it is hauled, then dumped and must be returned before+-- the truck is available for further loading. Hauling time is normally distributed.+-- When loaded, the average hauling time is 22 minutes. When unloaded, the average+-- time is 18 minutes. In both cases, the standard deviation is 3 minutes. Dumping+-- time is uniformly distributed between 2 and 8 minutes. Following a loading+-- operation, the loaded must rest for a 5 minute period before he is available+-- to begin loading again. The system is to be analyzed for 8 hours and all operations+-- in progress at the end of 8 hours should be completed before terminating+-- the operations for a run.+-- +-- [1] A. Alan B. Pritsker, Simulation with Visual SLAM and AweSim, 2nd ed.+-- [2] Труб И.И., Объектно-ориентированное моделирование на C++: Учебный курс. - СПб.: Питер, 2006++module Model (model) where++import Control.Monad+import Control.Monad.Trans+import Control.Arrow++import Data.Monoid+import Data.List+import Data.Array++import Simulation.Aivika+import qualified Simulation.Aivika.Queue.Infinite as IQ++data Truck = Truck++data Pile = Pile++data Loader = Loader1+            | Loader2+              deriving (Eq, Ord, Show, Ix)++awaitQueuesNonEmpty q1 q2 q3 =+  do n1 <- liftEvent $ IQ.queueCount q1+     n2 <- liftEvent $ IQ.queueCount q2+     n3 <- liftEvent $ IQ.queueCount q3+     when (n1 == 0 || n2 == 0 || n3 == 0) $+       do let signal = IQ.queueCountChanged_ q1 <>+                       IQ.queueCountChanged_ q2 <>+                       IQ.queueCountChanged_ q3+          processAwait signal+          awaitQueuesNonEmpty q1 q2 q3++-- | The simulation model.+model :: Simulation Results+model = do+  truckQueue <- runEventInStartTime IQ.newFCFSQueue+  loadQueue <- runEventInStartTime IQ.newFCFSQueue+  loaderQueue <- runEventInStartTime IQ.newFCFSQueue+  loaderOp1 <- runEventInStartTime $+               newRandomExponentialOperation 14+  loaderOp2 <- runEventInStartTime $+               newRandomExponentialOperation 12+  let loaderOps = array (Loader1, Loader2)+                  [(Loader1, loaderOp1),+                   (Loader2, loaderOp2)]+  let start :: Process ()+      start =+        do randomErlangProcess_ 4 2+           randomErlangProcess_ 4 2+           liftEvent $+             IQ.enqueue loadQueue Pile+           t <- liftDynamics time+           when (t <= 480) start+      begin :: Process ()+      begin =+        do awaitQueuesNonEmpty truckQueue loadQueue loaderQueue+           truck  <- IQ.dequeue truckQueue+           pile   <- IQ.dequeue loadQueue+           loader <- IQ.dequeue loaderQueue+           -- the load operation+           operationProcess (loaderOps ! loader) () +           -- truck hauling+           liftEvent $+             do runProcess $+                  do holdProcess 5+                     liftEvent $+                       IQ.enqueue loaderQueue loader+                runProcess $+                  do randomNormalProcess_ 22 3+                     randomUniformProcess_ 2 8+                     randomNormalProcess_ 18 3+                     liftEvent $+                       IQ.enqueue truckQueue truck+           begin+  runEventInStartTime $+    do forM_ [1..4] $ \i ->+         IQ.enqueue truckQueue Truck+       IQ.enqueue loaderQueue Loader1+       IQ.enqueue loaderQueue Loader2+  runProcessInStartTime begin+  runProcessInStartTime begin+  runProcessInStartTime start+  return $+    results+    [ resultSource+     "loadQueue" "Queue Load"+     loadQueue,+     --+     resultSource+     "truckQueue" "Queue Trucks"+     truckQueue,+     --+     resultSource+     "loaderQueue" "Queue Loader"+     loaderQueue,+     --+     resultSource+     "loaderOps" "Loader Operations"+     loaderOps]
+ examples/TruckHaulingSituation/README view
@@ -0,0 +1,27 @@++Example: A Truck Hauling Situation.++It is described in different sources [1, 2]. So, this is chapter 9 of [2] and section 7.16 of [1].++The system to be modeled in this example consists of one bulldozer, four trucks,+and two man-machine loaders. The bulldozer stockpiles material for the loaders.+Two piles of material must be stocked prior to the initiation of any load operation.+The time for the bulldozer to stockpile material is Erlang distributed and consists+of the sum of two exponential variables each with a men of 4. (This corresponds to+an Erlang variable with a mean of 8 and a variance of 32.) In addition to this+material, a loader and an unloaded truck must be available before the loading+operations can begin. Loading time is exponentially distributed with a mean time of+14 minutes for server 1 and 12 minutes for server 2.++After a truck is loaded, it is hauled, then dumped and must be returned before+the truck is available for further loading. Hauling time is normally distributed.+When loaded, the average hauling time is 22 minutes. When unloaded, the average+time is 18 minutes. In both cases, the standard deviation is 3 minutes. Dumping+time is uniformly distributed between 2 and 8 minutes. Following a loading+operation, the loaded must rest for a 5 minute period before he is available+to begin loading again. The system is to be analyzed for 8 hours and all operations+in progress at the end of 8 hours should be completed before terminating+the operations for a run.++[1] A. Alan B. Pritsker, Simulation with Visual SLAM and AweSim, 2nd ed.+[2] Труб И.И., Объектно-ориентированное моделирование на C++: Учебный курс. - СПб.: Питер, 2006