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;
91 cps_.add_here(
res[a_->label_of(t)],
92 state_to_class_.at(a_->dst_of(t)),
97 struct signature_hasher
113 struct signature_equal_to
118 if (as.size() != bs.size())
121 using std::begin;
using std::end;
122 for (
auto i = begin(as), i_end = end(as), j = begin(bs);
125 if (!minimizer_.ls_.equal(i->first, j->first)
126 || !minimizer_.cps_.equal(i->second, j->second))
137 signature_hasher, signature_equal_to>;
141 class_to_set_.clear();
142 state_to_class_.clear();
154 if (number == class_invalid)
155 number = num_classes_++;
158 state_to_class_[s] = number;
160 if (number < class_to_set_.size())
161 class_to_set_[number] = std::move(
set);
164 assert(number == class_to_set_.size());
165 class_to_set_.emplace_back(std::move(
set));
182 return class_to_set_;
191 std::unordered_set<class_t> classes;
193 const auto&
all = a_->all_states();
194 classes.insert(make_class(set_t{std::begin(
all), std::end(
all)}));
197 for (
bool go_on =
true; go_on; )
200 for (
auto i = std::begin(classes), end = std::end(classes);
205 const set_t& c_states = class_to_set_.at(c);
209 auto signature_to_state
211 signature_hasher{*
this},
212 signature_equal_to{*
this}};
213 for (
auto s: c_states)
214 signature_to_state[
signature(s)].emplace_back(s);
216 if (2 <= signature_to_state.size())
220 i = classes.erase(i);
224 for (
auto& p: signature_to_state)
226 bool singleton = p.second.size() == 1;
227 class_t c2 = make_class(std::move(p.second), c);
245 unsigned num_classes_ = 0;
static bool less(class_t l, class_t r)
automaton_t a_
Input automaton, supplied at construction time.
weightset_mixin< detail::r_impl > r
bool operator()(const signature_t &as, const signature_t &bs) const noexcept
typename detail::weightset_t_of_impl< base_t< ValueSet > >::type weightset_t_of
typename class_polynomialset_t::value_t class_polynomial_t
class_t make_class(set_t &&set, class_t number=class_invalid)
Make a new class with the given set of states.
std::unordered_map< signature_t, set_t, signature_hasher, signature_equal_to > signature_multimap
Cluster states per signature.
const minimizer & minimizer_
state_to_class_t state_to_class_
class_to_set_t & classes()
The minimized automaton.
typename detail::state_t_of_impl< base_t< ValueSet > >::type state_t_of
static size_t hash(class_t s)
void build_classes_()
Build the initial classes, and split until fix point.
class_to_set_t class_to_set_
label_t_of< automaton_t > label_t
Request for the weighted version of an algorithm.
std::map< label_t, class_polynomial_t > signature_t
A signature: for each label, the outgoing class polynomial.
labelset_t_of< automaton_t > labelset_t
auto all_out(const Aut &aut, state_t_of< Aut > s)
Indexes of transitions leaving state s.
An input/output format for valuesets.
Provide a variadic mul on top of a binary mul(), and one().
static bool equal(class_t l, class_t r)
weight_t_of< automaton_t > weight_t
const minimizer & minimizer_
static constexpr const char * me()
void hash_combine_hash(std::size_t &seed, size_t h)
auto hash_value(const T &v) -> decltype(std::hash< T >
Following the naming convention of Boost.
typename detail::labelset_t_of_impl< base_t< ValueSet > >::type labelset_t_of
static std::ostream & print(value_t v, std::ostream &out=std::cout, format={})
std::vector< set_t > class_to_set_t
std::unordered_map< state_t, class_t > state_to_class_t
typename detail::label_t_of_impl< base_t< ValueSet > >::type label_t_of
state_t_of< automaton_t > state_t
std::vector< state_t > set_t
Signature of a function call.
bool is_trim(const Aut &a)
Whether all its states are useful.
weightset_t_of< automaton_t > weightset_t
static constexpr bool is_letterized()
void require(Bool b, Args &&... args)
If b is not verified, raise an error with args as message.
Request the unordered_map implementation.
typename detail::weight_t_of_impl< base_t< ValueSet > >::type weight_t_of
Indentation relative functions.
signature_t signature(state_t s) const
The signature of state s.
bool all(Bool &&... values)
Whether all the values evaluate as true.
std::set< std::pair< std::string, std::string > > class_t
A set of label ranges.
auto out(const Aut &aut, state_t_of< Aut > s)
Indexes of visible transitions leaving state s.
size_t operator()(const signature_t &sig) const noexcept