Awali
Another Weighted Automata library
info.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_ALGOS_INFO_HH
18 # define AWALI_ALGOS_INFO_HH
19 
20 # include <iostream>
21 
30 #include <awali/sttc/algos/synchronizing_word.hh>
33 
34 namespace awali { namespace sttc {
35 
36 
37  namespace detail_info
38  {
39  /*---------------.
40  | is-ambiguous. |
41  `---------------*/
42  template <typename Aut>
43  typename std::enable_if<labelset_t_of<Aut>::is_free(),
44  bool>::type
45  is_ambiguous(const Aut& a)
46  {
47  return sttc::is_ambiguous(a);
48  }
49 
50  template <typename Aut>
51  typename std::enable_if<!labelset_t_of<Aut>::is_free(),
52  std::string>::type
53  is_ambiguous(const Aut&)
54  {
55  return "N/A";
56  }
57 
58  /*--------------.
59  | is-complete. |
60  `--------------*/
61  template <typename Aut>
62  typename std::enable_if<labelset_t_of<Aut>::is_free(),
63  bool>::type
64  is_complete(const Aut& a)
65  {
66  return sttc::is_complete(a);
67  }
68 
69  template <typename Aut>
70  typename std::enable_if<!labelset_t_of<Aut>::is_free(),
71  std::string>::type
72  is_complete(const Aut&)
73  {
74  return "N/A";
75  }
76 
77  /*-------------------.
78  | is_deterministic. |
79  `-------------------*/
80  template <typename Aut>
81  typename std::enable_if<labelset_t_of<Aut>::is_free(),
82  bool>::type
83  is_deterministic(const Aut& a)
84  {
85  return sttc::is_deterministic(a);
86  }
87 
88  template <typename Aut>
89  typename std::enable_if<!labelset_t_of<Aut>::is_free(),
90  std::string>::type
91  is_deterministic(const Aut&)
92  {
93  return "N/A";
94  }
95 
96  /*-------------------.
97  | is_synchronizing. |
98  `-------------------*/
99  template <typename Aut>
100  typename std::enable_if<labelset_t_of<Aut>::is_free(),
101  bool>::type
102  is_synchronizing(const Aut& a)
103  {
104  return sttc::is_synchronizing(a);
105  }
106 
107  template <typename Aut>
108  typename std::enable_if<!labelset_t_of<Aut>::is_free(),
109  std::string>::type
110  is_synchronizing(const Aut&)
111  {
112  return "N/A";
113  }
114 
115  /*---------------------------.
116  | num_deterministic_states. |
117  `---------------------------*/
118  template <typename Aut>
119  typename std::enable_if<labelset_t_of<Aut>::is_free(),
120  size_t>::type
122  {
124  }
125 
126  template <typename Aut>
127  typename std::enable_if<!labelset_t_of<Aut>::is_free(),
128  std::string>::type
130  {
131  return "N/A";
132  }
133 
134  /*----------------------.
135  | num_eps_transitions. |
136  `----------------------*/
137 
138  template <typename Aut>
139  ATTRIBUTE_CONST
140  typename std::enable_if<!labelset_t_of<Aut>::has_one(),
141  size_t>::type
143  {
144  return 0;
145  }
146 
147  template <typename Aut>
148  typename std::enable_if<labelset_t_of<Aut>::has_one(),
149  size_t>::type
150  num_eps_transitions_(const Aut& aut)
151  {
152  size_t res = 0;
153  for (auto t : aut->transitions())
154  res += aut->labelset()->is_one(aut->label_of(t));
155  return res;
156  }
157 
158  template <typename Aut>
159  size_t
160  num_eps_transitions(const Aut& aut)
161  {
162  return num_eps_transitions_(aut);
163  }
164  }
165 
166  /*--------------------------.
167  | info(automaton, stream). |
168  `--------------------------*/
169 
170  template <class A>
171  std::ostream&
172  info(const A& aut, std::ostream& out, bool detailed = false)
173  {
174 #define ECHO(Name, Value) \
175  out << Name ": " << Value << '\n'
176  ECHO("type", aut->vname(true));
177  ECHO("number of states", aut->num_states());
178  ECHO("number of initial states", aut->num_initials());
179  ECHO("number of final states", aut->num_finals());
180  ECHO("number of accessible states", num_accessible_states(aut));
181  ECHO("number of coaccessible states", num_coaccessible_states(aut));
182  ECHO("number of useful states", num_useful_states(aut));
183  ECHO("number of transitions", aut->num_transitions());
184  ECHO("number of deterministic states",
186  ECHO("number of eps transitions", detail_info::num_eps_transitions(aut));
187  if (detailed)
188  ECHO("is ambiguous", detail_info::is_ambiguous(aut));
189  ECHO("is complete", detail_info::is_complete(aut));
190  ECHO("is deterministic", detail_info::is_deterministic(aut));
191  ECHO("is empty", is_empty(aut));
192  ECHO("is eps-acyclic", is_eps_acyclic(aut));
193  ECHO("is normalized", is_normalized(aut));
194  ECHO("is proper", is_proper(aut));
195  ECHO("is standard", is_standard(aut));
196  if (detailed)
197  ECHO("is synchronizing", detail_info::is_synchronizing(aut));
198  ECHO("is trim", is_trim(aut));
199  ECHO("is useless", is_useless(aut));
200 #undef ECHO
201  // No eol for the last one.
202  out << "is valid: " << is_valid(aut);
203  return out;
204  }
205 
206  /*-----------------------.
207  | info(ratexp, stream). |
208  `-----------------------*/
209 
210  template <class RatExpSet>
211  void
212  info(const RatExpSet& rs, const typename RatExpSet::ratexp_t& e,
213  std::ostream& o)
214  {
215  rat::size<RatExpSet> sizer;
217  nfo(*e);
218 
219 # define DEFINE(Type) \
220  << "\n" #Type ": " << nfo.Type
221  o
222  << "type: " << rs.vname(true)
223  << "\nsize: " << sizer(e)
224  DEFINE(sum)
225  DEFINE(shuffle)
226  DEFINE(conjunction)
227  DEFINE(prod)
228  DEFINE(star)
230  DEFINE(zero)
231  DEFINE(one)
232  DEFINE(atom)
233  DEFINE(lweight)
234  DEFINE(rweight)
235  ;
236 # undef DEFINE
237  }
238 
239 }}//end of ns awali::stc
240 
241 #endif // !AWALI_ALGOS_INFO_HH
#define DEFINE(Type)
#define ECHO(Name, Value)
Definition: info.hh:31
Definition: size.hh:31
std::enable_if< labelset_t_of< Aut >::is_free(), bool >::type is_deterministic(const Aut &a)
Definition: info.hh:83
size_t num_eps_transitions(const Aut &aut)
Definition: info.hh:160
std::enable_if< labelset_t_of< Aut >::is_free(), bool >::type is_complete(const Aut &a)
Definition: info.hh:64
std::enable_if<!labelset_t_of< Aut >::is_free(), std::string >::type num_deterministic_states(const Aut &)
Definition: info.hh:129
ATTRIBUTE_CONST std::enable_if<!labelset_t_of< Aut >::has_one(), size_t >::type num_eps_transitions_(const Aut &)
Definition: info.hh:142
std::enable_if< labelset_t_of< Aut >::is_free(), bool >::type is_ambiguous(const Aut &a)
Definition: info.hh:45
std::enable_if< labelset_t_of< Aut >::is_free(), bool >::type is_synchronizing(const Aut &a)
Definition: info.hh:102
std::enable_if< labelset_t_of< Aut >::is_free(), size_t >::type num_deterministic_states(const Aut &a)
Definition: info.hh:121
bool is_empty(const Aut &aut) ATTRIBUTE_PURE
Test whether the automaton has no state.
Definition: accessible.hh:365
std::ostream & info(const A &aut, std::ostream &out, bool detailed=false)
Definition: info.hh:172
size_t num_useful_states(const Aut &aut)
Number of useful states.
Definition: accessible.hh:187
auto shuffle(const Lhs &lhs, const Rhs &rhs, bool keep_history=true) -> decltype(join_automata(lhs, rhs))
Definition: product.hh:445
auto sum(const Aut1 &aut1, const Aut2 &aut2, bool sum_standard=false) -> decltype(join_automata(aut1, aut2))
sums two automata
Definition: sum.hh:137
bool is_synchronizing(const Aut &aut)
Definition: synchronizing_word.hh:567
auto complement(const Aut &aut, bool keep_history=true) -> decltype(copy(aut))
Complementation of a deterministic complete automaton.
Definition: complement.hh:79
bool is_standard(const Aut &a)
Definition: standard.hh:40
Aut::element_type::automaton_nocv_t star(const Aut &aut)
Star of an automaton.
Definition: star.hh:100
size_t num_coaccessible_states(const Aut &aut)
Number of coaccessible states.
Definition: accessible.hh:170
bool is_useless(const Aut &aut)
Test whether the automaton has useful states.
Definition: accessible.hh:321
bool is_deterministic(const Aut &aut)
tests whether the automaton is deterministic
Definition: determinize.hh:210
bool is_complete(const Aut &aut)
Whether aut is complete.
Definition: is_complete.hh:28
bool is_proper(const Aut &aut) ATTRIBUTE_CONST
Test whether an automaton is proper.
Definition: is_proper.hh:94
bool is_ambiguous(const Aut &aut)
Definition: is_ambiguous.hh:27
ATTRIBUTE_CONST bool is_eps_acyclic(const Aut &aut)
Definition: is_eps_acyclic.hh:123
bool is_trim(const Aut &aut)
Test whether the automaton is trim.
Definition: accessible.hh:308
bool is_valid(const Aut &aut)
Tests if aut is valid.
Definition: is_valid.hh:162
size_t num_accessible_states(const Aut &aut)
Number of accessible states.
Definition: accessible.hh:153
bool is_normalized(const Aut &a)
Definition: is_normalized.hh:26
Main namespace of Awali.
Definition: ato.hh:22