26 template <Automaton Aut>
33 && a->weightset()->is_one(a->weight_of(inis.front()))
35 &&
in(a, a->dst_of(inis.front())).empty();
39 template <Automaton Aut>
52 template <Automaton Aut>
56 const auto& a = aut->
as<Aut>();
61 template <Automaton Aut>
65 const auto& a = aut->
as<Aut>();
78 template <Automaton Aut>
85 const auto& ws = *aut->weightset();
87 std::vector<transition_t_of<Aut>> initials{begin(inits), end(inits)};
92 auto ini = aut->new_state();
93 for (
auto ti: initials)
96 auto i = aut->dst_of(ti);
97 auto wi = aut->weight_of(ti);
100 aut->add_transition(ini, aut->dst_of(t), aut->label_of(t),
101 ws.mul(wi, aut->weight_of(t)));
102 aut->del_transition(ti);
106 if (
all_in(aut, i).empty())
111 aut->set_initial(ini);
114 template <Automaton Aut>
123 template <Automaton Aut>
126 -> decltype(
copy(aut))
137 template <Automaton Aut>
141 const auto& a = aut->
as<Aut>();
146 template <Automaton Aut>
150 const auto& a = aut->
as<Aut>();
170 :
public ExpSet::const_visitor
180 using super_t =
typename expressionset_t::const_visitor;
183 constexpr
static const char*
me() {
return "standard"; }
196 res_->set_initial(initial_);
197 return std::move(res_);
199 catch (
const std::runtime_error& e)
202 " while computing standard automaton of: ",
216 void visit(const tuple_t&,
std::true_type)
override 218 raise(me(),
": tuple is not supported");
223 initial_ = res_->new_state();
228 auto i = res_->new_state();
235 auto i = res_->new_state();
236 auto f = res_->new_state();
238 res_->new_transition(i, f, e.value());
253 res.insert(res_->src_of(t));
260 e.head()->accept(*
this);
262 for (
const auto& c: e.tail())
265 for (
auto t:
all_out(res_, initial_))
268 res_->add_transition(initial,
272 res_->del_state(initial_);
285 e.head()->accept(*
this);
289 for (
const auto& c: e.tail())
300 if (!
has(other_finals, res_->src_of(t1)))
314 auto s1 = res_->src_of(t1);
315 auto w1 = res_->weight_of(t1);
316 res_->del_transition(t1);
317 for (
auto t2:
all_out(res_, initial_))
318 res_->set_transition(s1,
321 ws_.mul(w1, res_->weight_of(t2)));
323 res_->del_state(initial_);
332 e.sub()->accept(*
this);
334 weight_t w = ws_.star(res_->get_final_weight(initial_));
337 for (
auto ti:
out(res_, initial_))
339 res_->lweight(ti, w);
341 if (res_->src_of(tf) != initial_
342 && !
has(other_finals, res_->src_of(tf)))
352 ws_.mul(res_->weight_of(tf), res_->weight_of(ti)));
355 res_->rweight(tf, w);
356 res_->set_final(initial_, w);
361 e.sub()->accept(*
this);
362 for (
auto t:
all_out(res_, initial_))
363 res_->lweight(t, e.weight());
369 e.sub()->accept(*
this);
371 if (!
has(other_finals, res_->src_of(t)))
372 res_->rweight(t, e.weight());
379 state_t initial_ = automaton_t::element_type::null_state();
392 standard(
const ExpSet& rs,
const typename ExpSet::value_t&
r)
403 template <
typename ExpSet>
409 using expressionset_t = ExpSet;
412 const auto& e = exp->
as<expressionset_t>();
413 return ::vcsn::standard<automaton_t>(e.valueset(), e.value());
std::shared_ptr< detail::mutable_automaton_impl< Context > > mutable_automaton
Aut transpose(const transpose_automaton< Aut > &aut)
The transpose of a transpose automaton is the original automaton.
automaton transpose(automaton &aut)
Bridge.
auto initial_transitions(const Aut &aut) -> decltype(aut->all_out(aut->pre()))
Indexes of transitions to (visible) initial states.
ATTRIBUTE_PURE bool has(const boost::container::flat_set< Key, Compare, Allocator > &s, const Key &e)
Whether e is member of s.
typename detail::weightset_t_of_impl< base_t< ValueSet > >::type weightset_t_of
static constexpr const char * me()
Name of this algorithm, for error messages.
automaton_t operator()(const expression_t &v)
The standard automaton of v.
std::set< state_t > states_t
The current set of final states.
typename detail::state_t_of_impl< base_t< ValueSet > >::type state_t_of
void standard_here(Aut &aut)
Turn aut into a standard automaton.
SharedPtr make_shared_ptr(Args &&... args)
Same as std::make_shared, but parameterized by the shared_ptr type, not the (pointed to) element_type...
An inner node with multiple children.
bool is_standard(const Aut &a)
Whether a is standard.
bool is_standard(const automaton &aut)
Bridge.
std::vector< typename Cont::value_type > make_vector(const Cont &cont)
The content of cont as a vector.
VCSN_RAT_VISIT(rweight, e)
auto final_transitions(const Aut &aut) -> decltype(aut->all_in(aut->post()))
Indexes of transitions from (visible) final states.
Aut standard(const ExpSet &rs, const typename ExpSet::value_t &r)
Build a standard automaton from an expression.
auto all_in(const Aut &aut, state_t_of< Aut > s)
Indexes of transitions entering state s.
An inner node to name the subexpression.
typename expressionset_t::value_t expression_t
auto all_out(const Aut &aut, state_t_of< Aut > s)
Indexes of transitions leaving state s.
Provide a variadic mul on top of a binary mul(), and one().
bool is_costandard(const automaton &aut)
Bridge.
automaton standard(const automaton &aut)
Bridge.
weight_t_of< expressionset_t > weight_t
auto in(const Aut &aut, state_t_of< Aut > s)
Indexes of visible transitions arriving to state s.
automaton standard_expression(const expression &exp)
Bridge (standard).
const expressionset_t & rs_
auto & as()
Extract wrapped typed automaton.
An inner node implementing a weight.
VCSN_RAT_VISIT(lweight, e)
weightset_t_of< expressionset_t > weightset_t
standard_visitor(const expressionset_t &rs)
automaton costandard(const automaton &aut)
Bridge.
Build a standard automaton from an expression.
value_impl< detail::expression_tag > expression
#define VCSN_RAT_UNSUPPORTED(Type)
typename detail::weight_t_of_impl< base_t< ValueSet > >::type weight_t_of
typename super_t::tuple_t tuple_t
std::string to_string(direction d)
Conversion to string.
bool is_costandard(const Aut &a)
Whether a is costandard.
state_t_of< automaton_t > state_t
typename expressionset_t::const_visitor super_t
automaton copy(const automaton &aut)
Bridge.
auto out(const Aut &aut, state_t_of< Aut > s)
Indexes of visible transitions leaving state s.