4 #include <unordered_map>
5 #include <unordered_set>
18 namespace detail_weighted
20 template <
typename Aut>
38 using set_t = std::vector<state_t>;
42 constexpr
static const char*
me() {
return "minimize-weighted"; }
89 for (
auto t: a_->all_out(s))
90 cps_.add_here(res[a_->label_of(t)],
91 state_to_class_.at(a_->dst_of(t)),
117 if (as.size() != bs.size())
120 using std::begin;
using std::end;
121 for (
auto i = begin(as), i_end = end(as), j = begin(bs);
140 class_to_set_.clear();
141 state_to_class_.clear();
153 if (number == class_invalid)
154 number = num_classes_++;
157 state_to_class_[s] = number;
159 if (number < class_to_set_.size())
160 class_to_set_[number] = std::move(set);
163 assert(number == class_to_set_.size());
164 class_to_set_.emplace_back(std::move(set));
173 , ls_(*a_->labelset())
174 , ws_(*a_->weightset())
192 std::unordered_set<class_t>
classes;
194 const auto& all = a_->all_states();
195 classes.insert(
make_class(set_t{std::begin(all), std::end(all)}));
198 for (
bool go_on =
true; go_on; )
201 for (
auto i = std::begin(classes), end = std::end(classes);
206 const set_t& c_states = class_to_set_.at(c);
210 auto signature_to_state
213 signature_equal_to{*
this}};
214 for (
auto s: c_states)
215 signature_to_state[
signature(s)].emplace_back(s);
217 if (2 <= signature_to_state.size())
221 i = classes.erase(i);
225 for (
auto& p: signature_to_state)
227 bool singleton = p.second.size() == 1;
243 template <
typename Aut>
static bool equal(class_t l, class_t r)
weight_t_of< automaton_t > weight_t
static size_t hash(class_t s)
std::unordered_map< signature_t, set_t, signature_hasher, signature_equal_to > signature_multimap
Cluster states per signature.
typename detail::label_t_of_impl< base_t< ValueSet >>::type label_t_of
weightset_mixin< detail::r_impl > r
partition_automaton_t< Aut > quotient_t
The return type when calling quotient on Aut.
class_to_set_t class_to_set_
std::vector< set_t > class_to_set_t
std::unordered_map< state_t, class_t > state_to_class_t
polynomialset< context< classset, weightset_t >> class_polynomialset_t
The output of a given letter from a given state, keeping into account classes and weights...
const minimizer & minimizer_
typename detail::state_t_of_impl< base_t< ValueSet >>::type state_t_of
auto quotient(const Aut &a, typename detail::quotienter< Aut >::class_to_set_t &cs) -> quotient_t< Aut >
typename detail::weightset_t_of_impl< base_t< ValueSet >>::type weightset_t_of
static constexpr const char * me()
automaton_t a_
Input automaton, supplied at construction time.
class_polynomialset_t cps_
Class polynomialset.
state_to_class_t state_to_class_
bool operator()(const signature_t &as, const signature_t &bs) const noexcept
typename class_polynomialset_t::value_t class_polynomial_t
auto hash_value(const T &v) -> decltype(std::hash< T >
Following the naming convention of Boost.
void build_classes_()
Build the initial classes, and split until fix point.
class_to_set_t & classes()
The minimized automaton.
auto minimize_weighted(const Aut &a) -> quotient_t< Aut >
vcsn::enable_if_t< std::is_same< weightset_t_of< Aut >, b >::value &&labelset_t_of< Aut >::is_free(), quotient_t< Aut > > minimize(const Aut &a, const std::string &algo="auto")
std::map< label_t, class_polynomial_t > signature_t
A signature: for each label, the outgoing class polynomial.
label_t_of< automaton_t > label_t
signature_t signature(state_t s) const
The signature of state s.
Provide a variadic mul on top of a binary mul(), and one().
state_t_of< automaton_t > state_t
void hash_combine_hash(std::size_t &seed, size_t h)
typename detail::labelset_t_of_impl< base_t< ValueSet >>::type labelset_t_of
void require(bool b, Args &&...args)
If b is not verified, raise an error with args as message.
size_t operator()(const signature_t &sig) const noexcept
std::vector< state_t > set_t
bool is_trim(const Aut &a)
Whether all its states are useful.
weightset_t_of< automaton_t > weightset_t
Dealing with class numbers.
const minimizer & minimizer_
class_t make_class(set_t &&set, class_t number=class_invalid)
Make a new class with the given set of states.
Indentation relative functions.
labelset_t_of< automaton_t > labelset_t
static bool less(class_t l, class_t r)
static constexpr class_t class_invalid
An invalid class.
typename detail::weight_t_of_impl< base_t< ValueSet >>::type weight_t_of