Vcsn  2.0
Be Rational
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
transpose.hh
Go to the documentation of this file.
1 #ifndef VCSN_ALGOS_TRANSPOSE_HH
2 # define VCSN_ALGOS_TRANSPOSE_HH
3 
4 # include <vcsn/algos/fwd.hh>
5 # include <vcsn/algos/strip.hh>
7 # include <vcsn/core/rat/ratexp.hh>
9 # include <vcsn/ctx/context.hh>
10 # include <vcsn/dyn/automaton.hh>
11 # include <vcsn/misc/attributes.hh>
12 
13 namespace vcsn
14 {
15 
16  /*-----------------------.
17  | transpose(automaton). |
18  `-----------------------*/
19  namespace detail
20  {
22  template <typename Aut>
23  class transpose_automaton_impl : public automaton_decorator<Aut>
24  {
25  public:
27  using automaton_t = Aut;
28 
32  using automaton_nocv_t
33  = transpose_automaton<typename
34  automaton_t::element_type::automaton_nocv_t>;
35 
42 
45  using kind_t = typename automaton_t::element_type::kind_t;
46 
47  using super_t::super_t;
48  using super_t::aut_;
49 
50  static std::string sname()
51  {
52  return "transpose_automaton<" + automaton_t::element_type::sname() + ">";
53  }
54 
55  std::string vname(bool full = true) const
56  {
57  return "transpose_automaton<" + aut_->vname(full) + ">";
58  }
59 
63  {
64  return aut_;
65  }
66 
67  auto
69  -> decltype(transpose(vcsn::strip(this->naked_automaton())))
70  {
71  return transpose(vcsn::strip(this->naked_automaton()));
72  }
73 
74 
75  /*-------------------------------.
76  | const methods that transpose. |
77  `-------------------------------*/
78 # define DEFINE(Signature, Value) \
79  auto \
80  Signature const \
81  -> decltype(aut_->Value) \
82  { \
83  return aut_->Value; \
84  }
85 
87  template <typename Pred>
88  DEFINE(all_in(state_t s, Pred pred), all_out(s, pred));
90  template <typename Pred>
91  DEFINE(all_out(state_t s, Pred pred), all_in(s, pred));
92 
95  DEFINE(in(state_t s), out(s));
100  DEFINE(out(state_t s), in(s));
104 
105  DEFINE(in(state_t s, label_t l),
106  out(s, aut_->labelset()->transpose(l)));
107  DEFINE(out(state_t s, label_t l),
108  in(s, aut_->labelset()->transpose(l)));
110  get_transition(d, s, aut_->labelset()->transpose(l)));
112  has_transition(d, s, aut_->labelset()->transpose(l)));
114  labelset()->transpose(aut_->label_of(t)));
115 
116  ATTRIBUTE_PURE
118  weightset()->transpose(aut_->get_final_weight(s)));
119 
120  ATTRIBUTE_PURE
122  weightset()->transpose(aut_->get_initial_weight(s)));
123 
124  ATTRIBUTE_PURE
126  weightset()->transpose(aut_->weight_of(t)));
127 
128 # undef DEFINE
129 
130 
131  /*-----------------------------------.
132  | non-const methods that transpose. |
133  `-----------------------------------*/
134 
135 # define DEFINE(Signature, Value) \
136  auto \
137  Signature \
138  -> decltype(aut_->Value) \
139  { \
140  return aut_->Value; \
141  }
142 
147 
149  set_weight(t, aut_->weightset()->transpose(k)));
151  add_weight(t, aut_->weightset()->transpose(k)));
153  lmul_weight(t, aut_->weightset()->transpose(k)));
155  rmul_weight(t, aut_->weightset()->transpose(k)));
156 
159  del_transition(d, s, aut_->labelset()->transpose(l)));
160 
162  add_transition(d, s,
163  aut_->labelset()->transpose(l),
164  aut_->weightset()->transpose(k)));
166  add_transition(d, s, aut_->labelset()->transpose(l)));
167 
169  new_transition(d, s,
170  aut_->labelset()->transpose(l),
171  aut_->weightset()->transpose(k)));
173  new_transition(d, s,
174  aut_->labelset()->transpose(l)));
175 
177  set_transition(d, s,
178  aut_->labelset()->transpose(l),
179  aut_->weightset()->transpose(k)));
181  set_final(s, aut_->weightset()->transpose(k)));
183  set_initial(s, aut_->weightset()->transpose(k)));
185  add_final(s, aut_->weightset()->transpose(k)));
187  add_initial(s, aut_->weightset()->transpose(k)));
188 
189  template <typename A>
191  const A& aut,
192  typename A::element_type::transition_t t,
193  bool transpose = false),
194  add_transition_copy(dst, src, aut, t, !transpose));
195 
196  template <typename A>
198  const A& aut,
199  typename A::element_type::transition_t t,
200  bool transpose = false),
201  new_transition_copy(dst, src, aut, t, !transpose));
202 
203 # undef DEFINE
204 
205 
206 
207  /*-----------------------------------.
208  | constexpr methods that transpose. |
209  `-----------------------------------*/
210 
211 # define DEFINE(Signature, Value) \
212  static constexpr \
213  auto \
214  Signature \
215  -> decltype(automaton_t::element_type::Value) \
216  { \
217  return automaton_t::element_type::Value; \
218  }
219 
220  DEFINE(post(), pre());
221  DEFINE(pre(), post());
222 
223 #undef DEFINE
224  };
225  }
226 
227  template <typename Aut>
228  inline
229  Aut
231  {
232  return aut->naked_automaton();
233  }
234 
235  template <typename Aut>
236  inline
237  transpose_automaton<Aut>
238  transpose(Aut aut)
239  {
240  return make_shared_ptr<transpose_automaton<Aut>>(aut);
241  }
242 
243  namespace dyn
244  {
245  namespace detail
246  {
248  template <typename Aut>
249  automaton
251  {
252  auto& a = aut->as<Aut>();
253  return make_automaton(vcsn::transpose(a));
254  }
255 
257  (automaton& aut) -> automaton);
258  }
259  }
260 
261 
262  /*-------------------------.
263  | dyn::transpose(ratexp). |
264  `-------------------------*/
265  namespace dyn
266  {
267  namespace detail
268  {
270  template <typename RatExpSet>
271  ratexp
273  {
274  const auto& e = exp->as<RatExpSet>();
275 
276  return make_ratexp(e.ratexpset(),
277  ::vcsn::transpose(e.ratexpset(),
278  e.ratexp()));
279  }
280 
282  (const ratexp& e) -> ratexp);
283  }
284  }
285 
286  /*-----------------------------.
287  | dyn::transposition(ratexp). |
288  `-----------------------------*/
289  namespace dyn
290  {
291  namespace detail
292  {
294  template <typename RatExpSet>
295  ratexp
297  {
298  const auto& e = exp->as<RatExpSet>();
299 
300  return make_ratexp(e.ratexpset(),
301  e.ratexpset().transposition(e.ratexp()));
302  }
303 
305  (const ratexp& e) -> ratexp);
306  }
307  }
308 
309 } // vcsn::
310 
311 #endif // !VCSN_ALGOS_TRANSPOSE_HH
ATTRIBUTE_PURE auto get_initial_weight(state_t s) const -> decltype(aut_-> weightset() ->transpose(aut_->get_ final _weight(s)))
Definition: transpose.hh:118
ratexp make_ratexp(const RatExpSet &rs, const typename RatExpSet::value_t &ratexp)
Definition: ratexp.hh:85
auto num_initials() const -> decltype(aut_-> num_ final s())
Definition: transpose.hh:99
auto del_transition(transition_t t) -> decltype(aut_-> del_transition(t))
Definition: transpose.hh:157
weightset_t_of< automaton_t > weightset_t
Definition: transpose.hh:44
auto set_final(state_t s) -> decltype(aut_-> set_initial(s))
Definition: transpose.hh:144
auto final_transitions() const -> decltype(aut_-> initial_transitions())
Definition: transpose.hh:94
auto is_initial(state_t s) const -> decltype(aut_-> is_ final(s))
Definition: transpose.hh:103
context_t_of< automaton_t > context_t
Definition: transpose.hh:37
auto label_of(transition_t t) const -> decltype(aut_-> labelset() ->transpose(aut_->label_of(t)))
Definition: transpose.hh:114
REGISTER_DECLARE(accessible,(const automaton &) -> automaton)
std::shared_ptr< detail::automaton_base > automaton
Definition: automaton.hh:71
auto labelset(Args &&...args) const -> decltype(aut_-> labelset(std::forward< Args >(args)...))
auto add_transition(state_t s, state_t d, label_t l, weight_t k) -> decltype(aut_-> add_transition(d, s, aut_->labelset() ->transpose(l), aut_->weightset() ->transpose(k)))
Definition: transpose.hh:164
auto unset_initial(state_t s) -> decltype(aut_-> unset_ final(s))
Definition: transpose.hh:145
Aut automaton_t
The type of automaton to wrap.
Definition: transpose.hh:27
ATTRIBUTE_PURE auto weight_of(transition_t t) const -> decltype(aut_-> weightset() ->transpose(aut_->weight_of(t)))
Definition: transpose.hh:126
typename detail::labelset_t_of_impl< base_t< ValueSet >>::type labelset_t_of
Definition: traits.hh:34
auto aut_ weightset() -> transpose(k)))
Definition: transpose.hh:181
auto has_transition(state_t s, state_t d, label_t l) const -> decltype(aut_-> has_transition(d, s, aut_->labelset() ->transpose(l)))
Definition: transpose.hh:112
auto add_transition(state_t s, state_t d, label_t l) -> decltype(aut_-> add_transition(d, s, aut_->labelset() ->transpose(l)))
Definition: transpose.hh:166
std::shared_ptr< detail::transpose_automaton_impl< Aut >> transpose_automaton
An automaton wrapper that presents the transposed automaton.
Definition: fwd.hh:61
auto get_transition(state_t s, state_t d, label_t l) const -> decltype(aut_-> get_transition(d, s, aut_->labelset() ->transpose(l)))
Definition: transpose.hh:110
ratexp transpose_ratexp(const ratexp &exp)
Bridge.
Definition: transpose.hh:272
RatExpSet::value_t transpose(const RatExpSet &rs, const typename RatExpSet::value_t &v)
Definition: transpose.hh:154
std::string sname()
Definition: name.hh:31
auto num_finals() const -> decltype(aut_-> num_initials())
Definition: transpose.hh:98
automaton make_automaton(const Aut &aut)
Build a dyn::automaton.
Definition: automaton.hh:77
auto lmul_weight(transition_t t, weight_t k) -> decltype(aut_-> lmul_weight(t, aut_->weightset() ->transpose(k)))
Definition: transpose.hh:153
auto new_transition_copy(state_t src, state_t dst, const A &aut, typename A::element_type::transition_t t, bool transpose=false) -> decltype(aut_-> new_transition_copy(dst, src, aut, t,!transpose))
Definition: transpose.hh:201
std::shared_ptr< detail::ratexp_base > ratexp
Definition: fwd.hh:64
transpose_automaton< typename automaton_t::element_type::automaton_nocv_t > automaton_nocv_t
The type to use to build an automaton of the same type: remove the inner const-volatile qualifiers...
Definition: transpose.hh:34
state_t_of< automaton_t > state_t
Definition: transpose.hh:38
labelset_t_of< automaton_t > labelset_t
Definition: transpose.hh:43
auto all_out(state_t s, Pred pred) const -> decltype(aut_-> all_in(s, pred))
Definition: transpose.hh:91
typename detail::context_t_of_impl< base_t< ValueSet >>::type context_t_of
Definition: traits.hh:32
auto add_final(state_t s, weight_t k) -> decltype(aut_-> add_initial(s, aut_->weightset() ->transpose(k)))
Definition: transpose.hh:187
auto all_in(state_t s) const -> decltype(aut_-> all_out(s))
Definition: transpose.hh:86
auto unset_final(state_t s) -> decltype(aut_-> unset_initial(s))
Definition: transpose.hh:146
auto is_final(state_t s) const -> decltype(aut_-> is_initial(s))
Definition: transpose.hh:97
auto set_weight(transition_t t, weight_t k) -> decltype(aut_-> set_weight(t, aut_->weightset() ->transpose(k)))
Definition: transpose.hh:149
auto add_weight(transition_t t, weight_t k) -> decltype(aut_-> add_weight(t, aut_->weightset() ->transpose(k)))
Definition: transpose.hh:151
static constexpr auto post() -> decltype(automaton_t::element_type::pre())
Definition: transpose.hh:220
typename automaton_t::element_type::kind_t kind_t
Definition: transpose.hh:45
typename detail::label_t_of_impl< base_t< ValueSet >>::type label_t_of
Definition: traits.hh:33
typename detail::weightset_t_of_impl< base_t< ValueSet >>::type weightset_t_of
Definition: traits.hh:38
auto set_transition(state_t s, state_t d, label_t l, weight_t k) -> decltype(aut_-> set_transition(d, s, aut_->labelset() ->transpose(l), aut_->weightset() ->transpose(k)))
Definition: transpose.hh:179
auto rmul_weight(transition_t t, weight_t k) -> decltype(aut_-> rmul_weight(t, aut_->weightset() ->transpose(k)))
Definition: transpose.hh:155
auto new_transition(state_t s, state_t d, label_t l, weight_t k) -> decltype(aut_-> new_transition(d, s, aut_->labelset() ->transpose(l), aut_->weightset() ->transpose(k)))
Definition: transpose.hh:171
static constexpr auto pre() -> decltype(automaton_t::element_type::post())
Definition: transpose.hh:221
typename detail::transition_t_of_impl< base_t< ValueSet >>::type transition_t_of
Definition: traits.hh:36
automaton_t naked_automaton()
The automaton we are decorating (typically a mutable_automaton).
Definition: transpose.hh:62
auto all_in(state_t s, Pred pred) const -> decltype(aut_-> all_out(s, pred))
Definition: transpose.hh:88
auto add_initial(state_t s, weight_t k) -> decltype(aut_-> add_ final(s
ratexp transposition_ratexp(const ratexp &exp)
Bridge.
Definition: transpose.hh:296
auto del_transition(state_t s, state_t d, label_t l) -> decltype(aut_-> del_transition(d, s, aut_->labelset() ->transpose(l)))
Definition: transpose.hh:159
auto out(state_t s) const -> decltype(aut_-> in(s))
Definition: transpose.hh:100
#define DEFINE(Signature, Value)
Definition: transpose.hh:211
std::string vname(bool full=true) const
Definition: transpose.hh:55
auto strip(const Aut &aut) -> decltype(detail::strip(aut, 0))
Remove (all) the decorations from a decorated automaton.
Definition: strip.hh:38
label_t_of< automaton_t > label_t
Definition: transpose.hh:40
typename detail::weight_t_of_impl< base_t< ValueSet >>::type weight_t_of
Definition: traits.hh:37
auto dst_of(transition_t t) const -> decltype(aut_-> src_of(t))
Definition: transpose.hh:93
auto set_initial(state_t s) -> decltype(aut_-> set_ final(s))
Definition: transpose.hh:143
Aut transpose(const transpose_automaton< Aut > &aut)
Definition: transpose.hh:230
auto in(state_t s) const -> decltype(aut_-> out(s))
Definition: transpose.hh:95
auto src_of(transition_t t) const -> decltype(aut_-> dst_of(t))
Definition: transpose.hh:102
weight_t_of< automaton_t > weight_t
Definition: transpose.hh:41
auto initial_transitions() const -> decltype(aut_-> final _transitions())
Definition: transpose.hh:96
ATTRIBUTE_PURE auto get_final_weight(state_t s) const -> decltype(aut_-> weightset() ->transpose(aut_->get_initial_weight(s)))
Definition: transpose.hh:122
typename detail::state_t_of_impl< base_t< ValueSet >>::type state_t_of
Definition: traits.hh:35
auto outin(state_t s, state_t d) const -> decltype(aut_-> outin(d, s))
Definition: transpose.hh:101
auto add_transition_copy(state_t src, state_t dst, const A &aut, typename A::element_type::transition_t t, bool transpose=false) -> decltype(aut_-> add_transition_copy(dst, src, aut, t,!transpose))
Definition: transpose.hh:194
auto strip() -> decltype(transpose(vcsn::strip(this->naked_automaton())))
Definition: transpose.hh:68
transition_t_of< automaton_t > transition_t
Definition: transpose.hh:39
automaton transpose(automaton &aut)
Bridge.
Definition: transpose.hh:250
auto all_out(state_t s) const -> decltype(aut_-> all_in(s))
Definition: transpose.hh:89
automaton_t aut_
The wrapped automaton, possibly const.