LearnTA  0.0.1
common_types.hh
1 #pragma once
2 
3 #include <cstdint>
4 #include <memory>
5 #include <vector>
6 
7 namespace learnta {
8  typedef char Alphabet;
9  typedef uint8_t ClockVariables;
10  // Special action for unobservable transitions
11  const Alphabet UNOBSERVABLE = 0;
12  const auto UNOBSERVABLE_STRING = "ε";
13 
17  template<class State>
18  struct Automaton {
19  struct TATransition;
20 
22  std::vector<std::shared_ptr<State>> states;
24  std::vector<std::shared_ptr<State>> initialStates;
25 
27  [[nodiscard]] inline std::size_t stateSize() const { return states.size(); }
28 
30  inline bool operator==(const Automaton<State> &A) const {
31  return initialStates == A.initialStates && states == A.states;
32  }
33  };
34 
38  template<class T>
39  bool is_ascending(const std::vector<T> &container) {
40  static_assert(std::is_arithmetic<T>::value, "The elements must be arithmetic.");
41  for (auto it = container.begin(); it != container.end() && std::next(it) != container.end(); ++it) {
42  if (*it > *std::next(it)) {
43  return false;
44  }
45  }
46 
47  return true;
48  }
49 
53  template<class T>
54  bool is_strict_ascending(const std::vector<T> &container) {
55  static_assert(std::is_arithmetic<T>::value, "The elements must be arithmetic.");
56  for (auto it = container.begin(); it != container.end() && std::next(it) != container.end(); ++it) {
57  if (*it >= *std::next(it)) {
58  return false;
59  }
60  }
61 
62  return true;
63  }
64 
68  template<class T, class U>
69  T first(const std::pair<T, U> &pair) {
70  return pair.first;
71  }
72 
76  template<class T, class U>
77  U second(const std::pair<T, U> &pair) {
78  return pair.second;
79  }
80 
84  template<class T, class U>
85  auto is_first(const T &value) {
86  return [&] (const std::pair<T, U> &pair) {
87  return pair.first == value;
88  };
89  }
90 
94  template<class T, class U>
95  auto is_second(const U &value) {
96  return [&] (const std::pair<T, U> &pair) {
97  return pair.second == value;
98  };
99  }
100 }
Definition: experiment_runner.hh:23
bool is_strict_ascending(const std::vector< T > &container)
Check if the elements are sorted in the strict ascending order.
Definition: common_types.hh:54
auto is_first(const T &value)
Return a function checking if the first element equal to the given value.
Definition: common_types.hh:85
T first(const std::pair< T, U > &pair)
Return the first element of a pair.
Definition: common_types.hh:69
bool is_ascending(const std::vector< T > &container)
Check if the elements are sorted in the ascending order.
Definition: common_types.hh:39
auto is_second(const U &value)
Return a function checking if the second element equal to the given value.
Definition: common_types.hh:95
U second(const std::pair< T, U > &pair)
Return the second element of a pair.
Definition: common_types.hh:77
An automaton.
Definition: common_types.hh:18
bool operator==(const Automaton< State > &A) const
Check the equivalence of two automata.
Definition: common_types.hh:30
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
std::size_t stateSize() const
Returns the number of the states.
Definition: common_types.hh:27
A state of timed automata.
Definition: timed_automaton.hh:82