Vcsn  2.4
Be Rational
to-spontaneous.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <vcsn/algos/copy.hh>
6 
7 namespace vcsn
8 {
11  template <Automaton Aut>
12  auto
13  to_spontaneous(const Aut& aut)
14  -> std::enable_if_t<!context_t_of<Aut>::is_lao,
16  *aut->weightset())))>
17  {
18  auto res
19  = make_mutable_automaton(make_context(oneset(), *aut->weightset()));
20 
21  using in_state_t = state_t_of<Aut>;
22  using out_state_t = state_t_of<decltype(res)>;
24  using state_map_t = std::unordered_map<in_state_t, out_state_t>;
25  auto out_state = state_map_t{{aut->pre(), res->pre()},
26  {aut->post(), res->post()}};
27  for (auto s: aut->states())
28  out_state[s] = res->new_state();
29 
30  const auto& ils = *aut->labelset();
31  const auto& ols = *res->labelset();
32 
33  for (auto t : all_transitions(aut))
34  res->add_transition(out_state[aut->src_of(t)],
35  out_state[aut->dst_of(t)],
36  ils.is_special(aut->label_of(t))
37  ? ols.special() : ols.one(),
38  aut->weight_of(t));
39  return res;
40  }
41 
45  template <Automaton Aut>
46  auto
47  to_spontaneous(const Aut& aut)
48  -> std::enable_if_t<context_t_of<Aut>::is_lao, decltype(copy(aut))>
49  {
50  return copy(aut);
51  }
52 }
return res
Definition: multiply.hh:398
Implementation of labels are ones: there is a single instance of label.
Definition: oneset.hh:16
auto to_spontaneous(const Aut &aut) -> std::enable_if_t<!context_t_of< Aut >::is_lao, decltype(make_mutable_automaton(make_context(oneset(), *aut->weightset())))>
Convert to spontaneous automaton: change every transition's label to the empty word.
mutable_automaton< Context > make_mutable_automaton(const Context &ctx)
Definition: a-star.hh:8
typename detail::state_t_of_impl< base_t< ValueSet >>::type state_t_of
Definition: traits.hh:64
auto copy(const AutIn &input, KeepState keep_state, KeepTrans keep_trans) -> decltype(keep_state(input->null_state()), keep_trans(input->null_transition()), make_fresh_automaton< AutIn, AutOut >(input))
A copy of input keeping only its states that are accepted by keep_state, and transitions accepted by ...
Definition: copy.hh:322
Ctx make_context(const std::string &name)
Build a context from its name.
Definition: make-context.hh:22
auto all_transitions(const Aut &aut)
All the transition indexes between all states (including pre and post).
Definition: automaton.hh:213