Awali
Another Weighted Automata library
restriction.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 /* @file accessible.hh
18  *
19  * This files contains static functions computing accessible states.
20  */
21 #ifndef AWALI_ALGOS_RESTRICTION_HH
22 #define AWALI_ALGOS_RESTRICTION_HH
23 
24 #include <set>
25 
26 #include <awali/sttc/ctx/traits.hh>
28 
29 namespace awali {
30  namespace sttc {
31 
32  namespace internal {
33  template<typename LS>
35  template<typename SET>
36  static LS make(const SET& letters) {
37  return LS(letters);
38  }
39  };
40 
41  template<typename LS>
43  template<typename SET>
44  static nullableset<LS> make(const SET& letters) {
45  return nullableset<LS>(LS(letters));
46  }
47  };
48 
49  }
50 
63  template<typename Aut>
64  void remove_letters(Aut& aut, const std::set<typename labelset_t_of<Aut>::letter_t>& letters, bool del_unvalid_transitions =true) {
65  std::set<typename labelset_t_of<Aut>::letter_t> new_alphabet;
66  for(auto l: aut->labelset()->genset())
67  new_alphabet.insert(l);
68  for(auto l: letters)
69  new_alphabet.erase(l);
70  context_t_of<Aut> ctx(internal::make_labelset_from_letters<labelset_t_of<Aut>>::make(new_alphabet), *(aut->weightset()));
71  aut->ctx_ = ctx;
72  if(del_unvalid_transitions) {
73  auto labelset = aut->labelset();
74  std::list<transition_t> to_erase;
75  for(auto tr: aut->transitions())
76  if(!labelset->is_valid(aut->label_of(tr)))
77  to_erase.emplace_back(tr);
78  for(auto tr: to_erase)
79  aut->del_transition(tr);
80  }
81  }
82 
83 
96  template<typename Aut>
97  void change_alphabet(Aut& aut, const std::set<typename labelset_t_of<Aut>::letter_t>& letters, bool del_unvalid_transitions =true) {
98  context_t_of<Aut> ctx(internal::make_labelset_from_letters<labelset_t_of<Aut>>::make(letters), *(aut->weightset()));
99  aut->ctx_ = ctx;
100  if(del_unvalid_transitions) {
101  auto labelset = aut->labelset();
102  std::list<transition_t> to_erase;
103  for(auto tr: aut->transitions())
104  if(!labelset->is_valid(aut->label_of(tr)))
105  to_erase.emplace_back(tr);
106  for(auto tr: to_erase)
107  aut->del_transition(tr);
108  }
109  }
110 
111  }
112 }//end of ns awali::stc
113 
114 #endif // !AWALI_ALGOS_RESTRICTION_HH
Implementation of labels are nullables (letter or empty).
Definition: nullableset.hh:189
typename internal::context_t_of_impl< internal::base_t< ValueSet > >::type context_t_of
Helper to retrieve the type of the context of a value set.
Definition: traits.hh:66
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
void change_alphabet(Aut &aut, const std::set< typename labelset_t_of< Aut >::letter_t > &letters, bool del_unvalid_transitions=true)
Change letters in the alphabet of the automaton.
Definition: restriction.hh:97
void remove_letters(Aut &aut, const std::set< typename labelset_t_of< Aut >::letter_t > &letters, bool del_unvalid_transitions=true)
Remove letters from the alphabet of the automaton.
Definition: restriction.hh:64
Main namespace of Awali.
Definition: ato.hh:22
static nullableset< LS > make(const SET &letters)
Definition: restriction.hh:44
static LS make(const SET &letters)
Definition: restriction.hh:36