1 #ifndef VCSN_ALGOS_U_HH
2 # define VCSN_ALGOS_U_HH
15 template <
typename Context>
16 mutable_automaton<Context>
17 u(
const Context& ctx,
unsigned n)
19 using context_t = Context;
22 require(2 <= n,
"u: n must be at least 3");
23 const auto& gens = ctx.labelset()->genset();
24 std::vector<typename context_t::labelset_t::letter_t> letters
25 {std::begin(gens), std::end(gens)};
26 require(3 <= letters.size(),
"u: the alphabet needs at least 3 letters");
27 automaton_t res = make_shared_ptr<automaton_t>(ctx);
30 std::vector<state_t> states;
31 for (
unsigned i = 0; i < n; ++i)
32 states.push_back(res->new_state());
33 res->set_initial(states[0]);
34 res->set_final(states[n-1]);
38 for (
unsigned i = 0; i < n; ++i)
39 res->new_transition(states[i], states[(i+1) % n], a);
43 res->new_transition(states[0], states[1],
b);
44 res->new_transition(states[1], states[0],
b);
45 for (
unsigned i = 2; i < n; ++i)
46 res->new_transition(states[i], states[i],
b);
50 for (
unsigned i = 0; i < n - 1; ++i)
51 res->new_transition(states[i], states[i], c);
52 res->new_transition(states[n - 1], states[0], c);
66 template <
typename Ctx,
typename Un
signed>
70 const auto& c = ctx->as<Ctx>();
81 #endif // !VCSN_ALGOS_U_HH
REGISTER_DECLARE(accessible,(const automaton &) -> automaton)
std::shared_ptr< detail::automaton_base > automaton
automaton make_automaton(const Aut &aut)
Build a dyn::automaton.
std::shared_ptr< detail::mutable_automaton_impl< Context >> mutable_automaton
Provide a variadic mul on top of a binary mul(), and one().
std::shared_ptr< const detail::context_base > context
mutable_automaton< Context > u(const Context &ctx, unsigned n)
The Brzozowski universal witness.
typename detail::state_t_of_impl< base_t< ValueSet >>::type state_t_of
automaton u(const context &ctx, unsigned n)
Bridge.
void require(bool b, Args &&...args)
If b is not verified, raise an error with args as message.