Vcsn  2.3a
Be Rational
lazy-tuple-automaton.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <vcsn/core/automaton.hh>
7 
8 namespace vcsn
9 {
10  namespace detail
11  {
12 
31  template <typename Decorated,
32  bool KeepTransitions,
33  bool Lazy,
34  Automaton Aut, Automaton... Auts>
36  : public automaton_decorator<tuple_automaton<Aut, Auts...>>
37  {
38  public:
39 
41  using tuple_automaton_t = tuple_automaton<Aut, Auts...>;
42  using tuple_automaton_impl = typename tuple_automaton_t::element_type;
45 
46 
47  template <size_t... I>
48  using seq = typename tuple_automaton_impl::template seq<I...>;
49 
52 
54  using decorated_t = Decorated;
55 
57 
58  using super_t::aut_;
59 
60  lazy_tuple_automaton(Aut aut, const Auts&... auts)
61  : super_t{make_tuple_automaton(aut, auts...)}
62  , transition_maps_{transition_map_t<Auts>{auts, ws_}...}
63  {
64  if (Lazy)
65  this->set_lazy(this->pre());
66  }
67 
68  template <typename... T>
69  static symbol sname_(const T&... t)
70  {
71  static auto res = symbol{tuple_automaton_impl::sname_(t...)};
72  return res;
73  }
74 
75 
77  auto origins() const
78  -> decltype(aut_->origins())
79  {
80  return aut_->origins();
81  }
82 
84  void complete_(state_t s) const
85  {
86  const auto& orig = origins();
87  state_name_t sn = orig.at(s);
88  auto& self = static_cast<decorated_t&>(const_cast<self_t&>(*this));
89  if (Lazy)
90  self.set_lazy(s, false);
91  self.add_transitions(s, sn);
92  }
93 
95  auto all_out(state_t s) const
96  -> decltype(all_out(aut_, s))
97  {
98  if (this->is_lazy(s))
99  complete_(s);
100  return vcsn::detail::all_out(aut_, s);
101  }
102 
103  protected:
104 
107  template <Automaton A>
109  false, true,
110  KeepTransitions>;
111 
113  template <typename... Args>
114  state_t state(Args&&... args)
115  {
116  return aut_->template state<Lazy>(std::forward<Args>(args)...);
117  }
118 
120  std::tuple<typename transition_map_t<Auts>::map_t&...>
121  out_(const state_name_t& ss)
122  {
123  return out_(ss, aut_->indices);
124  }
125 
126  template <size_t... I>
127  std::tuple<typename transition_map_t<Auts>::map_t&...>
129  {
130  return std::tie(std::get<I>(transition_maps_)[std::get<I>(ss)]...);
131  }
132 
133 
135  const weightset_t& ws_ = *aut_->weightset();
136 
138  std::tuple<transition_map_t<Auts>...> transition_maps_;
139  };
140  }
141 }
auto origins() const -> decltype(aut_->origins())
A map from result state to tuple of original states.
Decorator implementing the laziness for an algorithm.
static constexpr auto pre(Args &&...args) -> decltype(element_type::pre(std::forward< Args >(args)...))
auto all_out(const Aut &aut, state_t_of< Aut > s)
Indexes of transitions leaving state s.
Definition: automaton.hh:65
static symbol sname_(const T &...t)
Definition: a-star.hh:8
return res
Definition: multiply.hh:398
std::tuple< typename transition_map_t< Auts >::map_t &... > out_(const state_name_t &ss)
The outgoing tuple of transitions from state tuple ss.
Aggregate an automaton, and forward calls to it.
static std::string sname_(const T &...t)
The sname of the sub automata.
std::tuple< typename transition_map_t< Auts >::map_t &... > out_(const state_name_t &ss, seq< I... >)
boost::flyweight< std::string, boost::flyweights::no_tracking, boost::flyweights::intermodule_holder > symbol
An internalized string.
Definition: symbol.hh:23
const weightset_t & ws_
The resulting weightset.
auto is_lazy(Args &&...args) const -> decltype(aut_-> is_lazy(std::forward< Args >(args)...))
void complete_(state_t s) const
Complete a state: find its outgoing transitions.
std::shared_ptr< detail::tuple_automaton_impl< Auts... >> tuple_automaton
A tuple automaton as a shared pointer.
state_t state(Args &&...args)
Conversion from state name to state number.
typename detail::weightset_t_of_impl< base_t< ValueSet >>::type weightset_t_of
Definition: traits.hh:67
Cache the outgoing transitions of an automaton as efficient maps label -> vector<(weight, dst)>.
std::tuple< transition_map_t< Auts >... > transition_maps_
Transition caches.
transition_map< A, weightset_t, false, true, KeepTransitions > transition_map_t
The type of our transition maps: convert the weight to weightset_t, non deterministic, and including transitions to post().
typename super_t::state_t state_t
Result state type.
lazy_tuple_automaton(Aut aut, const Auts &...auts)
std::tuple< state_t_of< Auts >... > state_name_t
State names: Tuple of states of input automata.
tuple_automaton< Aut, Auts... > tuple_automaton_t
The underlying automaton, output and inputs.
automaton_t aut_
The wrapped automaton, possibly const.
#define Automaton
Definition: automaton.hh:23
auto set_lazy(Args &&...args) -> decltype(aut_-> set_lazy(std::forward< Args >(args)...))
auto make_tuple_automaton(const Auts &...auts) -> tuple_automaton< Auts... >
Build the (accessible part of the) product.
Definition: conjunction.hh:37
auto all_out(state_t s) const -> decltype(all_out(aut_, s))
All the outgoing transitions.