-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgymclient.cpp
96 lines (74 loc) · 2.23 KB
/
gymclient.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
* gymclient.cpp
*
* Created on: Apr 2, 2021
* Author: zf
*/
#include <gymtest/env/lunarenv.h>
#include <log4cxx/logger.h>
#include <log4cxx/basicconfigurator.h>
namespace
{
log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger("testgym"));
}
namespace {
void testGetInfo() {
std::string envName = "LunarLander-v2";
std::string serverAddr = "tcp://127.0.0.1:10201";
LOG4CXX_INFO(logger, "To connect to " << serverAddr);
LunarEnv env(serverAddr, envName);
auto info = env.init();
auto actionSpace = std::get<1>(info);
auto obSpace = std::get<0>(info);
LOG4CXX_INFO(logger, "Get actionSpace " << actionSpace.type);
LOG4CXX_INFO(logger, "Get observeSpace " << obSpace.type);
auto rc = env.reset();
LOG4CXX_INFO(logger, "next state: " << rc);
// LOG4CXX_INFO(logger, "next state: " << std::get<0>(rc));
// LOG4CXX_INFO(logger, "reward: " << std::get<1>(rc));
// LOG4CXX_INFO(logger, "Done: " << std::get<2>(rc));
bool isDone = false;
while (!isDone) {
auto result = env.step(2);
auto reward = std::get<1>(result);
isDone = std::get<2>(result);
LOG4CXX_INFO(logger, "Reward: " << reward);
}
env.reset();
LOG4CXX_INFO(logger, "Reset");
auto result = env.step(1);
LOG4CXX_INFO(logger, "reward: " << std::get<1>(result));
}
void testMultiClient() {
std::string envName = "LunarLander-v2";
const int clientNum = 2;
std::string serverAddr = "tcp://127.0.0.1:10201";
LOG4CXX_INFO(logger, "To connect to " << serverAddr);
LunarEnv env(serverAddr, envName, clientNum);
auto info = env.init();
auto actionSpace = std::get<1>(info);
auto obSpace = std::get<0>(info);
LOG4CXX_INFO(logger, "Get actionSpace " << actionSpace.type << ": " << actionSpace.shape);
LOG4CXX_INFO(logger, "Get observeSpace " << obSpace.type << ": " << obSpace.shape);
// bool done = false;
// std::vector<long> actions(clientNum, 1);
// do {
// auto result = env.step(actions);
// auto rewards = std::get<1>(result);
// auto dones = std::get<2>(result);
//
// LOG4CXX_INFO(logger, "Get rewards: " << rewards);
//
// done = true;
// for (auto isDone: dones) {
// done = done && isDone;
// }
// } while (!done);
}
}
int main() {
log4cxx::BasicConfigurator::configure();
testGetInfo();
// testMultiClient();
LOG4CXX_INFO(logger, "End of test");
}