00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef VCSN_ALGORITHMS_TRIM_HXX
00018 # define VCSN_ALGORITHMS_TRIM_HXX
00019
00020 # include <vaucanson/algorithms/trim.hh>
00021
00022 # include <vaucanson/automata/concept/automata_base.hh>
00023
00024 # include <vaucanson/algorithms/sub_automaton.hh>
00025 # include <vaucanson/algorithms/accessible.hh>
00026
00027 # include <algorithm>
00028
00029 namespace vcsn {
00030
00031
00032
00033
00034
00035
00036
00037 template <class A_, typename Auto_>
00038 std::set<hstate_t>
00039 do_useful_states(const AutomataBase<A_>&,
00040 const Auto_& a)
00041 {
00042 TIMER_SCOPED("useful_states");
00043 std::set<hstate_t> start = accessible_states(a);
00044 std::set<hstate_t> final = coaccessible_states(a);
00045 std::set<hstate_t> result;
00046 std::insert_iterator<std::set<hstate_t> > i(result, result.begin());
00047
00048 set_intersection(start.begin(), start.end(), final.begin(), final.end(), i);
00049 return result;
00050 }
00051
00052 template<typename A, typename T>
00053 std::set<hstate_t>
00054 useful_states(const Element<A, T>& a)
00055 {
00056 return do_useful_states(a.structure(), a);
00057 }
00058
00059 template<typename A, typename T>
00060 Element<A, T>
00061 trim(const Element<A, T>& a)
00062 {
00063 return sub_automaton(a, useful_states(a));
00064 }
00065
00066 template<typename A, typename T>
00067 void
00068 trim_here(Element<A, T>& a)
00069 {
00070 sub_automaton_here(a, useful_states(a));
00071 }
00072
00073 }
00074
00075 #endif // ! VCSN_ALGORITHMS_TRIM_HXX