|
1 | 1 |
|
2 | | -#include "bitrl/envs/gymnasium/classic_control/pendulum_env.h" |
| 2 | +//#include "bitrl/envs/gymnasium/classic_control/pendulum_env.h" |
| 3 | +//#include "bitrl/envs/gymnasium/classic_control/vector/acrobot_vec_env.h" |
| 4 | +#include "bitrl/envs/gymnasium/classic_control/cart_pole_env.h" |
3 | 5 | #include "bitrl/network/rest_rl_env_client.h" |
4 | 6 | #include "bitrl/bitrl_types.h" |
5 | 7 | #include "bitrl/bitrl_consts.h" |
|
14 | 16 | #include <random> |
15 | 17 | #include <unordered_map> |
16 | 18 |
|
17 | | - |
| 19 | +namespace example |
| 20 | +{ |
| 21 | + using namespace bitrl; |
| 22 | + using namespace bitrl::envs::gymnasium; |
| 23 | + using bitrl::network::RESTRLEnvClient; |
| 24 | + |
| 25 | + void test_cart_pole(RESTRLEnvClient& server) |
| 26 | + { |
| 27 | + // the environment is not registered with the server |
| 28 | + std::cout<<"Is environment registered: "<<server.is_env_registered(CartPole::name)<<std::endl; |
| 29 | + |
| 30 | + // create the environment |
| 31 | + CartPole env(server); |
| 32 | + |
| 33 | + std::cout<<"Name: "<<env.name<<std::endl; |
| 34 | + std::cout<<"Number of actions: "<<env.n_actions()<<std::endl; |
| 35 | + |
| 36 | + // make the environment |
| 37 | + std::unordered_map<std::string, std::any> options; |
| 38 | + std::unordered_map<std::string, std::any> reset_ops; |
| 39 | + reset_ops.insert({"seed", static_cast<uint_t>(42)}); |
| 40 | + env.make("v1", options, reset_ops); |
| 41 | + |
| 42 | + auto time_step = env.reset(); |
| 43 | + std::cout<<"Time step: "<<time_step<<std::endl; |
| 44 | + |
| 45 | + // step in the environment |
| 46 | + time_step = env.step(0); |
| 47 | + std::cout<<"Time step after action: "<<time_step<<std::endl; |
| 48 | + |
| 49 | + env.close(); |
| 50 | + } |
| 51 | + // void test_pendulum(RESTRLEnvClient& server) |
| 52 | + // { |
| 53 | + // |
| 54 | + // // the environment is not registered with the server |
| 55 | + // std::cout<<"Is environment registered: "<<server.is_env_registered(Pendulum::name)<<std::endl; |
| 56 | + // |
| 57 | + // // create the environment |
| 58 | + // Pendulum env(server); |
| 59 | + // |
| 60 | + // std::cout<<"Name: "<<env.name<<std::endl; |
| 61 | + // std::cout<<"Number of actions: "<<env.n_actions()<<std::endl; |
| 62 | + // |
| 63 | + // // make the environment |
| 64 | + // std::unordered_map<std::string, std::any> options; |
| 65 | + // std::unordered_map<std::string, std::any> reset_ops; |
| 66 | + // reset_ops.insert({"seed", static_cast<uint_t>(42)}); |
| 67 | + // env.make("v1", options, reset_ops); |
| 68 | + // |
| 69 | + // auto time_step = env.reset(); |
| 70 | + // std::cout<<"Time step: "<<time_step<<std::endl; |
| 71 | + // |
| 72 | + // // step in the environment |
| 73 | + // time_step = env.step(0.0); |
| 74 | + // std::cout<<"Time step after action: "<<time_step<<std::endl; |
| 75 | + // |
| 76 | + // env.close(); |
| 77 | + // } |
| 78 | + |
| 79 | +} |
18 | 80 |
|
19 | 81 |
|
20 | 82 | int main(){ |
21 | 83 |
|
22 | | - using namespace bitrl; |
23 | | - using namespace bitrl::envs::gymnasium; |
24 | | - using bitrl::network::RESTRLEnvClient; |
| 84 | + using namespace example; |
25 | 85 |
|
26 | 86 | const std::string SERVER_URL = "http://0.0.0.0:8001/api"; |
27 | 87 |
|
28 | 88 | RESTRLEnvClient server(SERVER_URL, true); |
| 89 | + |
| 90 | + std::cout<<"Testing FrozenLake..."<<std::endl; |
| 91 | + example::test_cart_pole(server); |
| 92 | + std::cout<<"===================="<<std::endl; |
| 93 | + std::cout<<"Testing Taxi..."<<std::endl; |
| 94 | + //example::test_pendulum(server); |
| 95 | + std::cout<<"===================="<<std::endl; |
| 96 | + // std::cout<<"Testing BlackJack..."<<std::endl; |
| 97 | + // example_1::test_black_jack(server); |
| 98 | + // std::cout<<"===================="<<std::endl; |
| 99 | + // std::cout<<"Testing CliffWorld..."<<std::endl; |
| 100 | + // example_1::test_cliff_world(server); |
| 101 | + // std::cout<<"===================="<<std::endl; |
| 102 | + return 0; |
29 | 103 |
|
30 | | - Pendulum env(server); |
31 | | - |
32 | | - std::cout<<"Name: "<<env.name<<std::endl; |
33 | | - std::cout<<"Number of actions: "<<env.n_actions()<<std::endl; |
34 | | - |
35 | | - // make the environment |
36 | | - std::unordered_map<std::string, std::any> options; |
37 | | - std::unordered_map<std::string, std::any> reset_ops; |
38 | | - reset_ops.insert({"seed", static_cast<uint_t>(42)}); |
39 | | - env.make("v1", options, reset_ops); |
40 | | - |
41 | | - auto time_step = env.reset(); |
42 | | - |
43 | | - std::cout<<"Time step: "<<time_step<<std::endl; |
44 | | - |
45 | | - // step in the environment |
46 | | - time_step = env.step(0.0); |
47 | | - |
48 | | - std::cout<<"Time step after action: "<<time_step<<std::endl; |
49 | | - |
50 | | - env.close(); |
51 | | - |
52 | | - std::cout<<"Is active? "<<env.is_alive()<<std::endl; |
53 | | - |
| 104 | + |
54 | 105 | return 0; |
55 | 106 | } |
0 commit comments