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.
- 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. IfNone, 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
- 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).- 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:
floatrepresenting angle heading in radiansa 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 directionNoneto 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
- class swarmsim.world.spawners.AgentSpawner.UniformAgentSpawner(world, region=None, holes=None, **kwargs)[source]#
Spawn agents uniformly within a rectangular or polygonal region.
- 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
PointAgentSpawnerandBaseAgentSpawner.
- 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
- class swarmsim.world.spawners.AgentSpawner.UniformCircleAgentSpawner(world, center=None, radius=None, **kwargs)[source]#
Spawn agents uniformly within a circle.
- 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
PointAgentSpawnerandBaseAgentSpawner.
- 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
Functions
|
Classes
|
Base class for Agent Spawners. |
|
A spawner that spawns agents at a point. |
|
Spawn agents uniformly within a rectangular or polygonal region. |
|
Spawn agents uniformly within a circle. |