5 #include <boost/heap/fibonacci_heap.hpp>
33 template <Automaton Aut,
typename ValueSet,
typename Mul,
typename GetValue>
41 using path_t = std::vector<transition_t>;
45 using value_t =
typename valueset_t::value_t;
72 using heap_t = boost::heap::fibonacci_heap<profile>;
74 template <Automaton AnyAut>
82 for (
auto t = path[dst];
83 t != aut->null_transition();
84 t = path[aut->src_of(t)])
87 if (aut->src_of(t) == src)
90 std::reverse(res.begin(), res.end());
94 template <Automaton AnyAut>
101 return std::move(algo(src, dst));
113 for (
unsigned i = 1
u; i < k; i++)
115 const auto& prev =
res[i - 1];
116 for (
unsigned j = 0
u; j < prev.size(); j++)
118 auto filter_aut = filter<automaton_t, true>(
aut_);
119 filter_aut->unhide_all_states();
120 filter_aut->unhide_all_transition();
121 auto spur_node = filter_aut->src_of(prev[j]);
122 auto root_path =
path_t(prev.begin(), prev.begin() + j);
124 for (
const auto& selected_path:
res)
125 if (j < selected_path.size())
127 auto diff = std::mismatch(root_path.begin(), root_path.end(),
128 selected_path.begin(), selected_path.begin() + j);
129 if (diff.first == root_path.end()
130 && filter_aut->has_transition(selected_path[j]))
131 filter_aut->hide_transition(selected_path[j]);
134 for (
auto t: root_path)
135 if (t != filter_aut->null_transition()
136 && filter_aut->src_of(t) != spur_node
137 && filter_aut->src_of(t) !=
aut_->pre()
138 && filter_aut->has_state(filter_aut->src_of(t)))
139 filter_aut->hide_state(filter_aut->src_of(t));
142 auto spur_path =
path(filter_aut, shortest_path, spur_node, dst);
143 root_path.insert(root_path.end(), spur_path.begin(), spur_path.end());
144 if (!root_path.empty()
145 && filter_aut->src_of(root_path.front()) == src
146 && filter_aut->dst_of(root_path.back()) == dst)
148 bool already_found =
false;
149 for (
const auto&
profile: heap)
152 if (root_path.size() == selected_path.size())
154 auto diff = std::mismatch(root_path.begin(), root_path.end(),
155 selected_path.begin(), selected_path.end());
156 if (diff.first == root_path.end())
158 already_found =
true;
172 res.push_back(heap.top().path_);
184 template <Automaton Aut,
typename ValueSet,
typename Mul,
typename GetValue>
186 make_yen(
const Aut& aut,
const ValueSet& vs, Mul mul, GetValue get_value)
192 template <Automaton Aut>
193 std::vector<std::vector<transition_t_of<Aut>>>
198 return aut->weightset()->mul(lhs, aut->weight_of(t));
200 auto get_value = [](
auto m) {
return m.second; };
202 return yen(source, dest, k);
205 template <Automaton Aut>
206 std::vector<transition_t_of<Aut>>
210 aut->null_transition());
212 if (t != aut->null_transition())
213 res[aut->dst_of(t)] = t;
217 template <Automaton Aut>
218 std::vector<transition_t_of<Aut>>
223 auto res = paths.empty() ? std::vector<transition_t_of<Aut>>() : paths.front();
context_t_of< automaton_t > context_t
typename detail::weight_t_of_impl< base_t< ValueSet >>::type weight_t_of
auto make_yen(const Aut &aut, const ValueSet &vs, Mul mul, GetValue get_value)
boost::heap::fibonacci_heap< profile > heap_t
std::vector< transition_t > path_t
bool operator<(const profile &rhs) const
typename detail::transition_t_of_impl< base_t< ValueSet >>::type transition_t_of
weight_t_of< automaton_t > weight_t
mutable_automaton< Context > u(const Context &ctx, unsigned n)
The Brzozowski universal witness.
size_t states_size(const Aut &aut)
The largest state number, plus one.
state_t_of< automaton_t > state_t
typename detail::context_t_of_impl< base_t< ValueSet >>::type context_t_of
std::vector< path_t > paths_t
transition_t_of< automaton_t > transition_t
std::vector< std::vector< transition_t_of< Aut > > > k_lightest_path(const Aut &aut, state_t_of< Aut > source, state_t_of< Aut > dest, unsigned k)
profile(const path_t &path, const value_t &v, const valueset_t &vs)
Yen implementation of the K lightest automaton algorithm.
std::vector< transition_t_of< Aut > > format_lightest(const Aut &aut, const std::vector< transition_t_of< Aut >> &path)
typename detail::state_t_of_impl< base_t< ValueSet >>::type state_t_of
yen_impl(const automaton_t &aut, const ValueSet &vs, Mul mul, GetValue get_value)
Paths in filesystems, i.e., file names.
auto make_word_polynomialset(const Ctx &ctx) -> word_polynomialset_t< Ctx >
The polynomialset of words of a labelset (not necessarily on words itself).
auto path_monomial(const Aut &aut, const std::vector< transition_t_of< Aut >> &path, state_t_of< Aut > src=Aut::element_type::pre(), state_t_of< Aut > dst=Aut::element_type::post()) -> boost::optional< typename detail::word_polynomialset_t< context_t_of< Aut >>::monomial_t >
Given a path (typically computed by lightest_path), the corresponding monomial (label, weight).
path_t path(const AnyAut &aut, const path_t &path, state_t_of< Aut > src=Aut::element_type::pre(), state_t_of< Aut > dst=Aut::element_type::post())
typename valueset_t::value_t value_t
paths_t operator()(state_t src, state_t dst, unsigned k)
path_t compute_lightest_path(const AnyAut &aut, state_t_of< Aut > src=Aut::element_type::pre(), state_t_of< Aut > dst=Aut::element_type::post())
std::vector< transition_t_of< Aut > > lightest_path(const Aut &aut, state_t_of< Aut > source, state_t_of< Aut > dest, a_star_tag)
auto make_dijkstra_impl(const Aut &aut, const ValueSet &vs, Mul mul)