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 <typename A, typename AI>
00038   std::set<typename Element<A, AI>::hstate_t>
00039   do_useful_states(const AutomataBase<A>&,
00040                    const Element<A, AI>&   a)
00041   {
00042     TIMER_SCOPED("useful_states");
00043     typedef typename Element<A, AI>::hstate_t hstate_t;
00044 
00045     std::set<hstate_t> start = accessible_states(a);
00046     std::set<hstate_t> final = coaccessible_states(a);
00047     std::set<hstate_t> result;
00048     std::insert_iterator<std::set<hstate_t> > i(result, result.begin());
00049 
00050     set_intersection(start.begin(), start.end(), final.begin(), final.end(), i);
00051     return result;
00052   }
00053 
00054   template<typename A, typename AI>
00055   std::set<typename Element<A, AI>::hstate_t>
00056   useful_states(const Element<A, AI>& a)
00057   {
00058     return do_useful_states(a.structure(), a);
00059   }
00060 
00061   template<typename A, typename AI>
00062   Element<A, AI>
00063   trim(const Element<A, AI>& a)
00064   {
00065     return sub_automaton(a, useful_states(a));
00066   }
00067 
00068   template<typename A, typename AI>
00069   void
00070   trim_here(Element<A, AI>& a)
00071   {
00072     sub_automaton_here(a, useful_states(a));
00073   }
00074 
00075 } 
00076 
00077 #endif // ! VCSN_ALGORITHMS_TRIM_HXX