trim.hxx

00001 // trim.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, 2006 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_TRIM_HXX
00018 # define VCSN_ALGORITHMS_TRIM_HXX
00019 
00020 # include <vaucanson/algorithms/trim.hh>
00021 
00022 # include <vaucanson/automata/concept/automata_base.hh>
00023 
00024 # include <vaucanson/algorithms/sub_automaton.hh>
00025 # include <vaucanson/algorithms/accessible.hh>
00026 
00027 # include <algorithm>
00028 
00029 namespace vcsn {
00030 
00031   /*---------------------.
00032   | do_start_trim_states |
00033   `---------------------*/
00034   // preconditions :
00035   //
00036   //
00037   template <class A_, typename Auto_>
00038   std::set<hstate_t>
00039   do_useful_states(const AutomataBase<A_>&,
00040                    const Auto_&            a)
00041   {
00042     std::set<hstate_t> start = accessible_states(a);
00043     std::set<hstate_t> final = coaccessible_states(a);
00044     std::set<hstate_t> result;
00045     std::insert_iterator<std::set<hstate_t> > i(result, result.begin());
00046 
00047     set_intersection(start.begin(), start.end(), final.begin(), final.end(), i);
00048     return result;
00049   }
00050 
00051   template<typename A, typename T>
00052   std::set<hstate_t>
00053   useful_states(const Element<A, T>& a)
00054   {
00055     return do_useful_states(a.structure(), a);
00056   }
00057 
00058   template<typename A, typename T>
00059   Element<A, T>
00060   trim(const Element<A, T>& a)
00061   {
00062     return sub_automaton(a, useful_states(a));
00063   }
00064 
00065   template<typename A, typename T>
00066   void
00067   trim_here(Element<A, T>& a)
00068   {
00069     sub_automaton_here(a, useful_states(a));
00070   }
00071 
00072 } // vcsn
00073 
00074 #endif // ! VCSN_ALGORITHMS_TRIM_HXX

Generated on Sat Jul 29 17:13:13 2006 for Vaucanson by  doxygen 1.4.6