17 #ifndef AWALI_ALGOS_ALLOW_WORDS_HH
18 #define AWALI_ALGOS_ALLOW_WORDS_HH
24 #include<unordered_map>
34 template <
typename Aut>
44 const auto &labelset=*aut->context().labelset();
47 std::unordered_map<state_t,state_t> state_map;
48 for(
auto s : aut->states()) {
49 state_map[s]=ret->add_state();
51 state_map[ret->pre()]=aut->pre();
52 state_map[ret->post()]=aut->post();
53 for(
auto tr: aut->all_transitions()) {
54 const auto& w=aut->label_of(tr);
55 if(labelset.is_special(w))
56 ret->new_transition(state_map[aut->src_of(tr)], state_map[aut->dst_of(tr)],
wordset.
special(), aut->weight_of(tr));
57 else if(labelset.is_one(w))
58 ret->new_transition(state_map[aut->src_of(tr)], state_map[aut->dst_of(tr)],
wordset.
one(), aut->weight_of(tr));
60 ret->new_transition(state_map[aut->src_of(tr)], state_map[aut->dst_of(tr)],
wordset.
word(w), aut->weight_of(tr));
63 auto history = std::make_shared<single_history<Aut>>(aut);
64 ret->set_history(history);
65 for (
auto p: aut->all_states()) {
66 history->add_state(state_map[p], p);
67 if(aut->has_name(p)) {
68 ret->set_state_name(state_map[p], aut->get_state_name(p));
88 template<
typename Aut>
103 template<
typename Aut>
105 auto& ws=*aut->context().weightset();
106 for(
auto s: aut->states()) {
107 if(aut->is_initial(s) || aut->is_final(s))
111 for(
auto tria: aut->all_in(s)) {
116 for(
auto troa: aut->all_out(s)) {
124 aut->add_transition(aut->src_of(tri),aut->dst_of(tro),aut->label_of(tri)+aut->label_of(tro),ws.mul(aut->weight_of(tri),aut->weight_of(tro)));
140 template <
typename Aut>
carries the algebraic settings of automata
Definition: context.hh:40
Implementation of labels are words.
Definition: wordset.hh:35
static value_t one()
Definition: wordset.hh:211
static value_t special()
Definition: wordset.hh:172
word_t word(const value_t &v) const
Convert to a word.
Definition: wordset.hh:106
weightset_description weightset(const std::string &k)
labelset_description wordset(std::string const &s)
auto compact(const Aut &aut, bool keep_history=true) -> typename internal::allowworder< Aut >::ret_automaton_t
Compacts non branching paths.
Definition: allow_words.hh:142
void compact_here(Aut &aut)
Compacts non branching paths.
Definition: allow_words.hh:104
auto allow_words(const Aut &aut, bool keep_history=true) -> typename internal::allowworder< Aut >::ret_automaton_t
Turns the automaton into an automaton labeled with words.
Definition: allow_words.hh:89
typename internal::labelset_t_of_impl< internal::base_t< ValueSet > >::type labelset_t_of
Helper to retrieve the type of the labelset of a value set.
Definition: traits.hh:76
auto get_wordset(const L &labelset) -> typename labelset_trait< L >::wordset_t
Definition: traits.hh:232
mutable_automaton< Context > make_mutable_automaton(const Context &ctx)
Definition: mutable_automaton.hh:915
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 transition_t
Definition: types.hh:22
Definition: allow_words.hh:35
typename labelset_trait< labelset_t >::wordset_t wordset_t
Definition: allow_words.hh:39
static ret_automaton_t allow_words(const automaton_t &aut, bool keep_history)
Definition: allow_words.hh:43
weightset_t_of< Aut > weightset_t
Definition: allow_words.hh:38
mutable_automaton< ret_context_t > ret_automaton_t
Definition: allow_words.hh:41
labelset_t_of< Aut > labelset_t
Definition: allow_words.hh:37
Aut automaton_t
Definition: allow_words.hh:36
L wordset_t
Definition: traits.hh:38