/
sars.cc
64 lines (51 loc) · 1.24 KB
/
sars.cc
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
/*
* Code by Chris Mansley
*/
#include "sars.hh"
/*!
* Output operator for the SARS class
*/
std::ostream& operator<<(std::ostream &out, const SARS &sars)
{
/* Print state */
for(State::const_iterator it = sars.s.begin(); it != sars.s.end(); ++it) {
out << *it << ",";
}
/* Print action */
for(Action::const_iterator it = sars.a.begin(); it != sars.a.end(); ++it) {
out << *it << ",";
}
/* Print reward */
out << sars.reward << ",";
/* Print next state */
for(State::const_iterator it = sars.s_prime.begin(); it != sars.s_prime.end(); ++it) {
out << *it << ",";
}
/* Print out terminal */
out << sars.terminal;
return out;
}
/*!
* Input operator for the SARS class
*/
std::istream& operator>>(std::istream &in, SARS &sars)
{
char c;
/* Grab state */
for(State::iterator it = sars.s.begin(); it != sars.s.end(); ++it) {
in >> *it >> c;
}
/* Grab action */
for(Action::iterator it = sars.a.begin(); it != sars.a.end(); ++it) {
in >> *it >> c;
}
/* Grab reward */
in >> sars.reward >> c;
/* Grab next state */
for(State::iterator it = sars.s_prime.begin(); it != sars.s_prime.end(); ++it) {
in >> *it >> c;
}
/* Grab terminal */
in >> sars.terminal;
return in;
}