swarmsim.agent.StaticAgent#

An Agent Class and Config for a non-moving agent.

Inheritance diagram of swarmsim.agent.StaticAgent.StaticAgent

class swarmsim.agent.StaticAgent.StaticAgentConfig(position: tuple[float, ...] | numpy.ndarray = (0, 0), angle: float | typing.Any = 0.0, name: str | typing.Any = None, controller: typing.Any | None = None, grounded: bool = False, collides: bool | int = True, sensors: list = <factory>, team: str | None = None, seed: int | None | str = 'unspecified', agent_radius: float = 0.0, body_color: tuple[int, int, int] = (255, 255, 255), body_filled: bool = False, points: list[tuple[float, float]] | numpy.ndarray | str = <factory>, anchor_point: None | tuple[float, float] | str = None, debug: bool = False)[source]#
Attributes:
anchor_point
controller
name
team

Methods

as_config_dict

as_dict

as_generator

asdict

attach_world_config

from_dict

agent_radius: float = 0.0[source]#

The radius of the agent.

Type:

float

anchor_point: None | tuple[float, float] | str = None[source]#
angle: float | Any = 0.0[source]#
as_config_dict()[source]#
as_dict()[source]#
as_generator()[source]#
asdict()[source]#
attach_world_config(world_config)[source]#
body_color: tuple[int, int, int] = (255, 255, 255)[source]#

The body color of the agent.

Type:

tuple[int, int, int]

body_filled: bool = False[source]#

Whether the body is filled.

Type:

bool

collides: bool | int = True[source]#

Whether the agent collides with other agents.

Type:

bool | int

controller: Any | None = None[source]#
debug: bool = False[source]#

Whether to draw the agent’s AABB in debug mode.

Type:

bool

classmethod from_dict(env)[source]#
grounded: bool = False[source]#
name: str | Any = None[source]#
points: list[tuple[float, float]] | ndarray | str[source]#

The points of the agent shape. If points is empty, the agent will be a circle.

Type:

list[tuple[float, float]] | np.ndarray | str

position: tuple[float, ...] | np.ndarray = (0, 0)[source]#
seed: int | None | str = 'unspecified'[source]#
sensors: list[source]#
team: str | None = None[source]#
class swarmsim.agent.StaticAgent.StaticAgent(config: StaticAgentConfig, world: RectangularWorld, name=None, initialize=True)[source]#
Attributes:
is_poly
poly_rotated
position

Alias for pos.

Methods

copy()

Create a copy of this agent.

from_config(config, world)

Returns a new agent instance from the given config and world.

getPosition()

Alias for pos.

getVelocity()

Alias for dpos.

get_aabb()

Get the agent's AABB.

get_sensors()

Alias for sensors.

make_aabb()

Return the Bounding Box of the agent

orientation_uvec([offset])

Returns the agent's 2D orientation matrix.

set_heading(new_heading)

Set the agent's heading (radians).

set_name(new_name)

Set the name of the agent.

set_pos_vec(vec)

Set the x, y, and angle of the agent.

setup_controller_from_config()

Creates and adds the AgentConfig.controller to the agent.

setup_sensors_from_config()

Creates and adds sensors from the AgentConfig.sensors to the agent.

attach_agent_to_sensors

build_collider

debug_draw

draw

draw_direction

getFrontalPoint

get_heading

get_name

get_simple_poly_radius

get_x_pos

get_y_pos

on_key_press

rotmat2d

rotmat2dT

rotmat3d

set_seed

set_x_pos

set_y_pos

step

DEBUG = False[source]#
aabb[source]#

The agent’s cached AABB.

Type:

AABB

angle[source]#

Agent’s heading in radians. 0 is facing frame right.

attach_agent_to_sensors()[source]#
build_collider()[source]#
collides[source]#

If True, the agent should be solid.

collision_flag[source]#

Colliders should set to True if a collision was detected.

config[source]#

Agent config.

controller[source]#

The Controller for this agent.

copy()[source]#

Create a copy of this agent.

Returns:

The new agent has the same type as the class/instance it was called from.

Return type:

Agent

Almost all attributes are deep-copied from this agent. However, some attributes do not get recursively deep-copied, such as the world attribute.

