Skip to main content

AntsModel

Struct AntsModel 

Source
pub struct AntsModel;
Expand description

Ant foraging, ported from krABMaga’s antsforaging.

A comparison with the reference has to state three differences. Deposits combine with max instead of the last writer winning. Every pheromone read sees the old field, and every write goes to the new field. The RNG is seeded per chunk per tick instead of drawn per call.

The reference’s biased neighbour tie-break is reproduced as it is (see step::advect_agent).

Trait Implementations§

Source§

impl AgentModel for AntsModel

Source§

const CHUNK: usize = 4096

Agents per chunk. The movement draws are seeded per chunk, so another value gives other results.

Source§

fn init( lanes: &mut AntLanes, extent: Extent, params: &[ParamValue], _rng: &mut u64, )

Ants start holding reward so they lay home pheromone immediately and the colony has a gradient to navigate back along.

Source§

const NAME: &'static str = "Ant Foraging"

Name shown in the UI.
Source§

const ID: &'static str = "ants"

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

const DESCRIPTION: &'static str = "Ants lay and follow pheromone trails between a nest and a food source, around obstacles"

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 ACTIONS: &'static [ActionDescriptor] = ACTION_SPECS

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

const DEFAULT_AGENTS: u32 = 2_000

Default of num_agents.
Source§

const MAX_AGENTS: u32 = 5_000_000

Upper bound of num_agents.
Source§

const DEFAULT_EXTENT: Extent

Defaults of world_width and world_height.
Source§

type Lanes = AntLanes

Agent storage, declared with agent_lanes!.
Source§

type Field = ScalarField<PheromoneField>

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

type Index = NoIndex

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

type Params = AntParams

Pre-extracted hot parameters, rebuilt once per tick.
Source§

type Tally = u64

Per chunk reduction, accumulated across ticks. () when there is nothing to count. Read more
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) -> AntParams

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 run_deposit_pass( lanes: &AntLanes, deposits: &mut Deposits, ctx: &StepCtx<'_, Self>, )

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

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

Runs the step pass and returns its tally. Read more
Source§

fn act( action: usize, lanes: &mut AntLanes, field: &mut ScalarField<PheromoneField>, extent: Extent, params: &[ParamValue], rng: &mut u64, )

Runs Self::ACTIONS entry action over the current lanes and field. Read more
Source§

fn stats( lanes: &AntLanes, field: &ScalarField<PheromoneField>, tally: &u64, ) -> Vec<StatValue>

Current statistics, in Self::STATS order.
Source§

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

Returns the neighbour index’s cell size for these params. Read more
Source§

impl Debug for AntsModel

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,

Source§

impl<T> WasmNotSync for T
where T: Sync,