|
bitsim
Model, simulate, estimate and control robots in C++
|
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>


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. | |
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
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).
| typedef std::pair<uint_t, uint_t> bitrl::envs::multi_agent::MultiAgentGridWorld::cell_type |
A cell: row, column.
| typedef base_type::joint_action_type bitrl::envs::multi_agent::MultiAgentGridWorld::joint_action_type |
| bitrl::envs::multi_agent::MultiAgentGridWorld::MultiAgentGridWorld | ( | ) |
|
inlinenoexcept |
The index of a cell, row * n_cols() + col.
|
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.
|
inlinenoexcept |
|
noexcept |
Whether a cell is inside the map and not a wall.
|
overridevirtual |
Build the environment.
| version | the version of the environment |
| make_options | the options of the environment; see the derived class |
| reset_options | the options of reset(), "seed" for one |
Reimplemented from bitrl::envs::multi_agent::MultiAgentEnvBase< uint_t, uint_t >.
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
The moves cancelled by collisions in the current episode.
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
The number of observations of one agent.
|
inlinenoexcept |
|
inlinenoexcept |
| std::string bitrl::envs::multi_agent::MultiAgentGridWorld::render | ( | ) | const |
The map with the agents in upper case and their goals in lower case.
|
inline |
Start a new episode with the next seed.
|
overridevirtual |
Start a new episode with the given seed.
Implements bitrl::envs::multi_agent::MultiAgentEnvBase< uint_t, uint_t >.
|
overridevirtual |
Apply one action per agent.
Implements bitrl::envs::multi_agent::MultiAgentEnvBase< uint_t, uint_t >.
|
staticconstexpr |