17 #ifndef AWALI_ALGOS_STANDARD_HH
18 # define AWALI_ALGOS_STANDARD_HH
31 namespace awali {
namespace sttc {
38 template <
typename Aut>
43 a->num_initials() == 1
44 && a->weightset()->is_one(a->weight_of(*(a->initial_transitions().begin())))
46 && a->in(a->dst_of(*(a->initial_transitions().begin()))).empty();
56 template <
typename Aut>
62 const auto& ws = *aut->weightset();
63 const auto& inits = aut->initial_transitions();
64 std::vector<transition_t> initials{begin(inits), end(inits)};
69 auto ini = aut->add_state();
70 for (
auto ti: initials)
73 auto i = aut->dst_of(ti);
74 auto wi = aut->weight_of(ti);
75 for (
auto t: aut->all_out(i))
76 aut->add_transition(ini, aut->dst_of(t), aut->label_of(t),
77 ws.mul(wi, aut->weight_of(t)));
78 aut->del_transition(ti);
82 if (aut->all_in(i).empty())
87 aut->set_initial(ini);
90 template <
typename Aut>
93 auto out =
copy(aut, keep_history);
108 template <
typename Aut,
109 typename Context = context_t_of<Aut>>
111 :
public Context::const_visitor
121 constexpr
static const char*
me() {
return "standard"; }
132 res_->set_initial(initial_);
133 return std::move(res_);
144 initial_ = res_->add_state();
149 auto i = res_->add_state();
156 auto i = res_->add_state();
157 auto f = res_->add_state();
159 res_->new_transition(i, f, e.value());
169 for (
auto t: res_->final_transitions())
170 res.insert(res_->src_of(t));
177 e.head()->accept(*
this);
179 for (
auto c: e.tail())
182 for (
auto t: res_->all_out(initial_))
185 res_->add_transition(initial,
189 res_->del_state(initial_);
202 e.head()->accept(*
this);
206 for (
auto c: e.tail())
209 auto ftr_ = res_->final_transitions();
211 using transs_t = std::vector<transition_t>;
212 transs_t ftr{ begin(ftr_), end(ftr_) };
233 auto s1 = res_->src_of(t1);
234 auto w1 = res_->weight_of(t1);
235 res_->del_transition(t1);
236 for (
auto t2: res_->all_out(initial_))
237 res_->set_transition(s1,
240 ws_.mul(w1, res_->weight_of(t2)));
242 res_->del_state(initial_);
251 e.sub()->accept(*
this);
253 weight_t w = ws_.star(res_->get_final_weight(initial_));
256 for (
auto ti: res_->out(initial_))
258 res_->lmul_weight(ti, w);
259 for (
auto tf: res_->final_transitions())
260 if (res_->src_of(tf) != initial_
271 ws_.mul(res_->weight_of(tf), res_->weight_of(ti)));
273 for (
auto tf: res_->final_transitions())
275 res_->rmul_weight(tf, w);
276 res_->set_final(initial_, w);
281 e.sub()->accept(*
this);
282 for (
auto t: res_->all_out(initial_))
283 res_->lmul_weight(t, e.weight());
289 e.sub()->accept(*
this);
290 for (
auto t: res_->final_transitions())
292 res_->rmul_weight(t, e.weight());
298 state_t initial_ = automaton_t::element_type::null_state();
311 template <
typename Aut,
312 typename Context = context_t_of<Aut>>
314 standard(
const Context& ctx,
const typename Context::ratexp_t& e)
327 template <
typename RatExpSet>
329 mutable_automaton<typename RatExpSet::context_t>
330 standard(
const RatExpSet& rs,
const typename RatExpSet::ratexp_t& e)
The semiring of complex numbers.
Definition: c.hh:44
Definition: ratexp.hh:280
Definition: ratexp.hh:262
Convert a ratexp to a standard automaton.
Definition: standard.hh:112
weight_t_of< context_t > weight_t
Definition: standard.hh:117
constexpr static const char * me()
Definition: standard.hh:121
AWALI_RAT_VISIT(atom, e)
Definition: standard.hh:154
AWALI_RAT_VISIT(one,)
Definition: standard.hh:147
AWALI_RAT_VISIT(rweight, e)
Definition: standard.hh:286
AWALI_RAT_VISIT(star, e)
Definition: standard.hh:248
standard_visitor(const context_t &ctx)
Definition: standard.hh:123
AWALI_RAT_VISIT(sum, e)
Definition: standard.hh:174
Context context_t
Definition: standard.hh:115
typename Context::const_visitor super_type
Definition: standard.hh:119
AWALI_RAT_VISIT(lweight, e)
Definition: standard.hh:279
automaton_t operator()(const typename context_t::ratexp_t &v)
Definition: standard.hh:129
weightset_t_of< context_t > weightset_t
Definition: standard.hh:116
AWALI_RAT_VISIT(zero,)
Definition: standard.hh:142
states_t finals()
Definition: standard.hh:166
AWALI_RAT_VISIT(prod, e)
Definition: standard.hh:194
std::set< state_t > states_t
The current set of final states.
Definition: standard.hh:164
Aut automaton_t
Definition: standard.hh:114
Definition: ratexp.hh:176
An inner node with multiple children.
Definition: ratexp.hh:115
An inner node implementing a weight.
Definition: ratexp.hh:208
weightset_description weightset(const std::string &k)
bool has(const std::map< Key, Value, Compare, Alloc > &s, const Key &e)
Definition: map.hh:53
bool is_standard(const Aut &a)
Definition: standard.hh:40
SharedPtr make_shared_ptr(Args &&... args)
Same as std::make_shared, but parameterized by the shared_ptr type, not the (pointed to) element_type...
Definition: memory.hh:29
typename internal::weight_t_of_impl< internal::base_t< ValueSet > >::type weight_t_of
Helper to retrieve the type of the weights of a value set.
Definition: traits.hh:81
Aut standard(Aut &aut, bool keep_history=true)
Definition: standard.hh:92
AutOut copy(const AutIn &input, Pred keep_state, bool keep_history=true, bool transpose=false)
A copy of input keeping only its states that are accepted by keep_state.
Definition: copy.hh:189
void standard_here(Aut &aut)
Turn aut into a standard automaton.
Definition: standard.hh:58
typename internal::weightset_t_of_impl< internal::base_t< ValueSet > >::type weightset_t_of
Helper to retrieve the type of the weightset of a value set.
Definition: traits.hh:86
Main namespace of Awali.
Definition: ato.hh:22
unsigned state_t
Definition: types.hh:21
#define AWALI_RAT_UNSUPPORTED(Type)
Definition: visitor.hh:73