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/tools/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_each_state(i, work)
00046 {
00047 for_each_letter(j, work.structure().series().monoid().alphabet())
00048 {
00049 aim.clear();
00050 work.letter_deltac(aim, *i, *j, 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(*i, sink_state, *j);
00059 }
00060 }
00061 }
00062 }
00063
00064
00065
00066
00067
00068 template <typename A, typename T>
00069 Element<A, T>
00070 complete(const Element<A, T>& e)
00071 {
00072 Element<A, T> res(e);
00073 complete_here(res);
00074 return res;
00075 }
00076
00077
00078
00079
00080
00081 template <class A, class T>
00082 bool
00083 is_complete(const Element<A, T>& e)
00084 {
00085 typedef Element<A, T> automaton_t;
00086 AUTOMATON_TYPES(automaton_t);
00087 AUTOMATON_FREEMONOID_TYPES(automaton_t);
00088 for_each_state(i, e)
00089 {
00090 std::set<hstate_t> aim;
00091 const alphabet_t& alpha = e.structure().series().monoid().alphabet();
00092 for_each_letter(j, alpha)
00093 {
00094 aim.clear();
00095 e.letter_deltac(aim, *i, *j, delta_kind::states());
00096
00097 if (aim.size() == 0)
00098 return false;
00099 }
00100 }
00101 return true;
00102 }
00103
00104 }
00105
00106 #endif // ! VCSN_ALGORITHMS_COMPLETE_HXX