Vcsn  2.0
Be Rational
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
is-complete.hh
Go to the documentation of this file.
1 #ifndef VCSN_ALGOS_IS_COMPLETE_HH
2 # define VCSN_ALGOS_IS_COMPLETE_HH
3 
4 # include <queue>
5 # include <set>
6 
7 # include <vcsn/dyn/automaton.hh>
8 # include <vcsn/dyn/fwd.hh>
9 
10 namespace vcsn
11 {
14  template <typename Aut>
15  bool is_complete(const Aut& aut)
16  {
17  static_assert(labelset_t_of<Aut>::is_free(),
18  "is_complete: requires free labelset");
19 
20  if (aut->num_initials() == 0)
21  return false;
22 
23  using label_set_t = std::set<typename labelset_t_of<Aut>::letter_t>;
24 
25  const auto& letters = aut->labelset()->genset();
26  for (auto state : aut->states())
27  {
28  label_set_t missing_letters = {std::begin(letters), std::end(letters)};
29 
30  for (auto tr : aut->all_out(state))
31  missing_letters.erase(aut->label_of(tr));
32 
33  if (!missing_letters.empty())
34  return false;
35  }
36 
37  return true;
38  }
39 
40  /*------------------.
41  | dyn::is-complete. |
42  `------------------*/
43 
44  namespace dyn
45  {
46  namespace detail
47  {
49  template <class Aut>
50  bool is_complete(const automaton& aut)
51  {
52  return is_complete(aut->as<Aut>());
53  }
54 
56  (const automaton&) -> bool);
57  }
58  }
59 }
60 
61 #endif // !VCSN_ALGOS_IS_COMPLETE_HH
REGISTER_DECLARE(accessible,(const automaton &) -> automaton)
std::shared_ptr< detail::automaton_base > automaton
Definition: automaton.hh:71
typename detail::labelset_t_of_impl< base_t< ValueSet >>::type labelset_t_of
Definition: traits.hh:34
bool is_complete(const Aut &aut)
Whether aut is complete.
Definition: is-complete.hh:15
bool is_complete(const automaton &aut)
Bridge.
Definition: is-complete.hh:50