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

- File List
- File Members

# domain.hxx

    00001 // domain.hxx: this file is part of the Vaucanson project.
    00002 //
    00003 // Vaucanson, a generic library for finite state machines.
    00004 //
    00005 // Copyright (C) 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_DOMAIN_HXX
    00018 # define VCSN_ALGORITHMS_DOMAIN_HXX
    00019
    00020 # include <vaucanson/algorithms/domain.hh>
    00021
    00022 namespace vcsn
    00023 {
    00024
    00025   /*-----------.
    00026   | FMP_Domain |
    00027   `-----------*/
    00028
    00029   template <typename src_t, typename dst_t>
    00030   void
    00031   do_fmp_domain(const src_t& src, dst_t& dst)
    00032   {
    00033     BENCH_TASK_SCOPED("fmp_domain");
    00034     AUTOMATON_TYPES_(src_t, trans_);
    00035     AUTOMATON_TYPES(dst_t);
    00036
    00037     typedef typename trans_series_set_elt_t::support_t  trans_support_t;
    00038     std::map<trans_hstate_t, hstate_t>  stmap;
    00039
    00040     const series_set_t&         series = dst.structure().series();
    00041     const monoid_t&             monoid = dst.structure().series().monoid();
    00042     const trans_monoid_t&       trans_monoid =
    00043       src.structure().series().monoid();
    00044
    00045    for_all_const_states(fmp_s, src)
    00046     {
    00047       hstate_t s = dst.add_state();
    00048       stmap[*fmp_s] = s;
    00049
    00050       if (src.is_initial(*fmp_s))
    00051       {
    00052       const trans_series_set_elt_t      trans_series_elt =
    00053         src.get_initial(*fmp_s);
    00054       trans_support_t                   trans_supp = trans_series_elt.supp();
    00055         const trans_monoid_elt_t        trans_monoid_elt
    00056              (trans_monoid, *(trans_supp.begin()));
    00057
    00058         const monoid_elt_value_t        word(trans_monoid_elt.value().first);
    00059
    00060         series_set_elt_t                series_elt(series);
    00061
    00062         series_elt.assoc(monoid_elt_t(monoid, word),
    00063                        trans_series_elt.get(trans_monoid_elt));
    00064
    00065             dst.set_initial(s, series_elt);
    00066       }
    00067       if (src.is_final(*fmp_s))
    00068       {
    00069       const trans_series_set_elt_t      trans_series_elt =
    00070         src.get_final(*fmp_s);
    00071       trans_support_t                   trans_supp = trans_series_elt.supp();
    00072         const trans_monoid_elt_t        trans_monoid_elt
    00073              (trans_monoid, *(trans_supp.begin()));
    00074
    00075         const monoid_elt_value_t        word(trans_monoid_elt.value().first);
    00076
    00077         series_set_elt_t                series_elt(series);
    00078
    00079         series_elt.assoc(monoid_elt_t(monoid, word),
    00080                        trans_series_elt.get(trans_monoid_elt));
    00081
    00082             dst.set_final(s, series_elt);
    00083       }
    00084     }
    00085
    00086     for_all_const_transitions_(trans_, fmp_e, src)
    00087     {
    00088       const trans_series_set_elt_t      trans_series_elt =
    00089         src.series_of(*fmp_e);
    00090       trans_support_t                   trans_supp = trans_series_elt.supp();
    00091       const trans_monoid_elt_t  trans_monoid_elt
    00092         (trans_monoid, *(trans_supp.begin()));
    00093       const monoid_elt_value_t  word(trans_monoid_elt.value().first);
    00094
    00095       series_set_elt_t          series_elt(series);
    00096
    00097       series_elt.assoc(monoid_elt_t(monoid, word),
    00098                        trans_series_elt.get(trans_monoid_elt));
    00099
    00100       dst.add_series_transition(stmap[src.src_of(*fmp_e)],
    00101                                 stmap[src.dst_of(*fmp_e)], series_elt);
    00102     }
    00103   }
    00104
    00105 // FIXME: non void version
    00106
    00107
    00108   /*----------.
    00109   | RW_Domain |
    00110   `----------*/
    00111
    00112   template <typename src_t, typename dst_t>
    00113   void
    00114   do_rw_domain(const src_t& src, dst_t& dst)
    00115   {
    00116     BENCH_TASK_SCOPED("rw_domain");
    00117     std::map<typename src_t::hstate_t, typename dst_t::hstate_t> m;
    00118     AUTOMATON_TYPES(src_t);
    00119
    00120     for_all_const_states(p, src)
    00121     {
    00122       m[*p] = dst.add_state();
    00123     }
    00124
    00125     for_all_const_initial_states(p, src)
    00126       dst.set_initial(m[*p]);
    00127
    00128     for_all_const_final_states(p, src)
    00129       dst.set_final(m[*p]);
    00130
    00131     for_all_const_transitions(e, src)
    00132     {
    00133       dst.add_series_transition(m[src.src_of(*e)],
    00134                                 m[src.dst_of(*e)],
    00135                                 src.input_of(*e));
    00136     }
    00137   }
    00138
    00139 // FIXME: non void version
    00140
    00141
    00142   /*-----------------.
    00143   | Dispatch methods |
    00144   `-----------------*/
    00145
    00146   template <typename S, typename S2, typename T, typename T2>
    00147   void
    00148   domain_dispatch(const AutomataBase<S>&, const Element<S,T>& src, Element<S2, T2>& dst)
    00149   {
    00150     do_fmp_domain(src, dst);
    00151   }
    00152
    00153   template <typename S, typename S2, typename T, typename T2>
    00154   void
    00155   domain_dispatch(const TransducerBase<S>&, const Element<S,T>& src, Element<S2, T2>& dst)
    00156   {
    00157     do_rw_domain(src, dst);
    00158   }
    00159
    00160   template <typename S, typename S2, typename T, typename T2>
    00161   void
    00162   domain(const Element<S,T>& src, Element<S2, T2>& dst)
    00163   {
    00164     domain_dispatch(src.structure(), src, dst);
    00165   }
    00166
    00167 } // End of namespace vcsn.
    00168
    00169 #endif // ! VCSN_ALGORITHMS_DOMAIN_HXX