Copyright | (c) Amy de Buitléir 2012-2014 |
---|---|
License | BSD-style |
Maintainer | amy@nualeargais.ie |
Stability | experimental |
Portability | portable |
Safe Haskell | None |
Language | Haskell98 |
Provides a habitat for artificial life.
- 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 Agent u
- type Clock u
- type Logger u
- type AgentDB u
- type Namer u
- type Checklist u
- type EnergyPool u
- clock :: u -> Clock u
- setClock :: u -> Clock u -> u
- logger :: u -> Logger u
- setLogger :: u -> Logger u -> u
- agentDB :: u -> AgentDB u
- setAgentDB :: u -> AgentDB u -> u
- agentNamer :: u -> Namer u
- setNamer :: u -> Namer u -> u
- checklist :: u -> Checklist u
- setChecklist :: u -> Checklist u -> u
- energyPool :: u -> EnergyPool u
- setEnergyPool :: u -> EnergyPool u -> u
- data SimpleUniverse a
- data CachedUniverse a
- mkSimpleUniverse :: String -> FilePath -> SimpleUniverse a
- mkCachedUniverse :: String -> FilePath -> Int -> CachedUniverse a
- currentTime :: Universe u => StateT u IO Time
- incTime :: Universe u => StateT u IO ()
- writeToLog :: Universe u => String -> StateT u IO ()
- agentIds :: Universe u => StateT u IO [AgentId]
- archivedAgentIds :: Universe u => StateT u IO [AgentId]
- popSize :: Universe u => StateT u IO Int
- getAgent :: (Universe u, Serialize (Agent u)) => AgentId -> StateT u IO (Either String (Agent u))
- getAgentFromArchive :: (Universe u, Serialize (Agent u)) => AgentId -> StateT u IO (Either String (Agent u))
- getAgents :: (Universe u, Serialize (Agent u)) => [AgentId] -> StateT u IO (Either String [Agent u])
- store :: (Universe u, Serialize (Agent u)) => Agent u -> StateT u IO ()
- genName :: Universe u => StateT u IO AgentId
- type AgentProgram u = Agent u -> StateT u IO (Agent u)
- withAgent :: (Universe u, Serialize (Agent u)) => AgentProgram u -> AgentId -> StateT u IO ()
- type AgentsProgram u = [Agent u] -> StateT u IO [Agent u]
- withAgents :: (Universe u, Serialize (Agent u)) => AgentsProgram u -> [AgentId] -> StateT u IO ()
- isNew :: Universe u => AgentId -> StateT u IO Bool
- lineup :: Universe u => StateT u IO [AgentId]
- startOfRound :: Universe u => StateT u IO Bool
- endOfRound :: Universe u => StateT u IO Bool
- refreshLineup :: Universe u => StateT u IO ()
- markDone :: Universe u => AgentId -> StateT u IO ()
- replenishEnergyPool :: Universe u => Double -> StateT u IO ()
- withdrawEnergy :: Universe u => Double -> StateT u IO Double
Constructors
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 Source
A habitat containing artificial life.
type EnergyPool u Source
setClock :: u -> Clock u -> u Source
logger :: u -> Logger u Source
setLogger :: u -> Logger u -> u Source
agentDB :: u -> AgentDB u Source
setAgentDB :: u -> AgentDB u -> u Source
agentNamer :: u -> Namer u Source
setNamer :: u -> Namer u -> u Source
checklist :: u -> Checklist u Source
setChecklist :: u -> Checklist u -> u Source
energyPool :: u -> EnergyPool u Source
setEnergyPool :: u -> EnergyPool u -> u Source
(Agent a, SizedRecord a) => Universe (CachedUniverse a) | |
(Agent a, Record a) => Universe (SimpleUniverse a) |
data SimpleUniverse a Source
Eq (SimpleUniverse a) | |
Show (SimpleUniverse a) | |
(Agent a, Record a) => Universe (SimpleUniverse a) | |
type Agent (SimpleUniverse a) = a | |
type Clock (SimpleUniverse a) = PersistentCounter | |
type Logger (SimpleUniverse a) = SimpleLogger | |
type AgentDB (SimpleUniverse a) = FSDatabase a | |
type Namer (SimpleUniverse a) = SimpleNamer | |
type Checklist (SimpleUniverse a) = PersistentChecklist | |
type EnergyPool (SimpleUniverse a) = PersistentEnergyPool |
data CachedUniverse a Source
Eq a => Eq (CachedUniverse a) | |
Show a => Show (CachedUniverse a) | |
(Agent a, SizedRecord a) => Universe (CachedUniverse a) | |
type Agent (CachedUniverse a) = a | |
type Clock (CachedUniverse a) = PersistentCounter | |
type Logger (CachedUniverse a) = SimpleLogger | |
type AgentDB (CachedUniverse a) = CachedFSDatabase a | |
type Namer (CachedUniverse a) = SimpleNamer | |
type Checklist (CachedUniverse a) = PersistentChecklist | |
type EnergyPool (CachedUniverse a) = PersistentEnergyPool |
mkSimpleUniverse :: String -> FilePath -> SimpleUniverse a Source
mkCachedUniverse :: String -> FilePath -> Int -> CachedUniverse a Source
Clock
currentTime :: Universe u => StateT u IO Time Source
The current "time" (counter) in this universe
incTime :: Universe u => StateT u IO () Source
Increment the current "time" (counter) in this universe.
Logging
writeToLog :: Universe u => String -> StateT u IO () Source
Write a message to the log file for this universe.
Database
archivedAgentIds :: Universe u => StateT u IO [AgentId] Source
Returns the list of (dead) agents in the archive.
getAgent :: (Universe u, Serialize (Agent u)) => AgentId -> StateT u IO (Either String (Agent u)) Source
Fetches the agent with the specified ID from the population.
Note: Changes made to this agent will not "take" until
is called.store
getAgentFromArchive :: (Universe u, Serialize (Agent u)) => AgentId -> StateT u IO (Either String (Agent u)) Source
Fetches the agent with the specified ID from the archive.
getAgents :: (Universe u, Serialize (Agent u)) => [AgentId] -> StateT u IO (Either String [Agent u]) Source
Fetches the agents with the specified IDs from the population.
store :: (Universe u, Serialize (Agent u)) => Agent u -> StateT u IO () Source
If the agent is alive, adds it to the population (replacing the the previous copy of that agent, if any). If the agent is dead, places it in the archive.
Names
Agent programs
type AgentProgram u = Agent u -> StateT u IO (Agent u) Source
A program involving one agent. The input parameter is the agent. The program must return the agent (which may have been modified).
withAgent :: (Universe u, Serialize (Agent u)) => AgentProgram u -> AgentId -> StateT u IO () Source
Run a program involving one agent
type AgentsProgram u = [Agent u] -> StateT u IO [Agent u] Source
A program involving multiple agents. The input parameter is a list of agents. The program must return a list of agents that have been *modified*. The order of the output list is not important.
withAgents :: (Universe u, Serialize (Agent u)) => AgentsProgram u -> [AgentId] -> StateT u IO () Source
Agent rotation
lineup :: Universe u => StateT u IO [AgentId] Source
Returns the current lineup of (living) agents in the universe.
Note: Check for
and call endOfRound
if needed
before invoking this function.refreshLineup
startOfRound :: Universe u => StateT u IO Bool Source
Returns true if no agents have yet their turn at the CPU for this round.
endOfRound :: Universe u => StateT u IO Bool Source
Returns true if the lineup is empty or if all of the agents in the lineup have had their turn at the CPU for this round.
refreshLineup :: Universe u => StateT u IO () Source
Creates a fresh lineup containing all of the agents in the population, in random order.
markDone :: Universe u => AgentId -> StateT u IO () Source
Mark the current agent done. If it is still alive, it will move to the end of the lineup.
replenishEnergyPool :: Universe u => Double -> StateT u IO () Source
Replenish the energy pool