4 #include <unordered_map>
5 #include <unordered_set>
22 template <Automaton Aut>
33 using set_t = std::vector<state_t>;
37 constexpr
static const char*
me() {
return "minimize-weighted"; }
40 constexpr
static class_t class_invalid = -1;
65 using class_polynomialset_t
77 cps_.add_here(res[a_->label_of(t)],
78 state_to_class_.at(a_->dst_of(t)),
83 struct signature_hasher
99 struct signature_equal_to
104 if (as.size() != bs.size())
107 using std::begin;
using std::end;
108 for (
auto i = begin(as), i_end = end(as), j = begin(bs);
111 if (!minimizer_.ls_.equal(i->first, j->first)
112 || !minimizer_.cps_.equal(i->second, j->second))
123 signature_hasher, signature_equal_to>;
127 class_to_set_.clear();
128 state_to_class_.clear();
140 if (number == class_invalid)
141 number = num_classes_++;
144 state_to_class_[s] = number;
146 if (number < class_to_set_.size())
147 class_to_set_[number] = std::move(set);
150 assert(number == class_to_set_.size());
151 class_to_set_.emplace_back(std::move(set));
168 return class_to_set_;
177 std::unordered_set<class_t> classes;
179 const auto&
all = a_->all_states();
180 classes.insert(make_class(set_t{std::begin(
all), std::end(
all)}));
183 for (
bool go_on =
true; go_on; )
186 for (
auto i = std::begin(classes), end = std::end(classes);
191 const set_t& c_states = class_to_set_.at(c);
195 auto signature_to_state
197 signature_hasher{*
this},
198 signature_equal_to{*
this}};
199 for (
auto s: c_states)
200 signature_to_state[
signature(s)].emplace_back(s);
202 if (2 <= signature_to_state.size())
206 i = classes.erase(i);
210 for (
auto& p: signature_to_state)
212 bool singleton = p.second.size() == 1;
213 class_t c2 = make_class(std::move(p.second), c);
231 unsigned num_classes_ = 0;
auto all_out(const Aut &aut, state_t_of< Aut > s)
Indexes of transitions leaving state s.
class_t make_class(set_t &&set, class_t number=class_invalid)
Make a new class with the given set of states.
std::set< std::pair< std::string, std::string >> class_t
A set of label ranges.
bool all(Bool &&...values)
automaton_t a_
Input automaton, supplied at construction time.
typename detail::weightset_t_of_impl< base_t< ValueSet >>::type weightset_t_of
auto hash_value(const T &v) -> decltype(std::hash< T >
Following the naming convention of Boost.
state_to_class_t state_to_class_
weight_t_of< automaton_t > weight_t
typename class_polynomialset_t::value_t class_polynomial_t
Request the set implementation (bool weights).
void require(Bool b, Args &&...args)
If b is not verified, raise an error with args as message.
class_to_set_t class_to_set_
std::map< label_t, class_polynomial_t > signature_t
A signature: for each label, the outgoing class polynomial.
void build_classes_()
Build the initial classes, and split until fix point.
bool is_trim(const Aut &a)
Whether all its states are useful.
static bool less(class_t l, class_t r)
typename detail::labelset_t_of_impl< base_t< ValueSet >>::type labelset_t_of
state_t_of< automaton_t > state_t
weightset_mixin< detail::r_impl > r
Indentation relative functions.
Provide a variadic mul on top of a binary mul(), and one().
typename detail::weight_t_of_impl< base_t< ValueSet >>::type weight_t_of
label_t_of< automaton_t > label_t
typename detail::state_t_of_impl< base_t< ValueSet >>::type state_t_of
weightset_t_of< automaton_t > weightset_t
const minimizer & minimizer_
const minimizer & minimizer_
static constexpr const char * me()
Request the unordered_map implementation.
signature_t signature(state_t s) const
The signature of state s.
std::vector< set_t > class_to_set_t
static size_t hash(class_t s)
typename detail::label_t_of_impl< base_t< ValueSet >>::type label_t_of
std::unordered_map< state_t, class_t > state_to_class_t
bool operator()(const signature_t &as, const signature_t &bs) const noexcept
std::vector< state_t > set_t
labelset_t_of< automaton_t > labelset_t
Request for the weighted version of an algorithm.
void hash_combine_hash(std::size_t &seed, size_t h)
static bool equal(class_t l, class_t r)
class_to_set_t & classes()
The minimized automaton.
std::unordered_map< signature_t, set_t, signature_hasher, signature_equal_to > signature_multimap
Cluster states per signature.
polynomialset< context< classset, weightset_t >> class_polynomialset_t
The output of a given letter from a given state, keeping into account classes and weights...
Signature of a function call.
size_t operator()(const signature_t &sig) const noexcept