pyLEAFS.simulation module
The simulation: a grid, a list of fields, a list of populations, a clock.
Simulation owns the shared Grid, a list of fields, and a
list of populations, and advances them together. Both are lists from the
start so that adding a pheromone field or a predator population later is an
append, not a rewrite. v1 has one resource field and one greedy forager
population; the forager() factory builds that world from the LEAFS applet
parameters.
- class pyLEAFS.simulation.Simulation(grid, fields, populations, dt, rng=None)[source]
Bases:
objectA clocked collection of fields and populations on a shared grid.
- Parameters:
grid (Grid) – Shared spatial grid.
fields (list) – Fields to step each timestep (e.g. a
ResourceField).populations (list of Population) – Populations to step each timestep.
dt (float) – Timestep.
rng (numpy.random.Generator, optional) – Random source; defaults to a fresh unseeded generator.
- step_count
Number of timesteps advanced.
- Type:
int
- time
Physical time elapsed (
step_count * dt).- Type:
float
Examples
>>> sim = Simulation.forager(seed=0) >>> sim.run(50) >>> sim.populations[0].count >= 0 True
- classmethod forager(seed=None, shape=(10, 10), n_agents=5, Xi=0.5)[source]
Build the v1 greedy-forager world from
forager_applet.js.The environment homogeneity
Xiis the primary control: the energy per resource is derived from it as in the applet,\[\epsilon = \Gamma / \big((\Xi / r_\mathrm{col})^2\,\gamma\big),\]so that the equilibrium resource density rises as
Xifalls (a more homogeneous field). Remaining parameters match the applet:mu0=0.1,dt=0.02,v=20,R_sense=6,r_collect=1,s_max=1, reproduction at0.8with the daughter buddedr_collectaway.- Parameters:
seed (int, optional) – RNG seed for reproducibility.
shape (tuple of int, optional) – Regions per axis; length 2 or 3 selects the dimension (default
(10, 10), the applet’s 100x100 domain at L=10).n_agents (int, optional) – Initial number of foragers (default 5).
Xi (float, optional) – Environment homogeneity parameter (default 0.5).
- Returns:
A seeded simulation with one resource field and one forager population, both populated near their initial conditions.
- Return type: