7 #include <boost/heap/binomial_heap.hpp>
8 #include <boost/optional.hpp>
34 template <
typename Aut>
54 using datum_t = std::tuple<state_t, word_t, weight_t>;
60 if (weightset_t::less(std::get<2>(l), std::get<2>(r)))
62 else if (weightset_t::less(std::get<2>(r), std::get<2>(l)))
64 else if (labelset_t::less(std::get<1>(l), std::get<1>(r)))
66 else if (labelset_t::less(std::get<1>(r), std::get<1>(l)))
69 return std::get<0>(l) < std::get<0>(r);
73 boost::heap::binomial_heap<
datum_t,
74 boost::heap::compare<datum_less>>;
97 queue.emplace(
aut_->pre(),
ls_.one(),
ws_.one());
101 while (!queue.empty())
104 std::tie(s, l, w) = queue.top();
108 for (
const auto t:
aut_->all_out(s))
110 auto dst =
aut_->dst_of(t);
111 auto nw =
ws_.mul(w,
aut_->weight_of(t));
113 queue.emplace(dst, l, std::move(nw));
114 else if (dst ==
aut_->post())
115 ps_.add_here(res, l, std::move(nw));
118 auto nl =
ls_.mul(l,
aut_->label_of(t));
119 queue.emplace(dst, std::move(nl), std::move(nw));
127 || (num == res.size()
128 && !
ls_.equal(std::get<1>(queue.top()), l)))
138 const char* sep =
"";
139 for (
auto i = q.ordered_begin(), end = q.ordered_end();
144 aut_->print_state_name(std::get<0>(*i),
os) <<
":<";
145 ws_.print(std::get<2>(*i),
os);
147 ls_.print(std::get<1>(*i),
os);
164 template <
typename Automaton>
167 lightest(
const Automaton& aut, boost::optional<unsigned> num = {})
169 detail::weighter<Automaton> weighter(aut);
170 return weighter(num);
177 template <
typename Automaton>
179 typename detail::weighter<Automaton>::polynomial_t
191 template <
typename Aut,
typename Num>
195 const auto& a = aut->as<Aut>();
state_t_of< automaton_t > state_t
weightset_t_of< automaton_t > weightset_t
detail::weighter< Automaton >::polynomial_t lightest(const Automaton &aut, boost::optional< unsigned > num={})
The approximated behavior of an automaton.
word_t_of< automaton_t > word_t
typename polynomialset_t::monomial_t monomial_t
detail::weighter< Automaton >::polynomial_t weigh(const Automaton &aut)
The approximated behavior of an automaton.
typename detail::state_t_of_impl< base_t< ValueSet >>::type state_t_of
typename detail::context_t_of_impl< base_t< ValueSet >>::type context_t_of
typename detail::weightset_t_of_impl< base_t< ValueSet >>::type weightset_t_of
const polynomialset_t ps_
weight_t_of< automaton_t > weight_t
automaton_t aut_
The automaton whose behavior to approximate.
typename labelset_t_of< base_t< ValueSet >>::word_t word_t_of
labelset_t_of< polynomialset_t > labelset_t
Wordset.
polynomial make_polynomial(const PolynomialSet &ps, const typename PolynomialSet::value_t &p)
weighter(const automaton_t &aut)
Prepare to compute an approximation of the behavior.
Provide a variadic mul on top of a binary mul(), and one().
auto make_word_polynomialset(const Ctx &ctx) -> word_polynomialset_t< Ctx >
The polynomialset of words of a labelset (not necessarily on words itself).
The lightest algorithm computes the paths between pre and post with the smallest weight possible...
std::shared_ptr< detail::automaton_base > automaton
polynomial_t operator()(boost::optional< unsigned > num)
The approximated behavior of the automaton.
context_t_of< Aut > context_t
typename detail::labelset_t_of_impl< base_t< ValueSet >>::type labelset_t_of
typename polynomialset_t::value_t polynomial_t
std::ostringstream os
The output stream: the corresponding C++ snippet to compile.
polynomial lightest(const automaton &aut, boost::optional< unsigned > num)
Bridge.
std::shared_ptr< const detail::polynomial_base > polynomial
std::tuple< state_t, word_t, weight_t > datum_t
polynomial_t lightest_(unsigned num)
bool operator()(const datum_t &r, const datum_t &l) const
Whether l < r (as this is a max heap).
boost::heap::binomial_heap< datum_t, boost::heap::compare< datum_less >> queue_t
void show_heap_(const queue_t &q, std::ostream &os=std::cerr)
Show the heap, for debugging.
typename detail::weight_t_of_impl< base_t< ValueSet >>::type weight_t_of