Agent

open inner class Agent(aName: String? = null) : ProcessModel.Entity, AgentLike(source)

An autonomous, reactive actor. An Agent is a ProcessModel.Entity (and therefore a QObject, not a ModelElement), so instances can be constructed at any time — including during a running replication. Each agent gets a POJO mailbox for receiving messages and may optionally have a statechart.

Two construction patterns:

Setup-time (before simulate()): the agent is added to the agents registry. Its statechart, if any, is started by AgentModel.initialize at each replication start and stopped by AgentModel.afterReplication. Use for the structural cast.

Runtime (during a replication): the agent is not added to the registry — it's an ephemeral actor that owns its own lifetime. Its statechart, if any, is auto-started by statechart { } since the simulation is already running. The caller is responsible for any cleanup; in typical arrival-driven patterns the agent's process completes and the agent is GC'd.

Behavior is supplied via the inherited process { } builder and/or a statechart. Both compose; see Statechart.

Parameters

aName

an optional name for the agent

Constructors

Link copied to clipboard
constructor(aName: String? = null)

Properties

Link copied to clipboard

Default mailbox for receiving AgentMessage traffic. Routes through the enclosing AgentModel's shared message bus.

Link copied to clipboard
open override var statechart: AgentModel.Statechart?

Optional statechart governing this agent's reactive behavior. Default null for AgentLike implementations that don't provide a statechart abstraction. The concrete agent types (AgentModel.Agent, AgentModel.PermanentAgent, AgentResource) each override this with their own backing field.

Functions

Link copied to clipboard

Build a statechart without installing it. Use to define alternative behaviors that can be selected via useStatechart — at construction time (e.g., per-instance design variants) or between runs (e.g., a Controls-package parameter that selects which design the next simulate() exercises).

Link copied to clipboard

Declare and install this agent's statechart in one step. May be called at most once per agent (use buildStatechart + useStatechart for the multi-variant case). If the simulation is already running (runtime creation), the chart starts immediately; otherwise AgentModel.initialize starts it at the beginning of each replication.

Link copied to clipboard

Gracefully stop the agent's active statechart, if any. Tears down its triggers and subscriptions and deregisters it. The agent persists; a different chart may be selected via useStatechart and started. Idempotent.

Link copied to clipboard

Select the agent's active statechart. Allowed only when the current chart (if any) is not started — between runs, before activation, or after the current chart has stopped / reached a final state. Throws otherwise. If the model is running when this is called, the new chart starts immediately; otherwise AgentModel.initialize starts it at the next replication.