Awali
Another Weighted Automata library
determinize.hh
Go to the documentation of this file.
1 // This file is part of Awali.
2 // Copyright 2016-2021 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_DETERMINIZE_HH
18 # define AWALI_ALGOS_DETERMINIZE_HH
19 
22 #include <awali/common/priority.hh>
23 
24 namespace awali {
25  namespace sttc {
38  template <typename Aut>
39  inline
40  auto
41  determinize(const Aut& a, bool keep_history = true)
43  {
44  // We use state numbers as indexes, so we need to know the last
45  // state number. If states were removed, it is not the same as
46  // the number of states.
47  unsigned state_size = a->max_state();
48  static const unsigned lim = std::numeric_limits<size_t>::digits;
49  if(state_size<lim)
50  {
52  auto res=algo();
53  if(keep_history)
54  algo.set_history();
55  return res;
56  }
57  if(state_size<2*lim)
58  {
60  auto res=algo();
61  if(keep_history)
62  algo.set_history();
63  return res;
64  }
66  auto res=algo();
67  if(keep_history)
68  algo.set_history();
69  return res;
70  }
71 
82  template <typename Aut>
83  inline
84  auto
85  codeterminize(const Aut& aut, bool keep_history = true)
87  {
88  return transpose(determinize(transpose_view(aut, keep_history)), keep_history);
89  }
90 
101  template <typename Aut>
102  inline
103  auto
104  weighted_determinize(const Aut& aut)
106  {
108  auto res = algo();
109  return res;
110  }
111 
123  template <class Aut>
124  inline bool
125  is_sequential(const Aut& aut)
126  {
127  static_assert(labelset_t_of<Aut>::is_free(),
128  "requires free labelset");
129 
130  if (1 < aut->num_initials())
131  return false;
132 
133  for (auto s: aut->states())
134  if (!internal::is_sequential(aut, s))
135  return false;
136  return true;
137  }
138 
150  template <class Aut>
151  inline bool
152  is_deterministic(const Aut& aut)
153  {
154  static_assert(labelset_t_of<Aut>::is_free(),
155  "requires free labelset");
156 
157  if (1 < aut->num_initials())
158  return false;
159  for (auto t : aut->initial_transitions())
160  if(!aut->weightset()->is_one(aut->weight_of(t)))
161  return false;
162  for (auto s: aut->states())
163  if (!internal::is_deterministic(aut, s))
164  return false;
165  return true;
166  }
167  }
168 }
169 #endif //AWALI_ALGOS_DETERMINIZE_HH
The subset construction automaton from another.
Definition: determinize.hxx:50
void set_history()
Definition: determinize.hxx:160
The subset construction automaton from another.
Definition: determinize.hxx:213
void set_history()
Definition: determinize.hxx:310
The weighted determinization of weighted automaton.
Definition: determinize.hxx:361
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
bool is_deterministic(const Aut &aut)
tests whether the automaton is deterministic
Definition: determinize.hh:152
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
auto determinize(const Aut &a, bool keep_history=true) -> mutable_automaton< context_t_of< Aut >>
Determinization of the automaton.
Definition: determinize.hh:41
auto codeterminize(const Aut &aut, bool keep_history=true) -> mutable_automaton< context_t_of< Aut >>
Co-determinization of the automaton.
Definition: determinize.hh:85
AutOut transpose(Aut &aut, bool keep_history=true)
Definition: transpose.hh:79
std::shared_ptr< internal::transpose_view_impl< Aut > > transpose_view(std::shared_ptr< Aut > aut)
Definition: transpose_view.hh:264
auto weighted_determinize(const Aut &aut) -> mutable_automaton< context_t_of< Aut >>
Weighted determinization of the automaton.
Definition: determinize.hh:104
std::shared_ptr< internal::mutable_automaton_impl< Context > > mutable_automaton
Definition: mutable_automaton.hh:45
bool is_sequential(const Aut &aut)
tests whether the automaton is deterministic
Definition: determinize.hh:125
Main namespace of Awali.
Definition: ato.hh:22