bitrl & cuberl Documentation
Simulation engine for reinforcement learning agents
Loading...
Searching...
No Matches
BitRL Example 4 Using Gymnasium environments (Part 3)

This example follows BitRL Example 1 Using Gymnasium environments (Part 1) and BitRL Example 3 Using Gymnasium environments (Part 2) and shows how to use bitrl::envs::gymnasium::LunarLanderDiscreteEnv and bitrl::envs::gymnasium::LunarLanderContinuousEnv.

#include <iostream>
#include <unordered_map>
#include <vector>
namespace box2d_example
{
using namespace bitrl;
const std::string SERVER_URL = "http://0.0.0.0:8001/api";
} // namespace box2d_example
int main()
{
using namespace box2d_example;
bitrl::network::RESTRLEnvClient server(SERVER_URL, true);
std::unordered_map<std::string, std::any> options;
options["wind_power"] = std::any(static_cast<bitrl::real_t>(10.0));
options["enable_wind"] = std::any(static_cast<bool>(true));
options["gravity"] = std::any(static_cast<bitrl::real_t>(-9.86));
options["turbulence_power"] = std::any(static_cast<bitrl::real_t>(1.5));
std::unordered_map<std::string, std::any> reset_ops;
reset_ops.insert({"seed", static_cast<uint_t>(42)});
{
std::cout<<"Working with LunarLanderDiscreteEnv..."<<std::endl;
std::cout << "Is environment registered: " << server.is_env_registered(LunarLanderDiscreteEnv::name)
<< std::endl;
env.make("v3", options, reset_ops);
std::cout<<"Is environment created? "<<env.is_created()<<std::endl;
std::cout<<"Is environment alive? "<<env.is_alive()<<std::endl;
std::cout<<"Number of valid actions? "<<env.n_actions()<<std::endl;
auto time_step = env.reset();
std::cout<<"Time step: "<<time_step<<std::endl;
time_step = env.step(1);
std::cout<<"Time step: "<<time_step<<std::endl;
env.close();
}
{
std::cout << "Working with LunarLanderContinuousEnv..." << std::endl;
env.make("v3", options, reset_ops);
std::cout << "Is environment created? " << env.is_created() << std::endl;
std::cout << "Is environment alive? " << env.is_alive() << std::endl;
std::cout << "Action space size " << env.n_actions() << std::endl;
std::cout << "Environment URI: " << server.get_uri(env.env_name()) << std::endl;
auto time_step = env.reset();
std::cout << "Time step: " << time_step << std::endl;
std::vector<real_t> action = {0.8, 0.9};
time_step = env.step(action);
std::cout << "Time step: " << time_step << std::endl;
env.close();
}
return 0;
}
Definition lunar_lander_env.h:271
LunarLanderDiscreteEnv environment with discrete action space.
Definition lunar_lander_env.h:202
Utility class to facilitate HTTP requests between the environments REST API and C++ drivers.
Definition rest_rl_env_client.h:29
int main()
Definition intro_example_1.cpp:31
Definition bitrl_consts.h:14
double real_t
real_t
Definition bitrl_types.h:23
std::size_t uint_t
uint_t
Definition bitrl_types.h:43
Definition example_4.cpp:11
const std::string SERVER_URL
Definition example_4.cpp:13
dict action
Definition play.py:41
env
Definition play.py:30