The Agent._always_shallow_copy attribute is a list of agent attribute names which determines which attributes do not get deep-copied. By default, this is ['world'].

On the new agent, Attributes of this agent not in this list will be a deep-copy of those in the original agent.

Attributes of this agent in this list will share the same reference as the original agent.

Examples

>>> agent = Agent(config, world)
>>> agent.copy().world is agent.world
True
>>> copy.deepcopy(agent).world is agent.world
False
debug_draw(screen, offset)[source]#
dpos: ndarray[source]#

Change in position since last step

draw(screen, offset=((0, 0), 1.0)) None[source]#
draw_direction(screen, offset=((0, 0), 1.0))[source]#
dt[source]#

Copy the world’s dt at agent creation.

Type:

float

dtheta[source]#

Change in heading since last step.

classmethod from_config(config, world)[source]#

Returns a new agent instance from the given config and world.

Parameters:
  • config (AgentConfig) – The config to create the agent from.

  • world (World) – This provides a back-reference to the world instance for the new agent.

Returns:

The new agent has the same type as the class/instance it was called from.

Return type:

Agent

getFrontalPoint(offset=0) tuple[source]#
getPosition()[source]#

Alias for pos.

getVelocity()[source]#

Alias for dpos.

get_aabb() AABB[source]#

Get the agent’s AABB.

get_heading() float[source]#
get_name()[source]#
get_sensors()[source]#

Alias for sensors.

get_simple_poly_radius()[source]#
get_x_pos() float[source]#
get_y_pos() float[source]#
grounded[source]#

If True, the agent should never change position or be pushed during collision resolution.

property is_poly[source]#
make_aabb() AABB[source]#

Return the Bounding Box of the agent

name: str | None[source]#

Agent’s name.

on_key_press(event)[source]#
orientation_uvec(offset=0.0)[source]#

Returns the agent’s 2D orientation matrix.

This is a unit vector pointing in the direction of the agent’s heading plus an offset.

Equivalent to

np.array([
    math.cos(self.angle + offset),
    math.sin(self.angle + offset)
], dtype=np.float64)
Parameters:

offset (float, default=0) – The offset to add to the agent’s heading (radians).

Returns:

The 2D orientation matrix.

Return type:

numpy.ndarray (2,)

property poly_rotated[source]#
pos: ndarray[source]#

Agent’s position in the world.

property position[source]#

Alias for pos.

radius[source]#

The radius of the agent.

Type:

float

rotmat2d(offset=0)[source]#
rotmat2dT(offset=0)[source]#
rotmat3d(offset=None)[source]#
sensors: list[source]#

List of this agent’s sensors.

set_heading(new_heading: float)[source]#

Set the agent’s heading (radians).

set_name(new_name: str | None | Any)[source]#

Set the name of the agent.

Parameters:

new_name (str | None | Any) – The new name of the agent. Strongly recommended to use str.

set_pos_vec(vec)[source]#

Set the x, y, and angle of the agent.

Parameters:

vec (tuple[float, float, float] | numpy.ndarray) – A vector with len() of 3 containing the x, y, angle

set_seed(seed)[source]#
set_x_pos(new_x: float)[source]#
set_y_pos(new_y: float)[source]#
setup_controller_from_config()[source]#

Creates and adds the AgentConfig.controller to the agent.

If config.controller is a dict with a type key, then it is created through the Configuration System and set as the agent’s controller. AbstractController instances copied and added to the list.

The controller is also given a back-reference to this agent via its set_agent().

Raises:

TypeError – if the element is not a dict or AbstractSensor instance.

setup_sensors_from_config()[source]#

Creates and adds sensors from the AgentConfig.sensors to the agent.

For each element of config.sensors, if the element is a dict with a type key, then it is created through the Configuration System and then added to the agent’s sensors list. AbstractSensor instances copied and added to the list.

The new sensor instances are also given a back-reference to this agent via their set_agent().

Raises:

TypeError – if the element is not a dict or AbstractSensor instance.

step(world=None, check_for_world_boundaries=None, check_for_agent_collisions=None) None[source]#
team[source]#

The agent’s team.

world[source]#

Back-reference to the world instance.

Classes

StaticAgent(config, world[, name, initialize])

StaticAgentConfig(position, ...)