Awali
Another Weighted Automata library
determinize.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_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 <typename Aut>
124  inline
125  auto
126  explore_by_length(const Aut& aut, unsigned depth)
128  {
129  internal::detweighted_algo_impl<Aut> algo(aut, depth);
130  auto res = algo();
131  return res;
132  }
133 
152  template <typename Aut>
153  inline
154  auto
155  explore_with_bound(const Aut& aut, typename weightset_t_of<Aut>::value_t bound)
157  {
159  auto ws = *aut->weightset();
160  auto bb=ws.mul(bound,bound);
161  auto res = algo([=](typename internal::detweighted_algo_impl<Aut>::state_name_t& st){
162  for (const auto& p : st)
163  if(ws.less_than(bb,ws.mul(p.second,p.second)))
164  return false;
165  return true;
166  });
167  return res;
168  }
169 
181  template <class Aut>
182  inline bool
183  is_sequential(const Aut& aut)
184  {
185  static_assert(labelset_t_of<Aut>::is_free(),
186  "requires free labelset");
187 
188  if (1 < aut->num_initials())
189  return false;
190 
191  for (auto s: aut->states())
192  if (!internal::is_sequential(aut, s))
193  return false;
194  return true;
195  }
196 
208  template <class Aut>
209  inline bool
210  is_deterministic(const Aut& aut)
211  {
212  static_assert(labelset_t_of<Aut>::is_free(),
213  "requires free labelset");
214 
215  if (1 < aut->num_initials())
216  return false;
217  for (auto t : aut->initial_transitions())
218  if(!aut->weightset()->is_one(aut->weight_of(t)))
219  return false;
220  for (auto s: aut->states())
221  if (!internal::is_deterministic(aut, s))
222  return false;
223  return true;
224  }
225  }
226 }
227 #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:362
typename state_nameset_t::value_t state_name_t
Definition: determinize.hxx:391
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:210
auto explore_by_length(const Aut &aut, unsigned depth) -> mutable_automaton< context_t_of< Aut >>
Exploration of the automaton up to a given depth.
Definition: determinize.hh:126
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:265
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:183
auto explore_with_bound(const Aut &aut, typename weightset_t_of< Aut >::value_t bound) -> mutable_automaton< context_t_of< Aut >>
Exploration of the automaton up to a given bound.
Definition: determinize.hh:155
typename internal::weightset_t_of_impl< internal::base_t< ValueSet > >::type weightset_t_of
Helper to retrieve the type of the weightset of a value set.
Definition: traits.hh:86
Main namespace of Awali.
Definition: ato.hh:22