Awali
Another Weighted Automata library
exp_stats.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_EXP_STATS_HH
18 # define AWALI_ALGOS_EXP_STATS_HH
19 
20 # include <set>
21 
22 #include <awali/sttc/ctx/fwd.hh>
23 #include <awali/sttc/ctx/traits.hh>
25 
26 namespace awali {
27  namespace sttc {
28 
33  struct exp_stats_t {
34  unsigned size;
35  unsigned length;
36  unsigned height;
37  unsigned star_height;
38  };
39 
40  namespace rat
41  {
42 
43  /*------------------------.
44  | exp_stats(ratexp). |
45  `------------------------*/
46 
48  template <typename RatExpSet>
50  : public RatExpSet::const_visitor
51  {
52  public:
53  using ratexpset_t = RatExpSet;
55  using ratexp_t = typename ratexpset_t::ratexp_t;
56 
57  using super_type = typename ratexpset_t::const_visitor;
58 
59  constexpr static const char* me() { return "exp_stats"; }
60 
62 
63  void
64  operator()(const ratexp_t& v) {
65  v->accept(*this);
66  }
67 
68  void exp_stats(const ratexp_t& v) {
69  v->accept(*this);
70  }
71 
73  size_ = 1;
74  length_ = 0;
75  sh_ = 0;
76  height_ = 1;
77  }
78 
80  size_ = 1;
81  length_ = 0;
82  height_ = 1;
83  sh_ = 0;
84  }
85 
87  size_ = 1;
88  length_ = 1;
89  sh_ = 0;
90  height_ = 1;
91  }
92 
94  {
95 
96  unsigned s=1, l=0, sh=0, height=0;
97  for (auto c: v) {
98  exp_stats(c);
99  s+=size_;
100  l+=length_;
101  sh=(sh_>sh)?sh_:sh;
102  height = (height_>height)?height_:height;
103  }
104  size_=s;
105  length_=l;
106  sh_=sh;
107  height_=height+1;
108  }
109 
111  {
112  unsigned s=1, l=0, sh=0, height=0;
113  for (auto c: v) {
114  exp_stats(c);
115  s+=size_;
116  l+=length_;
117  sh=(sh_>sh)?sh_:sh;
118  height = (height_>height)?height_:height;
119  }
120  size_=s;
121  length_=l;
122  sh_=sh;
123  height_=height+1;
124  }
125 
131 
133  {
134  exp_stats(v.sub());
135  ++sh_;
136  ++size_;
137  ++height_;
138  }
139 
141  {
142  exp_stats(v.sub());
143  }
144 
146  {
147  exp_stats(v.sub());
148  }
149 
150  unsigned size() {
151  return size_;
152  }
153 
154  unsigned length() {
155  return length_;
156  }
157 
158  unsigned star_height() {
159  return sh_;
160  }
161 
162  unsigned height() {
163  return height_;
164  }
165 
166  private:
167  //ratexpset_t ws_;
168  unsigned size_;
169  unsigned length_;
170  unsigned sh_;
171  unsigned height_;
172  };
173 
174  } // rat::
175 
192  template <typename RatExpSet>
193  exp_stats_t
194  exp_stats(const RatExpSet& rs, const typename RatExpSet::ratexp_t& exp)
195  {
197  exp_stats(exp);
199  }
200 
201 }}//end of ns awali::stc
202 
203 #endif // !AWALI_ALGOS_EXP_STATS_HH
The semiring of complex numbers.
Definition: c.hh:44
Definition: ratexp.hh:280
Definition: ratexp.hh:262
Definition: exp_stats.hh:51
exp_stats_visitor(const ratexpset_t &)
Definition: exp_stats.hh:61
AWALI_RAT_VISIT(lweight, v)
Definition: exp_stats.hh:140
AWALI_RAT_VISIT(zero,)
Definition: exp_stats.hh:72
AWALI_RAT_VISIT(one,)
Definition: exp_stats.hh:79
constexpr static const char * me()
Definition: exp_stats.hh:59
unsigned height()
Definition: exp_stats.hh:162
AWALI_RAT_VISIT(rweight, v)
Definition: exp_stats.hh:145
void operator()(const ratexp_t &v)
Definition: exp_stats.hh:64
AWALI_RAT_VISIT(prod, v)
Definition: exp_stats.hh:110
AWALI_RAT_VISIT(sum, v)
Definition: exp_stats.hh:93
context_t_of< ratexpset_t > context_t
Definition: exp_stats.hh:54
unsigned size()
Definition: exp_stats.hh:150
AWALI_RAT_VISIT(atom,)
Definition: exp_stats.hh:86
typename ratexpset_t::const_visitor super_type
Definition: exp_stats.hh:57
unsigned length()
Definition: exp_stats.hh:154
RatExpSet ratexpset_t
Definition: exp_stats.hh:53
unsigned star_height()
Definition: exp_stats.hh:158
typename ratexpset_t::ratexp_t ratexp_t
Definition: exp_stats.hh:55
void exp_stats(const ratexp_t &v)
Definition: exp_stats.hh:68
Definition: ratexp.hh:176
An inner node with multiple children.
Definition: ratexp.hh:115
An inner node implementing a weight.
Definition: ratexp.hh:208
exp_stats_t exp_stats(const RatExpSet &rs, const typename RatExpSet::ratexp_t &exp)
computes some statistics on a rational expression
Definition: exp_stats.hh:194
unsigned star_height
Definition: exp_stats.hh:37
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
unsigned height
Definition: exp_stats.hh:36
unsigned length
Definition: exp_stats.hh:35
unsigned size
Definition: exp_stats.hh:34
gathers informations on some rational expression
Definition: exp_stats.hh:33
Main namespace of Awali.
Definition: ato.hh:22
#define AWALI_RAT_UNSUPPORTED(Type)
Definition: visitor.hh:73