17 #ifndef AWALI_ALGOS_AUT_TO_EXP_HH
18 # define AWALI_ALGOS_AUT_TO_EXP_HH
26 namespace awali {
namespace sttc {
34 template <
typename Aut,
35 typename Lifted = internal::lifted_automaton_t<Aut>>
37 std::function<
state_t(
const Lifted&)>;
44 template <
typename Aut>
49 bool best_has_loop =
false;
51 for (
auto s: a->states())
55 bool has_loop =
false;
57 for (
auto t: a->all_out(s))
58 if (a->dst_of(t) != s)
62 size_t in = a->all_in(s).size();
63 size_t degree = in * out;
65 if (degree < best_degree
66 || (degree == best_degree && has_loop < best_has_loop))
70 best_has_loop = has_loop;
82 template <
typename Aut>
87 for (
auto s: a->states())
102 template <typename Aut, typename Kind = typename context_t_of<Aut>::kind_t>
105 template <
typename Aut>
109 "requires labels_are_one");
127 auto loop = ws_.zero();
128 assert(aut_->outin(s, s).begin()==aut_->outin(s, s).end()
129 || ++(aut_->outin(s, s).begin())==aut_->outin(s, s).end());
132 for (
auto t:
to_vector(aut_->outin(s, s)))
134 loop = ws_.add(loop, aut_->weight_of(t));
135 aut_->del_transition(t);
137 loop = ws_.star(loop);
140 auto outs = aut_->all_out(s);
141 for (
auto in: aut_->all_in(s))
144 (aut_->src_of(in), aut_->dst_of(out),
146 ws_.mul(aut_->weight_of(in), loop, aut_->weight_of(out)));
153 while (aut_->num_states())
154 operator()(next_state(aut_));
163 const weightset_t& ws_ = *aut_->weightset();
166 template <
typename Aut>
170 "requires labels_are_ratexps");
197 auto loop = rs_.zero();
198 for (
auto t:
to_vector(aut_->outin(s, s)))
201 rs_.lmul(aut_->weight_of(t), aut_->label_of(t)));
202 aut_->del_transition(t);
204 loop = rs_.star(loop);
207 auto outs = aut_->all_out(s);
208 for (
auto in: aut_->all_in(s))
211 (aut_->src_of(in), aut_->dst_of(out),
212 rs_.mul(rs_.lmul(aut_->weight_of(in), aut_->label_of(in)),
214 rs_.lmul(aut_->weight_of(out), aut_->label_of(out))));
221 while (aut_->num_states())
222 operator()(next_state(aut_));
231 const ratexpset_t& rs_ = *aut_->labelset();
233 const weightset_t& ws_ = *aut_->weightset();
252 template <
typename Aut,
253 typename Context = ratexpset_of<context_t_of<Aut>>>
254 typename Context::ratexp_t
261 eliminate_states(next_state);
262 return aut->get_initial_weight(aut->post());
283 template <
typename Aut,
284 typename Context = ratexpset_of<context_t_of<Aut>>>
285 typename Context::ratexp_t
302 template <
typename Aut,
303 typename Context = ratexpset_of<context_t_of<Aut>>>
304 typename Context::ratexp_t
internal::lifted_automaton_t< Aut > unnormalized_lift(const Aut &a, bool keep_history=true)
Definition: lift.hh:88
std::vector< typename Cont::value_type > to_vector(const Cont &cont)
Return the content of cont as a vector.
Definition: vector.hh:72
Definition: aut_to_exp.hh:103
std::string to_string(identities i)
Context::ratexp_t aut_to_exp_in_order(const Aut &a)
Basic state elimination algorithm.
Definition: aut_to_exp.hh:305
typename internal::context_t_of_impl< internal::base_t< ValueSet > >::type context_t_of
Helper to retrieve the type of the context of a value set.
Definition: traits.hh:66
typename internal::labelset_t_of_impl< internal::base_t< ValueSet > >::type labelset_t_of
Helper to retrieve the type of the labelset of a value set.
Definition: traits.hh:76
Context::ratexp_t aut_to_exp(const Aut &a, const state_chooser_t< Aut > &next_state)
Generic state elimination algorithm.
Definition: aut_to_exp.hh:255
state_t next_in_order(const Aut &a)
Definition: aut_to_exp.hh:84
std::function< state_t(const Lifted &)> state_chooser_t
A state (inner) from an automaton.
Definition: aut_to_exp.hh:37
state_t next_heuristic(const Aut &a)
Definition: aut_to_exp.hh:46
void require(bool b, Args &&... args)
If b is not verified, raise an error with args as message.
Definition: raise.hh:55
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
ATTRIBUTE_CONST int max(int a, int b)
Definition: arith.hh:54
Main namespace of Awali.
Definition: ato.hh:22
unsigned state_t
Definition: types.hh:21
std::function< state_t(const automaton_t &)> state_chooser_t
State selector type.
Definition: aut_to_exp.hh:114
void operator()(const state_chooser_t &next_state)
Eliminate all the states, in the order specified by next_state.
Definition: aut_to_exp.hh:151
weightset_t_of< automaton_t > weightset_t
Definition: aut_to_exp.hh:112
void operator()(state_t s)
Eliminate state s.
Definition: aut_to_exp.hh:122
typename std::remove_cv< Aut >::type automaton_t
Definition: aut_to_exp.hh:111
state_eliminator(automaton_t &aut)
Definition: aut_to_exp.hh:116
std::function< state_t(const automaton_t &)> state_chooser_t
State selector type.
Definition: aut_to_exp.hh:184
void operator()(const state_chooser_t &next_state)
Eliminate all the states, in the order specified by next_state.
Definition: aut_to_exp.hh:219
labelset_t_of< automaton_t > ratexpset_t
Definition: aut_to_exp.hh:181
state_eliminator(automaton_t &aut)
Definition: aut_to_exp.hh:186
void operator()(state_t s)
Eliminate state s.
Definition: aut_to_exp.hh:192
weightset_t_of< automaton_t > weightset_t
Definition: aut_to_exp.hh:182
typename std::remove_cv< Aut >::type automaton_t
Definition: aut_to_exp.hh:180
marker type for labelsets where labels are one
Definition: kind.hh:80
marker type for labelsets where labels are rational expressions
Definition: kind.hh:82