9 #include <boost/unordered_set.hpp>
11 #include "timed_automaton.hh"
12 #include "renaming_relation.hh"
13 #include "forward_regional_elementary_language.hh"
14 #include "neighbor_conditions.hh"
15 #include "timed_automaton_runner.hh"
23 boost::unordered_set<std::pair<TAState *, NeighborConditions>> impreciseNeighbors;
25 [[nodiscard]]
static std::optional<std::pair<TAState *, NeighborConditions>>
27 std::vector<TATransition> &newTransitions,
bool &matchBounded,
bool &noMatch) {
29 if (neighbor.
match(transition)) {
32 BOOST_LOG_TRIVIAL(debug) <<
"matched! " <<
"guard: " << transition.
guard;
34 const bool upperBounded = std::any_of(transition.
guard.begin(), transition.
guard.end(),
35 std::mem_fn(&Constraint::isUpperBound));
36 matchBounded = matchBounded || upperBounded;
37 BOOST_LOG_TRIVIAL(debug) <<
"matchBounded: " << matchBounded;
41 relaxedGuard.erase(std::remove_if(relaxedGuard.begin(), relaxedGuard.end(),
42 [](
const auto &constraint) {
43 return constraint.isUpperBound();
44 }), relaxedGuard.end());
46 BOOST_LOG_TRIVIAL(debug) <<
"relaxed guard: " << relaxedGuard;
47 if (isWeaker(relaxedGuard, transition.
guard) && !isWeaker(transition.
guard, relaxedGuard)) {
49 BOOST_LOG_TRIVIAL(debug) <<
"Relaxed!!";
54 newTransitions.emplace_back(transition.
target,
56 preciseClocksAfterReset,
58 std::move(relaxedGuard));
59 if (preciseClocksAfterReset.empty() || neighborAfterTransition.precise()) {
62 return std::make_pair(transition.
target, neighborAfterTransition);
78 BOOST_LOG_TRIVIAL(debug) <<
"new imprecise neighbors set is added: " << jumpedState <<
", "
79 << targetElementary <<
", " << renamingRelation;
80 impreciseNeighbors.emplace(jumpedState,
NeighborConditions{targetElementary, renamingRelation.rightVariables()});
88 std::unordered_set<std::size_t> visitedImpreciseNeighborsHash;
89 while (!impreciseNeighbors.empty()) {
90 BOOST_LOG_TRIVIAL(debug) <<
"visitedImpreciseNeighborsHash size: " << visitedImpreciseNeighborsHash.size();
91 BOOST_LOG_TRIVIAL(debug) <<
"impreciseNeighbors size: " << this->impreciseNeighbors.size();
92 auto [state, neighbor] = *impreciseNeighbors.begin();
93 const auto hash = boost::hash_value(*impreciseNeighbors.begin());
94 impreciseNeighbors.erase(impreciseNeighbors.begin());
96 if (visitedImpreciseNeighborsHash.find(hash) != visitedImpreciseNeighborsHash.end()) {
99 visitedImpreciseNeighborsHash.insert(hash);
104 BOOST_LOG_TRIVIAL(debug) <<
"current imprecise neighbors: " << state <<
", " << neighbor;
106 matchBounded =
false;
108 for (
auto &[action, transitions]: state->next) {
109 const auto neighborSuccessor = neighbor.successor(action);
110 std::vector<TATransition> newTransitions;
111 for (
const auto &transition: transitions) {
112 const auto result = handleOne(neighbor, action, transition, newTransitions, matchBounded, noMatch);
114 BOOST_LOG_TRIVIAL(debug) <<
"New imprecise neighbors by recursion: " << *result;
115 this->impreciseNeighbors.insert(*result);
118 const auto dummy = transitions;
120 assert(std::all_of(newTransitions.begin(), newTransitions.end(), [&] (
const auto &newTransition) {
121 return std::any_of(dummy.begin(), dummy.end(), [&] (const auto &transition) {
122 return transition.target == newTransition.target && isWeaker(newTransition.guard, transition.guard);
125 transitions.reserve(transitions.size() + newTransitions.size());
126 std::move(newTransitions.begin(), newTransitions.end(), std::back_inserter(transitions));
128 neighbor.successorAssign();
129 }
while (matchBounded || noMatch);
131 BOOST_LOG_TRIVIAL(debug) <<
"ImpreciseClockHandler: finished!";
135 static TATransition::Resets embedIfImprecise(TATransition::Resets resets,
136 const std::unordered_set<ClockVariables> &preciseClocks,
137 const std::vector<double> &embeddedValuation) {
139 resets.erase(std::remove_if(resets.begin(), resets.end(), [&](
const auto &reset) {
140 return preciseClocks.find(reset.first) == preciseClocks.end();
143 for (ClockVariables clock = 0; clock < static_cast<ClockVariables>(embeddedValuation.size()); ++clock) {
144 if (preciseClocks.find(clock) == preciseClocks.end()) {
145 resets.emplace_back(clock, embeddedValuation.at(clock));
A forward regional elementary language.
Definition: forward_regional_elementary_language.hh:23
Relax guards to handle imprecise clock variables.
Definition: imprecise_clock_handler.hh:21
void run()
Relax the guards if necessary.
Definition: imprecise_clock_handler.hh:87
void push(TAState *jumpedState, const RenamingRelation &renamingRelation, const ForwardRegionalElementaryLanguage &targetElementary)
Add new transition with imprecise clocks.
Definition: imprecise_clock_handler.hh:74
Elementary language with its neighbor conditions.
Definition: neighbor_conditions.hh:30
std::vector< double > toOriginalValuation() const
Construct the reset to embed to the target condition.
Definition: neighbor_conditions.hh:378
NeighborConditions makeAfterTransition(const Alphabet action, const TATransition &transition) const
Construct the neighbor conditions after a transition.
Definition: neighbor_conditions.hh:276
auto toRelaxedGuard() const
Return the guard of the original elementary language and its neighbors.
Definition: neighbor_conditions.hh:321
static auto preciseClocksAfterReset(const std::unordered_set< ClockVariables > &preciseClocks, const TATransition &transition)
Make precise clocks after applying a reset.
Definition: neighbor_conditions.hh:147
bool match(const std::vector< Constraint > &guard) const
Return if the given guard matches with this elementary language.
Definition: neighbor_conditions.hh:294
Definition: renaming_relation.hh:16
bool hasImpreciseClocks(const TimedCondition &target) const
Check if the application of this renaming causes implicit clocks.
Definition: renaming_relation.hh:171
Definition: experiment_runner.hh:23
A state of timed automata.
Definition: timed_automaton.hh:28
A state of timed automata.
Definition: timed_automaton.hh:82
TAState * target
The pointer to the target state.
Definition: timed_automaton.hh:85
std::vector< Constraint > guard
The guard for this transition.
Definition: timed_automaton.hh:93
std::vector< std::pair< ClockVariables, std::variant< double, ClockVariables > > > resetVars
The clock variables reset after this transition.
Definition: timed_automaton.hh:91