17 #ifndef AWALI_ALGOS_REALTIME_HH
18 #define AWALI_ALGOS_REALTIME_HH
24 #include<unordered_map>
33 #ifndef DETAILS_APPEND
34 #define DETAILS_APPEND
38 void append(std::string & s,
const std::string t) {
43 template <
typename Tdc>
46 using labelset0_t =
typename labelset_t::template valueset_t<0>;
47 using labelset1_t =
typename labelset_t::template valueset_t<1>;
60 using pair_t = std::pair<state_t, wordset1_value_t>;
63 for(
auto t : tdc->transitions())
64 if(is_epsilon<labelset0_t>(std::get<0>(tdc->label_of(t))))
72 if (1 < tdc->num_initials())
74 using label0_t =
typename labelset0_t::value_t;
75 for(
auto s : tdc->states()) {
76 std::unordered_set<label0_t> seen;
77 for(
auto t : tdc->out(s))
78 if (!seen.insert(std::get<0>(tdc->label_of(t))).second)
85 std::unordered_map<pair_t, state_t>
states;
86 std::stack<pair_t> todo;
88 auto lsets =tdc->context().labelset()->sets();
91 res_labelset_t(std::make_tuple(std::get<0>(lsets), wset1)),*tdc->context().weightset()});
105 std::vector<pair_t> finals;
107 for(
auto i : tdc->initial_transitions()) {
109 auto s = get_state(tu);
110 res->set_initial(s, tdc->weight_of(i));
113 while(!todo.empty()) {
114 auto pair = todo.top();
118 for(
auto tr : tdc->all_out(
pair.first)) {
120 if(t == tdc->post()) {
121 if(is_epsilon<wordset1_t>(
pair.second))
122 res->set_final(s, tdc->weight_of(tr));
124 finals.emplace_back(
pair);
127 auto l= tdc->label_of(tr);
132 if(!is_epsilon<labelset1_t>(std::get<1>(l))) {
135 if(!is_epsilon<labelset0_t>(std::get<0>(l))) {
139 res->set_transition(s, nt, std::make_tuple(std::get<0>(l),w), tdc->weight_of(tr));
144 res->set_transition(s, nt, std::make_tuple(std::get<0>(l),w), tdc->weight_of(tr));
149 if(!finals.empty()) {
151 auto a = labelset0_t::special();
152 for(
auto pair : finals) {
154 res->set_transition(s, res->post(), std::make_tuple(a,
pair.second),tdc->get_final_weight(
pair.first));
161 ret_labelset_t(std::make_tuple(nnlset0, wset1)),*tdc->context().weightset()});
164 auto final_history = std::make_shared<single_history<Tdc>>(tdc);
165 auto & ret_history = ret->history()->template as<
single_history<decltype(*res)>>();
166 std::unordered_map<state_t, state_t> inv_states;
168 inv_states[pp.second]=pp.first.first;
169 for(
auto s : ret->states())
170 final_history->
add_state(s,inv_states[ret_history.get_state(s)]);
171 ret->set_history(final_history);
178 template<
typename Tdc>
183 template<
typename Tdc>
188 template<
typename Tdc>
The semiring of complex numbers.
Definition: c.hh:44
carries the algebraic settings of automata
Definition: context.hh:40
The semiring of floating Numbers.
Definition: r.hh:35
specialisation of history_base
Definition: single_history.hh:50
void add_state(state_t s, const state_t &sb)
set the history of state s
Definition: single_history.hh:91
A ValueSet which is a Cartesian product of ValueSets.
Definition: tupleset.hh:80
std::vector< state_t > states(abstract_automaton_t const *aut, bool all)
void append(std::string &s, char c)
Definition: real_time.hh:35
constant< type_t::one, Label, Weight > one
Definition: fwd.hh:116
auto realtime(const Tdc &tdc, bool keep_history=true) -> typename internal::realtimer< Tdc >::automaton_t
Definition: real_time.hh:179
bool is_realtime(const Tdc &tdc)
Definition: real_time.hh:184
void copy_into(const AutIn &in, AutOut &out, Pred keep_state, bool keep_history=true, bool transpose=false)
Copy an automaton.
Definition: copy.hh:144
bool is_sequential_tdc(const Tdc &tdc)
Definition: real_time.hh:189
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
auto get_not_nullableset(const L &labelset) -> typename labelset_trait< L >::not_nullable_t
Definition: traits.hh:253
mutable_automaton< Context > make_mutable_automaton(const Context &ctx)
Definition: mutable_automaton.hh:915
void proper_here(Aut &aut, direction_t dir=BACKWARD, bool prune=true)
Eliminate spontaneous transitions in place.
Definition: proper.hh:427
std::shared_ptr< internal::mutable_automaton_impl< Context > > mutable_automaton
Definition: mutable_automaton.hh:45
pair_automaton< Aut > pair(const Aut &aut, bool keep_initials=false)
Definition: synchronizing_word.hh:266
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
Definition: real_time.hh:44
static bool is_realtime(const Tdc &tdc)
Definition: real_time.hh:62
static automaton_t realtime(const Tdc &tdc, bool keep_history)
Definition: real_time.hh:84
tupleset< labelset0_t, wordset1_t > res_labelset_t
Definition: real_time.hh:51
labelset_t_of< Tdc > labelset_t
Definition: real_time.hh:45
typename labelset_t::template valueset_t< 1 > labelset1_t
Definition: real_time.hh:47
mutable_automaton< ret_context_t > automaton_t
Definition: real_time.hh:57
std::pair< state_t, wordset1_value_t > pair_t
Definition: real_time.hh:60
typename labelset_t::template valueset_t< 0 > labelset0_t
Definition: real_time.hh:46
static bool is_sequential(const Tdc &tdc)
Definition: real_time.hh:69
typename labelset_trait< labelset0_t >::not_nullable_t notnullset0_t
Definition: real_time.hh:54
typename labelset_trait< labelset1_t >::wordset_t wordset1_t
Definition: real_time.hh:48
typename wordset1_t::value_t wordset1_value_t
Definition: real_time.hh:50
weightset_t_of< Tdc > weightset_t
Definition: real_time.hh:49
tupleset< notnullset0_t, wordset1_t > ret_labelset_t
Definition: real_time.hh:55
L not_nullable_t
Definition: traits.hh:36
L wordset_t
Definition: traits.hh:38