17 #ifndef AWALI_ALGOS_WEIGHTED_THOMPSON_HH 
   18 # define AWALI_ALGOS_WEIGHTED_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 "weighted thompson"; }
 
   55           keep_history_(keep_history)
 
   62           res_->set_history(history_);
 
   64         res_->set_initial(initial_);
 
   65         res_->set_final(final_);
 
   66         res_->set_final(initial_,cst_);
 
   67         return std::move(res_);
 
   72         initial_ = res_->add_state();
 
   73         final_ = res_->add_state();
 
   77         history_->add_state(initial_,
"zero");
 
   82         initial_ = res_->add_state();
 
   83         final_ = res_->add_state();
 
   87         history_->add_state(initial_,
"one");
 
   92         initial_ = res_->add_state();
 
   93         final_ = res_->add_state();
 
   94         res_->new_transition(initial_, final_, e.value());
 
   98         history_->add_state(initial_,
"letter");
 
  103         state_t initial = res_->add_state();
 
  104         state_t final = res_->add_state();
 
  109             res_->new_transition(initial, initial_, epsilon_);
 
  110             res_->new_transition(final_, 
final, epsilon_);
 
  118         history_->add_state(initial_,
"sum");
 
  129         state_t initial = res_->add_state();
 
  130         e.head()->accept(*
this);
 
  132         res_->new_transition(initial, initial_, epsilon_);
 
  133         state_t final = 0, current = final_;
 
  135         for(
auto c: e.tail()) {
 
  137             final = res_->add_state();
 
  139             res_->new_transition(current, initial_, epsilon_);
 
  140             res_->new_transition(final_, 
final, epsilon_);
 
  141             res_->new_transition(initial, initial_, epsilon_, w);
 
  142             res_->new_transition(current, 
final, epsilon_, cst_);
 
  143             w = ws_.mul(w, cst_);
 
  151         history_->add_state(initial_,
"product");
 
  156         e.sub()->accept(*
this);
 
  157         state_t initial = res_->add_state();
 
  158         state_t final = res_->add_state();
 
  160         res_->new_transition(initial, initial_, epsilon_,w);
 
  161         res_->new_transition(final_,  
final,    epsilon_,w);
 
  162         res_->new_transition(final_,  initial_, epsilon_,w);
 
  168         history_->add_state(initial_,
"star");
 
  173         e.sub()->accept(*
this);
 
  174         state_t initial = res_->add_state();
 
  175         state_t final = res_->add_state();
 
  177         res_->new_transition(initial, initial_, epsilon_, w);
 
  178         res_->new_transition(final_,  
final,    epsilon_);
 
  181         cst_ = ws_.mul(w, cst_);
 
  182         history_->add_state(initial_,
"left wgt"); 
 
  187         e.sub()->accept(*
this);
 
  188         state_t initial = res_->add_state();
 
  189         state_t final = res_->add_state();
 
  191         res_->new_transition(initial, initial_, epsilon_);
 
  192         res_->new_transition(final_,  
final,    epsilon_, w);
 
  195         cst_ = ws_.mul(cst_, w);
 
  196         history_->add_state(initial_,
"right wgt");  
 
  203       const label_t epsilon_ = res_->labelset()->one();
 
  204       state_t initial_ = automaton_t::element_type::null_state();
 
  205       state_t final_ = automaton_t::element_type::null_state();
 
  243     template <
typename Aut,
 
  244             typename Context = context_t_of<Aut>>
 
  246     weighted_thompson(
const Context& ctx, 
const typename Context::ratexp_t& exp, 
bool keep_history=
true)
 
  260   template <
typename RatExpSet>
 
  261   mutable_automaton<sttc::nullable_of<typename RatExpSet::context_t>>
 
  262   weighted_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: ratexp.hh:176
 
An inner node with multiple children.
Definition: ratexp.hh:115
 
An inner node implementing a weight.
Definition: ratexp.hh:208
 
Definition: weighted_thompson.hh:38
 
weight_t_of< context_t > weight_t
Definition: weighted_thompson.hh:43
 
AWALI_RAT_VISIT(rweight, e)
Definition: weighted_thompson.hh:185
 
AWALI_RAT_VISIT(atom, e)
Definition: weighted_thompson.hh:90
 
constexpr static const char * me()
Definition: weighted_thompson.hh:50
 
AWALI_RAT_VISIT(zero,)
Definition: weighted_thompson.hh:70
 
typename Context::const_visitor super_type
Definition: weighted_thompson.hh:46
 
AWALI_RAT_VISIT(one,)
Definition: weighted_thompson.hh:80
 
Aut automaton_t
Definition: weighted_thompson.hh:40
 
weightset_t_of< context_t > weightset_t
Definition: weighted_thompson.hh:42
 
AWALI_RAT_VISIT(sum, e)
Definition: weighted_thompson.hh:101
 
weighted_thompson_visitor(const context_t &ctx, bool keep_history)
Definition: weighted_thompson.hh:52
 
Context context_t
Definition: weighted_thompson.hh:41
 
AWALI_RAT_VISIT(star, e)
Definition: weighted_thompson.hh:154
 
std::shared_ptr< string_history > history_t
Definition: weighted_thompson.hh:44
 
automaton_t operator()(const typename Context::ratexp_t &v)
Definition: weighted_thompson.hh:59
 
AWALI_RAT_VISIT(lweight, e)
Definition: weighted_thompson.hh:171
 
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
 
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
 
Aut weighted_thompson(const Context &ctx, const typename Context::ratexp_t &exp, bool keep_history=true)
builds a variant of the Thompson automaton without epsilon cycles
Definition: weighted_thompson.hh:246
 
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