00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef VCSN_ALGORITHMS_IS_DETERMINISTIC_HXX
00018 # define VCSN_ALGORITHMS_IS_DETERMINISTIC_HXX
00019
00020 # include <vaucanson/algorithms/is_deterministic.hh>
00021 # include <set>
00022 # include <vaucanson/misc/usual_macros.hh>
00023 # include <vaucanson/automata/concept/automata_base.hh>
00024
00025 namespace vcsn {
00026
00027
00028
00029
00030
00031 template <typename input_t>
00032 static bool
00033 is_state_deterministic (input_t& input,
00034 typename input_t::state_iterator& current_state,
00035 typename input_t::series_set_elt_t::semiring_elt_t&
00036 zero_semiring)
00037 {
00038 AUTOMATON_TYPES(input_t);
00039
00040 typedef typename series_set_elt_t::support_t support_t;
00041 typedef typename std::set<htransition_t> delta_ret_t;
00042 delta_ret_t delta_ret;
00043
00044 input.deltac(delta_ret, *current_state, delta_kind::transitions());
00045
00046 for_all_const_(delta_ret_t, j, delta_ret)
00047 {
00048 series_set_elt_t s = input.series_of(*j);
00049 typename delta_ret_t::const_iterator k = j;
00050 ++k;
00051 for (; k != delta_ret.end(); ++k)
00052 {
00053 series_set_elt_t s_ = input.series_of(*k);
00054 for_all_(support_t, supp, s.supp())
00055 if (s_.get(*supp) != zero_semiring)
00056 return false;
00057 }
00058 }
00059 return true;
00060 }
00061
00062
00063
00064
00065
00066
00067
00068 template <typename A, typename input_t>
00069 bool
00070 do_is_deterministic(const AutomataBase<A>& ,
00071 const input_t& input)
00072 {
00073 AUTOMATON_TYPES(input_t);
00074 semiring_elt_t zero_semiring
00075 = input.structure().series().semiring()
00076 .zero(SELECT(typename semiring_elt_t::value_t));
00077
00078
00079 if (input.states().size() == 0)
00080 return false;
00081
00082 if (input.initial().size() != 1)
00083 return false;
00084
00085 for_all_states(i, input)
00086 if (not is_state_deterministic (input, i, zero_semiring))
00087 return false;
00088 return true;
00089 }
00090
00091
00092 template<typename A, typename T>
00093 bool
00094 is_deterministic(const Element<A, T>& a)
00095 {
00096 TIMER_SCOPED("is_deterministic");
00097 return do_is_deterministic(a.structure(), a);
00098 }
00099
00100 }
00101
00102 #endif // ! VCSN_ALGORITHMS_IS_DETERMINISTIC_HXX