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");
43 using state_t =
typename super_t::state_t;
44 using label_t =
typename super_t::label_t;
48 using state_name_t = std::pair<state_t, bool>;
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;
56 using origins_t =
typename bimap_t::right_map;
69 o <<
"insplit_automaton<";
70 return aut_->print_set(o, fmt) <<
">";
88 initialize_insplit_();
91 while (!todo_.empty())
93 const auto& p = todo_.front();
94 this->add_insplit_transitions_(std::get<1>(p), std::get<0>(p));
101 format fmt = {},
bool delimit =
false)
104 const auto& orig = origins();
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");
127 void complete_(
const state_t s)
const
129 auto&
self =
const_cast<self_t&
>(*this);
130 const auto& orig = origins();
131 const state_name_t& sn = orig.at(s);
132 self.aut_->set_lazy(s,
false);
133 self.add_insplit_transitions_(s, sn);
140 if (lazy_ &&
aut_->is_lazy(s))
142 return aut_->all_out(s);
146 out_automaton_t& aut_out()
152 const out_automaton_t& aut_out()
const
159 const origins_t& origins()
const
172 void initialize_insplit_()
174 pmap_().insert({state_name_t(aut_in()->
pre(),
false),
176 pmap_().insert({state_name_t(aut_in()->
post(),
false),
178 todo_.emplace_back(pre_(), aut_out()->
pre());
180 aut_out()->set_lazy(aut_out()->
pre());
183 state_name_t pre_()
const
185 return {
aut_->pre(),
false};
190 void add_insplit_transitions_(
const state_t s,
191 const state_name_t& sn)
193 for (
auto t : aut_in()->
all_out(std::get<0>(sn)))
194 aut_out()->new_transition_copy(s,
195 state({aut_in()->dst_of(t),
196 is_spontaneous_(t)}),
203 return aut_in()->labelset()->is_one(aut_in()->
label_of(t));
212 state_t state(
const state_name_t& sn)
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);
242 mutable bimap_t bimap_;
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>();
Aut automaton_t
The type of automaton to wrap.
static constexpr auto pre(Args &&...args) -> decltype(element_type::pre(std::forward< Args >(args)...))
automaton insplit(const automaton &aut, bool lazy)
Bridge.
auto all_out(const Aut &aut, state_t_of< Aut > s)
Indexes of transitions leaving state s.
state_t_of< automaton_t > state_t
auto state_has_name(Args &&...args) const -> decltype(aut_-> state_has_name(std::forward< Args >(args)...))
auto print_set(Args &&...args) const -> decltype(aut_-> print_set(std::forward< Args >(args)...))
Aggregate an automaton, and forward calls to it.
typename labelset_t::value_t label_t
An input/output format for valuesets.
detail::insplit_automaton< Aut > insplit_automaton
An insplit automaton as a shared pointer.
auto all_out(Args &&...args) const -> decltype(aut_-> all_out(std::forward< Args >(args)...))
auto print_state_name(Args &&...args) const -> decltype(aut_-> print_state_name(std::forward< Args >(args)...))
AutOut make_fresh_automaton(const AutIn &model)
Create an empty, mutable, automaton, based on another one.
boost::flyweight< std::string, boost::flyweights::no_tracking, boost::flyweights::intermodule_holder > symbol
An internalized string.
typename detail::labelset_t_of_impl< base_t< ValueSet >>::type labelset_t_of
Print as rich UTF-8 text, escaped.
std::shared_ptr< insplit_automaton_impl< Aut >> insplit_automaton
An insplit automaton as a shared pointer.
static constexpr auto post(Args &&...args) -> decltype(element_type::post(std::forward< Args >(args)...))
transition_t_of< automaton_t > transition_t
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.
auto make_insplit_automaton(const Aut &aut) -> insplit_automaton< Aut >
Build an insplit automaton from an automaton.
auto print_state(Args &&...args) const -> decltype(aut_-> print_state(std::forward< Args >(args)...))
typename Aut::element_type::template fresh_automaton_t< Context > fresh_automaton_t_of
Given an automaton type, the type of its copies.
static constexpr auto sname(Args &&...args) -> decltype(element_type::sname(std::forward< Args >(args)...))
auto label_of(Args &&...args) const -> decltype(aut_-> label_of(std::forward< Args >(args)...))
automaton_t aut_
The wrapped automaton, possibly const.
Insplit automaton decorator.
auto & as()
Extract wrapped typed automaton.
typename context_t::weightset_t weightset_t