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 AI, typename HStatesSet>
00035 void
00036 do_sub_automaton_here(const AutomataBase<A>&,
00037 Element<A, AI>& a,
00038 const HStatesSet& selected,
00039 bool check_states)
00040 {
00041 BENCH_TASK_SCOPED("sub_automaton");
00042 typedef Element<A, AI> automaton_t;
00043 std::list<typename automaton_t::hstate_t> to_be_removed;
00044 for (typename automaton_t::state_iterator i = a.states().begin();
00045 i != a.states().end(); ++i)
00046 if (std::find(selected.begin(), selected.end(), *i) == selected.end())
00047 to_be_removed.push_back(*i);
00048
00049 for_all_const_(std::list<typename automaton_t::hstate_t>, i, to_be_removed)
00050 if (!check_states
00051 || a.has_state(*i))
00052 a.del_state(*i);
00053 }
00054
00055
00056
00057 template<typename A, typename AI, typename HStatesSet>
00058 Element<A, AI>
00059 sub_automaton(const Element<A, AI>& a, const HStatesSet& s, bool check_states)
00060 {
00061 Element<A, AI> ret(a);
00062 std::set<typename Element<A, AI>::hstate_t> ret_s;
00063
00064 for_all_iterator(typename HStatesSet::const_iterator, i, s)
00065 ret_s.insert(ret.get_state(size_t(*i)));
00066 do_sub_automaton_here(ret.structure(), ret, ret_s, check_states);
00067 return ret;
00068 }
00069
00070 template<typename A, typename AI, typename HStatesSet>
00071 void
00072 sub_automaton_here(Element<A, AI>& a, const HStatesSet& s, bool check_states)
00073 {
00074 do_sub_automaton_here(a.structure(), a, s, check_states);
00075 }
00076
00077 }
00078
00079 #endif // ! VCSN_ALGORITHMS_SUB_AUTOMATON_HXX