Awali
Another Weighted Automata library
sub_automaton.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_SUB_AUTOMATON_HH
18 # define AWALI_ALGOS_SUB_AUTOMATON_HH
19 
20 # include <set>
21 
22 namespace awali { namespace sttc {
23 
24 
25  /*-----------------.
26  | sub-automaton). |
27  `-----------------*/
28 
29  template <typename Aut, typename Pred>
30  inline
31  void
32  sub_automaton(Aut& aut, Pred keep_state)
33  {
34  std::vector<state_t> to_erase;
35  for(auto s : aut->states())
36  if(!keep_state(s))
37  to_erase.emplace_back(s);
38  for(auto s : to_erase)
39  aut->del_state(s);
40  }
41 
42  template <typename Aut>
43  inline
44  void
45  sub_automaton(Aut& aut, const std::set<state_t>& sts)
46  {
47  std::vector<state_t> to_erase;
48  auto it=sts.begin();
49  for(auto s : aut->all_states())
50  if(it == sts.end() || *it != s) {
51  if(s!= aut->pre() && s!=aut->post())
52  to_erase.emplace_back(s);
53  }
54  else
55  ++it;
56  for(auto s : to_erase)
57  aut->del_state(s);
58  }
59 
60 }}//end of ns awali::stc
61 
62 #endif // !AWALI_ALGOS_SUB_AUTOMATON_HH
void sub_automaton(Aut &aut, Pred keep_state)
Definition: sub_automaton.hh:32
Main namespace of Awali.
Definition: ato.hh:22