Interface Context

All Known Subinterfaces:
AgentContext, EntityContext, EnvironmentContext
All Known Implementing Classes:
AgentSimulationContext, EnvironmentSimulationContext, SimulationContext

public sealed interface Context permits SimulationContext, EntityContext
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 Details

    • getClock

      ReadOnlyClock getClock()
      Returns the model's clock.
      Returns:
      a read-only view of the model's clock
    • doesAgentExistInThisCore

      boolean doesAgentExistInThisCore(String agentName)
      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

      ReadOnlyAgent getAgent(String targetAgentName)
      Retrieves an agent by name.
      Parameters:
      targetAgentName - the name of the agent to retrieve
      Returns:
      a read-only view of the requested agent
    • getFilteredAgents

      ReadOnlyAgentSet getFilteredAgents(Predicate<ReadOnlyAgent> filter)
      Retrieves the living-only agents matching a filter.
      Parameters:
      filter - a predicate to apply to each agent
      Returns:
      a new ReadOnlyAgentSet containing the matching agents
    • getFilteredAgents

      ReadOnlyAgentSet getFilteredAgents(Predicate<ReadOnlyAgent> agentFilter, boolean includeDeadAgents)
      Returns an agents matching a filter
      Parameters:
      agentFilter - a predicate to apply to each agent
      includeDeadAgents - a boolean which determines if dead agents are to be included in the output agent set or not
      Returns:
      a new ReadOnlyAgentSet containing only matching agents
    • getRandom

      RandomGenerator getRandom()
      Returns the random generator this model element can use.
      Returns:
      the element's RandomGenerator instance
    • addAgent

      void addAgent(Agent agent)
      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

      void addAgents(AgentSet agentSet)
      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

      void addAgents(List<Agent> agentList)
      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

      void killAgent(String agentName)
      Kills the agent with the given name.
      Parameters:
      agentName - the agent's name as a string
    • killAgent

      void killAgent(ReadOnlyAgent agent)
      Kills the agent of the given ReadOnlyAgent instance.
      Parameters:
      agent - the agent to kill
    • killAgents

      void killAgents(List<String> agentNames)
      Kills all the agents with names in a given List<String> instance.
      Parameters:
      agentNames - the list of names of agents to kill
    • killAgents

      void killAgents(ReadOnlyAgentSet agentSet)
      Kills all the agents in a given ReadOnlyAgentSet instance.
      Parameters:
      agentSet - the agent set of agents to kill