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 <vaucanson/algorithms/realtime.hh>
00022 # include <set>
00023 # include <vaucanson/misc/usual_macros.hh>
00024 # include <vaucanson/automata/concept/automata_base.hh>
00025
00026 namespace vcsn {
00027
00028
00029
00030
00031
00032 template <typename input_t>
00033 static bool
00034 is_state_deterministic (input_t& input,
00035 typename input_t::state_iterator& current_state,
00036 typename input_t::series_set_elt_t::semiring_elt_t&
00037 zero_semiring)
00038 {
00039 AUTOMATON_TYPES(input_t);
00040
00041 typedef typename series_set_elt_t::support_t support_t;
00042 typedef typename std::list<htransition_t> delta_ret_t;
00043 delta_ret_t delta_ret;
00044
00045
00046 for (delta_iterator j(input.value(), *current_state);
00047 ! j.done();
00048 j.next())
00049 delta_ret.push_back(*j);
00050 for_all_const_(delta_ret_t, j, delta_ret)
00051 {
00052 series_set_elt_t s = input.series_of(*j);
00053 typename delta_ret_t::const_iterator k = j;
00054 ++k;
00055 for (; k != delta_ret.end(); ++k)
00056 {
00057 series_set_elt_t s_ = input.series_of(*k);
00058 for_all_(support_t, supp, s.supp())
00059 if (s_.get(*supp) != zero_semiring)
00060 return false;
00061 }
00062 }
00063 return true;
00064 }
00065
00066
00067
00068
00069
00070
00071
00072 template <typename A, typename AI>
00073 bool
00074 do_is_deterministic(const AutomataBase<A>&,
00075 const Element<A, AI>& input)
00076 {
00077 precondition(is_realtime(input));
00078
00079 typedef Element<A, AI> automaton_t;
00080 AUTOMATON_TYPES(automaton_t);
00081 semiring_elt_t zero_semiring
00082 = input.structure().series().semiring()
00083 .zero(SELECT(typename semiring_elt_t::value_t));
00084
00085
00086 if (input.initial().size() > 1)
00087 return false;
00088
00089 for_all_const_states(i, input)
00090 if (not is_state_deterministic (input, i, zero_semiring))
00091 return false;
00092 return true;
00093 }
00094
00095
00096 template<typename A, typename AI>
00097 bool
00098 is_deterministic(const Element<A, AI>& a)
00099 {
00100 BENCH_TASK_SCOPED("is_deterministic");
00101 return do_is_deterministic(a.structure(), a);
00102 }
00103
00104 }
00105
00106 #endif // ! VCSN_ALGORITHMS_IS_DETERMINISTIC_HXX