Vcsn  2.4
Be Rational
ladybird.hh
Go to the documentation of this file.
1 #pragma once
2 
4 #include <vcsn/dyn/automaton.hh>
5 #include <vcsn/dyn/context.hh>
6 #include <vcsn/misc/raise.hh>
7 #include <vcsn/misc/vector.hh> // make_vector
8 
9 namespace vcsn
10 {
12  template <typename Context>
13  mutable_automaton<Context>
14  ladybird(const Context& ctx, unsigned n)
15  {
16  const auto& ls = *ctx.labelset();
17  auto letters = detail::make_vector(ls.generators());
18  require(3 <= letters.size(),
19  "ladybird: the alphabet needs at least 3 letters");
20  auto a = ls.value(letters[0]);
21  auto b = ls.value(letters[1]);
22  auto c = ls.value(letters[2]);
23 
24  auto res = make_mutable_automaton(ctx);
25 
26  auto s = res->new_state();
27  res->set_initial(s);
28  res->set_final(s);
29  auto x = s;
30  for (unsigned i = 1; i < n; ++i)
31  {
32  auto y = res->new_state();
33  res->new_transition(x, y, a);
34  res->new_transition(y, y, b);
35  res->new_transition(y, y, c);
36  res->new_transition(y, s, c);
37  x = y;
38  }
39  res->new_transition(x, s, a);
40  return res;
41  }
42 
43  /*----------------.
44  | dyn::ladybird. |
45  `----------------*/
46 
47  namespace dyn
48  {
49  namespace detail
50  {
52  template <typename Ctx, typename Unsigned>
53  automaton
54  ladybird(const dyn::context& ctx, unsigned n)
55  {
56  const auto& c = ctx->as<Ctx>();
58  }
59  }
60  }
61 }
std::vector< typename Cont::value_type > make_vector(const Cont &cont)
The content of cont as a vector.
Definition: vector.hh:20
mutable_automaton< Context > ladybird(const Context &ctx, unsigned n)
Build the ladybird automaton of n states.
Definition: ladybird.hh:14
return res
Definition: multiply.hh:398
mutable_automaton< Context > make_mutable_automaton(const Context &ctx)
void require(Bool b, Args &&...args)
If b is not verified, raise an error with args as message.
Definition: raise.hh:91
Provide a variadic mul on top of a binary mul(), and one().
Definition: fwd.hh:46
auto & as()
Downcast to the exact type.
Definition: context.hh:36
Definition: a-star.hh:8
Template-less root for contexts.
Definition: context.hh:16
automaton ladybird(const dyn::context &ctx, unsigned n)
Bridge.
Definition: ladybird.hh:54