14 #include <boost/functional/hash.hpp>
16 #include "common_types.hh"
28 std::vector<double> durations;
37 TimedWord(
const std::string& word,
const std::vector<double>& durations) {
38 assert(word.size() + 1 == durations.size());
39 this->word.reserve(word.size());
40 this->durations = {durations.front()};
41 this->durations.reserve(durations.size());
42 for (std::size_t i = 0; i < word.size(); ++i) {
43 if (word.at(i) != UNOBSERVABLE) {
44 this->word.push_back(word.at(i));
45 this->durations.push_back(durations.at(i + 1));
47 this->durations.back() += durations.at(i + 1);
51 assert(this->word.size() + 1 == this->durations.size());
61 result.word += another.word;
62 auto it = another.durations.begin();
63 result.durations.back() += *it++;
64 result.durations.reserve(this->durations.size() + another.durations.size() - 1);
65 for (; it != another.durations.end(); it++) {
66 result.durations.push_back(*it);
79 result.word.push_back(action);
80 result.durations.push_back(0);
92 result.durations.back() += duration;
102 std::ostream &
print(std::ostream &stream)
const {
103 stream << durations[0];
104 for (std::size_t i = 0; i < word.size(); i++) {
105 stream <<
" " << word[i] <<
" " << durations[i + 1];
110 [[nodiscard]]
const std::string &getWord()
const {
114 [[nodiscard]]
const std::vector<double> &getDurations()
const {
124 std::vector<double> accumulatedDurations;
125 accumulatedDurations.resize(durations.size());
127 accumulatedDurations.back() = durations.back();
128 for (
int i = durations.size() - 2; i >= 0; --i) {
129 accumulatedDurations.at(i) = accumulatedDurations.at(i + 1) +durations.at(i);
131 return accumulatedDurations;
140 const auto suffixWord = this->word.substr(prefix.
wordSize());
141 auto suffixDurations = std::vector<double>(this->durations.begin() + prefix.
wordSize(), this->durations.end());
142 suffixDurations.front() -= prefix.getDurations().back();
144 return TimedWord{suffixWord, suffixDurations};
151 return this->word.size();
154 bool operator==(
const TimedWord &another)
const {
155 return this->word == another.word && this->durations == another.durations;
160 os << word.getDurations().front();
161 for (std::size_t i = 0; i < word.
wordSize(); ++i) {
162 os <<
" " << word.getWord().at(i) <<
" " << word.getDurations().at(i + 1);
167 static inline std::ostream &operator<<(std::ostream &os,
const learnta::TimedWord &word) {
168 return learnta::print(os, word);
171 static inline std::size_t hash_value(
const TimedWord &word) {
172 return boost::hash_value(std::make_tuple(word.getWord(), word.getDurations()));
A timed word.
Definition: timed_word.hh:25
TimedWord operator+(const double duration)
Return the concatenation of this timed word and a time elapse.
Definition: timed_word.hh:90
TimedWord(const std::string &word, const std::vector< double > &durations)
Constructor of timed words.
Definition: timed_word.hh:37
std::ostream & print(std::ostream &stream) const
Print the timed word to the stream.
Definition: timed_word.hh:102
std::size_t wordSize() const
Return the number of the actions in this timed word.
Definition: timed_word.hh:150
TimedWord getSuffix(const TimedWord &prefix) const
Definition: timed_word.hh:139
TimedWord operator+(const char action)
Return the concatenation of this timed word and an action.
Definition: timed_word.hh:77
std::vector< double > getAccumulatedDurations() const
Construct and return the (tail) accumulated duration.
Definition: timed_word.hh:123
TimedWord operator+(const TimedWord &another) const
Return the concatenation of two timed words.
Definition: timed_word.hh:59
Definition: experiment_runner.hh:23