5 #include <boost/range/irange.hpp> 6 #include <boost/optional.hpp> 11 #include <vcsn/dyn/fwd.hh> 23 template <
typename Container,
bool Has = false>
27 template <
typename... Args>
32 template <
typename Container>
36 template <
typename... Args>
47 template <Automaton Aut,
bool Trans = false>
68 using super_t::src_of;
69 using super_t::dst_of;
77 const boost::optional<states_t>& ss = {},
78 const boost::optional<transitions_t>& ts = {})
87 ss_.set(input->pre());
88 ss_.set(input->post());
92 static_if<Trans>([&ts](
auto&
self) {
94 self.unhide_all_transitions();
101 static auto res =
symbol{
"filter_automaton<" 108 o <<
"filter_automaton<";
109 aut_->print_set(o, fmt);
113 bool state_has_name(state_t s) const 116 return aut_->state_has_name(s); 119 bool has_state(state_t s) const 121 return has(ss_, s) && aut_->has_state(s); 124 using super_t::has_transition; 126 template <bool U = Trans> 127 std::enable_if_t<U, bool> 128 has_transition(transition_t t) const 130 return has(this->cont_, t) && aut_->has_transition(t); 133 template <bool U = Trans> 134 std::enable_if_t<!U, bool> 135 has_transition(transition_t t) const 137 return aut_->has_transition(t); 140 std::ostream& print_state_name(state_t s, std::ostream& o, 142 bool delimit = false) const 145 return aut_->print_state_name(s, o, fmt, delimit); 148 size_t num_states() const 150 return states().size(); 153 size_t num_all_states() const 155 return all_states().size(); 158 template <typename Pred> 159 auto all_states(Pred pred) const 161 return aut_->all_states([this, pred](state_t s) 163 return pred(s) && has(ss_, s); 167 auto all_states() const 169 return all_states([](state_t) { return true; }); 174 return all_states([this](state_t s) 176 // When transposing post() < pre(). 177 return std::max(pre(), post()) < s; 183 auto all_transitions() const 185 return vcsn::detail::all_transitions 187 [this](transition_t t) 189 return has_transition(t) 190 && has(ss_, aut_->src_of(t)) 191 && has(ss_, aut_->dst_of(t)); 196 auto all_out(state_t s) const 198 return vcsn::detail::all_out(aut_, s, 199 [this](transition_t t) 201 return has_transition(t) 202 && has(ss_, aut_->dst_of(t)); 207 auto all_in(state_t s) const 209 return vcsn::detail::all_in(aut_, s, 210 [this](transition_t t) 212 return has_transition(t) 213 && has(ss_, aut_->src_of(t)); 218 hide_state(state_t s) 226 template <bool U = Trans> 227 std::enable_if_t<U, void> 228 hide_transition(transition_t t) 230 if (t < optional_container_t::cont_.size()) 231 optional_container_t::cont_.reset(t); 236 unhide_state(state_t s) 244 template <bool U = Trans> 245 std::enable_if_t<U, void> 246 unhide_transition(transition_t t) 248 if (t < optional_container_t::cont_.size()) 249 optional_container_t::cont_.set(t); 259 ss_.set(aut_->pre()); 260 ss_.set(aut_->post()); 272 template <bool U = Trans> 273 std::enable_if_t<U, void> 274 unhide_all_transitions() 276 optional_container_t::cont_.set(); 279 template <bool U = Trans> 280 std::enable_if_t<U, void> 281 hide_all_transitions() 283 optional_container_t::cont_.reset(); 286 fresh_automaton_t_of<automaton_t> 289 auto state_filter = [this](state_t_of<automaton_t> s) 291 return has(this->ss_, s); 293 auto transition_filter = [this](transition_t_of<automaton_t> t) 295 return this->has_transition(t); 297 return ::vcsn::copy(aut_, state_filter, transition_filter); 310 template <Automaton Aut, bool Trans = false> 311 using filter_automaton = 312 std::shared_ptr<detail::filter_automaton_impl<Aut, Trans>>; 319 template <Automaton Aut, bool Trans = false> 320 filter_automaton<Aut, Trans> 321 filter(const Aut& aut, 322 boost::optional<dynamic_bitset> ss = {}, 323 boost::optional<dynamic_bitset> ts = {}) 325 return make_shared_ptr<filter_automaton<Aut, Trans>>(aut, ss, ts); 332 template <Automaton Aut> 333 filter_automaton<Aut> 334 filter(const Aut& aut, const std::unordered_set<state_t_of<Aut>>& ss) 336 return filter(aut, make_dynamic_bitset(ss, states_size(aut))); 344 template <Automaton Aut, typename Unsigneds> 346 filter(const automaton& aut, const std::vector<unsigned>& states) 348 const auto& a = aut->as<Aut>(); 349 // FIXME: This is a problem for lazy automaton. 350 auto size = states_size(a); 351 auto ss = dynamic_bitset(size); 355 return ::vcsn::filter(a, ss); optional_container(Args &&... args)
typename detail::transition_t_of_impl< base_t< ValueSet > >::type transition_t_of
typename detail::state_t_of_impl< base_t< ValueSet > >::type state_t_of
size_t states_size(const Aut &aut)
The largest state number, plus one.
filter_automaton_impl(const automaton_t &input, const boost::optional< states_t > &ss={}, const boost::optional< transitions_t > &ts={})
Build a filtered view of an automaton.
state_t_of< automaton_t > state_t
label_t_of< automaton_t > label_t
boost::flyweight< std::string, boost::flyweights::no_tracking, boost::flyweights::intermodule_holder > symbol
An internalized string.
transition_t_of< automaton_t > transition_t
std::ostream & print_set(std::ostream &o, format fmt={}) const
An input/output format for valuesets.
dynamic_bitset transitions_t
typename detail::label_t_of_impl< base_t< ValueSet > >::type label_t_of
std::vector< transition_t > tr_cont_t
std::unordered_set< state_t_of< Aut > > states_t
boost::dynamic_bitset<> dynamic_bitset
Aggregate an automaton, and forward calls to it.
Enables or not the presence of a container in a class.
std::vector< std::pair< string_t, string_t > > transitions_t
size_t transitions_size(const Aut &aut)
The largest transition number, plus one.
Hide some states of an automaton.
optional_container(Args &&...)
static symbol sname()
Static name.