creatur 5.8.0 → 5.8.2
raw patch · 4 files changed
+15/−92 lines, 4 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- ALife.Creatur.EnergyPool: available :: EnergyPool e => StateT e IO Double
- ALife.Creatur.EnergyPool: class EnergyPool e
- ALife.Creatur.EnergyPool: instance EnergyPool PersistentEnergyPool
- ALife.Creatur.EnergyPool: mkPersistentEnergyPool :: FilePath -> PersistentEnergyPool
- ALife.Creatur.EnergyPool: replenish :: EnergyPool e => Double -> StateT e IO ()
- ALife.Creatur.EnergyPool: type PersistentEnergyPool = Persistent Double
- ALife.Creatur.EnergyPool: withdraw :: EnergyPool e => Double -> StateT e IO Double
- ALife.Creatur.Universe: energyPool :: Universe u => u -> EnergyPool u
- ALife.Creatur.Universe: replenishEnergyPool :: Universe u => Double -> StateT u IO ()
- ALife.Creatur.Universe: setEnergyPool :: Universe u => u -> EnergyPool u -> u
- ALife.Creatur.Universe: withdrawEnergy :: Universe u => Double -> StateT u IO Double
+ ALife.Creatur.Task: doNothing :: Monad m => m ()
- ALife.Creatur.Universe: class (Clock (Clock u), Logger (Logger u), Database (AgentDB u), Namer (Namer u), Checklist (Checklist u), EnergyPool (EnergyPool u), Agent (Agent u), Record (Agent u), Agent u ~ DBRecord (AgentDB u)) => Universe u where type family Agent u type family Clock u type family Logger u type family AgentDB u type family Namer u type family Checklist u type family EnergyPool u
+ ALife.Creatur.Universe: class (Clock (Clock u), Logger (Logger u), Database (AgentDB u), Namer (Namer u), Checklist (Checklist u), Agent (Agent u), Record (Agent u), Agent u ~ DBRecord (AgentDB u)) => Universe u where type family Agent u type family Clock u type family Logger u type family AgentDB u type family Namer u type family Checklist u
Files
- creatur.cabal +2/−3
- src/ALife/Creatur/EnergyPool.hs +0/−42
- src/ALife/Creatur/Task.hs +6/−0
- src/ALife/Creatur/Universe.hs +7/−47
creatur.cabal view
@@ -1,5 +1,5 @@ Name: creatur-Version: 5.8.0+Version: 5.8.2 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.8.0+ tag: 5.8.2 library GHC-Options: -Wall -fno-warn-orphans@@ -51,7 +51,6 @@ ALife.Creatur.Database.CachedFileSystem, ALife.Creatur.Database.CachedFileSystemInternal, ALife.Creatur.Database.FileSystem,- ALife.Creatur.EnergyPool, ALife.Creatur.Genetics.Analysis, ALife.Creatur.Genetics.BRGCBool, ALife.Creatur.Genetics.BRGCWord8,
− src/ALife/Creatur/EnergyPool.hs
@@ -1,42 +0,0 @@---------------------------------------------------------------------------- |--- Module : ALife.Creatur.EnergyPool--- Copyright : (c) Amy de Buitléir 2014--- License : BSD-style--- Maintainer : amy@nualeargais.ie--- Stability : experimental--- Portability : portable------ An exhaustible resource which persists between runs.-----------------------------------------------------------------------------{-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-}-module ALife.Creatur.EnergyPool- (- EnergyPool(..),- PersistentEnergyPool,- mkPersistentEnergyPool- ) where--import ALife.Creatur.Persistent (Persistent, mkPersistent, getPS, putPS)-import Control.Monad.State (StateT)--class EnergyPool e where- replenish :: Double -> StateT e IO ()- withdraw :: Double -> StateT e IO Double- available :: StateT e IO Double--type PersistentEnergyPool = Persistent Double---- | Creates a resource that will store its value in the specified file.-mkPersistentEnergyPool :: FilePath -> PersistentEnergyPool-mkPersistentEnergyPool = mkPersistent 0--instance EnergyPool PersistentEnergyPool where- replenish = putPS- withdraw xWanted = do- xTotal <- getPS- let x = min xWanted xTotal- putPS (xTotal - x)- return x- available = getPS
src/ALife/Creatur/Task.hs view
@@ -27,6 +27,7 @@ simpleJob, startupHandler, shutdownHandler,+ doNothing, exceptionHandler, checkPopSize, requestShutdown@@ -62,6 +63,11 @@ exceptionHandler :: Universe u => u -> SomeException -> IO u exceptionHandler u x = execStateT (writeToLog ("WARNING: " ++ show x)) u++-- | Can be used as a startupHandler, shutdownHandler,+-- startRoundProgram, or endRoundProgram+doNothing :: Monad m => m ()+doNothing = return () runNoninteractingAgents :: (Universe u, Serialize (Agent u))
src/ALife/Creatur/Universe.hs view
@@ -46,9 +46,7 @@ startOfRound, endOfRound, refreshLineup,- markDone,- replenishEnergyPool,- withdrawEnergy+ markDone ) where import Prelude hiding (lookup)@@ -63,7 +61,6 @@ import qualified ALife.Creatur.Database.CachedFileSystem as CFS import qualified ALife.Creatur.Logger as L import qualified ALife.Creatur.Logger.SimpleLogger as SL-import qualified ALife.Creatur.EnergyPool as E import ALife.Creatur.Util (stateMap, shuffle) import Control.Monad.IO.Class (liftIO) import Control.Monad.Random (evalRandIO)@@ -73,9 +70,8 @@ -- | A habitat containing artificial life. class (C.Clock (Clock u), L.Logger (Logger u), D.Database (AgentDB u),- N.Namer (Namer u), CL.Checklist (Checklist u),- E.EnergyPool (EnergyPool u), A.Agent (Agent u), D.Record (Agent u),- Agent u ~ D.DBRecord (AgentDB u))+ N.Namer (Namer u), CL.Checklist (Checklist u), A.Agent (Agent u),+ D.Record (Agent u), Agent u ~ D.DBRecord (AgentDB u)) => Universe u where type Agent u type Clock u@@ -93,9 +89,6 @@ type Checklist u checklist :: u -> Checklist u setChecklist :: u -> Checklist u -> u- type EnergyPool u- energyPool :: u -> EnergyPool u- setEnergyPool :: u -> EnergyPool u -> u withClock :: (Universe u, Monad m) => StateT (Clock u) m a -> StateT u m a withClock program = do@@ -130,13 +123,6 @@ u <- get stateMap (setChecklist u) checklist program -withEnergyPool- :: (Universe u, Monad m)- => StateT (EnergyPool u) m a -> StateT u m a-withEnergyPool program = do- u <- get- stateMap (setEnergyPool u) energyPool program- -- | The current "time" (counter) in this universe currentTime :: Universe u => StateT u IO A.Time currentTime = withClock C.currentTime@@ -290,30 +276,13 @@ shuffledAgentIds = agentIds >>= liftIO . evalRandIO . shuffle --- | Replenish the energy pool-replenishEnergyPool :: Universe u => Double -> StateT u IO ()-replenishEnergyPool e = do- withEnergyPool (E.replenish e)- y <- withEnergyPool E.available- writeToLog $ "Replenished energy pool, " ++ show y ++ " available"---- | Withdraw energy from the pool-withdrawEnergy :: Universe u => Double -> StateT u IO Double-withdrawEnergy e = do- x <- withEnergyPool (E.withdraw e)- y <- withEnergyPool E.available- writeToLog $ "Withdrew " ++ show x ++ " from energy pool, "- ++ show y ++ " available"- return x- data SimpleUniverse a = SimpleUniverse { suClock :: K.PersistentCounter, suLogger :: SL.SimpleLogger, suDB :: FS.FSDatabase a, suNamer :: N.SimpleNamer,- suChecklist :: CL.PersistentChecklist,- suEnergyPool :: E.PersistentEnergyPool+ suChecklist :: CL.PersistentChecklist } deriving (Show, Eq) instance (A.Agent a, D.Record a) => Universe (SimpleUniverse a) where@@ -333,19 +302,15 @@ type Checklist (SimpleUniverse a) = CL.PersistentChecklist checklist = suChecklist setChecklist u cl = u { suChecklist=cl }- type EnergyPool (SimpleUniverse a) = E.PersistentEnergyPool- energyPool = suEnergyPool- setEnergyPool u cl = u { suEnergyPool=cl } mkSimpleUniverse :: String -> FilePath -> SimpleUniverse a mkSimpleUniverse name dir- = SimpleUniverse c l d n cl e+ = SimpleUniverse c l d n cl where c = K.mkPersistentCounter (dir ++ "/clock") l = SL.mkSimpleLogger (dir ++ "/log/" ++ name ++ ".log") d = FS.mkFSDatabase (dir ++ "/db") n = N.mkSimpleNamer (name ++ "_") (dir ++ "/namer") cl = CL.mkPersistentChecklist (dir ++ "/todo")- e = E.mkPersistentEnergyPool (dir ++ "/energy") data CachedUniverse a = CachedUniverse {@@ -353,8 +318,7 @@ cuLogger :: SL.SimpleLogger, cuDB :: CFS.CachedFSDatabase a, cuNamer :: N.SimpleNamer,- cuChecklist :: CL.PersistentChecklist,- cuEnergyPool :: E.PersistentEnergyPool+ cuChecklist :: CL.PersistentChecklist } deriving (Show, Eq) instance (A.Agent a, D.SizedRecord a) => Universe (CachedUniverse a) where@@ -374,16 +338,12 @@ type Checklist (CachedUniverse a) = CL.PersistentChecklist checklist = cuChecklist setChecklist u cl = u { cuChecklist=cl }- type EnergyPool (CachedUniverse a) = E.PersistentEnergyPool- energyPool = cuEnergyPool- setEnergyPool u cl = u { cuEnergyPool=cl } mkCachedUniverse :: String -> FilePath -> Int -> CachedUniverse a mkCachedUniverse name dir cacheSize- = CachedUniverse c l d n cl e+ = CachedUniverse c l d n cl where c = K.mkPersistentCounter (dir ++ "/clock") l = SL.mkSimpleLogger (dir ++ "/log/" ++ name ++ ".log") d = CFS.mkCachedFSDatabase (dir ++ "/db") cacheSize n = N.mkSimpleNamer (name ++ "_") (dir ++ "/namer") cl = CL.mkPersistentChecklist (dir ++ "/todo")- e = E.mkPersistentEnergyPool (dir ++ "/energy")