ltl_to_pair.hxx

00001 // ltl_to_pair.hxx: this file is part of the Vaucanson project.
00002 //
00003 // Vaucanson, a generic library for finite state machines.
00004 //
00005 // Copyright (C) 2008 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_LTL_TO_PAIR_HXX
00018 # define VCSN_ALGORITHMS_LTL_TO_PAIR_HXX
00019 
00020 # include <vaucanson/algorithms/ltl_to_pair.hh>
00021 
00022 namespace vcsn
00023 {
00024 // Helper to write lighter code.
00025 # define MUTE_TRAITS mute_ltl_to_pair<S, T>
00026 
00027   template <typename S, typename T>
00028   inline typename MUTE_TRAITS::ret_alphabet_t
00029   MUTE_TRAITS::
00030   cartesian_product(const typename MUTE_TRAITS::first_alphabet_t& A,
00031                     const typename MUTE_TRAITS::second_alphabet_t& B)
00032   {
00033     ret_alphabet_t E;
00034 
00035     for_all_const_(first_alphabet_t, i, A)
00036     {
00037       for_all_const_(second_alphabet_t, j, B)
00038       {
00039         E.insert(std::make_pair(*i, *j));
00040       }
00041     }
00042 
00043     return E;
00044   }
00045 
00046   template <typename S, typename T>
00047   inline typename MUTE_TRAITS::ret
00048   MUTE_TRAITS::
00049   make_automaton(const typename MUTE_TRAITS::ret_alphabet_t& A)
00050   {
00051     semiring_t semiring;
00052     ret_monoid_t freemonoid(A);
00053     typename ret::series_set_t series(semiring, freemonoid);
00054 
00055     return ret(Automata<typename ret::series_set_t>(series));
00056   }
00057 
00058   template <typename S, typename T>
00059   inline typename MUTE_TRAITS::ret
00060   MUTE_TRAITS::
00061   make_automaton(const Element<S, T>& A)
00062   {
00063     ret_alphabet_t E = cartesian_product(A.structure().series().monoid().
00064                                          first_monoid().alphabet(),
00065                                          A.structure().series().monoid().
00066                                          second_monoid().alphabet());
00067 
00068     return make_automaton(E);
00069   }
00070 
00071   template <typename S, typename T>
00072   inline typename MUTE_TRAITS::ret::series_set_elt_t
00073   MUTE_TRAITS::
00074   series_convert(const typename MUTE_TRAITS::ret_series_set_t& series,
00075                  const typename MUTE_TRAITS::automaton_t::
00076                  series_set_elt_t& ss)
00077   {
00078     typename ret::series_set_elt_t R(series);
00079 
00080     // We assume that the src automaton is sub-normalized.
00081     std::basic_string<ret_letter_t> m;
00082     if (!(*(ss.supp().begin())).first.empty())
00083       m += std::make_pair(((*(ss.supp().begin())).first)[0],
00084                           ((*(ss.supp().begin())).second)[0]);
00085     R.assoc(m, ss.get(*(ss.supp().begin())));
00086 
00087     return R;
00088   }
00089 
00090   template <typename S, typename T>
00091   void
00092   do_ltl_to_pair(const Element<S, T>& src,
00093                  typename MUTE_TRAITS::ret& res)
00094   {
00095     TIMER_SCOPED("ltl_to_pair");
00096 
00097     // The input FMP automaton must be sub-normalized.
00098     // FIXME: is_letterized_transducer ?
00099     precondition(is_sub_normalized(src));
00100 
00101     // Type helpers.
00102     typedef typename MUTE_TRAITS::automaton_t automaton_t;
00103     typedef MUTE_TRAITS pair_automaton_traits_t;
00104     typedef typename pair_automaton_traits_t::ret res_t;
00105     AUTOMATON_TYPES(automaton_t);
00106     AUTOMATON_TYPES_(res_t, res_);
00107 
00108     // Helper map.
00109     std::map<hstate_t, res_hstate_t> m;
00110 
00111     for_all_const_states(p, src)
00112       m[*p] = res.add_state();
00113 
00114 
00115     // Setup initial transitions.
00116     for_all_const_initial_states(i, src)
00117     {
00118       res.set_initial(m[*i],
00119                       pair_automaton_traits_t::
00120                       series_convert(res.structure().series(),
00121                                      src.get_initial(*i)));
00122     }
00123 
00124     // Setup normal transitions.
00125     for_all_const_transitions(e, src)
00126     {
00127       res.add_series_transition(m[src.src_of(*e)],
00128                                 m[src.dst_of(*e)],
00129                                 pair_automaton_traits_t::
00130                                 series_convert(res.structure().series(),
00131                                                src.series_of(*e)));
00132     }
00133 
00134     // Setup final transitions.
00135     for_all_const_final_states(f, src)
00136     {
00137       res.set_final(m[*f],
00138                     pair_automaton_traits_t::
00139                     series_convert(res.structure().series(),
00140                                    src.get_final(*f)));
00141     }
00142   }
00143 
00144   //
00145   // Facade Functions
00146   //
00147 
00148   template <typename S, typename T>
00149   void
00150   ltl_to_pair(const Element<S, T>& ltl,
00151               typename MUTE_TRAITS::ret& res)
00152   {
00153     do_ltl_to_pair(ltl, res);
00154   }
00155 
00156   template <typename S, typename T>
00157   typename MUTE_TRAITS::ret
00158   ltl_to_pair(const Element<S, T>& ltl)
00159   {
00160     typename MUTE_TRAITS::ret res = MUTE_TRAITS::make_automaton(ltl);
00161 
00162     do_ltl_to_pair(ltl, res);
00163 
00164     return res;
00165   }
00166 
00167 # undef MUTE_TRAITS
00168 
00169 } // ! vcsn
00170 
00171 #endif // ! VCSN_ALGORITHMS_LTL_TO_PAIR_HXX

Generated on Thu Oct 9 20:22:40 2008 for Vaucanson by  doxygen 1.5.1