AIToolbox
A library that offers tools for AI problem solving.
CassandraParser.hpp
Go to the documentation of this file.
1 #ifndef AI_TOOLBOX_CASSANDRA_PARSER_HEADER_FILE
2 #define AI_TOOLBOX_CASSANDRA_PARSER_HEADER_FILE
3 
4 #include <AIToolbox/Types.hpp>
5 #include <string>
6 #include <vector>
7 #include <unordered_map>
8 #include <functional>
9 
10 namespace AIToolbox {
15  public:
16  using MDPVals = std::tuple<size_t, size_t, DumbMatrix3D, DumbMatrix3D, double>;
17  using POMDPVals = std::tuple<size_t, size_t, size_t, DumbMatrix3D, DumbMatrix3D, DumbMatrix3D, double>;
18 
23 
43  MDPVals parseMDP(std::istream & input);
44 
64  POMDPVals parsePOMDP(std::istream & input);
65 
66  private:
67  using IDMap = std::unordered_map<std::string, size_t>;
68  using ActionMap = std::unordered_map<std::string, std::function<void(const std::string &)>>;
69  using Tokens = std::vector<std::string>;
70 
78  void parseModelInfo(std::istream & input);
79 
88  size_t extractIDs(const std::string & line, IDMap & map);
89 
98  Tokens tokenize(const std::string & str, const char * list);
99 
112  std::vector<size_t> parseIndeces(const std::string & str, const IDMap & map, size_t max);
113 
125  std::vector<double> parseVector(Tokens::const_iterator begin, Tokens::const_iterator end, size_t N);
126 
138  std::vector<double> parseVector(const std::string & str, size_t N);
139 
153  void processMatrix(DumbMatrix3D & M, const IDMap & d1map, const IDMap & d3map);
154 
163  void processReward(DumbMatrix3D & R);
164 
165  // Storage for lines which are not empty and not used in the preamble.
166  std::vector<std::string> lines_;
167  size_t i_;
168 
169  // Storage for input preamble.
170  // We need these so that we can store lambdas in the initMap_ with
171  // the same signature.
172  size_t S_, A_, O_;
173  double discount_;
174 
175  // These are actions to perform for the preamble.
176  ActionMap initMap_;
177 
178  // These contain the stringToken->id maps.
179  IDMap stateMap_;
180  IDMap actionMap_;
181  IDMap observationMap_;
182  };
183 }
184 
185 #endif
AIToolbox::CassandraParser::CassandraParser
CassandraParser()
Basic constructor.
AIToolbox::DumbMatrix3D
boost::multi_array< double, 3 > DumbMatrix3D
Definition: Types.hpp:37
AIToolbox::CassandraParser::MDPVals
std::tuple< size_t, size_t, DumbMatrix3D, DumbMatrix3D, double > MDPVals
Definition: CassandraParser.hpp:16
AIToolbox::CassandraParser::POMDPVals
std::tuple< size_t, size_t, size_t, DumbMatrix3D, DumbMatrix3D, DumbMatrix3D, double > POMDPVals
Definition: CassandraParser.hpp:17
AIToolbox
Definition: Experience.hpp:6
Types.hpp
AIToolbox::CassandraParser::parsePOMDP
POMDPVals parsePOMDP(std::istream &input)
This function parses the input following Cassandra's rules.
AIToolbox::CassandraParser::parseMDP
MDPVals parseMDP(std::istream &input)
This function parses the input following Cassandra's rules.
AIToolbox::CassandraParser
This class can parse files containing MDPs and POMDPs in the Cassandra file format.
Definition: CassandraParser.hpp:14