17 #ifndef AWALI_ALGOS_MOORE_QUOTIENT_HH
18 #define AWALI_ALGOS_MOORE_QUOTIENT_HH
56 template <
typename Aut>
57 unsigned moore_quotient(
const Aut& aut, std::vector<std::vector<state_t> >& states_in_part) {
59 using automaton_t = Aut;
65 states_in_part.resize(3);
67 std::vector<unsigned> part(aut->max_state()+1);
70 states_in_part[0].emplace_back(aut->pre());
72 states_in_part[1].emplace_back(aut->post());
74 for(
auto s : aut->states() ) {
75 states_in_part[2].emplace_back(s);
81 std::queue<unsigned> queue_part;
82 if(states_in_part[2].size()>1)
83 queue_part.emplace(2);
87 queue_part.emplace(0);
90 unsigned iterations=0;
91 while(!queue_part.empty()) {
94 unsigned i= queue_part.front();
103 queue_part.emplace(0);
107 std::vector<state_t> states_without_successors;
111 for(
auto s : states_in_part[i]) {
112 bool no_successors=
true;
113 for(
auto tr : aut->all_out(s) ) {
118 std::tuple<state_t, weight_t, unsigned> tu{s,w,part[
r]};
119 meet[a].push_back(std::move(tu));
122 states_without_successors.emplace_back(s);
124 if(
meet.domain().empty())
128 for(
auto a :
meet.domain())
129 for(
auto p :
meet[a]){
130 std::tuple<state_t, weight_t, label_t> tu{std::get<0>(p),std::get<1>(p),a};
131 meet2[std::get<2>(p)].push_back(std::move(tu));
135 for(
auto j : meet2.
domain())
136 for(
auto p : meet2[j]) {
137 if(signature.
count(std::get<0>(p))) {
138 auto & t=signature[std::get<0>(p)].back();
139 if(std::get<0>(t)==std::get<2>(p) && std::get<1>(t)==j)
140 std::get<2>(t) = aut->context().weightset()->add(std::get<2>(t), std::get<1>(p));
142 std::tuple<label_t,unsigned, weight_t> tu{std::get<2>(p),j,std::get<1>(p)};
143 signature[std::get<0>(p)].push_back(std::move(tu));
147 std::tuple<label_t,unsigned, weight_t> tu{std::get<2>(p),j,std::get<1>(p)};
148 signature[std::get<0>(p)].push_back(std::move(tu));
153 std::vector<std::vector<state_t> > new_parts;
154 std::queue<std::vector<state_t> > list;
155 list.emplace(signature.
domain());
156 while(!list.empty()) {
157 std::vector<state_t>& pp = list.front();
158 std::vector<state_t> shorter;
161 std::vector<std::tuple<label_t,unsigned, weight_t>>& sig = signature[
r];
163 shorter.push_back(
r);
165 std::tuple<label_t,unsigned, weight_t> & tuple= sig.back();
166 tmplist[tuple].emplace_back(
r);
172 list.push(std::move(tmplist[
pair]));
174 new_parts.push_back(std::move(shorter));
178 unsigned lim=new_parts.size();
183 queue_part.emplace(i);
186 unsigned np=states_in_part.size();
187 for(
unsigned k=0; k<lim;++k) {
191 states_in_part[i].swap(new_parts[0]);
195 for(
auto r : new_parts[k])
197 states_in_part.push_back(std::move(new_parts[k]));
199 if(states_in_part[p].size()>1) {
200 queue_part.emplace(p);
203 if(!states_without_successors.empty()) {
204 for(
auto r : states_without_successors)
206 states_in_part.push_back(std::move(states_without_successors));
The semiring of floating Numbers.
Definition: r.hh:35
any_t label_t
Type for (transition) labels; it is an alias to any_t since its precise type depends on the weightset...
Definition: typedefs.hh:48
any_t weight_t
Type for (transition) weights; it is an alias to any_t since the its precise type depends on the weig...
Definition: typedefs.hh:61
typename internal::label_t_of_impl< internal::base_t< ValueSet > >::type label_t_of
Helper to retrieve the type of the labels of a value set.
Definition: traits.hh:71
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
auto meet(const ratexpset< Ctx1 > &a, const ratexpset< Ctx2 > &b) -> ratexpset< meet_t< Ctx1, Ctx2 >>
The meet of two ratexpsets.
Definition: ratexpset.hh:434
pair_automaton< Aut > pair(const Aut &aut, bool keep_initials=false)
Definition: synchronizing_word.hh:266
unsigned moore_quotient(const Aut &aut, std::vector< std::vector< state_t > > &states_in_part)
Definition: moore_quotient.hh:57
Main namespace of Awali.
Definition: ato.hh:22
unsigned state_t
Definition: types.hh:21
Definition: linkedhashmap.hh:31
unsigned count(const K &k) const
Definition: linkedhashmap.hh:46
const std::vector< K > & domain() const
Definition: linkedhashmap.hh:36