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;
72 const boost::optional<states_t>& ss = {},
73 const boost::optional<transitions_t>& ts = {})
78 ss_.set(input->pre());
79 ss_.set(input->post());
85 static auto res =
symbol{
"filter_automaton<" 92 o <<
"filter_automaton<";
93 aut_->print_set(o, fmt);
97 bool state_has_name(state_t s) const 100 return aut_->state_has_name(s); 103 bool has_state(state_t s) const 105 return has(ss_, s) && aut_->has_state(s); 108 using super_t::has_transition; 110 template <bool U = Trans> 111 std::enable_if_t<U, bool> 112 has_transition(transition_t t) const 114 return has(this->cont_, t) && aut_->has_transition(t); 117 template <bool U = Trans> 118 std::enable_if_t<!U, bool> 119 has_transition(transition_t t) const 121 return aut_->has_transition(t); 124 std::ostream& print_state_name(state_t s, std::ostream& o, 126 bool delimit = false) const 129 return aut_->print_state_name(s, o, fmt, delimit); 132 size_t num_states() const 134 return states().size(); 137 size_t num_all_states() const 139 return all_states().size(); 142 template <typename Pred> 143 auto all_states(Pred pred) const 145 return aut_->all_states([this, pred](state_t s) 147 return pred(s) && has(ss_, s); 151 auto all_states() const 153 return all_states([](state_t) { return true; }); 158 return all_states([this](state_t s) 160 // When transposing post() < pre(). 161 return std::max(pre(), post()) < s; 167 auto all_transitions() const 169 return vcsn::detail::all_transitions 171 [this](transition_t t) 173 return has_transition(t) 174 && has(ss_, aut_->src_of(t)) 175 && has(ss_, aut_->dst_of(t)); 180 auto all_out(state_t s) const 182 return vcsn::detail::all_out(aut_, s, 183 [this](transition_t t) 185 return has_transition(t) 186 && has(ss_, aut_->dst_of(t)); 191 auto all_in(state_t s) const 193 return vcsn::detail::all_in(aut_, s, 194 [this](transition_t t) 196 return has_transition(t) 197 && has(ss_, aut_->src_of(t)); 202 hide_state(state_t s) 210 template <bool U = Trans> 211 std::enable_if_t<U, void> 212 hide_transition(transition_t t) 214 if (t < optional_container_t::cont_.size()) 215 optional_container_t::cont_.reset(t); 220 unhide_state(state_t s) 228 template <bool U = Trans> 229 std::enable_if_t<U, void> 230 unhide_transition(transition_t t) 232 if (t < optional_container_t::cont_.size()) 233 optional_container_t::cont_.set(t); 243 ss_.set(aut_->pre()); 244 ss_.set(aut_->post()); 256 template <bool U = Trans> 257 std::enable_if_t<U, void> 258 unhide_all_transition() 260 optional_container_t::cont_.set(); 263 template <bool U = Trans> 264 std::enable_if_t<U, void> 265 hide_all_transition() 267 optional_container_t::cont_.reset(); 270 fresh_automaton_t_of<automaton_t> 273 auto state_filter = [this](state_t_of<automaton_t> s) 275 return has(this->ss_, s); 277 auto transition_filter = [this](transition_t_of<automaton_t> t) 279 return this->has_transition(t); 281 return ::vcsn::copy(aut_, state_filter, transition_filter); 294 template <Automaton Aut, bool Trans = false> 295 using filter_automaton = 296 std::shared_ptr<detail::filter_automaton_impl<Aut, Trans>>; 299 template <Automaton Aut, bool Trans = false> 300 filter_automaton<Aut, Trans> 301 filter(const Aut& aut, 302 boost::optional<dynamic_bitset> ss = {}, 303 boost::optional<dynamic_bitset> ts = {}) 305 return make_shared_ptr<filter_automaton<Aut, Trans>>(aut, ss, ts); 308 template <Automaton Aut> 309 filter_automaton<Aut> 310 filter(const Aut& aut, const std::unordered_set<state_t_of<Aut>>& ss) 312 return filter(aut, make_dynamic_bitset(ss, states_size(aut))); 320 template <Automaton Aut, typename Unsigneds> 322 filter(const automaton& aut, const std::vector<unsigned>& states) 324 const auto& a = aut->as<Aut>(); 325 // FIXME: This is a problem for lazy automaton. 326 auto size = states_size(a); 327 auto ss = dynamic_bitset(size); 331 return ::vcsn::filter(a, ss);
size_t transitions_size(const Aut &aut)
The largest transition number, plus one.
Aggregate an automaton, and forward calls to it.
state_t_of< automaton_t > state_t
boost::flyweight< std::string, boost::flyweights::no_tracking, boost::flyweights::intermodule_holder > symbol
An internalized string.
typename detail::state_t_of_impl< base_t< ValueSet > >::type state_t_of
optional_container(Args &&...)
std::vector< std::pair< string_t, string_t > > transitions_t
transition_t_of< automaton_t > transition_t
size_t states_size(const Aut &aut)
The largest state number, plus one.
std::vector< transition_t > tr_cont_t
std::unordered_set< state_t_of< Aut > > states_t
An input/output format for valuesets.
dynamic_bitset transitions_t
typename detail::transition_t_of_impl< base_t< ValueSet > >::type transition_t_of
std::ostream & print_set(std::ostream &o, format fmt={}) const
boost::dynamic_bitset<> dynamic_bitset
optional_container(Args &&... args)
Enables or not the presence of a container in a class.
label_t_of< automaton_t > label_t
Hide some states of an automaton.
static symbol sname()
Static name.
filter_automaton_impl(const automaton_t &input, const boost::optional< states_t > &ss={}, const boost::optional< transitions_t > &ts={})
typename detail::label_t_of_impl< base_t< ValueSet > >::type label_t_of