Awali
Another Weighted Automata library
is_complete.hh
Go to the documentation of this file.
1 // This file is part of Awali.
2 // Copyright 2016-2022 Sylvain Lombardy, Victor Marsault, Jacques Sakarovitch
3 //
4 // Awali is a free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef AWALI_ALGOS_IS_COMPLETE_HH
18 # define AWALI_ALGOS_IS_COMPLETE_HH
19 
20 # include <queue>
21 # include <set>
22 
23 namespace awali { namespace sttc {
24 
27  template <typename Aut>
28  bool is_complete(const Aut& aut)
29  {
30  static_assert(labelset_t_of<Aut>::is_free(),
31  "requires free labelset");
32 
33  if (aut->num_initials() == 0)
34  return false;
35 
36  using label_set_t = std::set<typename labelset_t_of<Aut>::letter_t>;
37 
38  const auto& letters = aut->labelset()->genset();
39  for (auto state : aut->states())
40  {
41  label_set_t missing_letters = {std::begin(letters), std::end(letters)};
42 
43  for (auto tr : aut->all_out(state))
44  missing_letters.erase(aut->label_of(tr));
45 
46  if (!missing_letters.empty())
47  return false;
48  }
49 
50  return true;
51  }
52 
53 }}//end of ns awali::stc
54 
55 #endif // !AWALI_ALGOS_IS_COMPLETE_HH
bool is_complete(const Aut &aut)
Whether aut is complete.
Definition: is_complete.hh:28
typename internal::labelset_t_of_impl< internal::base_t< ValueSet > >::type labelset_t_of
Helper to retrieve the type of the labelset of a value set.
Definition: traits.hh:76
Main namespace of Awali.
Definition: ato.hh:22