Vcsn  2.4
Be Rational
is-complete.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <set>
4 
5 #include <vcsn/core/automaton.hh> // all_out
6 #include <vcsn/dyn/automaton.hh>
7 #include <vcsn/dyn/fwd.hh>
8 
9 namespace vcsn
10 {
13  template <Automaton Aut>
14  bool is_complete(const Aut& aut)
15  {
16  static_assert(labelset_t_of<Aut>::is_free(),
17  "is_complete: requires free labelset");
18 
19  if (aut->num_initials() == 0)
20  return false;
21 
22  // FIXME: this is naive: an unordered_set and/or a bitset would
23  // probably be more efficient. See the benches.
24  using label_set_t = std::set<typename labelset_t_of<Aut>::letter_t>;
25 
26  const auto& letters = aut->labelset()->generators();
27  for (auto state : aut->states())
28  {
29  auto missing_letters
30  = label_set_t{std::begin(letters), std::end(letters)};
31 
32  for (auto tr : all_out(aut, state))
33  missing_letters.erase(aut->label_of(tr));
34 
35  if (!missing_letters.empty())
36  return false;
37  }
38 
39  return true;
40  }
41 
42  /*------------------.
43  | dyn::is-complete. |
44  `------------------*/
45 
46  namespace dyn
47  {
48  namespace detail
49  {
51  template <Automaton Aut>
52  bool is_complete(const automaton& aut)
53  {
54  return is_complete(aut->as<Aut>());
55  }
56  }
57  }
58 }
typename detail::labelset_t_of_impl< base_t< ValueSet >>::type labelset_t_of
Definition: traits.hh:63
bool is_complete(const Aut &aut)
Whether aut is complete.
Definition: is-complete.hh:14
Definition: a-star.hh:8
auto all_out(const Aut &aut, state_t_of< Aut > s)
Indexes of transitions leaving state s.
Definition: automaton.hh:66
A dyn automaton.
Definition: automaton.hh:17
bool is_complete(const automaton &aut)
Bridge.
Definition: is-complete.hh:52
auto & as()
Extract wrapped typed automaton.
Definition: automaton.hh:37