complete.hxx

00001 // complete.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 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_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   | complete_here |
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   | complete |
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   | is_complete |
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 } // vcsn
00105 
00106 #endif // ! VCSN_ALGORITHMS_COMPLETE_HXX

Generated on Fri Jul 28 12:18:30 2006 for Vaucanson by  doxygen 1.4.6