Vcsn  2.2
Be Rational
lightest-automaton.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <vcsn/algos/copy.hh>
4 #include <vcsn/algos/tags.hh>
6 #include <vcsn/dyn/automaton.hh>
7 #include <vcsn/dyn/fwd.hh>
8 #include <vcsn/misc/set.hh>
9 
10 namespace vcsn
11 {
20  template <Automaton Aut, typename Algo = auto_tag>
21  fresh_automaton_t_of<Aut>
22  lightest_automaton(const Aut& aut, Algo algo = {})
23  {
24  require(is_tropical<weightset_t_of<Aut>>(),
25  "lightest-automaton: require tropical weightset");
26  auto pred = lightest_path(aut, algo);
27  auto res = make_fresh_automaton(aut);
28  auto copy = make_copier(aut, res);
29  for (auto t = pred[aut->post()];
30  t != aut->null_transition();
31  t = pred[aut->src_of(t)])
32  copy(t);
33  return res;
34  }
35 
36  namespace dyn
37  {
38  namespace detail
39  {
41  template <Automaton Aut, typename String>
42  automaton
43  lightest_automaton(const automaton& aut, const std::string& algo)
44  {
45  const auto& a = aut->as<Aut>();
46  return make_automaton(::vcsn::lightest_automaton(a, algo));
47  }
48  }
49  }
50 }
automaton lightest_automaton(const automaton &aut, const std::string &algo)
Bridge.
automaton make_automaton(const Aut &aut)
Build a dyn::automaton.
Definition: automaton.hh:75
Definition: a-star.hh:8
void require(Bool b, Args &&...args)
If b is not verified, raise an error with args as message.
Definition: raise.hh:78
std::shared_ptr< detail::automaton_base > automaton
Definition: automaton.hh:69
AutOut make_fresh_automaton(const AutIn &model)
Create an empty, mutable, automaton, based on another one.
Definition: copy.hh:90
detail::copier< AutIn, AutOut > make_copier(const AutIn &in, AutOut &out, bool safe=true)
Build an automaton copier.
Definition: copy.hh:249
fresh_automaton_t_of< Aut > lightest_automaton(const Aut &aut, Algo algo={})
Lightest Automaton.
std::vector< transition_t_of< Aut > > lightest_path(const Aut &aut, state_t_of< Aut > source, state_t_of< Aut > dest, a_star_tag)
Definition: a-star.hh:151
auto copy(const AutIn &input, KeepState keep_state, KeepTrans keep_trans) -> decltype(keep_state(input->null_state()), keep_trans(input->null_transition()), make_fresh_automaton< AutIn, AutOut >(input))
A copy of input keeping only its states that are accepted by keep_state, and transitions accepted by ...
Definition: copy.hh:308