aivika 5.1 → 5.2
raw patch · 7 files changed
+39/−18 lines, 7 filesdep +mwc-randomPVP ok
version bump matches the API change (PVP)
Dependencies added: mwc-random
API changes (from Hackage documentation)
- Simulation.Aivika.Generator: SimpleGeneratorWithSeed :: Int -> GeneratorType
+ Simulation.Aivika.Generator: SimpleGeneratorWithSeed :: Word32 -> GeneratorType
Files
- CHANGELOG.md +15/−0
- Simulation/Aivika/Dynamics/Random.hs +0/−2
- Simulation/Aivika/Generator.hs +15/−6
- Simulation/Aivika/Parameter/Random.hs +0/−2
- Simulation/Aivika/PriorityQueue/Pure.hs +1/−1
- Simulation/Aivika/QueueStrategy.hs +6/−6
- aivika.cabal +2/−1
CHANGELOG.md view
@@ -1,4 +1,19 @@ +Version 5.2+-----++* Significantly improved in the examples the speed of simulation after using+ the mwc-random package by Bryan O'Sullivan for generating random numbers.+ It was possible to use custom random number generators before, but now+ the mentioned generator is used by default. Also the type signature of+ the SimpleGeneratorWithSeed data constructor has changed.++Version 5.1.1+-----++* Updated the pure-functional priority queue so that the events could be yielded+ in the distributed simulation module too.+ Version 5.1 -----
Simulation/Aivika/Dynamics/Random.hs view
@@ -34,8 +34,6 @@ memoRandomWeibullDynamics, memoRandomDiscreteDynamics) where -import System.Random- import Control.Monad.Trans import Simulation.Aivika.Generator
Simulation/Aivika/Generator.hs view
@@ -20,7 +20,10 @@ newRandomGenerator01) where import System.Random+import qualified System.Random.MWC as MWC import Data.IORef+import Data.Word+import Data.Vector -- | A discrete probability density function. type DiscretePDF a = [(a, Double)]@@ -99,9 +102,15 @@ -> IO Int generateUniformInt01 g min max = do x <- g- let min' = fromIntegral min- max' = fromIntegral max- return $ round (min' + x * (max' - min'))+ let min' = fromIntegral min - 0.5+ max' = fromIntegral max + 0.5+ z = round (min' + x * (max' - min'))+ z' = if z < min+ then min+ else if z > max+ then max+ else z+ return z' -- | Generate the triangular random number by the specified minimum, median and maximum. generateTriangular01 :: IO Double@@ -295,7 +304,7 @@ -- | Defines a type of the random number generator. data GeneratorType = SimpleGenerator -- ^ The simple random number generator.- | SimpleGeneratorWithSeed Int+ | SimpleGeneratorWithSeed Word32 -- ^ The simple random number generator with the specified seed. | CustomGenerator (IO Generator) -- ^ The custom random number generator.@@ -308,9 +317,9 @@ newGenerator tp = case tp of SimpleGenerator ->- newStdGen >>= newRandomGenerator+ MWC.uniform <$> MWC.withSystemRandom (return :: MWC.GenIO -> IO MWC.GenIO) >>= newRandomGenerator01 SimpleGeneratorWithSeed x ->- newRandomGenerator $ mkStdGen x+ MWC.uniform <$> MWC.initialize (singleton x) >>= newRandomGenerator01 CustomGenerator g -> g CustomGenerator01 g ->
Simulation/Aivika/Parameter/Random.hs view
@@ -36,8 +36,6 @@ randomTrue, randomFalse) where -import System.Random- import Control.Monad.Trans import Simulation.Aivika.Generator
Simulation/Aivika/PriorityQueue/Pure.hs view
@@ -43,7 +43,7 @@ -- | Enqueue a new element with the specified priority. enqueue :: PriorityQueue a -> Double -> a -> PriorityQueue a-enqueue pq k v = mergeQueues (Queue 1 k v 1 EmptyQueue EmptyQueue) pq+enqueue pq k v = mergeQueues pq (Queue 1 k v 1 EmptyQueue EmptyQueue) -- | Dequeue the element with the minimal priority. dequeue :: PriorityQueue a -> PriorityQueue a
Simulation/Aivika/QueueStrategy.hs view
@@ -13,10 +13,11 @@ -- module Simulation.Aivika.QueueStrategy where -import System.Random import Control.Monad.Trans import Data.Maybe +import Simulation.Aivika.Parameter+import Simulation.Aivika.Parameter.Random import Simulation.Aivika.Simulation import Simulation.Aivika.Event import Simulation.Aivika.DoubleLinkedList@@ -236,11 +237,10 @@ instance DequeueStrategy SIRO where strategyDequeue (SIROQueue q) =- liftIO $- do n <- V.vectorCount q- i <- getStdRandom (randomR (0, n - 1))- x <- V.readVector q i- V.vectorDeleteAt q i+ do n <- liftIO $ V.vectorCount q+ i <- liftParameter $ randomUniformInt 0 (n - 1)+ x <- liftIO $ V.readVector q i+ liftIO $ V.vectorDeleteAt q i return x -- | An implementation of the 'SIRO' queue strategy.
aivika.cabal view
@@ -1,5 +1,5 @@ name: aivika-version: 5.1+version: 5.2 synopsis: A multi-method simulation library description: Aivika is a discrete event simulation (DES) framework with support of activity-oriented,@@ -232,6 +232,7 @@ array >= 0.3.0.0, containers >= 0.4.0.0, random >= 1.0.0.3,+ mwc-random >= 0.13.0.0, vector >= 0.10.0.1, deepseq >= 1.1.0.0, binary >= 0.6.4.0