4 #include <boost/range/irange.hpp>
17 template <Automaton Aut>
45 ss_.emplace(input->pre());
46 ss_.emplace(input->post());
52 static auto res =
symbol{
"filter_automaton<"
59 o <<
"filter_automaton<";
60 aut_->print_set(o, fmt);
64 bool state_has_name(state_t s) const
67 return aut_->state_has_name(s);
70 bool has_state(state_t s) const
72 return has(ss_, s) && aut_->has_state(s);
75 std::ostream& print_state_name(state_t s, std::ostream& o,
77 bool delimit = false) const
80 return aut_->print_state_name(s, o, fmt, delimit);
83 size_t num_states() const
85 return states().size();
88 size_t num_all_states() const
90 return all_states().size();
93 template <typename Pred>
94 auto all_states(Pred pred) const
96 return aut_->all_states([this, pred](state_t s)
98 return pred(s) && has(ss_, s);
102 auto all_states() const
104 return all_states([](state_t) { return true; });
109 return all_states([this](state_t s)
111 // When transposing post() < pre().
112 return std::max(pre(), post()) < s;
118 auto all_transitions() const
120 return vcsn::detail::all_transitions
122 [this](transition_t t)
124 return (has(ss_, aut_->src_of(t))
125 && has(ss_, aut_->dst_of(t)));
130 auto all_out(state_t s) const
132 return vcsn::detail::all_out(aut_, s,
133 [this](transition_t t)
135 return has(ss_, aut_->dst_of(t));
140 auto all_in(state_t s) const
142 return vcsn::detail::all_in(aut_, s,
143 [this](transition_t t)
145 return has(ss_, aut_->src_of(t));
149 fresh_automaton_t_of<automaton_t>
152 return ::vcsn::copy(aut_, ss_);
165 template <Automaton Aut>
166 using filter_automaton =
167 std::shared_ptr<detail::filter_automaton_impl<Aut>>;
170 template <Automaton Aut>
171 filter_automaton<Aut>
172 filter(const Aut& aut, const std::unordered_set<state_t_of<Aut>>& ss)
174 return make_shared_ptr<filter_automaton<Aut>>(aut, ss);
182 template <Automaton Aut, typename Unsigneds>
184 filter(const automaton& aut, const std::vector<unsigned>& states)
186 const auto& a = aut->as<Aut>();
187 auto ss = std::unordered_set<state_t_of<Aut>>{};
188 // FIXME: this is wrong, of course.
191 return make_automaton(::vcsn::filter(a, ss));
std::unordered_set< state_t > states_t
States set that we want to filter.
std::ostream & print_set(std::ostream &o, format fmt={}) const
Hide some states of an automaton.
state_t_of< automaton_t > state_t
transition_t_of< automaton_t > transition_t
auto src_of(Args &&...args) const -> decltype(aut_-> src_of(std::forward< Args >(args)...))
static constexpr auto pre(Args &&...args) -> decltype(element_type::pre(std::forward< Args >(args)...))
label_t_of< automaton_t > label_t
static constexpr auto post(Args &&...args) -> decltype(element_type::post(std::forward< Args >(args)...))
automaton_t aut_
The wrapped automaton, possibly const.
An input/output format for valuesets.
states_t ss_
The states we keep.
typename detail::state_t_of_impl< base_t< ValueSet >>::type state_t_of
static symbol sname()
Static name.
auto dst_of(Args &&...args) const -> decltype(aut_-> dst_of(std::forward< Args >(args)...))
boost::flyweight< std::string, boost::flyweights::no_tracking, boost::flyweights::intermodule_holder > symbol
An internalized string.
Aggregate an automaton, and forward calls to it.
typename detail::transition_t_of_impl< base_t< ValueSet >>::type transition_t_of
typename detail::label_t_of_impl< base_t< ValueSet >>::type label_t_of
std::vector< transition_t > tr_cont_t
filter_automaton_impl(const automaton_t &input, const states_t &ss)