bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
cart_pole_env.h
Go to the documentation of this file.
1#ifndef CART_POLE_ENV_H
2#define CART_POLE_ENV_H
3
40
41#include "bitrl/base/bitrl_config.h"
47#include "bitsim/extern/nlohmann/json/json.hpp"
48
49#include <any>
50#include <string>
51#include <vector>
52
53namespace bitrl
54{
55
57template <typename StateTp> class TimeStep;
58
59namespace envs
60{
61namespace gymnasium
62{
63
67class CartPole final
68 : public GymnasiumEnvBase<TimeStep<std::vector<real_t>>,
69 ContinuousVectorStateDiscreteActionEnv<4, 2, 0, real_t>>
70{
71
72 public:
76 static const std::string name;
77
81 static const std::string URI;
82
88 2, // end of action space
89 0, // start of action space
90 real_t // type of state
92
98
103
108
113
118
123
127 CartPole(const CartPole &other);
128
132 ~CartPole() override = default;
133
137 virtual void
138 make(const std::string &version, const std::unordered_map<std::string, std::any> &options,
139 const std::unordered_map<std::string, std::any> &reset_options) override final;
140
144 virtual time_step_type step(const action_type &action) override final;
145
149 uint_t n_actions() const noexcept { return action_space_type::size; }
150
151 protected:
155 virtual time_step_type
156 create_time_step_from_response_(const nlohmann::json &response) const override final;
157};
158
159} // namespace gymnasium
160} // namespace envs
161} // namespace bitrl
162
163#endif // CART_POLE_H
Forward declaration.
Definition time_step.h:22
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
const std::unordered_map< std::string, std::any > & reset_options() const noexcept
Definition env_base.h:105
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
virtual time_step_type step(const action_type &action) override final
step. Step in the environment following the given action
base_type::state_space_type state_space_type
The type describing the state space for the environment.
Definition cart_pole_env.h:102
CartPole(network::RESTRLEnvClient &api_server)
CartPole. Constructor.
GymnasiumEnvBase< TimeStep< std::vector< real_t > >, ContinuousVectorStateDiscreteActionEnv< 4, 2, 0, real_t > >::base_type base_type
Base class type.
Definition cart_pole_env.h:91
static const std::string name
name
Definition cart_pole_env.h:76
CartPole(const CartPole &other)
copy ctor
virtual void make(const std::string &version, const std::unordered_map< std::string, std::any > &options, const std::unordered_map< std::string, std::any > &reset_options) override final
make. Build the environment
base_type::action_space_type action_space_type
The type of the action space for the environment.
Definition cart_pole_env.h:107
virtual time_step_type create_time_step_from_response_(const nlohmann::json &response) const override final
Handle the reset response from the environment server.
base_type::action_type action_type
The type of the action to be undertaken in the environment.
Definition cart_pole_env.h:112
~CartPole() override=default
~CartPole. Destructor
base_type::state_type state_type
The type of the state.
Definition cart_pole_env.h:117
uint_t n_actions() const noexcept
n_actions. Returns the number of actions
Definition cart_pole_env.h:149
base_type::time_step_type time_step_type
The time step type we return every time a step in the environment is performed.
Definition cart_pole_env.h:97
static const std::string URI
The URI for accessing the environment.
Definition cart_pole_env.h:81
GymnasiumEnvBase(network::RESTRLEnvClient &api_server, const std::string &name)
Definition gymnasium_env_base.h:139
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
Definition cart_pole.h:18
Various utilities used when working with RL problems.
Definition bitrl_log.h:25
std::size_t uint_t
uint_t
Definition bitsim_types.h:40
double real_t
real_t
Definition bitsim_types.h:20