Awali
Another Weighted Automata library
is_quotient.hh
Go to the documentation of this file.
1 // This file is part of Awali.
2 // Copyright 2016-2022 Sylvain Lombardy, Victor Marsault, Jacques Sakarovitch
3 //
4 // Awali is a free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 
18 #ifndef AWALI_ALGOS_IS_QUOTIENT_HH
19 # define AWALI_ALGOS_IS_QUOTIENT_HH
20 
21 # include <list>
22 # include <vector>
23 # include <map>
24 # include <set>
26 namespace awali { namespace sttc {
27 
28 
29  namespace internal
30  {
31  template <typename Aut1, typename Aut2>
33  {
34  private:
35  using automaton1_t = Aut1;
36  using context1_t = context_t_of<automaton1_t>;
37  using weightset1_t = weightset_t_of<automaton1_t>;
38  using labelset1_t = labelset_t_of<context1_t>;
39  using label1_t = label_t_of<automaton1_t>;
40  using weight1_t = weight_t_of<automaton1_t>;
41 
42  using automaton2_t = Aut2;
43  using context2_t = context_t_of<automaton2_t>;
44  using weightset2_t = weightset_t_of<automaton1_t>;
45  using labelset2_t = labelset_t_of<context2_t>;
46  using label2_t = label_t_of<automaton2_t>;
47  using weight2_t = weight_t_of<automaton2_t>;
48 
49  // FIXME: do we want to generalize this to heterogeneous contexts?
50  // It is not completely clear whether such behavior is desirable.
51  using weightset_t = weightset1_t; // FIXME: join!
52  using labelset_t = labelset1_t; // FIXME: join!
53 
54  using pair_t = std::pair<state_t, state_t>;
55 
56  const automaton1_t& a1_;
57  const automaton2_t& a2_;
58 
59  std::map<state_t, state_t> morphism;
60  std::vector<bool> visited;
61 
62  bool visit(state_t) {
63  return true;
64  }
65 // if (visited[s])
66 // return true;
67 // state1_t s_im= morphism[s];
68 // visited[s] = true;
69 // // std::vector<transition2_t> out_trs = a2_->out();
70 // std::set<label2_t> out_labels;
71 // for (transition2_t tr_id: out_trs){
72 // label2_t label= a2_->label_of(tr_id);
73 // out_labels.insert(label);
74 // }
75 //
76 // bool ret_val= visit_aux(s, s_im, out_labels.cbegin());
77 // visited[s] = ret_val;
78 // return ret_val;
79 //
80 //
81 // bool visit_aux(state2_t s, state1_t s_im, typename std::set<label2_t>::iterator &label_it)
82 // {
83 //
84 // }
85 
86  public:
87  is_quotient_computer_t(const automaton1_t &a1, const automaton2_t &a2)
88  : a1_(a1)
89  , a2_(a2)
90  {
91  visited.resize(a2_->num_states()+2, false);
92  morphism.insert(pair_t(a2_->pre(),a1_->pre()));
93  morphism.insert(pair_t(a2_->post(),a1_->post()));
94  }
95 
96  bool operator()()
97  {
98  return visit(a2_->pre());
99  }
100  };
101 
102  }//end of namespace internal
103 
104  template <typename Aut1, typename Aut2>
105  bool
106  is_quotient(const Aut1& a1, const Aut2& a2)
107  {
109  return computer();
110  }
111 
112 }}//end of ns awali::stc
113 
114 #endif //AWALI_ALGOS_IS_QUOTIENT_HH
is_quotient_computer_t(const automaton1_t &a1, const automaton2_t &a2)
Definition: is_quotient.hh:87
bool operator()()
Definition: is_quotient.hh:96
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
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
bool is_quotient(const Aut1 &a1, const Aut2 &a2)
Definition: is_quotient.hh:106
typename internal::context_t_of_impl< internal::base_t< ValueSet > >::type context_t_of
Helper to retrieve the type of the context of a value set.
Definition: traits.hh:66
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
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