3 #include <unordered_map>
5 #include <boost/bimap.hpp>
6 #include <boost/bimap/unordered_set_of.hpp>
10 #include <vcsn/algos/fwd.hh>
21 template <Automaton Aut,
bool HasOne>
43 using bimap_t = boost::bimap<boost::bimaps::unordered_set_of<state_name_t>,
44 boost::bimaps::unordered_set_of<state_t>>;
45 using map_t =
typename bimap_t::left_map;
58 o <<
"insplit_automaton<";
59 return aut_->print_set(o, fmt) <<
">";
79 while (!
todo_.empty())
81 const auto& p =
todo_.front();
95 format fmt = {},
bool delimit =
false)
99 auto i = orig.find(s);
106 aut_in()->print_state_name(i->second.first, o, fmt,
true);
109 o << (i->second.second ?
"" :
"\\not ") <<
"\\varepsilon";
111 o << (i->second.second ?
"ε" :
"!ε");
113 o << (i->second.second ?
"\\e" :
"!\\e");
141 -> decltype(
aut_->all_out(s))
145 return aut_->all_out(s);
185 return {
aut_->pre(),
false};
192 aut_out()->new_transition_copy(st,
217 auto lb =
pmap_().find(state);
218 if (lb ==
pmap_().end())
222 todo_.emplace_back(state, s);
252 std::deque<std::pair<state_name_t, state_t>>
todo_;
255 template <Automaton Aut>
289 template<Automaton Aut>
292 -> std::enable_if_t<labelset_t_of<Aut>::has_one(),
300 template <Automaton Aut>
301 std::enable_if_t<!labelset_t_of<Aut>::has_one(), Aut>
310 template <Automaton Aut>
312 = std::shared_ptr<detail::insplit_automaton_impl<Aut, labelset_t_of<Aut>::has_one()>>;
314 template <Automaton Aut>
319 return make_shared_ptr<insplit_automaton<Aut>>(aut);
322 template <Automaton Aut>
333 template <Automaton Aut>
347 template <Automaton Aut,
typename Bool>
351 const auto& a = aut->as<Aut>();
insplit_automaton_impl(const Aut &aut)
std::shared_ptr< detail::insplit_automaton_impl< Aut, labelset_t_of< Aut >::has_one()>> insplit_automaton
A compose automaton as a shared pointer.
void complete_(state_t s) const
Complete a state: find its outgoing transitions.
std::ostream & print_set(std::ostream &o, format fmt={}) const
automaton make_automaton(const Aut &aut)
Build a dyn::automaton.
Print as rich UTF-8 text, escaped.
state_name_t pre_() const
automaton_t in_
The input automaton.
typename detail::weightset_t_of_impl< base_t< ValueSet >>::type weightset_t_of
insplit_automaton_impl(const Aut &aut)
transition_t_of< automaton_t > transition_t
state_t_of< automaton_t > state_t
typename super_t::label_t label_t
bool is_lazy(state_t s) const
Whether a given state's outgoing transitions have been computed.
static constexpr auto pre(Args &&...args) -> decltype(element_type::pre(std::forward< Args >(args)...))
static constexpr auto post(Args &&...args) -> decltype(element_type::post(std::forward< Args >(args)...))
auto insplit(const Aut &aut) -> decltype(detail::insplit(aut))
std::deque< std::pair< state_name_t, state_t > > todo_
Worklist of state tuples.
map_t & pmap_()
A map from original state and status (spontaneous or proper state) to result state.
boost::bimap< boost::bimaps::unordered_set_of< state_name_t >, boost::bimaps::unordered_set_of< state_t >> bimap_t
const automaton_t & aut_out() const
out_automaton_t & aut_out()
automaton_t aut_
The wrapped automaton, possibly const.
typename detail::labelset_t_of_impl< base_t< ValueSet >>::type labelset_t_of
auto insplit(Aut &aut) -> std::enable_if_t< labelset_t_of< Aut >::has_one(), decltype(make_insplit_automaton(aut))>
An input/output format for valuesets.
void add_insplit_transitions(const state_t st, const state_name_t &psrc)
auto insplit_lazy(const Aut &aut) -> decltype(make_insplit_automaton(aut))
bool exists(state_t st, bool epsilon)
static constexpr bool state_has_name(state_t)
typename super_t::transition_t transition_t
bimap_t bimap_
Map input-state, status -> result-state.
typename super_t::state_t state_t
auto print_state(Args &&...args) const -> decltype(aut_-> print_state(std::forward< Args >(args)...))
typename labelset_t::value_t label_t
weightset_t_of< Aut > weightset_t
boost::flyweight< std::string, boost::flyweights::no_tracking, boost::flyweights::intermodule_holder > symbol
An internalized string.
Aggregate an automaton, and forward calls to it.
typename Aut::element_type::template fresh_automaton_t< Context > fresh_automaton_t_of
Given an automaton type, the type of its copies.
std::shared_ptr< detail::automaton_base > automaton
bool is_spontaneous(transition_t tr)
std::ostream & print_state_name(state_t s, std::ostream &o, format fmt={}, bool delimit=false) const
state_t state(const state_name_t &state)
The state in the insplit corresponding to a state and a status (spontaneous or proper state)...
const automaton_t & aut_in() const
auto all_out(Args &&...args) const -> decltype(aut_-> all_out(std::forward< Args >(args)...))
ATTRIBUTE_PURE bool has(const boost::container::flat_set< Key, Compare, Allocator > &s, const Key &e)
Whether e is member of s.
AutOut make_fresh_automaton(const AutIn &model)
Create an empty, mutable, automaton, based on another one.
void add_transitions(const state_t src, const state_name_t &psrc)
typename bimap_t::right_map origins_t
void initialize_insplit()
void insplit(bool lazy=false)
const out_automaton_t & aut_out() const
typename bimap_t::left_map map_t
automaton insplit(const automaton &aut, bool lazy)
Bridge.
auto make_insplit_automaton(const Aut &aut) -> insplit_automaton< Aut >
std::set< state_t > done_
When performing the lazy construction, list of states that have been completed (i.e., their outgoing transitions have been computed).
auto all_out(state_t s) const -> decltype(aut_->all_out(s))
std::pair< state_t, bool > state_name_t
Tuple of states of input automata.
fresh_automaton_t_of< Aut > out_automaton_t
const weightset_t & ws_
The resulting weightset.
auto label_of(Args &&...args) const -> decltype(aut_-> label_of(std::forward< Args >(args)...))
const origins_t & origins() const
A map from result state to original state and status (spontaneous or proper state).