LearnTA  0.0.1
single_morphism.hh
1 
6 #pragma once
7 
8 #include <utility>
9 #include <ostream>
10 
11 #include "elementary_language.hh"
12 #include "renaming_relation.hh"
13 
14 namespace learnta {
19  private:
20  ElementaryLanguage domain, codomain;
21  RenamingRelation renaming;
22  public:
29  ElementaryLanguage codomain,
30  RenamingRelation renaming): domain(std::move(domain)), codomain(std::move(codomain)), renaming(std::move(renaming)) {}
31 
35  [[nodiscard]] bool inDomain(const TimedWord &word) const {
36  return this->domain.contains(word);
37  }
38 
42  [[nodiscard]] bool isDomain(const ElementaryLanguage &elementaryLanguage) const {
43  return this->domain == elementaryLanguage;
44  }
45 
46  [[nodiscard]] const ElementaryLanguage &getDomain() const {
47  return domain;
48  }
49 
55  [[nodiscard]] TimedWord maps(const TimedWord &word) const {
56  assert(this->inDomain(word));
57  // Juxtapose the timed conditions to constrain with the renaming relation
58  auto juxtaposedCondition = TimedCondition::makeExact(word.getAccumulatedDurations()) ^ codomain.getTimedCondition();
59  juxtaposedCondition.addRenaming(this->renaming);
60  juxtaposedCondition.canonize();
61  assert(juxtaposedCondition.isSatisfiableNoCanonize());
62  // Sample a value from the juxtaposed timed condition
63  const auto values = juxtaposedCondition.sample();
64  std::vector<double> durations;
65  durations.resize(codomain.wordSize() + 1);
66  for (int i = static_cast<int>(codomain.wordSize()); i >= 0; --i) {
67  if (i == static_cast<int>(codomain.wordSize())) {
68  durations.at(i) = values.back();
69  } else {
70  durations.at(i) = values.at(i + 1 + domain.wordSize()) - values.at(i + 2 + domain.wordSize());
71  }
72  }
73 
74  return TimedWord{this->codomain.getWord(), durations};
75  }
76 
77  bool operator==(const SingleMorphism &rhs) const {
78  return domain == rhs.domain &&
79  codomain == rhs.codomain &&
80  renaming == rhs.renaming;
81  }
82 
83  bool operator!=(const SingleMorphism &rhs) const {
84  return !(rhs == *this);
85  }
86 
87  friend std::ostream &operator<<(std::ostream &os, const SingleMorphism &morphism) {
88  os << "domain: " << morphism.domain << " codomain: " << morphism.codomain << " renaming: " << morphism.renaming;
89  return os;
90  }
91  };
92 }
An elementary language.
Definition: elementary_language.hh:23
std::size_t wordSize() const
Returns the number of the events in this elementary language.
Definition: elementary_language.hh:73
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
Definition: renaming_relation.hh:16
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
bool isDomain(const ElementaryLanguage &elementaryLanguage) const
Check if the given timed word is in the domain of this morphism.
Definition: single_morphism.hh:42
bool inDomain(const TimedWord &word) const
Check if the given timed word is in the domain of this morphism.
Definition: single_morphism.hh:35
SingleMorphism(ElementaryLanguage domain, ElementaryLanguage codomain, RenamingRelation renaming)
Definition: single_morphism.hh:28
static TimedCondition makeExact(const std::vector< double > &accumulatedDuration)
Construct a timed condition from concrete values of T_{i,j}. The generated timed condition only conta...
Definition: timed_condition.hh:61
A timed word.
Definition: timed_word.hh:25
std::vector< double > getAccumulatedDurations() const
Construct and return the (tail) accumulated duration.
Definition: timed_word.hh:123
Definition: experiment_runner.hh:23
Definition: external_transition_maker.hh:149