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 aut_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);
185 return {
aut_->pre(),
false};
194 aut_out()->new_transition_copy(s,
214 auto lb =
pmap_().find(sn);
215 if (lb ==
pmap_().end())
219 aut_->set_lazy(s,
true);
220 lb =
pmap_().insert(lb, {sn, s});
221 todo_.emplace_back(sn, s);
245 std::deque<std::pair<state_name_t, state_t>>
todo_;
249 template <Automaton Aut>
251 = std::shared_ptr<insplit_automaton_impl<Aut>>;
254 template <Automaton Aut>
259 return make_shared_ptr<insplit_automaton<Aut>>(aut);
264 template <Automaton Aut>
267 -> std::enable_if_t<labelset_t_of<Aut>::has_one(),
278 template <Automaton Aut>
281 -> std::enable_if_t<!labelset_t_of<Aut>::has_one(),
290 template <Automaton Aut>
301 template <Automaton Aut,
typename Bool>
305 const auto& a = aut->
as<Aut>();
std::ostream & print_state_name(state_t s, std::ostream &o, format fmt={}, bool delimit=false) const
static constexpr auto pre(Args &&...args) -> decltype(element_type::pre(std::forward< Args >(args)...))
bool is_spontaneous_(transition_t t) const
Whether transition t is labeled by one.
automaton_t in_
The input automaton.
state_t_of< automaton_t > state_t
typename super_t::label_t label_t
auto all_out(const state_t s) const
fresh_automaton_t_of< Aut > out_automaton_t
map_t & pmap_()
A map from original state and status (spontaneous or proper state) to result state.
Aggregate an automaton, and forward calls to it.
typename labelset_t::value_t label_t
An input/output format for valuesets.
typename bimap_t::left_map map_t
typename super_t::state_t state_t
std::ostream & print_set(std::ostream &o, format fmt={}) const
typename Aut::element_type::template fresh_automaton_t< Context > fresh_automaton_t_of
Given an automaton type, the type of its copies.
typename bimap_t::right_map origins_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)...
out_automaton_t & aut_out()
boost::flyweight< std::string, boost::flyweights::no_tracking, boost::flyweights::intermodule_holder > symbol
An internalized string.
void add_insplit_transitions_(const state_t s, const state_name_t &sn)
Split the original outgoing transitions to the insplit states.
typename detail::labelset_t_of_impl< base_t< ValueSet >>::type labelset_t_of
bool lazy_
Whether the computation is lazy.
std::pair< state_t, bool > state_name_t
Tuple of states of input automata.
auto label_of(Args &&...args) const -> decltype(aut_-> label_of(std::forward< Args >(args)...))
boost::bimap< boost::bimaps::unordered_set_of< state_name_t >, boost::bimaps::unordered_set_of< state_t >> bimap_t
Print as rich UTF-8 text, escaped.
automaton insplit(const automaton &aut, bool lazy)
Bridge.
static constexpr auto post(Args &&...args) -> decltype(element_type::post(std::forward< Args >(args)...))
transition_t_of< automaton_t > transition_t
typename super_t::transition_t transition_t
weightset_t_of< Aut > weightset_t
void initialize_insplit_()
auto make_insplit_automaton(const Aut &aut) -> insplit_automaton< Aut >
Build an insplit automaton from an automaton.
void complete_(const state_t s) const
Complete a lazy state: find its outgoing transitions.
std::deque< std::pair< state_name_t, state_t > > todo_
Worklist of state tuples.
AutOut make_fresh_automaton(const AutIn &model)
Create an empty, mutable, automaton, based on another one.
const automaton_t & aut_in() const
The input automaton.
Insplit automaton decorator.
detail::insplit_automaton< Aut > insplit_automaton
An insplit automaton as a shared pointer.
void insplit(bool lazy=false)
Insplit the automaton.
const origins_t & origins() const
A map from result state to original state and status (spontaneous or proper state).
bimap_t bimap_
Map (input-state, status) -> result-state.
auto print_state(Args &&...args) const -> decltype(aut_-> print_state(std::forward< Args >(args)...))
const out_automaton_t & aut_out() const
typename detail::weightset_t_of_impl< base_t< ValueSet >>::type weightset_t_of
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.
state_name_t pre_() const
automaton_t aut_
The wrapped automaton, possibly const.
std::shared_ptr< insplit_automaton_impl< Aut >> insplit_automaton
An insplit automaton as a shared pointer.
auto & as()
Extract wrapped typed automaton.
static constexpr bool state_has_name(state_t)
insplit_automaton_impl(const Aut &aut)
auto all_out(Args &&...args) const -> decltype(aut_-> all_out(std::forward< Args >(args)...))