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§
Sourceconst ID: &'static str
const ID: &'static str
Stable id that identifies the model in a model set, on the command line and in a spec file.
Sourceconst DESCRIPTION: &'static str
const DESCRIPTION: &'static str
One-line description shown in the UI.
Sourceconst STATS: &'static [StatDescriptor]
const STATS: &'static [StatDescriptor]
Stat series for the history chart. Declared once, so stats returns bare values.
Sourceconst DEFAULT_AGENTS: u32
const DEFAULT_AGENTS: u32
Default of num_agents.
Sourceconst DEFAULT_EXTENT: Extent
const DEFAULT_EXTENT: Extent
Defaults of world_width and world_height.
Provided Associated Constants§
Sourceconst ACTIONS: &'static [ActionDescriptor] = _
const ACTIONS: &'static [ActionDescriptor] = _
One-off steps the user can trigger. Each gets a button in the Parameters panel.
Sourceconst CHUNK: usize = 512
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.
Sourceconst MAX_AGENTS: u32 = 10_000_000
const MAX_AGENTS: u32 = 10_000_000
Upper bound of num_agents.
Required Associated Types§
Sourcetype Lanes: AgentLanes
type Lanes: AgentLanes
Agent storage, declared with agent_lanes!.
Sourcetype Field: FieldLayer
type Field: FieldLayer
Grid layer under the population, or NoField for a model
without a field.
Sourcetype Index: NeighborIndex
type Index: NeighborIndex
Neighbour index, SpatialHash when agents read each other and NoIndex otherwise.
Sourcetype Tally: ChunkTally
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§
Sourcefn param_descriptors() -> Vec<ParamDescriptor>
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.
Sourcefn from_params(params: &[ParamValue], extent: Extent) -> Self::Params
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.
Sourcefn init(
lanes: &mut Self::Lanes,
extent: Extent,
params: &[ParamValue],
rng: &mut u64,
)
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.
Provided Methods§
Sourcefn index_cell_size(_params: &Self::Params) -> f32
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.
Sourcefn run_deposit_pass(
_lanes: &Self::Lanes,
_deposits: &mut <Self::Field as FieldLayer>::DepositLanes,
_ctx: &StepCtx<'_, Self>,
)
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.
Sourcefn act(
_action: usize,
_lanes: &mut Self::Lanes,
_field: &mut Self::Field,
_extent: Extent,
_params: &[ParamValue],
_rng: &mut u64,
)
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".