7 #include <unordered_map>
11 #include "common_types.hh"
12 #include "constraint.hh"
32 std::unordered_map<Alphabet, std::vector<TATransition>>
next;
35 std::unordered_map<Alphabet, std::vector<TATransition>>
next)
70 std::unordered_map<
TAState *, std::shared_ptr<TAState>> &old2new)
const {
74 for (
auto oldState :
states) {
75 dest.
states.emplace_back(std::make_shared<TAState>(*oldState));
76 old2new[oldState.get()] = dest.
states.back();
81 dest.
initialStates.emplace_back(old2new[oldInitialState.get()]);
84 for (
auto &state : dest.
states) {
85 for (
auto &edges : state->next) {
86 for (
auto &edge : edges.second) {
87 auto oldTarget = edge.target;
88 edge.target = old2new[oldTarget].get();
102 bool isMember(
const std::vector<std::pair<Alphabet, double>> &w)
const {
103 std::vector<std::pair<TAState *, std::valarray<double>>> CStates;
106 CStates.emplace_back(s.get(), std::valarray<double>(0.0,
clockSize()));
108 for (std::size_t i = 0; i < w.size(); i++) {
109 std::vector<std::pair<TAState *, std::valarray<double>>> NextStates;
110 for (std::pair<
TAState *, std::valarray<double>> &config : CStates) {
112 config.second += w[i].second - w[i - 1].second;
114 config.second += w[i].second;
116 auto it = config.first->next.find(w[i].first);
117 if (it == config.first->next.end()) {
120 for (
const auto &edge : it->second) {
121 if (std::all_of(edge.guard.begin(), edge.guard.end(),
123 return g.satisfy(config.second[g.x]);
125 auto tmpConfig = config;
126 tmpConfig.first = edge.target;
127 if (tmpConfig.first) {
128 for (ClockVariables x : edge.resetVars) {
129 tmpConfig.second[x] = 0;
131 NextStates.emplace_back(std::move(tmpConfig));
136 CStates = std::move(NextStates);
138 return std::any_of(CStates.begin(), CStates.end(),
139 [](std::pair<
const TAState *, std::valarray<double>> p) {
140 return p.first->isMatch;
146 static inline std::ostream &operator<<(std::ostream &os,
148 std::unordered_map<TAState *, bool> isInit;
149 std::unordered_map<TAState *, unsigned int> stateNumber;
151 for (
unsigned int i = 0; i < TA.
states.size(); ++i) {
153 isInit[TA.
states.at(i).get()] =
157 stateNumber[TA.
states.at(i).get()] = i + 1;
159 os <<
"digraph G {\n";
161 for (std::shared_ptr<TAState> state : TA.
states) {
162 os <<
" loc" << stateNumber.at(state.get())
163 <<
" [init=" << isInit.at(state.get()) <<
", match=" << state->isMatch;
164 if (state->zeroDuration) {
165 os <<
", zero_duration=" << state->zeroDuration;
170 for (std::shared_ptr<TAState> source : TA.
states) {
171 for (
auto edges : source->next) {
174 os <<
" loc" << stateNumber.at(source.get()) <<
"->loc"
175 << stateNumber.at(target) <<
" [label=\"" << edges.first <<
"\"";
176 if (!edge.
guard.empty()) {
191 for (
const ClockVariables var : edge.
resetVars) {
Definition: constraint.hh:73
An automaton.
Definition: common_types.hh:13
std::size_t stateSize() const
Returns the number of the states.
Definition: common_types.hh:22
std::vector< std::shared_ptr< State > > states
The states of this automaton.
Definition: common_types.hh:14
std::vector< std::shared_ptr< State > > initialStates
The initial states of this automaton.
Definition: common_types.hh:19
A constraint in a guard of transitions.
Definition: constraint.hh:16
A state of timed automata.
Definition: timed_automaton.hh:19
std::unordered_map< Alphabet, std::vector< TATransition > > next
An mapping of a character to the transitions.
Definition: timed_automaton.hh:32
bool zeroDuration
The value is true if the duration to stay this state must be zero.
Definition: timed_automaton.hh:27
bool isMatch
The value is true if and only if the state is an accepting state.
Definition: timed_automaton.hh:21
A state of timed automata.
Definition: timed_automaton.hh:42
std::vector< Constraint > guard
The guard for this transition.
Definition: timed_automaton.hh:48
TAState * target
The pointer to the target state.
Definition: timed_automaton.hh:44
std::vector< ClockVariables > resetVars
The clock variables reset after this transition.
Definition: timed_automaton.hh:46
A timed automaton.
Definition: timed_automaton.hh:54
void deepCopy(TimedAutomaton &dest, std::unordered_map< TAState *, std::shared_ptr< TAState >> &old2new) const
make a deep copy of this timed automaton.
Definition: timed_automaton.hh:68
size_t clockSize() const
Returns the number of clock variables used in the timed automaton.
Definition: timed_automaton.hh:95
bool isMember(const std::vector< std::pair< Alphabet, double >> &w) const
solve membership problem for observable timed automaton
Definition: timed_automaton.hh:102
std::vector< int > maxConstraints
The maximum constraints for each clock variables.
Definition: timed_automaton.hh:60