Awali
Another Weighted Automata library
eval_tdc.hh
Go to the documentation of this file.
1 // This file is part of Awali.
2 // Copyright 2016-2022 Sylvain Lombardy, Victor Marsault, Jacques Sakarovitch
3 //
4 // Awali is a free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef AWALI_ALGOS_EVAL_TDC_HH
18 #define AWALI_ALGOS_EVAL_TDC_HH
19 
20 #include <awali/sttc/ctx/traits.hh>
22 #include <awali/sttc/algos/eval.hh>
24 
25 namespace awali {
26  namespace sttc {
27 
28  /* @brief evaluation of a pair of words in a transducer
29  *
30  * The transducer should have at least two tapes.
31  * The words are evaluated on the first two tapes.
32  * @tparam Tdc the type of the transducer
33  * @param tdc the transducer
34  * @param w1 the first word
35  * @param w2 the second word
36  * @return the evaluation of the pair (\p w1,\p w2) in \p tdc
37  */
38  template <typename Tdc>
39  inline
40  auto
41  eval_words_in_tdc(const Tdc& tdc,
45  {
46  using tdc_context_t = context_t_of<Tdc>;
47  using tdc_labelset_t = labelset_t_of<tdc_context_t>;
48  using weightset_t = weightset_t_of<tdc_context_t>;
49  using labelset1_t = typename internal::select<tdc_labelset_t,0>::labelset_t;
50  using aut_context1_t = context<labelset1_t, weightset_t>;
51  auto tdc_labelset = tdc->labelset();
52  auto weightset = tdc->weightset();
53  auto labelset1 = internal::select<tdc_labelset_t,0>::get(*tdc_labelset);
54  aut_context1_t aut_context1{labelset1, *weightset};
55  auto aut1 = make_mutable_automaton(aut_context1);
56  state_t p = aut1->add_state();
57  aut1->set_initial(p);
58  for(auto l : w1) {
59  state_t q = aut1->add_state();
60  aut1->new_transition(p,q,l);
61  p=q;
62  }
63  aut1->set_final(p);
64  auto aut2 = to_lal(eval_tdc(aut1, tdc));
65  auto w = eval(aut2, w2);
66  return w;
67  }
68 
69  }
70 }//end of ns awali::stc
71 
72 #endif // !AWALI_ALGOS_EVAL_TDC_HH
carries the algebraic settings of automata
Definition: context.hh:40
const labelset_ptr & labelset() const
Definition: context.hh:152
The semiring of rational numbers.
Definition: q.hh:42
weightset_description weightset(const std::string &k)
any_t word_t
Type for words; it is an alias to any_t since the precise type depends on the context (most of the ti...
Definition: typedefs.hh:67
auto eval(const Aut &a, const typename labelset_trait< labelset_t_of< Aut >>::wordset_t::word_t &w, bool check_alphabet=true) -> weight_t_of< Aut >
Definition: eval.hh:112
typename internal::weight_t_of_impl< internal::base_t< ValueSet > >::type weight_t_of
Helper to retrieve the type of the weights of a value set.
Definition: traits.hh:81
typename internal::context_t_of_impl< internal::base_t< ValueSet > >::type context_t_of
Helper to retrieve the type of the context of a value set.
Definition: traits.hh:66
typename internal::labelset_t_of_impl< internal::base_t< ValueSet > >::type labelset_t_of
Helper to retrieve the type of the labelset of a value set.
Definition: traits.hh:76
auto to_lal(const Aut &aut, direction_t dir=BACKWARD, bool prune=true, bool keep_history=true) -> typename internal::dispatch_lal_lan< Aut, labelset_t_of< Aut >>::l_automaton_t
Definition: lal_lan_conversion.hh:87
mutable_automaton< Context > make_mutable_automaton(const Context &ctx)
Definition: mutable_automaton.hh:915
auto eval_tdc(const Aut &aut, const Tdc &tdc, bool keep_history=true) -> decltype(projection< 1 >(tdc))
Evaluation of an automaton by a transducer.
Definition: compose.hh:305
typename internal::weightset_t_of_impl< internal::base_t< ValueSet > >::type weightset_t_of
Helper to retrieve the type of the weightset of a value set.
Definition: traits.hh:86
auto eval_words_in_tdc(const Tdc &tdc, const typename internal::select< labelset_t_of< Tdc >, 0 >::labelset_t::word_t &w1, const typename internal::select< labelset_t_of< Tdc >, 1 >::labelset_t::word_t &w2) -> weight_t_of< Tdc >
Definition: eval_tdc.hh:41
Main namespace of Awali.
Definition: ato.hh:22
unsigned state_t
Definition: types.hh:21
Definition: reduce.hh:103