Package modelarium.entities.contexts
Interface Context
- All Known Subinterfaces:
AgentContext,EntityContext,EnvironmentContext
- All Known Implementing Classes:
AgentSimulationContext,EnvironmentSimulationContext,SimulationContext
Interface for providing model elements with access to shared simulation resources.
This interface exposes the model's clock and random generator along with read-only access to other agents, whether those agents live on the same core or (in a synchronised model) on another core via the co-ordinator.
-
Method Summary
Modifier and TypeMethodDescriptionvoidAdds an agent to the current core's local agent set, creating the context the agent needs to run.voidAdds each agent in a list to the current core's local agent set, creating the contexts the agents need to run.voidAdds each agent in an agent set to the current core's local agent set, creating the contexts the agents need to run.booleandoesAgentExistInThisCore(String agentName) Returns whether an agent with the given name exists on the current core.Retrieves an agent by name.getClock()Returns the model's clock.intReturns the model's current population size.getFilteredAgents(Predicate<ReadOnlyAgent> filter) Retrieves the living-only agents matching a filter.getFilteredAgents(Predicate<ReadOnlyAgent> agentFilter, boolean includeDeadAgents) Returns an agents matching a filterReturns the random generator this model element can use.voidKills the agent with the given name.voidkillAgent(ReadOnlyAgent agent) Kills the agent of the givenReadOnlyAgentinstance.voidkillAgents(List<String> agentNames) voidkillAgents(ReadOnlyAgentSet agentSet) Kills all the agents in a givenReadOnlyAgentSetinstance.
-
Method Details
-
getClock
ReadOnlyClock getClock()Returns the model's clock.- Returns:
- a read-only view of the model's clock
-
doesAgentExistInThisCore
Returns whether an agent with the given name exists on the current core.- Parameters:
agentName- the name of the agent to check for- Returns:
- true if the agent exists in this core's local agent set, false otherwise
-
getCurrentPopulationSize
int getCurrentPopulationSize()Returns the model's current population size.- Returns:
- the current population size as an int
-
getAgent
Retrieves an agent by name.- Parameters:
targetAgentName- the name of the agent to retrieve- Returns:
- a read-only view of the requested agent
-
getFilteredAgents
Retrieves the living-only agents matching a filter.- Parameters:
filter- a predicate to apply to each agent- Returns:
- a new
ReadOnlyAgentSetcontaining the matching agents
-
getFilteredAgents
Returns an agents matching a filter- Parameters:
agentFilter- a predicate to apply to each agentincludeDeadAgents- a boolean which determines if dead agents are to be included in the output agent set or not- Returns:
- a new
ReadOnlyAgentSetcontaining only matching agents
-
getRandom
RandomGenerator getRandom()Returns the random generator this model element can use.- Returns:
- the element's
RandomGeneratorinstance
-
addAgent
Adds an agent to the current core's local agent set, creating the context the agent needs to run.- Parameters:
agent- the agent to add
-
addAgents
Adds each agent in an agent set to the current core's local agent set, creating the contexts the agents need to run.- Parameters:
agentSet- the agents to add
-
addAgents
Adds each agent in a list to the current core's local agent set, creating the contexts the agents need to run.- Parameters:
agentList- the agents to add
-
killAgent
Kills the agent with the given name.- Parameters:
agentName- the agent's name as a string
-
killAgent
Kills the agent of the givenReadOnlyAgentinstance.- Parameters:
agent- the agent to kill
-
killAgents
- Parameters:
agentNames- the list of names of agents to kill
-
killAgents
Kills all the agents in a givenReadOnlyAgentSetinstance.- Parameters:
agentSet- the agent set of agents to kill
-