bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
bitrl::envs::multi_agent::MultiAgentGridWorld Class Referencefinal

Agents that walk a grid at the same time, each to its own goal, without bumping into each other. More...

#include <multi_agent_grid_world.h>

Inheritance diagram for bitrl::envs::multi_agent::MultiAgentGridWorld:
Collaboration diagram for bitrl::envs::multi_agent::MultiAgentGridWorld:

Public Types

typedef MultiAgentEnvBase< uint_t, uint_t > base_type
typedef base_type::time_step_type time_step_type
typedef base_type::joint_action_type joint_action_type
typedef std::pair< uint_t, uint_t > cell_type
 A cell: row, column.
Public Types inherited from bitrl::envs::multi_agent::MultiAgentEnvBase< uint_t, uint_t >
typedef uint_t observation_type
typedef uint_t action_type
typedef MultiAgentTimeStep< uint_t > time_step_type
typedef std::vector< action_type > joint_action_type
 One action per agent, in the order of the agents.

Public Member Functions

 MultiAgentGridWorld ()
void make (const std::string &version, const std::unordered_map< std::string, std::any > &make_options, const std::unordered_map< std::string, std::any > &reset_options) override
 Build the environment.
time_step_type reset (uint_t seed) override
 Start a new episode with the given seed.
time_step_type step (const joint_action_type &actions) override
 Apply one action per agent.
uint_t n_rows () const noexcept
uint_t n_cols () const noexcept
uint_t n_cells () const noexcept
uint_t n_states () const noexcept
 The number of observations of one agent.
uint_t n_actions () const noexcept
GridObservation observation_type () const noexcept
bool is_free (const cell_type &cell) const noexcept
 Whether a cell is inside the map and not a wall.
uint_t cell_index (const cell_type &cell) const noexcept
 The index of a cell, row * n_cols() + col.
const std::vector< cell_type > & positions () const noexcept
const std::vector< cell_type > & goals () const noexcept
uint_t n_collisions () const noexcept
 The moves cancelled by collisions in the current episode.
std::string render () const
 The map with the agents in upper case and their goals in lower case.
time_step_type reset ()
 Start a new episode with the next seed.
Public Member Functions inherited from bitrl::envs::multi_agent::MultiAgentEnvBase< uint_t, uint_t >
virtual ~MultiAgentEnvBase ()=default
time_step_type reset ()
 Start a new episode with the next seed.
virtual void close ()
 Release the environment; make() builds it again.
uint_t n_agents () const noexcept
const std::string & agent_name (uint_t agent) const
 The name of an agent, for printing.
bool is_created () const noexcept
std::string env_name () const noexcept
std::string version () const noexcept
uint_t n_steps () const noexcept
 The steps of the current episode so far.
uint_t max_steps () const noexcept
 The steps after which an episode is truncated.
uint_t last_reset_seed () const noexcept
const std::unordered_map< std::string, std::any > & make_options () const noexcept

Static Public Member Functions

static std::vector< std::string > default_layout ()
 Two rooms joined by a corridor one cell wide. Agent A goes from the top left to the bottom right, B from the top right to the bottom left, so they meet in the corridor and one of them has to let the other through.

Static Public Attributes

static constexpr uint_t N_ACTIONS = 5
Static Public Attributes inherited from bitrl::envs::multi_agent::MultiAgentEnvBase< uint_t, uint_t >
static constexpr uint_t DEFAULT_ENV_SEED

Additional Inherited Members

Protected Member Functions inherited from bitrl::envs::multi_agent::MultiAgentEnvBase< uint_t, uint_t >
 MultiAgentEnvBase (const std::string &name)
void set_agents_ (std::vector< std::string > names)
 Name the agents; their number is the number of names.
void set_max_steps_ (uint_t max_steps) noexcept
void make_created_ () noexcept
void start_episode_ () noexcept
 Start counting the steps of a new episode, for reset().
bool count_step_ () noexcept
 Count a step, for step().
void check_step_ (const joint_action_type &actions) const
 Throw unless make() was called and actions has one action per agent.
T option_ (const std::string &name, const T &default_value) const
 Read a make option, or give default_value when it is missing.

Detailed Description

Agents that walk a grid at the same time, each to its own goal, without bumping into each other.

The map is a list of rows of characters: '#' is a wall, '.' a free cell, an upper case letter the start of an agent and the same letter in lower case its goal; 'A' is agent 0, 'B' agent 1, and so on. Every step each agent moves one cell up, right, down or left, or stays. A move into a wall keeps the agent where it is. Moves that would put two agents in one cell, or make two agents swap cells, are cancelled, and every agent whose move was cancelled gets collision_reward and counts as a collision; an agent may follow another into the cell it leaves. An agent that reaches its goal is done and stays there.

