Package modelarium

Class ModelElement

java.lang.Object
modelarium.ModelElement
All Implemented Interfaces:
DeepCopyable<ModelElement>
Direct Known Subclasses:
Agent, Environment

public abstract class ModelElement extends Object implements DeepCopyable<ModelElement>
Abstract base class for all model elements in the simulation.

Each model element represents either an Agent or the Environment and holds a unique name, a set of attributes, and a reference to its ModelElementAccessor.

  • Constructor Details

    • ModelElement

      public ModelElement(String name, AttributeSetCollection attributeSetCollection)
      Constructs a model element with the given name and attribute set collection.
      Parameters:
      name - the unique name of the element
      attributeSetCollection - the set of attributes to associate with this element
  • Method Details

    • getName

      public String getName()
      Returns:
      the name of this model element
    • getAttributeSetCollection

      public AttributeSetCollection getAttributeSetCollection()
      Returns:
      the attribute set collection for this model element
    • setModelElementAccessor

      public void setModelElementAccessor(ModelElementAccessor modelElementAccessor)
      Sets the model element accessor, which provides external access to model context, data, and messaging.

      This method is protected, as it should only be called during model setup.

      Parameters:
      modelElementAccessor - the accessor to associate with this element
    • getModelElementAccessor

      public ModelElementAccessor getModelElementAccessor()
      Returns:
      the accessor associated with this element, if initialised
    • accessExternalAgentByName

      protected Agent accessExternalAgentByName(String targetAgentName)
      Retrieves an external agent by name using the accessor associated with this element.
      Parameters:
      targetAgentName - the name of the agent to retrieve
      Returns:
      the agent instance, or null if not found or if retrieval failed
    • accessExternalAgentsByFilter

      protected AgentSet accessExternalAgentsByFilter(Predicate<Agent> filter)
      Retrieves a set of agents that match the given filter predicate.
      Parameters:
      filter - the predicate used to select agents
      Returns:
      an AgentSet containing the matching agents, or null if retrieval fails
    • accessEnvironment

      protected Environment accessEnvironment()
      Retrieves the current environment for the model element.
      Returns:
      the environment instance available to this model element
    • setup

      public void setup()
      Initialises the attribute set for this element by calling its setup method. This should be called before the simulation begins.
    • run

      public abstract void run()
      Defines the logic to be executed on each simulation tick. Must be implemented by all concrete subclasses (agents and environment).