-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_8.cpp
54 lines (39 loc) · 1.39 KB
/
example_8.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "rlenvs/rlenvs_types_v2.h"
#include "rlenvs/envs/gymnasium/classic_control/vector/acrobot_vec_env.h"
#include "rlenvs/envs/api_server/apiserver.h"
#include "rlenvs/rlenvs_consts.h"
#include <iostream>
#include <string>
#include <unordered_map>
#include <any>
#include <vector>
#include <ios>
int main(){
using namespace rlenvscpp::envs::gymnasium;
using rlenvscpp::uint_t;
using rlenvscpp::envs::RESTApiServerWrapper;
const std::string SERVER_URL = "http://0.0.0.0:8001/api";
RESTApiServerWrapper server(SERVER_URL, true);
// Acrobot vector environment
AcrobotV env(server);
std::cout<<"Name: "<<env.name<<std::endl;
std::cout<<"Number of actions: "<<env.n_actions()<<std::endl;
std::unordered_map<std::string, std::any> options;
options["num_envs"] = std::any(static_cast<uint_t>(3));
// make the environment
env.make("v1", options);
std::cout<<"Reseting the environment... "<<std::endl;
auto time_step = env.reset();
std::cout<<"Time step: "<<time_step<<std::endl;
std::cout<<"Acting on the environment... "<<std::endl;
// step in the environment
std::vector<uint_t> actions(3, 0);
actions[1] = 1;
actions[2] = 2;
time_step = env.step(actions);
std::cout<<"Time step after action: "<<time_step<<std::endl;
std::cout<<"Closing the environment... "<<std::endl;
env.close();
std::cout<<"Is active? "<<env.is_alive()<<std::noboolalpha <<std::endl;
return 0;
}