12 #include "timed_automaton.hh"
26 std::vector<double> clockValuation;
27 std::size_t numQueries;
28 const bool isEmpty =
false;
31 isEmpty(this->automaton.
states.empty()) {
35 this->clockValuation.resize(this->automaton.
maxConstraints.size());
44 assert(this->clockValuation.size() == this->automaton.maxConstraints.size());
46 std::fill(this->clockValuation.begin(), this->clockValuation.end(), 0);
53 assert(this->clockValuation.size() == this->automaton.maxConstraints.size());
60 static std::vector<double>
applyReset(
const std::vector<double> &oldValuation,
const TATransition::Resets &resets) {
61 auto valuation = oldValuation;
62 for (
const auto &[resetVariable, targetVariable]: resets) {
63 if (targetVariable.index() == 1) {
64 valuation.at(resetVariable) = oldValuation.at(std::get<ClockVariables>(targetVariable));
66 valuation.at(resetVariable) = std::get<double>(targetVariable);
77 this->clockValuation =
applyReset(this->clockValuation, resets);
80 bool step(
char action)
override {
84 assert(this->clockValuation.size() == this->automaton.maxConstraints.size());
86 if (this->state ==
nullptr) {
91 if (std::all_of(transition.guard.begin(), transition.guard.end(), [&](
const Constraint &guard) {
92 return guard.satisfy(this->clockValuation.at(guard.x));
96 this->state = transition.target;
107 bool step(
double duration)
override {
111 assert(this->clockValuation.size() == this->automaton.maxConstraints.size());
113 if (this->state ==
nullptr) {
119 const auto unobservableIt = this->state->
next.find(UNOBSERVABLE);
120 if (unobservableIt != this->state->
next.end() && !unobservableIt->second.empty()) {
123 auto candidateTransition = unobservableIt->second.end();
124 if (unobservableIt->second.size() == 1) {
125 minDuration = lowerBoundDurationToSatisfy(unobservableIt->second.front().guard, this->clockValuation);
126 candidateTransition = unobservableIt->second.begin();
128 candidateTransition = std::min_element(unobservableIt->second.begin(), unobservableIt->second.end(),
129 [&](
const auto &a,
const auto &b) {
130 return lowerBoundDurationToSatisfy(a.guard, this->clockValuation) <
131 lowerBoundDurationToSatisfy(b.guard, this->clockValuation);
133 minDuration = lowerBoundDurationToSatisfy(candidateTransition->guard, this->clockValuation);
135 if (std::isfinite(minDuration.first) && minDuration.first <= 0 && Bounds{-duration, true} <= minDuration) {
137 std::transform(this->clockValuation.begin(), this->clockValuation.end(), this->clockValuation.begin(),
139 return value + -minDuration.first;
143 assert(candidateTransition != unobservableIt->second.end());
144 this->
applyReset(candidateTransition->resetVars);
145 this->state = candidateTransition->target;
146 return this->
step(duration - ((minDuration.first == 0 && !minDuration.second) ? 1.0e-10 : -minDuration.first));
148 BOOST_LOG_TRIVIAL(debug) <<
"Unobservable transitions are skipped";
149 BOOST_LOG_TRIVIAL(debug) <<
"std::isfinite(-minDuration): " << std::isfinite(-minDuration.first);
150 BOOST_LOG_TRIVIAL(debug) <<
"minDuration: " << minDuration.first <<
", " << minDuration.second;
151 BOOST_LOG_TRIVIAL(debug) <<
"duration: " << duration;
155 std::transform(this->clockValuation.begin(), this->clockValuation.end(), this->clockValuation.begin(),
157 return value + duration;
163 [[nodiscard]] std::size_t
count()
const override {
Interface of the system under learning.
Definition: sul.hh:14
Class to execute a timed automaton.
Definition: timed_automaton_runner.hh:22
bool step(char action) override
Feed a discrete action.
Definition: timed_automaton_runner.hh:80
std::size_t count() const override
Returns the number of queries.
Definition: timed_automaton_runner.hh:163
static std::vector< double > applyReset(const std::vector< double > &oldValuation, const TATransition::Resets &resets)
Apply the given reset to the clock valuation.
Definition: timed_automaton_runner.hh:60
void applyReset(const TATransition::Resets &resets)
Apply the given reset to the clock valuation.
Definition: timed_automaton_runner.hh:76
bool step(double duration) override
Feed time elapse.
Definition: timed_automaton_runner.hh:107
void post() override
The function should be called after feeding each timed word.
Definition: timed_automaton_runner.hh:51
void pre() override
Reset the configuration.
Definition: timed_automaton_runner.hh:41
Definition: experiment_runner.hh:23
std::vector< std::shared_ptr< State > > initialStates
The initial states of this automaton.
Definition: common_types.hh:24
std::vector< std::shared_ptr< State > > states
The states of this automaton.
Definition: common_types.hh:19
A constraint in a guard of transitions.
Definition: constraint.hh:32
A state of timed automata.
Definition: timed_automaton.hh:28
std::unordered_map< Alphabet, std::vector< TATransition > > next
A mapping of a character to the transitions.
Definition: timed_automaton.hh:35
bool isMatch
The value is true if and only if the state is an accepting state.
Definition: timed_automaton.hh:30
A state of timed automata.
Definition: timed_automaton.hh:82
A timed automaton.
Definition: timed_automaton.hh:213
std::vector< int > maxConstraints
The maximum constraints for each clock variables.
Definition: timed_automaton.hh:215