Vcsn  2.0
Be Rational
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
info.hh
Go to the documentation of this file.
1 #ifndef VCSN_ALGOS_INFO_HH
2 # define VCSN_ALGOS_INFO_HH
3 
4 # include <iostream>
5 
6 # include <vcsn/algos/accessible.hh>
12 # include <vcsn/algos/normalize.hh>
13 # include <vcsn/algos/is-valid.hh>
15 # include <vcsn/algos/scc.hh>
16 # include <vcsn/algos/standard.hh>
18 # include <vcsn/core/rat/info.hh>
19 # include <vcsn/core/rat/size.hh>
20 # include <vcsn/dyn/fwd.hh>
21 # include <vcsn/dyn/ratexp.hh>
22 
23 namespace vcsn
24 {
25 
26  namespace detail_info
27  {
28  /*---------------.
29  | is-ambiguous. |
30  `---------------*/
31  template <typename Aut>
32  typename std::enable_if<labelset_t_of<Aut>::is_free(),
33  bool>::type
34  is_ambiguous(const Aut& a)
35  {
36  return vcsn::is_ambiguous(a);
37  }
38 
39  template <typename Aut>
40  typename std::enable_if<!labelset_t_of<Aut>::is_free(),
41  std::string>::type
42  is_ambiguous(const Aut&)
43  {
44  return "N/A";
45  }
46 
47  /*--------------.
48  | is-complete. |
49  `--------------*/
50  template <typename Aut>
51  typename std::enable_if<labelset_t_of<Aut>::is_free(),
52  bool>::type
53  is_complete(const Aut& a)
54  {
55  return vcsn::is_complete(a);
56  }
57 
58  template <typename Aut>
59  typename std::enable_if<!labelset_t_of<Aut>::is_free(),
60  std::string>::type
61  is_complete(const Aut&)
62  {
63  return "N/A";
64  }
65 
66  /*---------------------.
67  | is_cycle_ambiguous. |
68  `---------------------*/
69  template <typename Aut>
70  typename std::enable_if<labelset_t_of<Aut>::is_free(),
71  bool>::type
72  is_cycle_ambiguous(const Aut& a)
73  {
74  return vcsn::is_cycle_ambiguous(a);
75  }
76 
77  template <typename Aut>
78  typename std::enable_if<!labelset_t_of<Aut>::is_free(),
79  std::string>::type
80  is_cycle_ambiguous(const Aut&)
81  {
82  return "N/A";
83  }
84 
85  /*---------------------.
86  | is_codeterministic. |
87  `---------------------*/
88  template <typename Aut>
89  typename std::enable_if<labelset_t_of<Aut>::is_free(),
90  bool>::type
91  is_codeterministic(const Aut& a)
92  {
93  return vcsn::is_codeterministic(a);
94  }
95 
96  template <typename Aut>
97  typename std::enable_if<!labelset_t_of<Aut>::is_free(),
98  std::string>::type
99  is_codeterministic(const Aut&)
100  {
101  return "N/A";
102  }
103 
104  /*-------------------.
105  | is_deterministic. |
106  `-------------------*/
107  template <typename Aut>
108  typename std::enable_if<labelset_t_of<Aut>::is_free(),
109  bool>::type
110  is_deterministic(const Aut& a)
111  {
112  return vcsn::is_deterministic(a);
113  }
114 
115  template <typename Aut>
116  typename std::enable_if<!labelset_t_of<Aut>::is_free(),
117  std::string>::type
118  is_deterministic(const Aut&)
119  {
120  return "N/A";
121  }
122 
123  /*-------------------.
124  | is_synchronizing. |
125  `-------------------*/
126  template <typename Aut>
127  typename std::enable_if<labelset_t_of<Aut>::is_free(),
128  bool>::type
129  is_synchronizing(const Aut& a)
130  {
131  return vcsn::is_synchronizing(a);
132  }
133 
134  template <typename Aut>
135  typename std::enable_if<!labelset_t_of<Aut>::is_free(),
136  std::string>::type
137  is_synchronizing(const Aut&)
138  {
139  return "N/A";
140  }
141 
142  /*---------------------------.
143  | num_codeterministic_states. |
144  `---------------------------*/
145  template <typename Aut>
146  typename std::enable_if<labelset_t_of<Aut>::is_free(),
147  size_t>::type
149  {
151  }
152 
153  template <typename Aut>
154  typename std::enable_if<!labelset_t_of<Aut>::is_free(),
155  std::string>::type
157  {
158  return "N/A";
159  }
160 
161  /*---------------------------.
162  | num_deterministic_states. |
163  `---------------------------*/
164  template <typename Aut>
165  typename std::enable_if<labelset_t_of<Aut>::is_free(),
166  size_t>::type
168  {
170  }
171 
172  template <typename Aut>
173  typename std::enable_if<!labelset_t_of<Aut>::is_free(),
174  std::string>::type
176  {
177  return "N/A";
178  }
179 
180  /*----------------------.
181  | num_eps_transitions. |
182  `----------------------*/
183  template <typename Aut>
184  ATTRIBUTE_CONST
185  typename std::enable_if<!labelset_t_of<Aut>::has_one(),
186  size_t>::type
188  {
189  return 0;
190  }
191 
192  template <typename Aut>
193  typename std::enable_if<labelset_t_of<Aut>::has_one(),
194  size_t>::type
195  num_eps_transitions_(const Aut& aut)
196  {
197  size_t res = 0;
198  for (auto t : aut->transitions())
199  res += aut->labelset()->is_one(aut->label_of(t));
200  return res;
201  }
202 
203  template <typename Aut>
204  size_t
205  num_eps_transitions(const Aut& aut)
206  {
207  return num_eps_transitions_(aut);
208  }
209 
210  }
211 
212  /*--------------------------.
213  | info(automaton, stream). |
214  `--------------------------*/
215 
216  template <class A>
217  std::ostream&
218  info(const A& aut, std::ostream& out, bool detailed = false)
219  {
220 #define ECHO(Name, Value) \
221  out << Name ": " << Value << '\n'
222  ECHO("type", aut->vname(true));
223  ECHO("number of states", aut->num_states());
224  ECHO("number of initial states", aut->num_initials());
225  ECHO("number of final states", aut->num_finals());
226  ECHO("number of accessible states", num_accessible_states(aut));
227  ECHO("number of coaccessible states", num_coaccessible_states(aut));
228  ECHO("number of useful states", num_useful_states(aut));
229  ECHO("number of transitions", aut->num_transitions());
230  ECHO("number of codeterministic states",
232  ECHO("number of deterministic states",
234  ECHO("number of eps transitions", detail_info::num_eps_transitions(aut));
235  if (detailed)
236  ECHO("number of strongly connected components", num_sccs(aut));
237  if (detailed)
238  ECHO("is ambiguous", detail_info::is_ambiguous(aut));
239  ECHO("is complete", detail_info::is_complete(aut));
240  if (detailed)
241  ECHO("is cycle ambiguous", detail_info::is_cycle_ambiguous(aut));
242  ECHO("is deterministic", detail_info::is_deterministic(aut));
243  ECHO("is codeterministic", detail_info::is_codeterministic(aut));
244  ECHO("is empty", is_empty(aut));
245  ECHO("is eps-acyclic", is_eps_acyclic(aut));
246  ECHO("is normalized", is_normalized(aut));
247  ECHO("is proper", is_proper(aut));
248  ECHO("is standard", is_standard(aut));
249  if (detailed)
250  ECHO("is synchronizing", detail_info::is_synchronizing(aut));
251  ECHO("is trim", is_trim(aut));
252  ECHO("is useless", is_useless(aut));
253 #undef ECHO
254  // No eol for the last one.
255  out << "is valid: " << is_valid(aut);
256  return out;
257  }
258 
259  namespace dyn
260  {
261  namespace detail
262  {
264  template <typename Aut, typename Ostream, typename Bool>
265  std::ostream& info(const automaton& aut, std::ostream& out,
266  bool detailed)
267  {
268  info(aut->as<Aut>(), out, detailed);
269  return out;
270  }
271 
273  (const automaton& aut, std::ostream& out,
274  bool detailed) -> std::ostream&);
275  }
276  }
277 
278 
279  /*-----------------------.
280  | info(ratexp, stream). |
281  `-----------------------*/
282 
283  template <class RatExpSet>
284  void
285  info(const RatExpSet& rs, const typename RatExpSet::value_t& e,
286  std::ostream& o)
287  {
288  rat::size<RatExpSet> sizer;
290  nfo(*e);
291 
292 # define DEFINE(Type) \
293  << "\n" #Type ": " << nfo.Type
294  o
295  << "type: " << rs.vname(true)
296  << "\nsize: " << sizer(e)
297  DEFINE(sum)
298  DEFINE(shuffle)
300  DEFINE(prod)
301  DEFINE(star)
303  DEFINE(zero)
304  DEFINE(one)
305  DEFINE(atom)
306  DEFINE(lweight)
307  DEFINE(rweight)
308  ;
309 # undef DEFINE
310  }
311 
312 
313  namespace dyn
314  {
315  namespace detail
316  {
318  template <typename RatExpSet, typename Ostream>
319  std::ostream& info_ratexp(const ratexp& exp, std::ostream& o)
320  {
321  const auto& e = exp->as<RatExpSet>();
322  vcsn::info<RatExpSet>(e.ratexpset(), e.ratexp(), o);
323  return o;
324  }
325 
327  (const ratexp& aut, std::ostream& o) -> std::ostream&);
328  }
329  }
330 }
331 
332 #endif // !VCSN_ALGOS_INFO_HH
std::enable_if< labelset_t_of< Aut >::is_free(), bool >::type is_cycle_ambiguous(const Aut &a)
Definition: info.hh:72
bool is_deterministic(const Aut &aut, state_t_of< Aut > s)
Whether state s is deterministic in aut.
#define DEFINE(Type)
bool is_ambiguous(const Aut &aut)
Definition: is-ambiguous.hh:41
REGISTER_DECLARE(accessible,(const automaton &) -> automaton)
std::shared_ptr< detail::automaton_base > automaton
Definition: automaton.hh:71
size_t num_accessible_states(const Aut &a)
Number of accessible states, not counting pre() and post().
Definition: accessible.hh:84
std::enable_if< labelset_t_of< Aut >::is_free(), size_t >::type num_deterministic_states(const Aut &a)
Definition: info.hh:167
std::enable_if< labelset_t_of< Aut >::is_free(), bool >::type is_codeterministic(const Aut &a)
Definition: info.hh:91
std::enable_if< labelset_t_of< Aut >::is_free(), bool >::type is_synchronizing(const Aut &a)
Definition: info.hh:129
std::enable_if< labelset_t_of< Aut >::is_free(), bool >::type is_deterministic(const Aut &a)
Definition: info.hh:110
std::ostream & info(const A &aut, std::ostream &out, bool detailed=false)
Definition: info.hh:218
bool is_trim(const Aut &a)
Definition: accessible.hh:151
bool is_useless(const Aut &a)
Definition: accessible.hh:157
bool is_standard(const Aut &a)
Whether a is standard.
Definition: standard.hh:27
RatExpSet::value_t conjunction(const RatExpSet &rs, const typename RatExpSet::value_t &lhs, const typename RatExpSet::value_t &rhs)
Intersection/Hadamard product of ratexps.
Definition: product.hh:741
#define ECHO(Name, Value)
std::size_t num_sccs(const Aut &aut)
Get number of strongly connected components.
Definition: scc.hh:278
std::enable_if< labelset_t_of< Aut >::is_free(), size_t >::type num_codeterministic_states(const Aut &a)
Definition: info.hh:148
std::shared_ptr< detail::ratexp_base > ratexp
Definition: fwd.hh:64
bool is_complete(const Aut &aut)
Whether aut is complete.
Definition: is-complete.hh:15
bool is_valid(const Aut &aut)
Definition: is-valid.hh:138
size_t num_codeterministic_states(const Aut &aut)
Number of non-deterministic states of transpositive automaton.
bool is_codeterministic(const Aut &aut)
Whether the transpositive automaton is deterministic.
bool is_proper(const Aut &aut)
Test whether an automaton is proper.
Definition: is-proper.hh:49
std::ostream & info_ratexp(const ratexp &exp, std::ostream &o)
Bridge.
Definition: info.hh:319
ATTRIBUTE_CONST bool is_eps_acyclic(const Aut &aut)
auto complement(const Aut &aut) -> decltype(copy(aut))
Definition: complement.hh:52
std::enable_if< labelset_t_of< Aut >::is_free(), bool >::type is_complete(const Aut &a)
Definition: info.hh:53
std::enable_if< labelset_t_of< Aut >::is_free(), bool >::type is_ambiguous(const Aut &a)
Definition: info.hh:34
size_t num_eps_transitions(const Aut &)
Definition: info.hh:205
ATTRIBUTE_CONST std::enable_if<!labelset_t_of< Aut >::has_one(), size_t >::type num_eps_transitions_(const Aut &)
Definition: info.hh:187
bool is_empty(const Aut &a) ATTRIBUTE_PURE
Definition: accessible.hh:178
auto shuffle(const Auts &...as) -> product_automaton< decltype(join_automata(as...)), Auts...>
The (accessible part of the) shuffle product.
Definition: product.hh:520
size_t num_deterministic_states(const Aut &aut)
Number of non-deterministic states.
size_t num_useful_states(const Aut &a)
Number of accessible states, not counting pre() and post().
Definition: accessible.hh:107
auto sum(const A &lhs, const B &rhs) -> decltype(join_automata(lhs, rhs))
Definition: sum.hh:65
bool is_cycle_ambiguous(const Aut &aut)
Whether aut is cycle-ambiguous.
size_t num_coaccessible_states(const Aut &a)
Number of accessible states, not counting pre() and post().
Definition: accessible.hh:99
std::ostream & info(const automaton &aut, std::ostream &out, bool detailed)
Bridge.
Definition: info.hh:265
Aut::element_type::automaton_nocv_t star(const Aut &aut)
Star of a standard automaton.
Definition: star.hh:61
bool is_synchronizing(const Aut &aut)
bool is_normalized(const Aut &a)
Whether a is standard and co-standard.
Definition: normalize.hh:13