AgentGenerator

protected inner class AgentGenerator<A : AgentModel.Agent>(agentFactory: () -> A, timeUntilFirst: RVariableIfc, timeBetween: RVariableIfc, context: AgentModel.Context<A>? = null, maxAgents: Long = Long.MAX_VALUE, timeOfLast: Double = Double.POSITIVE_INFINITY, var activationPriority: Int = KSLEvent.DEFAULT_PRIORITY + 1, name: String? = null) : EventGenerator(source)

Schedules the creation of agents over time and activates each new agent's default process. The agent-layer mirror of ksl.modeling.entity.ProcessModel.EntityGenerator, and the most direct translation of "entities arrive from a stochastic process" into the agent view. Being a subclass of EventGenerator, the usual generator controls apply.

Being protected, it is constructed from inside an AgentModel subclass — the same visibility EntityGenerator has.

private val arrivals = AgentGenerator(
agentFactory = { Shopper("shopper-${++created}") },
timeUntilFirst = ExponentialRV(2.0, streamNum = 1),
timeBetween = ExponentialRV(2.0, streamNum = 2),
context = shoppers,
)

What the generator does, and what it leaves to you

It creates the agent, optionally adds it to context, and activates its default process. It does not place the agent in a projection, because where a new agent belongs — which cell, which point, which node — is a modelling decision the generator cannot make. Do that in agentFactory, which runs before activation:

agentFactory = {
Shopper("shopper-${++created}").also { grid.placeAt(it, Cell(0, midRow)) }
}

The failure mode is quiet, so it is worth stating: an agent that never joins a context has no projection position, is invisible to Population queries, and does not appear in animation. Nothing raises an error — the model simply runs with an agent nobody can see. Passing context removes the commonest half of that mistake; the placement half stays with the factory.

Parameters

agentFactory

builds one agent; also the right place to position it

timeUntilFirst

time until the first agent is created

timeBetween

time between successive creations

context

optional context to add each new agent to before activation. Null means the factory is responsible for membership, if any is wanted

maxAgents

maximum number of agents to create

timeOfLast

simulated time after which no further agents are created

activationPriority

tie-break priority for the activation event

name

optional name for the generator

Constructors

Link copied to clipboard
constructor(agentFactory: () -> A, timeUntilFirst: RVariableIfc, timeBetween: RVariableIfc, context: AgentModel.Context<A>? = null, maxAgents: Long = Long.MAX_VALUE, timeOfLast: Double = Double.POSITIVE_INFINITY, activationPriority: Int = KSLEvent.DEFAULT_PRIORITY + 1, name: String? = null)

Properties

Link copied to clipboard

Functions

Link copied to clipboard
protected open override fun generate()