3 #include <unordered_map> 5 #include <boost/bimap.hpp> 6 #include <boost/bimap/unordered_set_of.hpp> 10 #include <vcsn/algos/fwd.hh> 28 template <Automaton Aut>
33 "insplit: the labelset must have a one label");
53 = boost::bimap<boost::bimaps::unordered_set_of<state_name_t>,
54 boost::bimaps::unordered_set_of<state_t>>;
55 using map_t =
typename bimap_t::left_map;
69 o <<
"insplit_automaton<";
70 return aut_->print_set(o, fmt) <<
">";
91 while (!
todo_.empty())
93 const auto& p =
todo_.front();
101 format fmt = {},
bool delimit =
false)
105 auto i = orig.find(s);
112 in_->print_state_name(i->second.first, o, fmt,
true);
115 o << (i->second.second ?
"" :
"\\not ") <<
"\\varepsilon";
117 o << (i->second.second ?
"ε" :
"!ε");
119 o << (i->second.second ?
"\\e" :
"!\\e");
129 auto&
self =
const_cast<self_t&
>(*this);
132 self.aut_->set_lazy(s,
false);
133 self.add_insplit_transitions_(s, sn);
142 return aut_->all_out(s);
166 return {
aut_->pre(),
false};
174 for (
auto t :
in_->all_out(std::get<0>(sn)))
175 aut_->new_transition_copy(s,
184 return in_->labelset()->is_one(
in_->label_of(t));
195 auto lb =
pmap_().find(sn);
196 if (lb ==
pmap_().end())
200 aut_->set_lazy(s,
true);
201 lb =
pmap_().insert(lb, {sn, s});
202 todo_.emplace_back(sn, s);
226 std::deque<std::pair<state_name_t, state_t>>
todo_;
230 template <Automaton Aut>
232 = std::shared_ptr<insplit_automaton_impl<Aut>>;
235 template <Automaton Aut>
240 return make_shared_ptr<insplit_automaton<Aut>>(aut);
245 template <Automaton Aut>
248 -> std::enable_if_t<labelset_t_of<Aut>::has_one(),
259 template <Automaton Aut>
262 -> std::enable_if_t<!labelset_t_of<Aut>::has_one(),
271 template <Automaton Aut>
282 template <Automaton Aut,
typename Bool>
286 const auto& a = aut->
as<Aut>();
auto all_out(const state_t s) const
void add_insplit_transitions_(const state_t s, const state_name_t &sn)
Split the original outgoing transitions to the insplit states.
typename bimap_t::left_map map_t
typename detail::weightset_t_of_impl< base_t< ValueSet > >::type weightset_t_of
std::ostream & print_state_name(state_t s, std::ostream &o, format fmt={}, bool delimit=false) const
auto print_state(Args &&... args) const -> decltype(aut_-> print_state(std::forward< Args >(args)...))
detail::insplit_automaton< Aut > insplit_automaton
An insplit automaton as a shared pointer.
boost::flyweight< std::string, boost::flyweights::no_tracking, boost::flyweights::intermodule_holder > symbol
An internalized string.
automaton_t aut_
The wrapped automaton, possibly const.
auto insplit(Aut aut, bool lazy=false) -> std::enable_if_t< labelset_t_of< Aut >::has_one(), decltype(make_insplit_automaton(aut))>
Insplit an automaton with possible spontaneous transitions.
auto all_out(Args &&... args) const -> decltype(aut_-> all_out(std::forward< Args >(args)...))
void initialize_insplit_()
void insplit(bool lazy=false)
Insplit the automaton.
map_t & pmap_()
A map from original state and status (spontaneous or proper state) to result state.
Print as rich UTF-8 text, escaped.
An input/output format for valuesets.
typename bimap_t::right_map origins_t
void complete_(const state_t s) const
Complete a lazy state: find its outgoing transitions.
std::shared_ptr< insplit_automaton_impl< Aut > > insplit_automaton
An insplit automaton as a shared pointer.
std::ostream & print_set(std::ostream &o, format fmt={}) const
automaton insplit(const automaton &aut, bool lazy)
Bridge.
typename super_t::state_t state_t
typename detail::labelset_t_of_impl< base_t< ValueSet > >::type labelset_t_of
bool lazy_
Whether the computation is lazy.
Insplit automaton decorator.
insplit_automaton_impl(const Aut &aut)
std::pair< state_t, bool > state_name_t
Tuple of states of input automata.
fresh_automaton_t_of< Aut > out_automaton_t
automaton_t in_
The input automaton.
const origins_t & origins() const
A map from result state to original state and status (spontaneous or proper state).
auto & as()
Extract wrapped typed automaton.
AutOut make_fresh_automaton(const AutIn &model)
Create an empty, mutable, automaton, based on another one.
Aggregate an automaton, and forward calls to it.
typename super_t::label_t label_t
weightset_t_of< Aut > weightset_t
typename labelset_t::value_t label_t
static constexpr bool state_has_name(state_t)
auto make_insplit_automaton(const Aut &aut) -> insplit_automaton< Aut >
Build an insplit automaton from an automaton.
bool is_spontaneous_(transition_t t) const
Whether transition t is labeled by one.
boost::bimap< boost::bimaps::unordered_set_of< state_name_t >, boost::bimaps::unordered_set_of< state_t > > bimap_t
typename super_t::transition_t transition_t
state_t state(const state_name_t &sn)
The state in the insplit corresponding to a state and a status (spontaneous or proper state)...
std::deque< std::pair< state_name_t, state_t > > todo_
Worklist of state tuples.
typename Aut::element_type::template fresh_automaton_t< Context > fresh_automaton_t_of
Given an automaton type, the type of its copies.
transition_t_of< automaton_t > transition_t
state_name_t pre_() const
bimap_t bimap_
Map (input-state, status) -> result-state.
state_t_of< automaton_t > state_t