Vcsn  2.0
Be Rational
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
is-deterministic.hh
Go to the documentation of this file.
1 #ifndef VCSN_ALGOS_IS_DETERMINISTIC_HH
2 # define VCSN_ALGOS_IS_DETERMINISTIC_HH
3 
4 # include <queue>
5 # include <unordered_set>
6 
7 # include <vcsn/algos/transpose.hh>
8 # include <vcsn/ctx/traits.hh>
9 # include <vcsn/dyn/automaton.hh>
10 
11 namespace vcsn
12 {
13 
15  template <typename Aut>
16  inline bool
17  is_deterministic(const Aut& aut, state_t_of<Aut> s)
18  {
19  using automaton_t = Aut;
21  "is_deterministic: requires free labelset");
22 
24  std::unordered_set<label_t> seen;
25  for (auto t : aut->all_out(s))
26  if (!seen.insert(aut->label_of(t)).second)
27  return false;
28  return true;
29  }
30 
32  template <class Aut>
33  inline size_t
34  num_deterministic_states(const Aut& aut)
35  {
36  static_assert(labelset_t_of<Aut>::is_free(),
37  "num_deterministic_states: requires free labelset");
38 
39  size_t res = 0;
40  for (auto s: aut->states())
41  res += is_deterministic(aut, s);
42  return res;
43  }
44 
46  template <class Aut>
47  inline size_t
49  {
51  }
52 
55  template <class Aut>
56  inline bool
57  is_deterministic(const Aut& aut)
58  {
59  static_assert(labelset_t_of<Aut>::is_free(),
60  "is_deterministic: requires free labelset");
61 
62  if (1 < aut->initial_transitions().size())
63  return false;
64 
65  for (auto s: aut->states())
66  if (!is_deterministic(aut, s))
67  return false;
68  return true;
69  }
70 
72  template <class Aut>
73  inline bool
74  is_codeterministic(const Aut& aut)
75  {
76  return is_deterministic(transpose(aut));
77  }
78 
79  namespace dyn
80  {
81  namespace detail
82  {
84  template <typename Aut>
85  bool
87  {
88  return is_deterministic(aut->as<Aut>());
89  }
90 
92  (const automaton& aut) -> bool);
93 
94  template <typename Aut>
95  bool
97  {
98  return is_codeterministic(aut->as<Aut>());
99  }
100 
102  (const automaton& aut) -> bool);
103 
104  }
105  }
106 } // namespace vscn
107 
108 #endif // !VCSN_ALGOS_IS_DETERMINISTIC_HH
bool is_deterministic(const Aut &aut, state_t_of< Aut > s)
Whether state s is deterministic in aut.
REGISTER_DECLARE(accessible,(const automaton &) -> automaton)
std::shared_ptr< detail::automaton_base > automaton
Definition: automaton.hh:71
bool is_codeterministic(const automaton &aut)
typename detail::labelset_t_of_impl< base_t< ValueSet >>::type labelset_t_of
Definition: traits.hh:34
size_t num_codeterministic_states(const Aut &aut)
Number of non-deterministic states of transpositive automaton.
bool is_codeterministic(const Aut &aut)
Whether the transpositive automaton is deterministic.
typename detail::label_t_of_impl< base_t< ValueSet >>::type label_t_of
Definition: traits.hh:33
size_t num_deterministic_states(const Aut &aut)
Number of non-deterministic states.
Aut transpose(const transpose_automaton< Aut > &aut)
Definition: transpose.hh:230
typename detail::state_t_of_impl< base_t< ValueSet >>::type state_t_of
Definition: traits.hh:35
bool is_deterministic(const automaton &aut)
Bridge.