Awali
Another Weighted Automata library
transpose_view.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 #ifndef AWALI_CORE_TRANSPOSE_VIEW_HH
18 # define AWALI_CORE_TRANSPOSE_VIEW_HH
19 
21 # include <memory>
22 
23 namespace awali { namespace sttc {
24 
25  namespace internal
26  {
27  template <typename Aut>
29  {
30  public:
31  using context_t = typename Aut::context_t;
34  using kind_t = typename context_t::kind_t;
35 
36  using labelset_ptr = typename context_t::labelset_ptr;
37  using weightset_ptr = typename context_t::weightset_ptr;
38 
40  using label_t = typename labelset_t::value_t;
42  using weight_t = typename weightset_t::value_t;
44  using history_t = typename Aut::history_t;
45  using names_t = typename Aut::names_t;
46 
47  using st_store_t = typename Aut::st_store_t;
48  using tr_store_t = typename Aut::tr_store_t;
49  using tr_cont_t = typename Aut::tr_cont_t;
50 
51  transpose_view_impl() = delete;
53  transpose_view_impl(const Aut& aut)
54  : aut_{&aut}
55  {}
56  private:
57  const Aut* aut_;
58  public:
60 
62 
63  // Related sets
65 
66  static std::string sname()
67  {
68  return "transpose_view<" + context_t::sname() + ">";
69  }
70 
71  std::string vname(bool full = true) const
72  {
73  return "transpose_view<" + context().vname(full) + ">";
74  }
75 
76  const context_t& context() const { return aut_->context(); }
77  const weightset_ptr& weightset() const { return aut_->weightset(); }
78  const labelset_ptr& labelset() const { return aut_->labelset(); }
79 
80  // Special states and transitions
82 
83  // pseudo-initial and final states.
84  // The code below assumes that pre() and post() are the first
85  // two states of the automaton. In other words, all other states
86  // have greater numbers.
87  static constexpr state_t pre() { return Aut::post(); }
88  static constexpr state_t post() { return Aut::pre(); }
89 
91  {
92  return aut_->prepost_label();
93  }
94 
95  // Statistics
97 
98  size_t num_all_states() const { return aut_->num_all_states(); }
99  size_t num_states() const { return aut_->num_states(); }
100  size_t num_initials() const { return aut_->num_initials(); }
101  size_t num_finals() const { return aut_->num_finals(); }
102  size_t num_transitions() const { return aut_->num_transitions(); }
103 
104  // Queries on states
106 
107  bool has_state(state_t s) const { return aut_->has_state(s); }
108 
109  state_t max_state() const { return aut_->max_state(); }
110 
111  bool is_initial(state_t s) const { return aut_->is_final(s); }
112  bool is_final(state_t s) const { return aut_->is_initial(s); }
113  weight_t get_initial_weight(state_t s) const { return aut_->get_final_weight(s); }
114  weight_t get_final_weight(state_t s) const { return aut_->get_initial_weight(s); }
115 
116  // Queries on transitions
118 
120  {
121  return aut_->get_transition(dst, src, l);
122  }
123 
124  bool
126  {
127  return aut_->has_transition(dst, src, l);
128  }
129 
130  bool has_transition(transition_t t) const {return aut_->has_transition(t); }
131 
132  state_t src_of(transition_t t) const { return aut_->dst_of(t); }
133  state_t dst_of(transition_t t) const { return aut_->src_of(t); }
134  label_t label_of(transition_t t) const { return aut_->label_of(t); }
135  weight_t weight_of(transition_t t) const { return aut_->weight_of(t); }
136 
137  history_t history() const { return aut_->history(); }
138 
139  std::ostream&
140  print_state(state_t s, std::ostream& o) const {
141  return aut_->print_state(s, o);
142  }
143 
144  std::ostream&
145  print_state_name(state_t s, std::ostream& o,
146  const std::string& fmt = "text") const {
147  return aut_->print_state_name(s, o, fmt);
148  }
149 
150  void set_name(const std::string& n) {
151  aut_->set_name(n);
152  }
153 
154  void set_desc(const std::string& d) {
155  aut_->set_desc(d);
156  }
157 
158  const std::string& get_name() const {
159  return aut_->get_name();
160  }
161 
162  const std::string& get_desc() const {
163  return aut_->get_desc();
164  }
165 
166  std::string get_state_name(state_t s) const {
167  return aut_->get_state_name(s);
168  }
169 
170  std::ostream& print_state_history(state_t s, std::ostream& o,
171  const std::string& fmt = "text") const {
172  return aut_->print_state_history(s, o, fmt);
173  }
174 
175  bool has_history(state_t s) const {
176  return aut_->has_history(s);
177  }
178 
179  bool has_explicit_name(state_t s) const {
180  return aut_->has_explicit_name(s);
181  }
182 
183  state_t get_state_by_name(const std::string& name) const {
184  return aut_->get_state_by_name(name);
185  }
186 
187  // Iteration on states and transitions
189 
191 
194  states_output_t states() const { return aut_->states(); }
195 
198  states_output_t all_states() const { return aut_->all_states(); }
199 
201 
203  transitions_output_t transitions() const { return aut_->transitions(); }
204 
206  transitions_output_t all_transitions() const { return aut_->all_transitions(); }
207 
209 
213  {
214  return out(pre());
215  }
216 
220  {
221  return in(post());
222  }
223 
226  transitions_s_output_t out(state_t s) const { return aut_->in(s); }
227 
230  const tr_cont_t& all_out(state_t s) const { return aut_->all_in(s); }
231 
235  {
236  return aut_->in(s, l);
237  }
238 
241  transitions_s_output_t in(state_t s) const { return aut_->out(s); }
242 
245  const tr_cont_t& all_in(state_t s) const { return aut_->all_out(s); }
246 
250  {
251  return aut_->out(s, l);
252  }
253 
257  {
258  return aut_->outin(d,s);
259  }
260  };
261  }
262 
263  template <typename Aut>
264  std::shared_ptr<internal::transpose_view_impl<Aut>>
265  transpose_view(std::shared_ptr<Aut> aut)
266  {
267  return std::make_shared<internal::transpose_view_impl<Aut>>(*aut);
268  }
269 }}//end of ns awali::stc
270 
271 #endif // !AWALI_CORE_TRANSPOSE_VIEW_HH
Definition: transpose_view.hh:29
transitions_s_output_t in(state_t s) const
Indexes of visible transitions arriving to state s.
Definition: transpose_view.hh:241
weightset_t_of< context_t > weightset_t
Definition: transpose_view.hh:33
typename Aut::tr_store_t tr_store_t
Definition: transpose_view.hh:48
weight_t get_final_weight(state_t s) const
Definition: transpose_view.hh:114
state_t get_state_by_name(const std::string &name) const
Definition: transpose_view.hh:183
size_t num_all_states() const
Definition: transpose_view.hh:98
const tr_cont_t & all_in(state_t s) const
Indexes of all transitions arriving to state s.
Definition: transpose_view.hh:245
typename context_t::weightset_ptr weightset_ptr
Definition: transpose_view.hh:37
typename Aut::names_t names_t
Definition: transpose_view.hh:45
void set_desc(const std::string &d)
Definition: transpose_view.hh:154
size_t num_initials() const
Definition: transpose_view.hh:100
size_t num_transitions() const
Definition: transpose_view.hh:102
label_t prepost_label() const
Definition: transpose_view.hh:90
typename Aut::st_store_t st_store_t
Definition: transpose_view.hh:47
transpose_view_impl(transpose_view_impl &&that)=delete
bool is_initial(state_t s) const
Definition: transpose_view.hh:111
transitions_output_t transitions() const
All the transition indexes between visible states.
Definition: transpose_view.hh:203
typename weightset_t::value_t weight_t
Transition weight.
Definition: transpose_view.hh:42
bool has_transition(state_t src, state_t dst, label_t l) const
Definition: transpose_view.hh:125
typename context_t::kind_t kind_t
Definition: transpose_view.hh:34
bool has_state(state_t s) const
Definition: transpose_view.hh:107
weight_t weight_of(transition_t t) const
Definition: transpose_view.hh:135
std::string get_state_name(state_t s) const
Definition: transpose_view.hh:166
static std::string sname()
Definition: transpose_view.hh:66
bool has_transition(transition_t t) const
Definition: transpose_view.hh:130
size_t num_states() const
Definition: transpose_view.hh:99
labelset_t_of< context_t > labelset_t
Definition: transpose_view.hh:32
std::ostream & print_state_name(state_t s, std::ostream &o, const std::string &fmt="text") const
Definition: transpose_view.hh:145
static constexpr state_t pre()
Definition: transpose_view.hh:87
history_t history() const
Definition: transpose_view.hh:137
transitions_output_t all_transitions() const
All the transition indexes between all states (including pre and post).
Definition: transpose_view.hh:206
transitions_s_output_t outin(state_t s, state_t d) const
Indexes of visible transitions from state s to state d.
Definition: transpose_view.hh:256
transitions_s_output_t out(state_t s) const
Indexes of visible transitions leaving state s.
Definition: transpose_view.hh:226
size_t num_finals() const
Definition: transpose_view.hh:101
transition_t get_transition(state_t src, state_t dst, label_t l) const
Definition: transpose_view.hh:119
state_t src_of(transition_t t) const
Definition: transpose_view.hh:132
transpose_view_impl & operator=(transpose_view_impl &&that)=delete
std::ostream & print_state(state_t s, std::ostream &o) const
Definition: transpose_view.hh:140
states_output_t states() const
All states excluding pre()/post().
Definition: transpose_view.hh:194
std::string vname(bool full=true) const
Definition: transpose_view.hh:71
bool has_history(state_t s) const
Definition: transpose_view.hh:175
typename Aut::tr_cont_t tr_cont_t
Definition: transpose_view.hh:49
transitions_s_output_t final_transitions() const
Indexes of transitions from visible final states.
Definition: transpose_view.hh:219
std::ostream & print_state_history(state_t s, std::ostream &o, const std::string &fmt="text") const
Definition: transpose_view.hh:170
state_t max_state() const
Definition: transpose_view.hh:109
const tr_cont_t & all_out(state_t s) const
Indexes of all transitions leaving state s.
Definition: transpose_view.hh:230
const context_t & context() const
Definition: transpose_view.hh:76
bool has_explicit_name(state_t s) const
Definition: transpose_view.hh:179
void set_name(const std::string &n)
Definition: transpose_view.hh:150
transitions_s_output_t in(state_t s, const label_t &l) const
Indexes of visible transitions arriving to state s on label l.
Definition: transpose_view.hh:249
transpose_view_impl(const Aut &aut)
Definition: transpose_view.hh:53
const std::string & get_name() const
Definition: transpose_view.hh:158
typename Aut::history_t history_t
History.
Definition: transpose_view.hh:44
const weightset_ptr & weightset() const
Definition: transpose_view.hh:77
cont_filter< tr_cont_t > transitions_s_output_t
Definition: transpose_view.hh:208
typename Aut::context_t context_t
Definition: transpose_view.hh:31
transpose_view_impl(const transpose_view_impl &)=delete
label_t label_of(transition_t t) const
Definition: transpose_view.hh:134
states_output_t all_states() const
All states including pre()/post().
Definition: transpose_view.hh:198
weight_t get_initial_weight(state_t s) const
Definition: transpose_view.hh:113
transitions_s_output_t out(state_t s, const label_t &l) const
Indexes of all transitions leaving state s on label l.
Definition: transpose_view.hh:234
bool is_final(state_t s) const
Definition: transpose_view.hh:112
state_t dst_of(transition_t t) const
Definition: transpose_view.hh:133
transitions_s_output_t initial_transitions() const
Indexes of transitions to visible initial states.
Definition: transpose_view.hh:212
const std::string & get_desc() const
Definition: transpose_view.hh:162
const labelset_ptr & labelset() const
Definition: transpose_view.hh:78
typename labelset_t::value_t label_t
Transition label.
Definition: transpose_view.hh:40
static constexpr state_t post()
Definition: transpose_view.hh:88
typename context_t::labelset_ptr labelset_ptr
Definition: transpose_view.hh:36
The semiring of Natural numbers.
Definition: n.hh:34
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
std::shared_ptr< internal::transpose_view_impl< Aut > > transpose_view(std::shared_ptr< Aut > aut)
Definition: transpose_view.hh:265
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
static const std::string full
Completely version of Awali as a std::string.
Definition: version.hh:42
Main namespace of Awali.
Definition: ato.hh:22
unsigned state_t
Definition: types.hh:21
unsigned transition_t
Definition: types.hh:22
Definition: cont_filter.hh:145
Definition: cont_filter.hh:69