matrx.agents.agent_types.patrolling_agent

Module Contents

class PatrollingAgentBrain(waypoints, move_speed=0)

Bases: matrx.agents.AgentBrain

A simple agent that moves along a given path.

initialize(self)

Resets the agent’s to be visited waypoints.

This method is called each time a new world is created or the same world is reset. This prevents the agent to remember that it already moved and visited some waypoints.

filter_observations(self, state)

Instead of filtering any observations, it just returns the given state.

This means that the agent has no fancy observation mechanisms.

Parameters
stateState

The state object already filtered on the sensing range of the agent.

Returns
dict

The unchanged State instance.

decide_on_action(self, state)

Makes use of the navigator to decide upon the next move action to get one step closer to the next waypoint.

Parameters
stateState

The State instance returned from filter_observations. In the case of this agent, that is the unchanged instance from the grid world who filtered only on the sensing range of this agent.

Returns
str

The name of the next action.

dict

A dictionary containing any additional arguments for the action to perform. This agent provides the duration how long its move action should take.

get_log_data(self)

Provides a dictionary of data for any Logger

This method functions to relay data from an agent’s decision logic (this AgentBrain class) through the GridWorld into a Logger. Here it can be further processed and stored.

Returns
datadict

A dictionary with keys identifiable names and the data as its value.

send_message(self, message)

Sends a Message from this agent to others

Method that allows you to construct a message that will be send to either a specified agent, a team of agents or all agents.

Parameters
messageMessage

A message object that needs to be send. Should be of type Message. It’s to_id can contain a single recipient, a list of recipients or None. If None, it is send to all other agents.

is_action_possible(self, action, action_kwargs)

Checks if an action would be possible.

This method can be called from the AgentBrain to check if a certain action is possible to perform with the current state of the GridWorld. It requires as input an action name and its arguments (if any), same as the decide_on_action method should return.

This method does not guarantees that if the action is return by the brain it actually succeeds, as other agents may intervene.

Parameters
actionstr

The name of an Action class.

action_kwargsdict

A dictionary with keys any action arguments and as values the actual argument values.

Returns
succeededbool

True if the action can be performed, False otherwise.

action_resultsActionResult

An ActionResult object containing the success or failure of the action, and (if failed) the reason why.

create_context_menu_for_other(self, agent_id_who_clicked, clicked_object_id, click_location)

Generate options for a context menu for a specific object/location that a user NOT controlling this human agent opened.

Thus: another human agent selected this agent, opened a context menu by right clicking on an object or location. This function is called. It should return actions, messages, or other info for what this agent can do relevant to that object / location. E.g. pick it up, move to it, display information on it, etc.

Example usecase: tasking another agent that is not yourself, e.g. to move to a specific location.

For the default MATRX visualization, the context menu is opened by right clicking on an object. This function should generate a list of options (actions, messages, or something else) which relate to that object or location. Each option is in the shape of a text shown in the context menu, and a message which is send to this agent if the user actually clicks that context menu option.

Parameters
agent_id_who_clickedstr

The ID of the (human) agent that selected this agent and requested for a context menu.

clicked_object_idstr

A string indicating the ID of an object. Is None if the user clicked on a background tile (which has no ID).

click_locationlist

A list containing the [x,y] coordinates of the object on which the user right clicked.

Returns
context_menulist

A list containing context menu items. Each context menu item is a dict with a ‘OptionText’ key, which is the text shown in the menu for the option, and a ‘Message’ key, which is the message instance that is sent to this agent when the user clicks on the context menu option.