Context
A typed collection of agents with optional Projections attached. Modeled on Repast Simphony's context concept: membership lives here, structure (positions, edges, networks) lives in attached projections.
Why a separate abstraction from AgentModel._agents:
The model-level registry tracks every setup-time agent for lifecycle dispatch. Contexts are user-defined groupings — pedestrians vs. vehicles, friendlies vs. adversaries, members of organization X — and the same agent can belong to multiple contexts.
Projections need a stable, queryable membership set to attach to. Contexts give it to them; projections subscribe to add / remove via
Projection.onAgentJoined/onAgentLeft.
Context is a ModelElement so it gets a stable name in the model, lifecycle hooks (in case future projections need them), and a place in KSL reporting output. Membership changes during a replication are fine; the context itself must be constructed before simulate().
Generic in the agent type A — typically AgentModel.Agent or a user subclass. Bounded by AgentLike so contexts can also hold PermanentAgent or AgentResource instances.
Properties
Functions
Attach projection to this context. The projection's lifecycle hooks fire on subsequent add / remove operations. Existing members do NOT retroactively trigger onAgentJoined — projections that need to initialize state for all existing members should do so explicitly.
Clear all members and notify projections. Rarely needed now that initialize resets runtime membership automatically; still available for models that want to empty the context mid-replication.
Reset context membership at the start of every replication.