bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
bitrl::envs::multi_agent::DistributedAgentEnv< EnvType > Class Template Reference

One agent of a multi-agent environment, in a process of its own. More...

#include <distributed_agent_env.h>

Public Types

typedef EnvType env_type
typedef EnvType::time_step_type time_step_type
typedef EnvType::action_type action_type
typedef EnvType::observation_type observation_type
typedef EnvType::joint_action_type joint_action_type

Public Member Functions

 DistributedAgentEnv (EnvType &env, uint_t agent, bitsim::distributed::Transport &transport, const DistributedAgentConfig &config={})
time_step_type reset ()
 Start a new episode with the next seed of the copy.
time_step_type reset (uint_t seed)
 Start a new episode with seed; every participant must use the same.
time_step_type step (const action_type &action)
 Send this agent's action, wait for the others', and step the copy.
void leave ()
 Tell the others that this participant stops.
uint_t agent () const noexcept
uint_t n_agents () const noexcept
const EnvType & env () const noexcept
const bitsim::distributed::Synchroniser & synchroniser () const noexcept

Detailed Description

template<typename EnvType>
class bitrl::envs::multi_agent::DistributedAgentEnv< EnvType >

One agent of a multi-agent environment, in a process of its own.

Every agent of the environment is a participant with its own DistributedAgentEnv: a thread, a process or a machine, meeting the others through a bitsim::distributed::Transport. Every participant holds a copy of the whole environment, made with the same options, and only the actions travel: step() sends this agent's action, waits for the actions of the others at the same step, with bitsim::distributed::Synchroniser in lockstep, and steps its copy with the joint action. The copies start alike and get the same joint actions, so they stay alike, and the episodes are the same as in one process. That suits environments that are cheap next to the agents, such as a learner or a controller per robot, or a real robot's on-board computer, and that are deterministic; bitsim's distributed simulation, where every participant simulates only its own robots, suits worlds that are not.

With check_replicas, every action comes with a checksum of the observation its agent acted on, and step() throws if it is not the observation of that agent in this copy: an environment that is not deterministic, made with other options, or reset with another seed.

The time steps are those of the copy, so they hold the observation and the reward of every agent; a decentralised agent reads only its own, observation(agent()).

Template Parameters
EnvTypea bitrl::envs::multi_agent::MultiAgentEnvBase

Member Typedef Documentation

◆ action_type

template<typename EnvType>
typedef EnvType::action_type bitrl::envs::multi_agent::DistributedAgentEnv< EnvType >::action_type

◆ env_type

template<typename EnvType>
typedef EnvType bitrl::envs::multi_agent::DistributedAgentEnv< EnvType >::env_type

◆ joint_action_type

template<typename EnvType>
typedef EnvType::joint_action_type bitrl::envs::multi_agent::DistributedAgentEnv< EnvType >::joint_action_type

◆ observation_type

template<typename EnvType>
typedef EnvType::observation_type bitrl::envs::multi_agent::DistributedAgentEnv< EnvType >::observation_type

◆ time_step_type

template<typename EnvType>
typedef EnvType::time_step_type bitrl::envs::multi_agent::DistributedAgentEnv< EnvType >::time_step_type

Constructor & Destructor Documentation

◆ DistributedAgentEnv()

template<typename EnvType>
bitrl::envs::multi_agent::DistributedAgentEnv< EnvType >::DistributedAgentEnv ( EnvType & env,
uint_t agent,
bitsim::distributed::Transport & transport,
const DistributedAgentConfig & config = {} )
Parameters
envthe copy of the environment, made; it must outlive this
agentthe agent this participant is
transportwhere the participants meet; it must outlive this

Member Function Documentation

◆ agent()

template<typename EnvType>
uint_t bitrl::envs::multi_agent::DistributedAgentEnv< EnvType >::agent ( ) const
inlinenoexcept

◆ env()

template<typename EnvType>
const EnvType & bitrl::envs::multi_agent::DistributedAgentEnv< EnvType >::env ( ) const
inlinenoexcept

◆ leave()

template<typename EnvType>
void bitrl::envs::multi_agent::DistributedAgentEnv< EnvType >::leave ( )
inline

Tell the others that this participant stops.

◆ n_agents()

template<typename EnvType>
uint_t bitrl::envs::multi_agent::DistributedAgentEnv< EnvType >::n_agents ( ) const
inlinenoexcept

◆ reset() [1/2]

template<typename EnvType>
time_step_type bitrl::envs::multi_agent::DistributedAgentEnv< EnvType >::reset ( )
inline

Start a new episode with the next seed of the copy.

◆ reset() [2/2]

template<typename EnvType>
time_step_type bitrl::envs::multi_agent::DistributedAgentEnv< EnvType >::reset ( uint_t seed)
inline

Start a new episode with seed; every participant must use the same.

◆ step()

template<typename EnvType>
DistributedAgentEnv< EnvType >::time_step_type bitrl::envs::multi_agent::DistributedAgentEnv< EnvType >::step ( const action_type & action)

Send this agent's action, wait for the others', and step the copy.

Exceptions
std::runtime_errorif a peer did not send the step within timeout, or with check_replicas if the copies differ

◆ synchroniser()

template<typename EnvType>
const bitsim::distributed::Synchroniser & bitrl::envs::multi_agent::DistributedAgentEnv< EnvType >::synchroniser ( ) const
inlinenoexcept

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