Skip to main content

AgentModel

Trait AgentModel 

Source
pub trait AgentModel:
    Send
    + Sync
    + 'static {
    type Lanes: AgentLanes;
    type Field: FieldLayer;
    type Index: NeighborIndex;
    type Params: Send + Sync;
    type Tally: ChunkTally;
Show 10 associated constants and 8 methods const NAME: &'static str; const ID: &'static str; const DESCRIPTION: &'static str; const PALETTE: &'static [[u8; 4]]; const STATS: &'static [StatDescriptor]; const DEFAULT_AGENTS: u32; const DEFAULT_EXTENT: Extent; const ACTIONS: &'static [ActionDescriptor] = _; const CHUNK: usize = 512; const MAX_AGENTS: u32 = 10_000_000; // Required methods fn param_descriptors() -> Vec<ParamDescriptor>; fn from_params(params: &[ParamValue], extent: Extent) -> Self::Params; fn init( lanes: &mut Self::Lanes, extent: Extent, params: &[ParamValue], rng: &mut u64, ); fn run_step_pass( lanes: &mut Self::Lanes, ctx: &StepCtx<'_, Self>, seed: u64, tick: u64, ) -> Self::Tally; fn stats( lanes: &Self::Lanes, field: &Self::Field, tally: &Self::Tally, ) -> Vec<StatValue>; // Provided methods fn index_cell_size(_params: &Self::Params) -> f32 { ... } fn run_deposit_pass( _lanes: &Self::Lanes, _deposits: &mut <Self::Field as FieldLayer>::DepositLanes, _ctx: &StepCtx<'_, Self>, ) { ... } fn act( _action: usize, _lanes: &mut Self::Lanes, _field: &mut Self::Field, _extent: Extent, _params: &[ParamValue], _rng: &mut u64, ) { ... }
}
Expand description

A population of agents, optionally over a field.

The engine owns lane allocation, double buffering, chunking, seeding, parameter storage, the views, and the whole SimState impl.

Required Associated Constants§

Source

const NAME: &'static str

Name shown in the UI.

Source

const ID: &'static str

Stable id that identifies the model in a model set, on the command line and in a spec file.

Source

const DESCRIPTION: &'static str

One-line description shown in the UI.

Source

const PALETTE: &'static [[u8; 4]]

Agent colours. The field layer carries its own colours.

Source

const STATS: &'static [StatDescriptor]

Stat series for the history chart. Declared once, so stats returns bare values.

Source

const DEFAULT_AGENTS: u32

Default of num_agents.

Source

const DEFAULT_EXTENT: Extent

Defaults of world_width and world_height.

Provided Associated Constants§

Source

const ACTIONS: &'static [ActionDescriptor] = _

One-off steps the user can trigger. Each gets a button in the Parameters panel.

Source

const CHUNK: usize = 512

Agents per chunk in a step pass.

The chunk index seeds the RNG, so the value is a fixed constant and never derived from the thread count. Keep it small enough that a typical population still splits across every core.

Source

const MAX_AGENTS: u32 = 10_000_000

Upper bound of num_agents.

Required Associated Types§

Source

type Lanes: AgentLanes

Agent storage, declared with agent_lanes!.

Source

type Field: FieldLayer

Grid layer under the population, or NoField for a model without a field.

Source

type Index: NeighborIndex

Neighbour index, SpatialHash when agents read each other and NoIndex otherwise.

Source

type Params: Send + Sync

Pre-extracted hot parameters, rebuilt once per tick.

Source

type Tally: ChunkTally

Per chunk reduction, accumulated across ticks. () when there is nothing to count.

The engine merges each tick’s tally into one total for the whole run, and never resets it. A count of events per tick therefore grows with the run. A u32 total stops at u32::MAX, and a u64 holds any count a run can reach.

Required Methods§

Source

fn param_descriptors() -> Vec<ParamDescriptor>

Model parameters. num_agents, world_width and world_height are prepended by the engine at indices 0, 1 and 2.

Source

fn from_params(params: &[ParamValue], extent: Extent) -> Self::Params

Extracts the hot parameters for one tick. params is this model’s own slice, so its indices are 0 based and cannot shift when the engine or a field layer changes.

Source

fn init( lanes: &mut Self::Lanes, extent: Extent, params: &[ParamValue], rng: &mut u64, )

Fills the lanes for a new run.

lanes holds num_agents agents at their initial values, and params is this model’s own slice.

Source

fn run_step_pass( lanes: &mut Self::Lanes, ctx: &StepCtx<'_, Self>, seed: u64, tick: u64, ) -> Self::Tally

Runs the step pass and returns its tally.

The body is normally one call to the run_pass method that agent_lanes! generates, with a per agent kernel.

Source

fn stats( lanes: &Self::Lanes, field: &Self::Field, tally: &Self::Tally, ) -> Vec<StatValue>

Current statistics, in Self::STATS order.

Provided Methods§

Source

fn index_cell_size(_params: &Self::Params) -> f32

Returns the neighbour index’s cell size for these params.

The engine reads it every tick, so a live edit takes effect.

Source

fn run_deposit_pass( _lanes: &Self::Lanes, _deposits: &mut <Self::Field as FieldLayer>::DepositLanes, _ctx: &StepCtx<'_, Self>, )

Fills the field’s deposit lanes before the step pass, without moving any agent.

The default does nothing.

Source

fn act( _action: usize, _lanes: &mut Self::Lanes, _field: &mut Self::Field, _extent: Extent, _params: &[ParamValue], _rng: &mut u64, )

Runs Self::ACTIONS entry action over the current lanes and field.

Receives the arguments of init plus the field. An action is a setup step that the user requests mid run. rng is a separate stream, so a press leaves the tick’s draws where they were.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§