swarmsim.agent.Agent#
Base Agent Config and Class to be inherited by all agents.
- class swarmsim.agent.Agent.BaseAgentConfig(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 = False, sensors: list = <factory>, team: str | None = None)[source]#
- Attributes:
- controller
- name
- team
Methods
as_config_dict
as_dict
as_generator
asdict
from_dict
- class swarmsim.agent.Agent.Agent(config, world, name=None, group=0, initialize=True)[source]#
-
Methods
copy()Create a copy of this agent.
from_config(config, world)Returns a new agent instance from the given config and world.
Alias for
pos.Alias for
dpos.get_aabb()Get the agent's
AABB.Alias for
sensors.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, andangleof the agent.Creates and adds the
AgentConfig.controllerto the agent.Creates and adds sensors from the
AgentConfig.sensorsto the agent.attach_agent_to_sensors
draw
getFrontalPoint
get_heading
get_name
get_x_pos
get_y_pos
on_key_press
set_x_pos
set_y_pos
step
- controller[source]#
The
Controllerfor 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:
Almost all attributes are deep-copied from this agent. However, some attributes do not get recursively deep-copied, such as the
worldattribute.The
Agent._always_shallow_copyattribute 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
- classmethod from_config(config, world)[source]#
Returns a new agent instance from the given config and world.
- grounded[source]#
If True, the agent should never change position or be pushed during collision resolution.
- 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,)
- 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, andangleof the agent.- Parameters:
vec (tuple[float, float, float] | numpy.ndarray) – A vector with
len()of3containing thex, y, angle
- setup_controller_from_config()[source]#
Creates and adds the
AgentConfig.controllerto the agent.If
config.controlleris a dict with atypekey, then it is created through the Configuration System and set as the agent’scontroller.AbstractControllerinstances 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
elementis not a dict orAbstractSensorinstance.
- setup_sensors_from_config()[source]#
Creates and adds sensors from the
AgentConfig.sensorsto the agent.For each
elementofconfig.sensors, if theelementis a dict with atypekey, then it is created through the Configuration System and then added to the agent’ssensorslist.AbstractSensorinstances 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
elementis not a dict orAbstractSensorinstance.
Classes
|
|
|