Awali
Another Weighted Automata library
is_proper.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_PROPER_HH
18 # define AWALI_ALGOS_IS_PROPER_HH
19 
20 # include <type_traits>
21 
22 #include <awali/sttc/ctx/traits.hh>
24 #include <awali/sttc/core/kind.hh>
25 
26 namespace awali { namespace sttc {
27 
28 
29  namespace internal
30  {
31  template <typename Aut>
32  typename std::enable_if<labelset_t_of<Aut>::has_one(),
33  bool>::type
34  is_proper_(const Aut& aut)
35  {
36  for (auto t: aut->transitions())
37  if (aut->labelset()->is_one(aut->label_of(t)))
38  return false;
39  return true;
40  }
41 
42  template <typename Aut>
43  constexpr
44  typename std::enable_if<!labelset_t_of<Aut>::has_one(),
45  bool>::type
46  is_proper_(const Aut&)
47  {
48  return true;
49  }
50 
51  template <size_t I, typename Tdc>
52  typename std::enable_if<!labelset_t_of<Tdc>::template valueset_t<I>::has_one(),
53  bool>::type
54  is_proper_tape_(const Tdc&)
55  {
56  return true;
57  }
58 
59  template <size_t I, typename Tdc>
60  typename std::enable_if<labelset_t_of<Tdc>::template valueset_t<I>::has_one(),
61  bool>::type
62  is_proper_tape_(const Tdc& tdc)
63  {
64  auto ls=tdc->context().labelset()->template set<I>();
65  for (auto t: tdc->transitions())
66  if (ls.is_one(std::get<I>(tdc->label_of(t))))
67  return false;
68  return true;
69  }
70 
71  template <typename Tdc>
72  constexpr
73  typename std::enable_if<!labelset_t_of<Tdc>::has_one(),
74  bool>::type
75  is_proper_tape_(const Tdc&)
76  {
77  return true;
78  }
79 
80  }
81 
89  template <typename Aut>
90  bool is_proper(const Aut& aut) ATTRIBUTE_CONST;
91 
92  template <typename Aut>
93  bool
94  is_proper(const Aut& aut)
95  {
96  return internal::is_proper_(aut);
97  }
98 
99  template <size_t I, typename Tdc>
100  bool
101  is_proper_tape(const Tdc& tdc)
102  {
103  return internal::is_proper_tape_<I>(tdc);
104  }
105 }}//end of ns awali::stc
106 
107 #endif // !AWALI_ALGOS_IS_PROPER_HH
std::enable_if< labelset_t_of< Aut >::has_one(), bool >::type is_proper_(const Aut &aut)
Definition: is_proper.hh:34
std::enable_if<!labelset_t_of< Tdc >::template valueset_t< I >::has_one(), bool >::type is_proper_tape_(const Tdc &)
Definition: is_proper.hh:54
bool is_proper(const Aut &aut) ATTRIBUTE_CONST
Test whether an automaton is proper.
Definition: is_proper.hh:94
bool is_proper_tape(const Tdc &tdc)
Definition: is_proper.hh:101
Main namespace of Awali.
Definition: ato.hh:22