Awali
Another Weighted Automata library
is_deterministic.hxx
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_DETERMINISTIC_HXX
18 # define AWALI_ALGOS_IS_DETERMINISTIC_HXX
19 
20 # include <queue>
21 # include <unordered_set>
22 
23 #include <awali/sttc/ctx/traits.hh>
24 
25 namespace awali {
26  namespace sttc {
27  namespace internal {
28 
30  template <typename Aut>
31  inline bool
32  is_sequential(const Aut& aut, state_t s)
33  {
34  using automaton_t = Aut;
36  "requires free labelset");
38  std::unordered_set<label_t> seen;
39  for (auto t : aut->out(s))
40  if (!seen.insert(aut->label_of(t)).second)
41  return false;
42  return true;
43  }
44 
46  template <typename Aut>
47  inline bool
48  is_deterministic(const Aut& aut, state_t s)
49  {
50  using automaton_t = Aut;
52  "requires free labelset");
54  std::unordered_set<label_t> seen;
55  for (auto t : aut->out(s)) {
56  if (!aut->weightset()->is_one(aut->weight_of(t)))
57  return false;
58  if (!seen.insert(aut->label_of(t)).second)
59  return false;
60  }
61  return true;
62  }
63 
65  template <class Aut>
66  inline size_t
67  num_deterministic_states(const Aut& aut)
68  {
69  static_assert(labelset_t_of<Aut>::is_free(),
70  "requires free labelset");
71 
72  size_t res = 0;
73  for (auto s: aut->states())
74  res += is_deterministic(aut, s);
75  return res;
76  }
77 
78  }
79  }
80 }//end of ns awali::stc
81 
82 #endif // !AWALI_ALGOS_IS_DETERMINISTIC_HXX
any_t label_t
Type for (transition) labels; it is an alias to any_t since its precise type depends on the weightset...
Definition: typedefs.hh:48
bool is_deterministic(const Aut &aut, state_t s)
Whether state s is deterministic in aut.
Definition: is_deterministic.hxx:48
bool is_sequential(const Aut &aut, state_t s)
Whether state s is sequential in aut.
Definition: is_deterministic.hxx:32
size_t num_deterministic_states(const Aut &aut)
Number of non-deterministic states.
Definition: is_deterministic.hxx:67
typename internal::label_t_of_impl< internal::base_t< ValueSet > >::type label_t_of
Helper to retrieve the type of the labels of a value set.
Definition: traits.hh:71
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
unsigned state_t
Definition: types.hh:21