bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
toy_text_base.h
Go to the documentation of this file.
1#ifndef TOY_TEXT_BASE_ENV_H
2#define TOY_TEXT_BASE_ENV_H
3
4#include "bitrl/base/bitrl_config.h"
9#include "bitsim/extern/nlohmann/json/json.hpp"
10
11#include <any>
12#include <string>
13#include <tuple>
14#include <unordered_map>
15#include <vector>
16
17#ifdef BITRL_DEBUG
18#include <cassert>
19#endif
20
21namespace bitrl
22{
23namespace envs::gymnasium
24{
25
30
31template <typename TimeStepType, uint_t state_end, uint_t action_end>
33 : public GymnasiumEnvBase<TimeStepType, ScalarDiscreteEnv<state_end, action_end, 0, 0>>
34{
35 public:
39 typedef typename GymnasiumEnvBase<
41
47
52
57
62
67
71 typedef std::vector<std::tuple<real_t, uint_t, real_t, bool>> dynamics_t;
72
76 virtual ~ToyTextEnvBase() = default;
77
83 dynamics_t p(uint_t sidx, uint_t aidx) const;
84
88 uint_t n_actions() const noexcept { return action_space_type::size; }
89
93 uint_t n_states() const noexcept { return state_space_type::size; }
94
95 protected:
99 ToyTextEnvBase(network::RESTRLEnvClient &api_server, const std::string &name);
100
105
109 virtual dynamics_t build_dynamics_from_response_(const nlohmann::json &response) const;
110};
111
112template <typename TimeStepType, uint_t state_end, uint_t action_end>
114 network::RESTRLEnvClient &api_server, const std::string &name)
115 : GymnasiumEnvBase<TimeStepType, ScalarDiscreteEnv<state_end, action_end>>(api_server, name)
116{
117}
118
119template <typename TimeStepType, uint_t state_end, uint_t action_end>
125
126template <typename TimeStepType, uint_t state_end, uint_t action_end>
129{
130
131#ifdef BITRL_DEBUG
132 assert(this->is_created() && "Environment has not been created");
133#endif
134
135 auto response = this->get_api_server().dynamics(this->env_name(), this->idx(), sidx, aidx);
136 return build_dynamics_from_response_(response);
137}
138
139template <typename TimeStepType, uint_t state_end, uint_t action_end>
142 const nlohmann::json &response) const
143{
144 auto dynamics = response["dynamics"];
145 return dynamics;
146}
147
148} // namespace envs::gymnasium
149} // namespace bitrl
150#endif
SpaceType::state_space state_space_type
Type describing the environment state space.
Definition env_base.h:45
SpaceType::state_type state_type
Type describing an individual state.
Definition env_base.h:48
SpaceType::action_space action_space_type
Type describing the environment action space.
Definition env_base.h:51
TimeStepType time_step_type
Alias for the type returned when stepping the environment.
Definition env_base.h:42
SpaceType::action_type action_type
Type representing an individual action.
Definition env_base.h:54
GymnasiumEnvBase(network::RESTRLEnvClient &api_server, const std::string &name)
Definition gymnasium_env_base.h:139
network::RESTRLEnvClient & get_api_server() const
Definition gymnasium_env_base.h:98
base_type::time_step_type time_step_type
Definition toy_text_base.h:46
virtual ~ToyTextEnvBase()=default
~FrozenLake. Destructor.
std::vector< std::tuple< real_t, uint_t, real_t, bool > > dynamics_t
Definition toy_text_base.h:71
base_type::action_type action_type
Definition toy_text_base.h:61
base_type::action_space_type action_space_type
Definition toy_text_base.h:56
base_type::state_type state_type
Definition toy_text_base.h:66
ToyTextEnvBase(network::RESTRLEnvClient &api_server, const std::string &name)
Constructor.
Definition toy_text_base.h:113
virtual dynamics_t build_dynamics_from_response_(const nlohmann::json &response) const
build the dynamics from response
Definition toy_text_base.h:141
GymnasiumEnvBase< TimeStep< std::vector< uint_t > >, ScalarDiscreteEnv< state_end, action_end, 0, 0 > >::base_type base_type
Definition toy_text_base.h:40
base_type::state_space_type state_space_type
Definition toy_text_base.h:51
uint_t n_states() const noexcept
Number of states.
Definition toy_text_base.h:93
uint_t n_actions() const noexcept
n_actions. Returns the number of actions
Definition toy_text_base.h:88
ToyTextEnvBase(const ToyTextEnvBase &other)
Copy constructor.
Definition toy_text_base.h:120
dynamics_t p(uint_t sidx, uint_t aidx) const
P.
Definition toy_text_base.h:128
Utility class to facilitate HTTP requests between the environments REST API and C++ drivers.
Definition rest_rl_env_client.h:28
Definition lunar_lander_env.h:18
Various utilities used when working with RL problems.
Definition bitrl_log.h:25
Models of how things move: wheeled robots, a bicycle, a quadrotor and a fixed wing aircraft,...
Definition bicycle_vehicle_model_dynamics.cpp:10
std::size_t uint_t
uint_t
Definition bitsim_types.h:40
Definition env_types.h:13