- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

# is_deterministic.hxx

    00001 // is_deterministic.hxx: this file is part of the Vaucanson project.
    00002 //
    00003 // Vaucanson, a generic library for finite state machines.
    00004 //
    00005 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 The Vaucanson Group.
    00006 //
    00007 // This program is free software; you can redistribute it and/or
    00008 // modify it under the terms of the GNU General Public License
    00009 // as published by the Free Software Foundation; either version 2
    00010 // of the License, or (at your option) any later version.
    00011 //
    00012 // The complete GNU General Public Licence Notice can be found as the
    00013 // `COPYING' file in the root directory.
    00014 //
    00015 // The Vaucanson Group consists of people listed in the `AUTHORS' file.
    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   | is_state_deterministic.  |
    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::set<htransition_t>            delta_ret_t;
    00043     delta_ret_t delta_ret;
    00044
    00045     input.deltac(delta_ret, *current_state, delta_kind::transitions());
    00046     // FIXME : O(n^2) => O(nlog(n)) There is maybe an algorithm in O(nlog(n))
    00047     for_all_const_(delta_ret_t, j, delta_ret)
    00048     {
    00049       series_set_elt_t s = input.series_of(*j);
    00050       typename delta_ret_t::const_iterator k = j;
    00051       ++k;
    00052       for (; k != delta_ret.end(); ++k)
    00053       {
    00054         series_set_elt_t s_ = input.series_of(*k);
    00055         for_all_(support_t, supp, s.supp())
    00056           if (s_.get(*supp) != zero_semiring)
    00057             return false;
    00058       }
    00059     }
    00060     return true;
    00061   }
    00062
    00063
    00064
    00065
    00066   /*-------------------.
    00067   | is_deterministic.  |
    00068   `-------------------*/
    00069   template <typename A, typename input_t>
    00070   bool
    00071   do_is_deterministic(const AutomataBase<A>&    ,
    00072                       const input_t&            input)
    00073   {
    00074     precondition(is_realtime(input));
    00075
    00076     AUTOMATON_TYPES(input_t);
    00077     semiring_elt_t                zero_semiring
    00078       = input.structure().series().semiring()
    00079       .zero(SELECT(typename semiring_elt_t::value_t));
    00080
    00081     // Empty automaton is not deterministic
    00082     if (input.states().size() == 0)
    00083       return false;
    00084
    00085     if (input.initial().size() != 1)
    00086       return false;
    00087
    00088     for_all_states(i, input)
    00089       if (not is_state_deterministic (input, i, zero_semiring))
    00090         return false;
    00091     return true;
    00092   }
    00093
    00094
    00095   template<typename A, typename T>
    00096   bool
    00097   is_deterministic(const Element<A, T>& a)
    00098   {
    00099     TIMER_SCOPED("is_deterministic");
    00100     return do_is_deterministic(a.structure(), a);
    00101   }
    00102
    00103 } // vcsn
    00104
    00105 #endif // ! VCSN_ALGORITHMS_IS_DETERMINISTIC_HXX