1 #ifndef VCSN_ALGOS_MINIMIZE_MOORE_HH
2 # define VCSN_ALGOS_MINIMIZE_MOORE_HH
4 # include <unordered_map>
19 namespace detail_moore
21 template <
typename Aut>
25 "minimize: moore: requires Boolean weights");
27 "minimize: moore: requires free labelset");
41 using set_t = std::vector<state_t>;
47 constexpr
static const char*
me() {
return "minimize-moore"; }
72 for (
unsigned i = 0; i < c2ss.size(); ++i)
74 o << sep <<
'[' << i <<
"] = ";
88 std::unordered_map<state_t, std::unordered_map<label_t, state_t>>
103 assert(! set.empty());
126 auto i =
out_.find(s);
129 auto j = i->second.find(l);
130 if (j == i->second.end())
138 ,
gs_(
a_->labelset()->genset())
144 for (
auto t :
a_->all_transitions())
145 out_[
a_->src_of(t)][
a_->label_of(t)] =
a_->dst_of(t);
155 set_t nonfinals, finals;
156 for (
auto s :
a_->states())
158 finals.emplace_back(s);
160 nonfinals.emplace_back(s);
161 if (! nonfinals.empty())
163 if (! finals.empty())
179 for (
auto s : c_states)
182 target_class_to_c_states[c2].emplace_back(s);
188 if (2 <= target_class_to_c_states.size())
192 for (
auto& p : target_class_to_c_states)
215 template <
typename Aut>
228 #endif // !VCSN_ALGOS_MINIMIZE_MOORE_HH
std::enable_if< std::is_same< weightset_t_of< Aut >, b >::value &&labelset_t_of< Aut >::is_free(), partition_automaton< Aut > >::type minimize(const Aut &a, const std::string &algo)
bool is_deterministic(const Aut &aut, state_t_of< Aut > s)
Whether state s is deterministic in aut.
class_t make_class(set_t &&set, class_t number=class_invalid)
Make a new class with the given set of states.
typename detail::labelset_t_of_impl< base_t< ValueSet >>::type labelset_t_of
void build_classes_()
Build the initial classes, and split until fix point.
bool is_trim(const Aut &a)
std::vector< set_t > class_to_set_t
std::unordered_map< state_t, class_t > state_to_class_t
auto quotient(const Aut &a, typename detail::quotienter< Aut >::class_to_set_t &classes) -> partition_automaton< Aut >
std::vector< class_t > classes_t
state_to_class_t state_to_class_
const labelset_t_of< Aut >::genset_t gs_
The generators.
state_t_of< automaton_t > state_t
static constexpr const char * me()
std::ostream & print_(const set_t &ss, std::ostream &o) const
class_to_set_t class_to_set_
std::ostream & print_(const class_to_set_t &c2ss, std::ostream &o) const
typename detail::label_t_of_impl< base_t< ValueSet >>::type label_t_of
typename detail::weightset_t_of_impl< base_t< ValueSet >>::type weightset_t_of
std::vector< state_t > class_to_state_t
const automaton_t & a_
Input automaton, supplied at construction time.
class_to_state_t class_to_res_state_
std::unordered_map< state_t, std::unordered_map< label_t, state_t > > out_
An auxiliary data structure enabling fast access to transitions from a given state and label...
Provide a variadic mul on top of a binary mul(), and one().
partition_automaton< automaton_t > operator()()
Return the quotient.
auto minimize_moore(const Aut &a) -> partition_automaton< Aut >
label_t_of< automaton_t > label_t
static constexpr class_t class_invalid
An invalid class.
class_t out_class(state_t s, label_t l)
The destination class of s with l in a.
typename detail::state_t_of_impl< base_t< ValueSet >>::type state_t_of
std::shared_ptr< detail::partition_automaton_impl< Aut >> partition_automaton
A partition automaton as a shared pointer.
std::unordered_map< class_t, set_t > target_class_to_states_t
void require(bool b, Args &&...args)
If b is not verified, raise an error with args as message.
std::vector< state_t > set_t