11 #include "single_morphism.hh"
12 #include "forward_regional_elementary_language.hh"
20 std::vector<ElementaryLanguage> prefixes;
21 std::vector<ElementaryLanguage>
final;
22 std::vector<SingleMorphism> morphisms;
28 return split(word)->apply();
34 std::vector<ElementaryLanguage>
final,
35 std::vector<SingleMorphism> morphisms) : prefixes(std::move(prefixes)),
36 final(std::move(
final)),
37 morphisms(std::move(morphisms)) {
39 assert(std::all_of(this->
final.begin(), this->
final.end(), [&] (
const ElementaryLanguage &finalLanguage) {
40 return std::find(this->prefixes.begin(), this->prefixes.end(), finalLanguage) != this->prefixes.end();
48 return std::any_of(prefixes.begin(), prefixes.end(), [&] (
const ElementaryLanguage &language) {
49 return language.contains(word);
57 return std::any_of(
final.begin(),
final.end(), [&] (
const ElementaryLanguage &language) {
67 BOOST_LOG_TRIVIAL(debug) <<
"applying: " << *
this;
68 return morphism.
maps(prefix) + suffix;
72 return prefix == rhs.prefix &&
73 suffix == rhs.suffix &&
74 morphism == rhs.morphism;
78 return !(rhs == *
this);
81 friend std::ostream &operator<<(std::ostream &os,
const SplitTriple &triple) {
82 os <<
"prefix: " << triple.prefix <<
" suffix: " << triple.suffix <<
" morphism: " << triple.morphism;
92 [[nodiscard]] std::optional<SplitTriple>
split(
const TimedWord &word)
const {
96 const auto elemPrefixes = regionalElementary.prefixes();
98 const auto it = std::find_if(this->morphisms.begin(), this->morphisms.end(), [&] (
const auto &morphism) {
99 return std::any_of(elemPrefixes.begin(), elemPrefixes.end(), [&] (const auto& prefix) {
100 return morphism.isDomain(prefix);
103 if (it == this->morphisms.end()) {
107 if (it->getDomain().contains(word)) {
108 return SplitTriple {word, TimedWord{
"", {0}}, *it};
111 auto prefixDomainTimedCondition = it->getDomain().getTimedCondition();
112 std::vector<double> prefixDurations;
113 prefixDurations.reserve(it->getDomain().wordSize());
114 for (std::size_t i = 0; i < it->getDomain().wordSize(); ++i) {
115 prefixDomainTimedCondition.restrictUpperBound(i, i, Bounds{word.getDurations().at(i),
true});
116 prefixDomainTimedCondition.restrictLowerBound(i, i, Bounds{-word.getDurations().at(i),
true});
117 prefixDurations.push_back(word.getDurations().at(i));
119 const auto upperBound = prefixDomainTimedCondition.getUpperBound(it->getDomain().wordSize(), it->getDomain().wordSize());
120 if (Bounds{word.getDurations().at(it->getDomain().wordSize()),
true} <= upperBound) {
122 prefixDurations.push_back(word.getDurations().at(it->getDomain().wordSize()));
123 }
else if (upperBound.second){
125 prefixDurations.push_back(upperBound.first);
128 const auto tmpPrefix = ElementaryLanguage{it->getDomain().getWord(), prefixDomainTimedCondition}.sample();
129 prefixDurations.push_back(tmpPrefix.getDurations().back());
131 const auto prefix = TimedWord{it->getDomain().getWord(), prefixDurations};
133 return SplitTriple {prefix, word.
getSuffix(prefix), *it};
140 while (!this->inPrefixes(word)) {
141 word = this->maps(word);
143 return this->isFinal(word);
148 for (
const auto& morphism: language.morphisms) {
149 os << morphism <<
"\n";
An elementary language.
Definition: elementary_language.hh:23
bool contains(const TimedWord &testedWord) const
Check if the given the timed word is a member of this elementary languages.
Definition: elementary_language.hh:185
static ForwardRegionalElementaryLanguage fromTimedWord(const TimedWord &timedWord)
Construct the fractional elementary language containing the given timed word.
Definition: forward_regional_elementary_language.hh:46
Recognizable timed language in [MP04].
Definition: recognizable_languages.hh:18
bool inPrefixes(const TimedWord &word) const
Returns if the given timed word is in the prefixes.
Definition: recognizable_languages.hh:47
bool isFinal(const TimedWord &word) const
Returns if the given timed word is in the final prefixes.
Definition: recognizable_languages.hh:56
std::optional< SplitTriple > split(const TimedWord &word) const
Split the given timed word with the morphism.
Definition: recognizable_languages.hh:92
bool contains(TimedWord word) const
Returns if this recognizable timed language contains the given timed word.
Definition: recognizable_languages.hh:139
Morphism from an external elementary language to an internal one.
Definition: single_morphism.hh:18
TimedWord maps(const TimedWord &word) const
Apply this single morphism to the given timed word.
Definition: single_morphism.hh:55
A timed word.
Definition: timed_word.hh:25
TimedWord getSuffix(const TimedWord &prefix) const
Definition: timed_word.hh:139
Definition: experiment_runner.hh:23
Definition: recognizable_languages.hh:62