creatur 5.4.2 → 5.5.0
raw patch · 3 files changed
+25/−17 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- ALife.Creatur.Task: runInteractingAgents :: (Universe u, Serialize (Agent u)) => AgentsProgram u -> Int -> SummaryProgram u -> StateT u IO Bool
+ ALife.Creatur.Task: runInteractingAgents :: (Universe u, Serialize (Agent u)) => AgentsProgram u -> (Int, Int) -> SummaryProgram u -> StateT u IO Bool
Files
- creatur.cabal +2/−2
- src/ALife/Creatur/Genetics/Recombination.hs +7/−7
- src/ALife/Creatur/Task.hs +16/−8
creatur.cabal view
@@ -1,5 +1,5 @@ Name: creatur-Version: 5.4.2+Version: 5.5.0 Stability: experimental Synopsis: Framework for artificial life experiments. Description: A software framework for automating experiments@@ -36,7 +36,7 @@ source-repository this type: git location: https://github.com/mhwombat/creatur.git- tag: 5.4.2+ tag: 5.5.0 library GHC-Options: -Wall -fno-warn-orphans
src/ALife/Creatur/Genetics/Recombination.hs view
@@ -68,7 +68,7 @@ -- | Same as @'cutAndSplice'@, except that the two locations are -- chosen at random.-randomCutAndSplice :: (RandomGen g) => ([a], [a]) -> Rand g ([a], [a])+randomCutAndSplice :: RandomGen g => ([a], [a]) -> Rand g ([a], [a]) randomCutAndSplice (as, bs) = do n <- getRandomR (0,length as - 1) m <- getRandomR (0,length bs - 1)@@ -81,7 +81,7 @@ -- | Same as @'crossover'@, except that the location is chosen at -- random.-randomCrossover :: (RandomGen g) => ([a], [a]) -> Rand g ([a], [a])+randomCrossover :: RandomGen g => ([a], [a]) -> Rand g ([a], [a]) randomCrossover (as, bs) = do n <- getRandomR (0,length as - 1) return (crossover n (as, bs))@@ -134,19 +134,19 @@ -- | Randomly select a boolean, but weighted to return True with probability -- p.-weightedRandomBoolean :: (RandomGen g) => Double -> Rand g Bool+weightedRandomBoolean :: RandomGen g => Double -> Rand g Bool weightedRandomBoolean p = do x <- getRandomR (0.0,1.0) return (x < p) -randomOneOfPair :: (RandomGen g) => (a, a) -> Rand g a+randomOneOfPair :: RandomGen g => (a, a) -> Rand g a randomOneOfPair pair = do chooseFst <- weightedRandomBoolean 0.5 if chooseFst then return $ fst pair else return $ snd pair -randomOneOfList :: (RandomGen g) => [a] -> Rand g a+randomOneOfList :: RandomGen g => [a] -> Rand g a randomOneOfList xs = do (_, z) <- randomListSelection xs return z@@ -154,7 +154,7 @@ ---- | Sample a random element from a weighted list. ---- The total weight of all elements must not be 0. ---- Adapted from the code in MonadRandom---randomWeightedChoice :: (RandomGen g) => [(a, Double)] -> Rand g a+--randomWeightedChoice :: RandomGen g => [(a, Double)] -> Rand g a --randomWeightedChoice [] = error "randomFromList called with empty list" --randomWeightedChoice [(x,_)] = return x --randomWeightedChoice xs = do@@ -165,7 +165,7 @@ -- | Choose an element at random from a list and return the element and its -- index-randomListSelection :: (RandomGen g) => [a] -> Rand g (Int, a)+randomListSelection :: RandomGen g => [a] -> Rand g (Int, a) randomListSelection xs = do i <- getRandomR (0,length xs - 1) return (i, xs !! i)
src/ALife/Creatur/Task.hs view
@@ -90,21 +90,29 @@ runInteractingAgents :: (Universe u, Serialize (Agent u))- => AgentsProgram u -> Int -> SummaryProgram u -> StateT u IO Bool-runInteractingAgents agentsProgram minAgents summaryProgram = do+ => AgentsProgram u -> (Int, Int) -> SummaryProgram u -> StateT u IO Bool+runInteractingAgents agentsProgram (minAgents, maxAgents) summaryProgram = do atEndOfRound summaryProgram as <- lineup- if length (take minAgents as) < minAgents -- efficient way of checking length, I think+ let n = length as+ if n < minAgents then do writeToLog "Population too small" summaryProgram writeToLog "Requesting shutdown (population too small)" return False- else do- markDone (head as)- -- do that first in case the next line triggers an exception- withAgents agentsProgram as- return True+ else+ if n > maxAgents+ then do+ writeToLog "Population too big"+ summaryProgram+ writeToLog "Requesting shutdown (population too big)"+ return False+ else do+ markDone (head as)+ -- do that first in case the next line triggers an exception+ withAgents agentsProgram as+ return True atEndOfRound :: Universe u