13 #include "timed_condition.hh"
14 #include "timed_word.hh"
31 word(std::move(word)), timedCondition(std::move(timedCondition)) {
32 assert(this->word.size() + 1 == this->timedCondition.size());
40 assert(elementary.word.size() + 1 == elementary.timedCondition.size());
50 if (elementaryLanguages.empty()) {
54 for (
const auto& elementary: elementaryLanguages) {
55 assert(elementary.word == result.word);
58 assert(result.word.size() + 1 == result.timedCondition.
size());
67 return this->timedCondition.
isSimple();
74 return this->word.size();
81 return {this->word + another.word, this->timedCondition + another.timedCondition};
87 void enumerate(std::vector<ElementaryLanguage> &result)
const {
92 std::vector<TimedCondition> simpleTimedConditions;
93 this->timedCondition.
enumerate(simpleTimedConditions);
94 result.resize(simpleTimedConditions.size());
95 std::transform(simpleTimedConditions.begin(), simpleTimedConditions.end(), result.begin(),
97 return ElementaryLanguage{this->word, cond};
104 [[nodiscard]] std::vector<ElementaryLanguage>
enumerate()
const {
105 std::vector<ElementaryLanguage> result;
106 this->enumerate(result);
115 std::vector<double> durations;
116 std::size_t N = this->wordSize() + 1;
118 for (std::size_t i = 0; i < N; i++) {
119 Bounds lowerBound = this->timedCondition.getLowerBound(i, i);
120 Bounds upperBound = this->timedCondition.getUpperBound(i, i);
121 if (
isPoint(upperBound, lowerBound)) {
122 durations[i] = upperBound.first;
124 double lower = -lowerBound.first;
125 double upper = upperBound.first;
127 for (
int j = i - 1; j >= 0; j--) {
130 Bounds tmpLowerBound = this->timedCondition.getLowerBound(j, i);
131 Bounds tmpUpperBound = this->timedCondition.getUpperBound(j, i);
132 lower = std::max(lower, -tmpLowerBound.first - sum);
133 upper = std::min(upper, tmpUpperBound.first - sum);
135 assert(lower <= upper);
136 durations[i] = (lower + upper) * 0.5;
141 assert(this->contains(
TimedWord{this->word, durations}));
142 return {this->word, durations};
145 void removeEqualityUpperBoundAssign() {
146 assert(word.size() + 1 == timedCondition.size());
147 timedCondition.removeEqualityUpperBoundAssign();
150 void removeUpperBoundAssign() {
151 assert(word.size() + 1 == timedCondition.size());
152 timedCondition.removeUpperBoundAssign();
155 [[nodiscard]] ElementaryLanguage removeUpperBound()
const {
156 assert(word.size() + 1 == timedCondition.size());
158 result.removeUpperBoundAssign();
169 assert(this->word.compare(0, prefix.
wordSize(), prefix.getWord()) == 0);
171 for (std::size_t i = 0; i < prefix.
wordSize(); ++i) {
172 assert(-resultingCondition.
getLowerBound(i, i).first <= prefix.getDurations().at(i));
173 resultingCondition.
restrictLowerBound(i, i, Bounds{-prefix.getDurations().at(i),
true},
false);
174 assert(resultingCondition.
getUpperBound(i, i).first >= prefix.getDurations().at(i));
175 resultingCondition.
restrictUpperBound(i, i, Bounds{prefix.getDurations().at(i),
true},
false);
186 if (testedWord.getWord() != this->getWord()) {
189 auto condition = this->timedCondition;
190 for (std::size_t i = 0; i < condition.size(); ++i) {
191 condition.restrictUpperBound(i, i, {testedWord.getDurations().at(i),
true},
false);
192 condition.restrictLowerBound(i, i, {-testedWord.getDurations().at(i),
true},
false);
195 return static_cast<bool>(condition);
198 [[nodiscard]]
const std::string &getWord()
const {
202 [[nodiscard]]
const TimedCondition &getTimedCondition()
const {
203 return timedCondition;
206 friend std::ostream &operator<<(std::ostream &os,
const ElementaryLanguage &language);
208 bool operator==(
const ElementaryLanguage &another)
const {
209 return word == another.word && timedCondition == another.timedCondition;
212 bool operator!=(
const ElementaryLanguage &another)
const {
213 return !(another == *
this);
217 inline std::ostream &operator<<(std::ostream &os,
const ElementaryLanguage &language) {
218 os <<
"(" << language.word <<
", " << language.timedCondition <<
")";
223 return boost::hash_value(std::make_tuple(lang.getWord(), lang.getTimedCondition()));
An elementary language.
Definition: elementary_language.hh:23
bool isSimple() const
Returns if this elementary language is simple.
Definition: elementary_language.hh:66
ElementaryLanguage constrain(const TimedWord &prefix) const
Constrain the valuation using a timed word.
Definition: elementary_language.hh:167
static ElementaryLanguage empty()
Construct the empty elementary language containing only 0.
Definition: elementary_language.hh:38
std::size_t wordSize() const
Returns the number of the events in this elementary language.
Definition: elementary_language.hh:73
void enumerate(std::vector< ElementaryLanguage > &result) const
Make a vector of simple elementary languages in this elementary language.
Definition: elementary_language.hh:87
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
TimedWord sample() const
Return a timed word in this elementary language.
Definition: elementary_language.hh:114
static ElementaryLanguage convexHull(const std::list< ElementaryLanguage > &elementaryLanguages)
Construct a convex-hull of the given timed conditions.
Definition: elementary_language.hh:49
ElementaryLanguage operator+(const ElementaryLanguage &another) const
Concatenate two elementary languages.
Definition: elementary_language.hh:80
std::vector< ElementaryLanguage > enumerate() const
Make a vector of simple elementary languages in this elementary language.
Definition: elementary_language.hh:104
A timed condition, a finite conjunction of inequalities of the form , where and .
Definition: timed_condition.hh:19
void restrictUpperBound(std::size_t i, std::size_t j, Bounds upperBound, bool force=false)
Restrict the upper bound of .
Definition: timed_condition.hh:263
bool isSimple() const
Returns if this timed condition is simple.
Definition: timed_condition.hh:98
Bounds getUpperBound(std::size_t i, std::size_t j) const
Returns the upper bound of .
Definition: timed_condition.hh:232
void restrictLowerBound(std::size_t i, std::size_t j, Bounds lowerBound, bool force=false)
Restrict the lower bound of .
Definition: timed_condition.hh:247
Bounds getLowerBound(std::size_t i, std::size_t j) const
Returns the lower bound of .
Definition: timed_condition.hh:219
size_t size() const
Return the number of the variables in this timed condition.
Definition: timed_condition.hh:89
void enumerate(std::vector< TimedCondition > &simpleConditions) const
Make a vector of simple timed conditions in this timed condition.
Definition: timed_condition.hh:299
static TimedCondition empty()
Construct the empty timed condition, i.e. .
Definition: timed_condition.hh:79
void convexHullAssign(const TimedCondition &condition)
Make it to be the convex hull of this timed condition and the given timed condition.
Definition: timed_condition.hh:277
A timed word.
Definition: timed_word.hh:25
std::size_t wordSize() const
Return the number of the actions in this timed word.
Definition: timed_word.hh:150
Definition: experiment_runner.hh:23
static bool isPoint(const Bounds &upperBound, const Bounds &lowerBound)
Check if the upper and lower bounds define a point.
Definition: bounds.hh:17