AgentResource

open class AgentResource @JvmOverloads constructor(val agentModel: AgentModel, name: String? = null, capacity: Int = Defaults.capacity, queue: RequestQ? = null) : ResourceWithQ, AgentLike(source)

A resource that is also an agent. Behaves like an ordinary ResourceWithQ from the seizing entity's perspective — entities pass it to seize / release from inside a process — and on top of that exposes the agent capabilities the user might want for a forklift, repair worker, or nurse:

  • a mailbox for receiving AgentMessage traffic, which a send delivers into directly, in the sender's call,

  • an optional AgentModel.Statechart for reactive autonomous behavior,

  • convenience helpers for taking the resource off-shift (goOffShift) and back on-shift (goOnShift).

AgentResource sits in the permanent tier of agents — it is a ResourceWithQ, which is a ksl.simulation.ModelElement, so instances must be constructed before simulate() runs. Its statechart lifecycle is driven by its own initialize() / afterReplication() hooks rather than by AgentModel's registry.

Note that AgentResource is intentionally not an AgentModel.Agent subclass — it's-a Resource first. The AgentLike interface gives it the same mailbox/statechart capabilities without forcing the inheritance.

Per-request decisions (shouldGrant / refuse) are not in this version: the cleanest hook for that intercepts inside ProcessModel's seize implementation, which is out of scope. The on/off-shift pattern (capacity manipulation) covers most of the practical refusal use cases — an off-shift resource cannot be newly seized, and in-flight allocations finish naturally.

Parameters

agentModel

the enclosing AgentModel (needed for mailbox / statechart machinery; passed explicitly so AgentResource can be parented to it)

name

optional name for the resource

capacity

initial capacity (also the on-shift capacity to restore after returning from a break)

queue

optional shared request queue; if null a private one is created

Inheritors

Constructors

Link copied to clipboard
constructor(agentModel: AgentModel, name: String? = null, capacity: Int = Defaults.capacity, queue: RequestQ? = null)

Types

Link copied to clipboard
object Defaults

Mutable global defaults for AgentResource construction.

Properties

Link copied to clipboard

The agent model this resource belongs to, through which its behavior can reach other agents.

Link copied to clipboard
open override val currentTime: Double

The current simulation time, exposed via AgentLike so statechart actions can read it without reaching for time on the outer model element.

Link copied to clipboard

Default mailbox for receiving AgentMessage traffic. A send to this resource delivers into it directly, in the sender's call.

Link copied to clipboard

The capacity goOnShift restores after a break: the resource's initialCapacity for the current replication.

Link copied to clipboard

Optional performance observer attached to this resource's mailbox (and statechart, if one is configured). Created by collectPerformance; null otherwise.

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

Optional statechart governing this resource's reactive behavior. Configured via statechart and started automatically at replication initialization by this resource's own initialize() hook.

Functions

Link copied to clipboard
protected open override fun afterReplication()

It is essential that subclasses that override this function call the super. This ensures that suspended entities are cleaned up after a replication

Link copied to clipboard

Build a statechart without installing it. See AgentModel.Agent.buildStatechart.

Link copied to clipboard
protected open override fun checkBehaviorAllowed()

A resource with a statechart cannot also have a behavior: it has one source of truth for its reactions.

Link copied to clipboard

Opt this resource in to mailbox-traffic and (if a statechart was configured before this call) statechart-state statistics. Must be called before simulate() runs since the returned AgentModel.AgentPerformance is a ksl.simulation.ModelElement. Idempotent — a second call returns the existing observer.

Link copied to clipboard
protected open override fun initialize()

This method should be overridden by subclasses that need actions performed to initialize prior to a replication. It is called once before each replication occurs if the model element wants initialization. It is called after beforeReplication() is called

Link copied to clipboard

Declare and install this resource's statechart in one step. May be called at most once; a second call throws. Use buildStatechart + useStatechart for the multi-variant / design-comparison case. See AgentModel.Statechart for the DSL and semantics. Throws when the resource has a behavior: a resource has a statechart or a behavior, not both.

Link copied to clipboard

Gracefully stop this resource's statechart, if any. Idempotent.

Link copied to clipboard

Select the active statechart. Allowed only when the current chart (if any) is not started — between replications for a setup-time resource. The selected chart is started by this resource's initialize at the next replication. See AgentModel.Agent.useStatechart. Installing a chart throws when the resource has a behavior; useStatechart(null) is always allowed.