00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef VCSN_ALGORITHMS_COMPLETE_HXX
00018 # define VCSN_ALGORITHMS_COMPLETE_HXX
00019
00020 # include <vaucanson/algorithms/complete.hh>
00021
00022 # include <vaucanson/automata/concept/automata_base.hh>
00023 # include <vaucanson/misc/usual_macros.hh>
00024
00025 # include <list>
00026 # include <set>
00027
00028 namespace vcsn {
00029
00030
00031
00032
00033
00034 template <typename A, typename T>
00035 void
00036 complete_here(Element<A, T>& work)
00037 {
00038 typedef Element<A, T> automaton_t;
00039 AUTOMATON_TYPES(automaton_t);
00040 AUTOMATON_FREEMONOID_TYPES(automaton_t);
00041 hstate_t sink_state;
00042 bool sink_added = false;
00043 std::list<hstate_t> aim;
00044
00045 for_all_states(s, work)
00046 {
00047 for_all_letters(l, work.structure().series().monoid().alphabet())
00048 {
00049 aim.clear();
00050 work.letter_deltac(aim, *s, *l, delta_kind::states());
00051 if (aim.size() == 0)
00052 {
00053 if (not sink_added)
00054 {
00055 sink_state = work.add_state();
00056 sink_added = true;
00057 }
00058 work.add_letter_transition(*s, sink_state, *l);
00059 }
00060 }
00061 }
00062 if (sink_added)
00063 for_all_letters(l, work.structure().series().monoid().alphabet())
00064 work.add_letter_transition(sink_state, sink_state, *l);
00065 }
00066
00067
00068
00069
00070
00071 template <typename A, typename T>
00072 Element<A, T>
00073 complete(const Element<A, T>& e)
00074 {
00075 Element<A, T> res(e);
00076 complete_here(res);
00077 return res;
00078 }
00079
00080
00081
00082
00083
00084 template <class A, class T>
00085 bool
00086 is_complete(const Element<A, T>& e)
00087 {
00088 typedef Element<A, T> automaton_t;
00089 AUTOMATON_TYPES(automaton_t);
00090 AUTOMATON_FREEMONOID_TYPES(automaton_t);
00091 for_all_states(i, e)
00092 {
00093 std::set<hstate_t> aim;
00094 const alphabet_t& alpha = e.structure().series().monoid().alphabet();
00095 for_all_letters(j, alpha)
00096 {
00097 aim.clear();
00098 e.letter_deltac(aim, *i, *j, delta_kind::states());
00099
00100 if (aim.size() == 0)
00101 return false;
00102 }
00103 }
00104 return true;
00105 }
00106
00107 }
00108
00109 #endif // ! VCSN_ALGORITHMS_COMPLETE_HXX