Package modelarium

Class ModelElementAccessor

java.lang.Object
modelarium.ModelElementAccessor

public class ModelElementAccessor extends Object
Provides a model element (either an agent or the environment) with access to relevant simulation resources such as the local environment, other agents, and shared utilities, including communication and caching systems.

This class abstracts access logic based on model settings, including:

  • Local access versus coordinated inter-thread access
  • Optional caching of agents and environments
  • Safe agent filtering with predicate functions
  • The associated model clock
  • Constructor Details

    • ModelElementAccessor

      public ModelElementAccessor(ModelElement modelElement, AgentSet localAgentSet, ModelSettings settings, WorkerCache cache, RequestResponseInterface requestResponseInterface, Environment localEnvironment)
      Constructs a new accessor for a model element.
      Parameters:
      modelElement - the model element (agent or environment) this accessor serves
      localAgentSet - the set of agents assigned to this core/thread
      settings - the shared model settings object
      cache - the local cache for agent/environment access (may be null if not used)
      requestResponseInterface - the communication interface for synchronised coordination
      localEnvironment - the local copy of the environment assigned to this model element
  • Method Details

    • setModelClock

      public void setModelClock(ModelClock clock)
      Sets the associated clock instance. Once a clock has been set, it cannot be reset.
      Parameters:
      clock - the ModelClock instance to set with
    • getModelClock

      public ModelClock getModelClock()
      Retrieves the associated clock instance.
      Returns:
      the ModelClock instance
    • doesAgentExistInThisCore

      public boolean doesAgentExistInThisCore(String agentName)
      Checks whether an agent with the given name exists in this core/thread.
      Parameters:
      agentName - the name of the agent to check
      Returns:
      true if the agent exists locally
    • getAgentByName

      public Agent getAgentByName(String targetAgentName)
      Retrieves an agent by name, checking local storage first, then cache, then (if enabled) contacting the coordinator.
      Parameters:
      targetAgentName - the name of the agent to retrieve
      Returns:
      the agent instance, or null if not found or if retrieval failed
    • getFilteredAgents

      public AgentSet getFilteredAgents(Predicate<Agent> filter)
      Retrieves a set of agents that match the given filter predicate. May involve coordinator requests or use of cached results, depending on settings.
      Parameters:
      filter - the predicate used to select agents
      Returns:
      an AgentSet containing the matching agents, or null if retrieval fails
    • getEnvironment

      public Environment getEnvironment()
      Retrieves the current environment for the model element. This may be the local environment, a cached copy, or one retrieved from the coordinator.
      Returns:
      the environment instance available to this model element