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