swarmsim.world.spawners.AgentSpawner#

Agent Spawners

class swarmsim.world.spawners.AgentSpawner.BaseAgentSpawner(world, agent=None, n: int | None = 1, seed='unspecified', mode='oneshot', oneshot=False, delay=0, **kwargs)[source]#

Base class for Agent Spawners.

Inheritance diagram of swarmsim.world.spawners.AgentSpawner.BaseAgentSpawner

Parameters:
  • world (World) – The world to spawn agents in.

  • agent (Agent | BaseAgentConfig | dict) – The agent config to use for the spawned agents. Can be a config dataclass, dictionary, or instance of an agent.

  • n (int | None, default=1) – The number of agents to spawn.

  • seed (str, default='unspecified') – The seed for the random number generator. If 'unspecified', the world’s RNG is used. If None, the system time is used.

  • mode (str, default='oneshot') – The mode to use for spawning agents. Currently, only 'oneshot' is supported.

  • delay (int, default=0) – The delay before the next spawn is allowed.

Methods

generate_config

make_agent

set_agent_config

set_seed

step

generate_config()[source]#
make_agent(config)[source]#
set_agent_config(agent)[source]#
class swarmsim.world.spawners.AgentSpawner.PointAgentSpawner(world, facing=None, avoid_overlap=False, **kwargs)[source]#

A spawner that spawns agents at a point.

The agents will be spawned at the location of the prototype agent (agent.position).

Inheritance diagram of swarmsim.world.spawners.AgentSpawner.PointAgentSpawner

Parameters:
  • world (RectangularWorld) – The world to spawn agents in.

  • agent (Agent | BaseAgentConfig | dict) – The agent config to use for the spawned agents. Can be a config dataclass, dictionary, or instance of an agent.

  • facing (str | float | tuple[float, float] | np.ndarray | None, default=None) –

    The direction to face when spawning agents. Can be:

    • float representing angle heading in radians

    • a coordinate pair representing the direction to point all agents towards

    • 'towards' to point all agents towards the center of the spawner

    • 'away' to point all agents away from the center of the spawner

    • 'random' to randomly point all agents in a random direction

    • None to use the prototype agent’s heading

  • avoid_overlap (bool, default=False) – Whether to shift the agents post-spawn to avoid overlapping agents.

  • **kwargs – Additional keyword arguments to pass to the base class. This spawner takes the same arguments as BaseAgentSpawner.

Attributes:
center_point

Methods

angle_between

do_spawn

generate_config

make_agent

set_agent_config

set_angle_post_spawn

set_seed

step

static angle_between(a, b)[source]#
property center_point[source]#
do_spawn(name=None)[source]#
generate_config(name=None)[source]#
set_angle_post_spawn(agent)[source]#
step()[source]#
class swarmsim.world.spawners.AgentSpawner.UniformAgentSpawner(world, region=None, holes=None, **kwargs)[source]#

Spawn agents uniformly within a rectangular or polygonal region.

Inheritance diagram of swarmsim.world.spawners.AgentSpawner.UniformAgentSpawner

Parameters:
  • world (RectangularWorld) – The world to spawn agents in.

  • agent (Agent | BaseAgentConfig | dict) – The agent config to use for the spawned agents. Can be a config dataclass, dictionary, or instance of an agent.

  • region (Polygon | list[tuple] | np.ndarray) – The region to spawn agents in.

  • holes (Polygon, default=None) – holes for the region

  • **kwargs – Additional keyword arguments to pass to the base class. This spawner takes the same arguments as PointAgentSpawner and BaseAgentSpawner.

Raises:

ValueError – If the region is not specified or invalid.

Attributes:
center_point

Methods

angle_between

do_spawn

generate_config

generate_points_in_polygon

make_agent

set_agent_config

set_angle_post_spawn

set_seed

step

property center_point[source]#
generate_config(name=None)[source]#
generate_points_in_polygon(n: int)[source]#
class swarmsim.world.spawners.AgentSpawner.UniformCircleAgentSpawner(world, center=None, radius=None, **kwargs)[source]#

Spawn agents uniformly within a circle.

Inheritance diagram of swarmsim.world.spawners.AgentSpawner.UniformCircleAgentSpawner

Parameters:
  • world (RectangularWorld) – The world to spawn agents in.

  • agent (Agent | BaseAgentConfig | dict) – The agent config to use for the spawned agents. Can be a config dataclass, dictionary, or instance of an agent.

  • center (tuple[float, float] | np.ndarray) – The center of the circle.

  • radius (float) – The radius of the circle.

  • **kwargs – Additional keyword arguments to pass to the base class. This spawner takes the same arguments as PointAgentSpawner and BaseAgentSpawner.

Attributes:
center_point

Methods

angle_between

do_spawn

generate_config

generate_points_in_circle

make_agent

set_agent_config

set_angle_post_spawn

set_seed

step

property center_point[source]#
generate_config(name=None)[source]#
generate_points_in_circle(n: int)[source]#

Functions

AgentSpawner(*args, **kwargs)

Classes

BaseAgentSpawner(world[, agent, n, seed, ...])

Base class for Agent Spawners.

PointAgentSpawner(world[, facing, avoid_overlap])

A spawner that spawns agents at a point.

UniformAgentSpawner(world[, region, holes])

Spawn agents uniformly within a rectangular or polygonal region.

UniformCircleAgentSpawner(world[, center, ...])

Spawn agents uniformly within a circle.