17 #ifndef AWALI_ALGOS_IS_FUNCTIONAL_HH
18 #define AWALI_ALGOS_IS_FUNCTIONAL_HH
21 # include <unordered_map>
32 namespace awali {
namespace sttc {
34 template <
typename Tdc>
37 auto inv = sttc::projections<1,0>(transducer);
38 auto tdc =
compose(inv, transducer);
40 std::unordered_map<unsigned, std::pair<std::string,std::string>> valuations;
41 std::stack<unsigned> todo;
43 std::pair<std::string,std::string> base{
"",
""};
46 for(
auto ti : tdc->initial_transitions()) {
48 auto it1 = valuations.find(tdc->dst_of(ti));
49 if(it1 != valuations.end()) {
51 if(it1->second != base)
55 valuations.emplace(std::make_pair(tdc->dst_of(ti),base));
56 todo.emplace(tdc->dst_of(ti));
58 while(!todo.empty()) {
59 unsigned s = todo.top();
62 auto valuation = valuations.find(s)->second;
63 for(
auto tr : tdc->all_out(s)) {
64 unsigned t = tdc->dst_of(tr);
65 if(t == tdc->post()) {
71 auto l= tdc->label_of(tr);
73 std::pair<std::string,std::string> t_val{valuation};
75 if(!is_epsilon<labelset_t>(std::get<0>(l))) {
76 auto c = std::get<0>(l);
77 t_val.first = t_val.first+
c;
79 if(!is_epsilon<labelset_t>(std::get<1>(l))) {
80 auto c = std::get<1>(l);
81 t_val.second = t_val.second+
c;
85 for(p=0; p< t_val.first.length() && p<t_val.second.length() && t_val.first[p]==t_val.second[p]; ++p)
88 t_val.first = t_val.first.substr(p);
89 t_val.second = t_val.second.substr(p);
91 if(t_val.first.length() >0 && t_val.second.length()>0)
94 auto it2 = valuations.find(t);
95 if(it2 != valuations.end()) {
96 if(it2->second != t_val)
100 valuations.emplace(std::make_pair(t,t_val));
The semiring of complex numbers.
Definition: c.hh:44
auto compose(const TDC1 &tdc1, const TDC2 &tdc2, bool keep_history=true) -> typename internal::composer< TDC1, TDC2, 1, 0 >::automaton_t
Composition of two transducers.
Definition: compose.hh:285
void trim_here(Aut &aut)
In-place trim subautomaton.
Definition: accessible.hh:292
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
bool is_functional(Tdc &transducer)
Definition: is_functional.hh:35
Main namespace of Awali.
Definition: ato.hh:22