Vcsn  2.2
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  typename Aut, typename... Auts>
36  : public automaton_decorator<tuple_automaton<Aut, Auts...>>
37  {
38  public:
39 
41  using tuple_automaton_t = tuple_automaton<Aut, Auts...>;
42  using state_name_t
43  = typename tuple_automaton_t::element_type::state_name_t;
44  using state_t
45  = typename tuple_automaton_t::element_type::state_t;
46 
47 
48  template <size_t... I>
49  using seq
50  = typename tuple_automaton_t::element_type::template seq<I...>;
51 
54 
56  using decorated_t = Decorated;
57 
59 
60  using super_t::aut_;
61 
62  lazy_tuple_automaton(Aut aut, const Auts&... auts)
63  : super_t{make_tuple_automaton(aut, auts...)}
64  , transition_maps_{{auts, ws_}...}
65  {
66  if (Lazy)
67  this->set_lazy(this->pre());
68  }
69 
70  template <typename... T>
71  static symbol sname_(const T&... t)
72  {
73  static symbol res(tuple_automaton_t::element_type::sname_(t...));
74  return res;
75  }
76 
77 
79  auto origins() const
80  -> decltype(aut_->origins())
81  {
82  return aut_->origins();
83  }
84 
86  template <bool L = Lazy>
87  std::enable_if_t<L, void> complete_(state_t s) const
88  {
89  const auto& orig = origins();
90  state_name_t sn = orig.at(s);
91  auto& self = static_cast<decorated_t&>(const_cast<self_t&>(*this));
92  self.set_lazy(s, false);
93  self.add_transitions(s, sn);
94  }
95 
96  template <bool L = Lazy>
97  std::enable_if_t<!L, void> complete_(state_t s) const
98  {
99  const auto& orig = origins();
100  state_name_t sn = orig.at(s);
101  static_cast<decorated_t&>(const_cast<self_t&>(*this)).add_transitions(s, sn);
102  }
103 
104 
106  auto all_out(state_t s) const
107  -> decltype(all_out(aut_, s))
108  {
109  if (this->is_lazy(s))
110  complete_(s);
111  return vcsn::detail::all_out(aut_, s);
112  }
113 
114  protected:
115 
118  template <typename A>
120  false, true,
121  KeepTransitions>;
122 
123 
125  template <typename... Args>
126  state_t state(Args&&... args)
127  {
128  return aut_->template state<Lazy>(std::forward<Args>(args)...);
129  }
130 
132  std::tuple<typename transition_map_t<Auts>::map_t&...>
133  out_(const state_name_t& ss)
134  {
135  return out_(ss, aut_->indices);
136  }
137 
138  template <size_t... I>
139  std::tuple<typename transition_map_t<Auts>::map_t&...>
141  {
142  return std::tie(std::get<I>(transition_maps_)[std::get<I>(ss)]...);
143  }
144 
145 
147  const weightset_t& ws_ = *aut_->weightset();
148 
150  std::tuple<transition_map_t<Auts>...> transition_maps_;
151  };
152  }
153 }
auto all_out(const Aut &aut, state_t_of< Aut > s)
Indexes of transitions leaving state s.
Definition: automaton.hh:37
Decorator implementing the laziness for an algorithm.
std::tuple< typename transition_map_t< Auts >::map_t &... > out_(const state_name_t &ss, seq< I... >)
typename detail::weightset_t_of_impl< base_t< ValueSet >>::type weightset_t_of
Definition: traits.hh:59
auto origins() const -> decltype(aut_->origins())
A map from result state to tuple of original states.
auto make_tuple_automaton(const Auts &...auts) -> tuple_automaton< Auts... >
Definition: a-star.hh:8
static constexpr auto pre(Args &&...args) -> decltype(element_type::pre(std::forward< Args >(args)...))
state_t state(Args &&...args)
Conversion from state name to state number.
auto all_out(state_t s) const -> decltype(all_out(aut_, s))
All the outgoing transitions.
std::tuple< typename transition_map_t< Auts >::map_t &... > out_(const state_name_t &ss)
The outgoing tuple of transitions from state tuple ss.
automaton_t aut_
The wrapped automaton, possibly const.
Cache the outgoing transitions of an automaton as efficient maps label -> vector<(weight, dst)>.
std::enable_if_t<!L, void > complete_(state_t s) const
std::enable_if_t< L, void > complete_(state_t s) const
Complete a state: find its outgoing transitions.
lazy_tuple_automaton(Aut aut, const Auts &...auts)
std::shared_ptr< detail::tuple_automaton_impl< Auts... >> tuple_automaton
A tuple automaton as a shared pointer.
auto is_lazy(Args &&...args) const -> decltype(aut_-> is_lazy(std::forward< Args >(args)...))
boost::flyweight< std::string, boost::flyweights::no_tracking, boost::flyweights::intermodule_holder > symbol
An internalized string.
Definition: symbol.hh:23
Build the (accessible part of the) product.
Definition: conjunction.hh:31
Aggregate an automaton, and forward calls to it.
std::tuple< transition_map_t< Auts >... > transition_maps_
Transition caches.
static symbol sname_(const T &...t)
tuple_automaton< Aut, Auts... > tuple_automaton_t
The underlying automaton, output and inputs.
auto set_lazy(Args &&...args) -> decltype(aut_-> set_lazy(std::forward< Args >(args)...))
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().
const weightset_t & ws_
The resulting weightset.