00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef VCSN_ALGORITHMS_SUB_AUTOMATON_HXX
00019 # define VCSN_ALGORITHMS_SUB_AUTOMATON_HXX
00020
00021 # include <vaucanson/algorithms/sub_automaton.hh>
00022
00023 # include <vaucanson/automata/concept/automata_base.hh>
00024 # include <vaucanson/misc/usual_macros.hh>
00025
00026 # include <list>
00027
00028 namespace vcsn {
00029
00030
00031
00032
00033
00034 template<typename A, typename auto_t, typename list_t>
00035 void
00036 do_sub_automaton_here(const AutomataBase<A>&,
00037 auto_t& a,
00038 const list_t& selected,
00039 bool check_states)
00040 {
00041 TIMER_SCOPED("sub_automaton");
00042 std::list<typename auto_t::hstate_t> to_be_removed;
00043 for (typename auto_t::state_iterator i = a.states().begin();
00044 i != a.states().end(); ++i)
00045 if (std::find(selected.begin(), selected.end(), *i) == selected.end())
00046 to_be_removed.push_back(*i);
00047
00048 for_all_const_(std::list<typename auto_t::hstate_t>, i, to_be_removed)
00049 if (!check_states
00050 || a.has_state(*i))
00051 a.del_state(*i);
00052 }
00053
00054
00055
00056 template<typename A, typename T, typename StatesSet>
00057 Element<A, T>
00058 sub_automaton(const Element<A, T>& a, const StatesSet& s, bool check_states)
00059 {
00060 Element<A, T> ret(a);
00061 std::set<typename Element<A, T>::hstate_t> ret_s;
00062
00063 for_all_iterator(typename StatesSet::iterator, i, s)
00064 ret_s.insert(ret.get_state(size_t(*i)));
00065 do_sub_automaton_here(ret.structure(), ret, ret_s, check_states);
00066 return ret;
00067 }
00068
00069 template<typename A, typename T, typename StatesSet>
00070 void
00071 sub_automaton_here(Element<A, T>& a, const StatesSet& s, bool check_states)
00072 {
00073 do_sub_automaton_here(a.structure(), a, s, check_states);
00074 }
00075
00076 }
00077
00078 #endif // ! VCSN_ALGORITHMS_SUB_AUTOMATON_HXX