Vaucanson  1.4.1
trim.hxx
1 // trim.hxx: this file is part of the Vaucanson project.
2 //
3 // Vaucanson, a generic library for finite state machines.
4 //
5 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2008 The Vaucanson Group.
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
11 //
12 // The complete GNU General Public Licence Notice can be found as the
13 // `COPYING' file in the root directory.
14 //
15 // The Vaucanson Group consists of people listed in the `AUTHORS' file.
16 //
17 #ifndef VCSN_ALGORITHMS_TRIM_HXX
18 # define VCSN_ALGORITHMS_TRIM_HXX
19 
21 
22 # include <vaucanson/automata/concept/automata_base.hh>
23 
26 
27 # include <algorithm>
28 
29 namespace vcsn {
30 
31  /*---------------------.
32  | do_start_trim_states |
33  `---------------------*/
34  // preconditions :
35  //
36  //
37  template <typename A, typename AI>
38  std::set<typename Element<A, AI>::hstate_t>
39  do_useful_states(const AutomataBase<A>&,
40  const Element<A, AI>& a)
41  {
42  BENCH_TASK_SCOPED("useful_states");
43  typedef typename Element<A, AI>::hstate_t hstate_t;
44 
45  std::set<hstate_t> start = accessible_states(a);
46  std::set<hstate_t> final = coaccessible_states(a);
47  std::set<hstate_t> result;
48  std::insert_iterator<std::set<hstate_t> > i(result, result.begin());
49 
50  set_intersection(start.begin(), start.end(), final.begin(), final.end(), i);
51  return result;
52  }
53 
54  template<typename A, typename AI>
55  std::set<typename Element<A, AI>::hstate_t>
57  {
58  return do_useful_states(a.structure(), a);
59  }
60 
61  template<typename A, typename AI>
62  Element<A, AI>
63  trim(const Element<A, AI>& a)
64  {
65  return sub_automaton(a, useful_states(a));
66  }
67 
68  template<typename A, typename AI>
69  void
71  {
73  }
74 
75 } // vcsn
76 
77 #endif // ! VCSN_ALGORITHMS_TRIM_HXX