Vcsn  2.2
Be Rational
to-spontaneous.hh
Go to the documentation of this file.
1 #pragma once
2 
4 #include <vcsn/algos/copy.hh>
5 
6 namespace vcsn
7 {
12  template <Automaton Aut>
13  auto
14  to_spontaneous(const Aut& aut)
15  -> std::enable_if_t<!context_t_of<Aut>::is_lao,
17  *aut->weightset())))>
18  {
19  auto res = 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  state_map_t out_state_{{aut->pre(), res->pre()},
26  {aut->post(), res->post()}};
27  for (auto s: aut->states())
28  out_state_[s] = res->new_state();
29 
30  for (auto t : all_transitions(aut))
31  {
32  auto src = out_state_.find(aut->src_of(t));
33  auto dst = out_state_.find(aut->dst_of(t));
34  if (src != out_state_.end() && dst != out_state_.end())
35  {
36  if (src->second == res->pre() || dst->second == res->post())
37  res->new_transition(src->second, dst->second,
38  res->labelset()->special(), aut->weight_of(t));
39  else
40  res->new_transition(src->second, dst->second,
41  res->labelset()->one(), aut->weight_of(t));
42  }
43  }
44  return res;
45  }
46 
50  template <Automaton Aut>
51  auto
52  to_spontaneous(const Aut& aut)
53  -> std::enable_if_t<context_t_of<Aut>::is_lao, decltype(copy(aut))>
54  {
55  return copy(aut);
56  }
57 }
Definition: a-star.hh:8
typename detail::state_t_of_impl< base_t< ValueSet >>::type state_t_of
Definition: traits.hh:56
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())))>
to_spontaneous
Implementation of labels are ones: there is a single instance of label.
Definition: oneset.hh:16
mutable_automaton< Context > make_mutable_automaton(const Context &ctx)
auto all_transitions(const Aut &aut)
All the transition indexes between all states (including pre and post).
Definition: automaton.hh:184
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:308
Ctx make_context(const std::string &name)
Definition: make-context.hh:21