Package modelarium
Class ModelElement
java.lang.Object
modelarium.ModelElement
- All Implemented Interfaces:
DeepCopyable<ModelElement>
- Direct Known Subclasses:
Agent,Environment
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 Summary
ConstructorsConstructorDescriptionModelElement(String name, AttributeSetCollection attributeSetCollection) Constructs a model element with the given name and attribute set collection. -
Method Summary
Modifier and TypeMethodDescriptionprotected EnvironmentRetrieves the current environment for the model element.protected AgentaccessExternalAgentByName(String targetAgentName) Retrieves an external agent by name using the accessor associated with this element.protected AgentSetaccessExternalAgentsByFilter(Predicate<Agent> filter) Retrieves a set of agents that match the given filter predicate.getName()abstract voidrun()Defines the logic to be executed on each simulation tick.voidsetModelElementAccessor(ModelElementAccessor modelElementAccessor) Sets the model element accessor, which provides external access to model context, data, and messaging.voidsetup()Initialises the attribute set for this element by calling its setup method.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface utils.DeepCopyable
deepCopy
-
Constructor Details
-
ModelElement
Constructs a model element with the given name and attribute set collection.- Parameters:
name- the unique name of the elementattributeSetCollection- the set of attributes to associate with this element
-
-
Method Details
-
getName
- Returns:
- the name of this model element
-
getAttributeSetCollection
- Returns:
- the attribute set collection for this model element
-
setModelElementAccessor
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
- Returns:
- the accessor associated with this element, if initialised
-
accessExternalAgentByName
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
Retrieves a set of agents that match the given filter predicate.- Parameters:
filter- the predicate used to select agents- Returns:
- an
AgentSetcontaining the matching agents, or null if retrieval fails
-
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).
-