1 #ifndef VCSN_ALGOS_STANDARD_HH
2 # define VCSN_ALGOS_STANDARD_HH
25 template <
typename Aut>
29 auto inis = a->initial_transitions();
32 && a->weightset()->is_one(a->weight_of(inis.front()))
34 && a->in(a->dst_of(inis.front())).empty();
38 template <
typename Aut>
51 template <
typename Aut>
55 const auto& a = aut->as<Aut>();
63 template <
typename Aut>
67 const auto& a = aut->as<Aut>();
83 template <
typename Aut>
90 const auto& ws = *aut->weightset();
91 const auto& inits = aut->initial_transitions();
92 std::vector<transition_t_of<Aut>> initials{begin(inits), end(inits)};
97 auto ini = aut->new_state();
98 for (
auto ti: initials)
101 auto i = aut->dst_of(ti);
102 auto wi = aut->weight_of(ti);
103 for (
auto t: aut->all_out(i))
104 aut->new_transition(ini, aut->dst_of(t), aut->label_of(t),
105 ws.mul(wi, aut->weight_of(t)));
106 aut->del_transition(ti);
110 if (aut->all_in(i).empty())
115 aut->set_initial(ini);
118 template <
typename Aut>
121 -> decltype(
copy(aut))
123 auto res =
copy(aut);
128 template <
typename Aut>
131 -> decltype(
copy(aut))
142 template <
typename Aut>
146 const auto& a = aut->as<Aut>();
153 template <
typename Aut>
157 const auto& a = aut->as<Aut>();
176 template <
typename Aut,
179 :
public RatExpSet::const_visitor
188 using super_t =
typename ratexpset_t::const_visitor;
190 constexpr
static const char*
me() {
return "standard"; }
218 auto i =
res_->new_state();
225 auto i =
res_->new_state();
226 auto f =
res_->new_state();
228 res_->new_transition(i, f, e.value());
238 for (
auto t:
res_->final_transitions())
239 res.insert(
res_->src_of(t));
246 e.head()->accept(*
this);
248 for (
auto c: e.tail())
254 res_->add_transition(initial,
271 e.head()->accept(*
this);
275 for (
auto c: e.tail())
278 auto ftr_ =
res_->final_transitions();
280 using transs_t = std::vector<transition_t_of<automaton_t>>;
281 transs_t ftr{ begin(ftr_), end(ftr_) };
289 if (!
has(other_finals,
res_->src_of(t1)))
303 auto s1 =
res_->src_of(t1);
304 auto w1 =
res_->weight_of(t1);
305 res_->del_transition(t1);
307 res_->set_transition(s1,
310 ws_.mul(w1,
res_->weight_of(t2)));
321 e.sub()->accept(*
this);
328 res_->lmul_weight(ti, w);
329 for (
auto tf:
res_->final_transitions())
331 && !
has(other_finals,
res_->src_of(tf)))
341 ws_.mul(
res_->weight_of(tf),
res_->weight_of(ti)));
343 for (
auto tf:
res_->final_transitions())
344 res_->rmul_weight(tf, w);
350 e.sub()->accept(*
this);
352 res_->lmul_weight(t, e.weight());
358 e.sub()->accept(*
this);
359 for (
auto t:
res_->final_transitions())
360 if (!
has(other_finals,
res_->src_of(t)))
361 res_->rmul_weight(t, e.weight());
378 template <
typename Aut,
381 standard(
const RatExpSet& rs,
const typename RatExpSet::value_t&
r)
392 template <
typename RatExpSet>
398 using ratexpset_t = RatExpSet;
400 const auto& e = exp->as<ratexpset_t>();
401 return make_automaton(::vcsn::standard<automaton_t>(e.ratexpset(),
412 #endif // !VCSN_ALGOS_STANDARD_HH
bool is_costandard(const automaton &aut)
Bridge.
An inner node with multiple children.
#define VCSN_RAT_UNSUPPORTED(Type)
std::set< state_t > states_t
The current set of final states.
automaton standard(const automaton &aut)
Bridge.
REGISTER_DECLARE(accessible,(const automaton &) -> automaton)
std::shared_ptr< detail::automaton_base > automaton
bool is_standard(const Aut &a)
Whether a is standard.
automaton make_automaton(const Aut &aut)
Build a dyn::automaton.
std::shared_ptr< detail::mutable_automaton_impl< Context >> mutable_automaton
std::shared_ptr< detail::ratexp_base > ratexp
automaton standard_ratexp(const ratexp &exp)
Bridge.
weightset_t_of< ratexpset_t > weightset_t
auto costandard(const Aut &aut) -> decltype(copy(aut))
static constexpr const char * me()
AutOut copy(const AutIn &input, Pred keep_state)
A copy of input keeping only its states that are accepted by keep_state.
typename ratexpset_t::const_visitor super_t
bool is_standard(const automaton &aut)
Bridge.
typename detail::weightset_t_of_impl< base_t< ValueSet >>::type weightset_t_of
auto standard(const Aut &aut) -> decltype(copy(aut))
automaton costandard(const automaton &aut)
Bridge.
bool is_costandard(const Aut &a)
Whether a is costandard.
VCSN_RAT_VISIT(lweight, e)
Provide a variadic mul on top of a binary mul(), and one().
automaton_t operator()(const typename ratexpset_t::value_t &v)
An inner node implementing a weight.
typename detail::weight_t_of_impl< base_t< ValueSet >>::type weight_t_of
Aut transpose(const transpose_automaton< Aut > &aut)
state_t_of< automaton_t > state_t
weight_t_of< ratexpset_t > weight_t
VCSN_RAT_VISIT(rweight, e)
Build a standard automaton from a ratexp.
typename detail::state_t_of_impl< base_t< ValueSet >>::type state_t_of
SharedPtr make_shared_ptr(Args &&...args)
Same as std::make_shared, but parameterized by the shared_ptr type, not the (pointed to) element_type...
void standard_here(Aut &aut)
Turn aut into a standard automaton.
bool has(const std::map< Key, Value, Compare, Alloc > &s, const Key &e)
standard_visitor(const ratexpset_t &rs)