5 #include <boost/heap/fibonacci_heap.hpp>
38 template <
Automaton Aut,
typename ValueSet,
39 typename Mul,
typename GetValue>
51 using value_t =
typename valueset_t::value_t;
54 Mul mul, GetValue get_value)
80 using heap_t = boost::heap::fibonacci_heap<profile>;
90 template <Automaton AnyAut>
98 for (
auto t = path[dst];
99 t != aut->null_transition();
100 t = path[aut->src_of(t)])
103 if (aut->src_of(t) == src)
106 std::reverse(
res.begin(),
res.end());
116 template <Automaton AnyAut>
123 return std::move(algo(src, dst));
135 for (
unsigned i = 1
u; i < k; i++)
137 const auto& prev =
res[i - 1];
138 for (
unsigned j = 0
u; j < prev.size(); j++)
140 auto filter_aut = filter<automaton_t, true>(
aut_);
141 filter_aut->unhide_all_states();
142 filter_aut->unhide_all_transition();
143 auto spur_node = filter_aut->src_of(prev[j]);
144 auto root_path =
path_t(prev.begin(), prev.begin() + j);
146 for (
const auto& selected_path:
res)
147 if (j < selected_path.size())
149 auto diff = std::mismatch(root_path.begin(), root_path.end(),
150 selected_path.begin(), selected_path.begin() + j);
151 if (diff.first == root_path.end()
152 && filter_aut->has_transition(selected_path[j]))
153 filter_aut->hide_transition(selected_path[j]);
156 for (
auto t: root_path)
157 if (t != filter_aut->null_transition()
158 && filter_aut->src_of(t) != spur_node
159 && filter_aut->src_of(t) !=
aut_->pre()
160 && filter_aut->has_state(filter_aut->src_of(t)))
161 filter_aut->hide_state(filter_aut->src_of(t));
166 =
path(filter_aut, shortest_path, spur_node, dst);
167 root_path.insert(root_path.end(),
168 spur_path.begin(), spur_path.end());
169 if (!root_path.empty()
170 && filter_aut->src_of(root_path.front()) == src
171 && filter_aut->dst_of(root_path.back()) == dst)
173 bool already_found =
false;
174 for (
const auto&
profile: heap)
177 if (root_path.size() == selected_path.size())
179 auto diff = std::mismatch(root_path.begin(), root_path.end(),
180 selected_path.begin(), selected_path.end());
181 if (diff.first == root_path.end())
183 already_found =
true;
197 res.push_back(heap.top().path_);
209 template <Automaton Aut,
typename ValueSet,
typename Mul,
typename GetValue>
211 make_yen(
const Aut& aut,
const ValueSet& vs, Mul mul, GetValue get_value)
214 (aut, vs, mul, get_value));
219 template <Automaton Aut>
220 std::vector<path_t_of<Aut>>
226 return aut->weightset()->mul(lhs, aut->weight_of(t));
228 auto get_value = [](
auto m) {
return m.second; };
230 return yen(src, dst, k);
239 template <Automaton Aut>
240 predecessors_t_of<Aut>
245 if (t != aut->null_transition())
246 res[aut->dst_of(t)] = t;
250 template <Automaton Aut>
251 predecessors_t_of<Aut>
257 = paths.empty() ? std::vector<transition_t_of<Aut>>() : paths.front();
profile(const path_t &path, const valueset_t &vs, const value_t &v)
std::vector< path_t_of< Aut > > k_lightest_path(const Aut &aut, state_t_of< Aut > src, state_t_of< Aut > dst, unsigned k)
Yen implementation of the K lightest automaton algorithm.
mutable_automaton< Context > u(const Context &ctx, unsigned n)
The Brzozowski universal witness.
paths_t operator()(state_t src, state_t dst, unsigned k)
path_t_of< AnyAut > path(const AnyAut &aut, const predecessors_t_of< AnyAut > &path, state_t_of< AnyAut > src=AnyAut::element_type::pre(), state_t_of< AnyAut > dst=AnyAut::element_type::post())
Transform a map transition_t -> transition_t representing the predecessors of each transition into a ...
weight_t_of< automaton_t > weight_t
predecessors_t_of< Aut > format_lightest(const Aut &aut, const std::vector< transition_t_of< Aut >> &path)
A state-indexed vector of predecessor transitions from the path path.
state_t_of< automaton_t > state_t
auto make_word_polynomialset(const Ctx &ctx) -> word_polynomialset_t< Ctx >
The polynomialset of words of a labelset (not necessarily on words itself).
size_t states_size(const Aut &aut)
The largest state number, plus one.
predecessors_t_of< AnyAut > compute_lightest_path(const AnyAut &aut, state_t_of< AnyAut > src=Aut::element_type::pre(), state_t_of< AnyAut > dst=Aut::element_type::post())
Compute a lightest path on a part of the automaton.
bool operator<(const profile &rhs) const
typename detail::weight_t_of_impl< base_t< ValueSet >>::type weight_t_of
transition_t_of< automaton_t > transition_t
typename detail::state_t_of_impl< base_t< ValueSet >>::type state_t_of
typename valueset_t::value_t value_t
auto make_yen(const Aut &aut, const ValueSet &vs, Mul mul, GetValue get_value)
yen_impl(const automaton_t &aut, const ValueSet &vs, Mul mul, GetValue get_value)
typename detail::transition_t_of_impl< base_t< ValueSet >>::type transition_t_of
std::vector< path_t > paths_t
auto make_dijkstra_impl(const Aut &aut, const ValueSet &vs, Mul mul)
path_t_of< automaton_t > path_t
std::vector< transition_t_of< Aut >> path_t_of
A list of transitions representing a path.
boost::heap::fibonacci_heap< profile > heap_t
std::vector< transition_t_of< Aut >> predecessors_t_of
A state-indexed vector of predecessor transitions from the path path.
context_t_of< automaton_t > context_t
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).
typename detail::context_t_of_impl< base_t< ValueSet >>::type context_t_of
std::vector< transition_t_of< Aut > > lightest_path(const Aut &aut, state_t_of< Aut > source, state_t_of< Aut > dest, a_star_tag)
Paths in filesystems, i.e., file names.