17 #ifndef AWALI_ALGOS_THOMPSON_HH
18 # define AWALI_ALGOS_THOMPSON_HH
27 namespace awali {
namespace sttc {
33 template <
typename Aut,
34 typename Context = context_t_of<Aut>
37 :
public Context::const_visitor
48 static_assert(context_t::has_one(),
"requires nullable labels");
50 constexpr
static const char*
me() {
return "thompson"; }
55 keep_history_(keep_history)
62 res_->set_history(history_);
64 res_->set_initial(initial_);
65 res_->set_final(final_);
66 return std::move(res_);
71 initial_ = res_->add_state();
72 final_ = res_->add_state();
75 history_->add_state(initial_,
"zero");
80 initial_ = res_->add_state();
81 final_ = res_->add_state();
84 res_->new_transition(initial_, final_, epsilon_);
85 history_->add_state(initial_,
"one");
90 initial_ = res_->add_state();
91 final_ = res_->add_state();
94 res_->new_transition(initial_, final_, e.value());
95 history_->add_state(initial_,
"letter");
100 state_t initial = res_->add_state();
101 state_t final = res_->add_state();
105 res_->new_transition(initial, initial_, epsilon_);
106 res_->new_transition(final_,
final, epsilon_);
112 history_->add_state(initial_,
"sum");
123 e.head()->accept(*
this);
127 for (
auto c: e.tail())
131 res_->new_transition(
final, initial_, epsilon_);
138 e.sub()->accept(*
this);
139 state_t initial = res_->add_state();
140 state_t final = res_->add_state();
141 res_->new_transition(initial, initial_, epsilon_);
142 res_->new_transition(final_,
final, epsilon_);
143 res_->new_transition(final_, initial_, epsilon_);
144 res_->new_transition(initial,
final, epsilon_);
149 history_->add_state(initial_,
"star");
154 e.sub()->accept(*
this);
155 state_t initial = res_->add_state();
156 state_t final = res_->add_state();
158 res_->new_transition(initial, initial_, epsilon_, w);
159 res_->new_transition(final_,
final, epsilon_);
162 history_->add_state(initial_,
"left wgt");
167 e.sub()->accept(*
this);
168 state_t initial = res_->add_state();
169 state_t final = res_->add_state();
171 res_->new_transition(initial, initial_, epsilon_);
172 res_->new_transition(final_,
final, epsilon_, w);
175 history_->add_state(initial_,
"right wgt");
182 const label_t epsilon_ = res_->labelset()->one();
183 state_t initial_ = automaton_t::element_type::null_state();
184 state_t final_ = automaton_t::element_type::null_state();
201 template <
typename Aut,
202 typename Context = context_t_of<Aut>>
204 thompson(
const Context& ctx,
const typename Context::ratexp_t& exp,
bool keep_history=
true)
218 template <
typename RatExpSet>
219 mutable_automaton<sttc::nullable_of<typename RatExpSet::context_t>>
220 thompson(
const RatExpSet& rs,
const typename RatExpSet::ratexp_t& exp,
bool keep_history=
true)
The semiring of complex numbers.
Definition: c.hh:44
Definition: ratexp.hh:280
Definition: ratexp.hh:262
Definition: thompson.hh:38
automaton_t operator()(const typename Context::ratexp_t &v)
Definition: thompson.hh:59
AWALI_RAT_VISIT(atom, e)
Definition: thompson.hh:88
AWALI_RAT_VISIT(sum, e)
Definition: thompson.hh:98
AWALI_RAT_VISIT(zero,)
Definition: thompson.hh:69
thompson_visitor(const context_t &ctx, bool keep_history)
Definition: thompson.hh:52
AWALI_RAT_VISIT(lweight, e)
Definition: thompson.hh:152
constexpr static const char * me()
Definition: thompson.hh:50
AWALI_RAT_VISIT(star, e)
Definition: thompson.hh:136
AWALI_RAT_VISIT(rweight, e)
Definition: thompson.hh:165
weightset_t_of< context_t > weightset_t
Definition: thompson.hh:42
typename Context::const_visitor super_type
Definition: thompson.hh:45
weight_t_of< context_t > weight_t
Definition: thompson.hh:43
AWALI_RAT_VISIT(one,)
Definition: thompson.hh:78
std::shared_ptr< string_history > history_t
Definition: thompson.hh:46
Context context_t
Definition: thompson.hh:41
Aut automaton_t
Definition: thompson.hh:40
Definition: ratexp.hh:176
An inner node with multiple children.
Definition: ratexp.hh:115
An inner node implementing a weight.
Definition: ratexp.hh:208
Definition: string_history.hh:29
std::string to_string(identities i)
typename internal::label_t_of_impl< internal::base_t< ValueSet > >::type label_t_of
Helper to retrieve the type of the labels of a value set.
Definition: traits.hh:71
Aut thompson(const Context &ctx, const typename Context::ratexp_t &exp, bool keep_history=true)
builds a Thompson automaton
Definition: thompson.hh:204
SharedPtr make_shared_ptr(Args &&... args)
Same as std::make_shared, but parameterized by the shared_ptr type, not the (pointed to) element_type...
Definition: memory.hh:29
typename internal::weight_t_of_impl< internal::base_t< ValueSet > >::type weight_t_of
Helper to retrieve the type of the weights of a value set.
Definition: traits.hh:81
auto get_nullable_context(const Context &ctx) -> nullable_of< Context >
Definition: traits.hh:302
std::shared_ptr< internal::mutable_automaton_impl< Context > > mutable_automaton
Definition: mutable_automaton.hh:45
typename internal::weightset_t_of_impl< internal::base_t< ValueSet > >::type weightset_t_of
Helper to retrieve the type of the weightset of a value set.
Definition: traits.hh:86
Main namespace of Awali.
Definition: ato.hh:22
unsigned state_t
Definition: types.hh:21
#define AWALI_RAT_UNSUPPORTED(Type)
Definition: visitor.hh:73