Every agent that is not done gets step_reward per step, and goal_reward when it arrives. With shared_reward every agent gets the sum of the rewards of all, so that they cooperate.

An observation is a cell index, row * n_cols() + col, of the agent itself (GridObservation::OWN_POSITION) or of all agents (GridObservation::JOINT_POSITIONS): own cell

  • n_cells * (cell of the first other agent) + n_cells^2 * (cell of the second) and so on, so that tabular methods can learn with either. n_states() is the number of observations.

Make options, all optional: "layout" (std::vector<std::string>, default default_layout()), "observation" (GridObservation, default OWN_POSITION), "shared_reward" (bool, false), "step_reward" (real_t, -0.05), "goal_reward" (real_t, 1.0), "collision_reward" (real_t, -0.5), "max_steps" (uint_t, 50).

Member Typedef Documentation

◆ base_type

◆ cell_type

◆ joint_action_type

◆ time_step_type

Constructor & Destructor Documentation

◆ MultiAgentGridWorld()

bitrl::envs::multi_agent::MultiAgentGridWorld::MultiAgentGridWorld ( )

Member Function Documentation

◆ cell_index()

uint_t bitrl::envs::multi_agent::MultiAgentGridWorld::cell_index ( const cell_type & cell) const
inlinenoexcept

The index of a cell, row * n_cols() + col.

◆ default_layout()

std::vector< std::string > bitrl::envs::multi_agent::MultiAgentGridWorld::default_layout ( )
static

Two rooms joined by a corridor one cell wide. Agent A goes from the top left to the bottom right, B from the top right to the bottom left, so they meet in the corridor and one of them has to let the other through.

◆ goals()

const std::vector< cell_type > & bitrl::envs::multi_agent::MultiAgentGridWorld::goals ( ) const
inlinenoexcept

◆ is_free()

bool bitrl::envs::multi_agent::MultiAgentGridWorld::is_free ( const cell_type & cell) const
noexcept

Whether a cell is inside the map and not a wall.

◆ make()

void bitrl::envs::multi_agent::MultiAgentGridWorld::make ( const std::string & version,
const std::unordered_map< std::string, std::any > & make_options,
const std::unordered_map< std::string, std::any > & reset_options )
overridevirtual

Build the environment.

Parameters
versionthe version of the environment
make_optionsthe options of the environment; see the derived class
reset_optionsthe options of reset(), "seed" for one

Reimplemented from bitrl::envs::multi_agent::MultiAgentEnvBase< uint_t, uint_t >.

◆ n_actions()

uint_t bitrl::envs::multi_agent::MultiAgentGridWorld::n_actions ( ) const
inlinenoexcept

◆ n_cells()

uint_t bitrl::envs::multi_agent::MultiAgentGridWorld::n_cells ( ) const
inlinenoexcept

◆ n_collisions()

uint_t bitrl::envs::multi_agent::MultiAgentGridWorld::n_collisions ( ) const
inlinenoexcept

The moves cancelled by collisions in the current episode.

◆ n_cols()

uint_t bitrl::envs::multi_agent::MultiAgentGridWorld::n_cols ( ) const
inlinenoexcept

◆ n_rows()

uint_t bitrl::envs::multi_agent::MultiAgentGridWorld::n_rows ( ) const
inlinenoexcept

◆ n_states()

uint_t bitrl::envs::multi_agent::MultiAgentGridWorld::n_states ( ) const
inlinenoexcept

The number of observations of one agent.

◆ observation_type()

◆ positions()

const std::vector< cell_type > & bitrl::envs::multi_agent::MultiAgentGridWorld::positions ( ) const
inlinenoexcept

◆ render()

std::string bitrl::envs::multi_agent::MultiAgentGridWorld::render ( ) const

The map with the agents in upper case and their goals in lower case.

◆ reset() [1/2]

Start a new episode with the next seed.

◆ reset() [2/2]

time_step_type bitrl::envs::multi_agent::MultiAgentGridWorld::reset ( uint_t seed)
overridevirtual

Start a new episode with the given seed.

Implements bitrl::envs::multi_agent::MultiAgentEnvBase< uint_t, uint_t >.

◆ step()

time_step_type bitrl::envs::multi_agent::MultiAgentGridWorld::step ( const joint_action_type & actions)
overridevirtual

Apply one action per agent.

Implements bitrl::envs::multi_agent::MultiAgentEnvBase< uint_t, uint_t >.

Member Data Documentation

◆ N_ACTIONS

uint_t bitrl::envs::multi_agent::MultiAgentGridWorld::N_ACTIONS = 5
staticconstexpr

The documentation for this class was generated from the following file: