SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
CADCellsStatistics.h
Go to the documentation of this file.
1 #pragma once
2 
4 
5 #ifdef SMTRAT_DEVOPTION_Statistics
6 
7 #include "./common.h"
8 #include <carl-arith/ran/common/RealRoots.h>
9 #include "datastructures/roots.h"
10 
11 
12 namespace smtrat {
13 namespace cadcells {
14 
15 using carl::operator<<;
16 
17 class CADCellsStatistics : public Statistics {
18 
19 public:
20  enum class ProjectionType {
21  resultant, discriminant, leading_coefficient, coefficient, derivative, factor
22  };
23  static std::string to_string(const ProjectionType& p) {
24  switch(p) {
25  case ProjectionType::resultant: return "resultant";
26  case ProjectionType::discriminant: return "discriminant";
27  case ProjectionType::leading_coefficient: return "leading_coefficient";
28  case ProjectionType::coefficient: return "coefficient";
29  case ProjectionType::derivative: return "derivative";
30  case ProjectionType::factor: return "factor";
31  default: return "x";
32  }
33  }
34 
35 private:
36  carl::statistics::MultiCounter<std::pair<std::size_t, std::size_t>> m_depth_section_common_zeros_count;
37 
38  carl::statistics::MultiCounter<std::size_t> m_interval_point_count_by_depth;
39  carl::statistics::MultiCounter<std::size_t> m_interval_open_count_by_depth;
40  carl::statistics::MultiCounter<std::size_t> m_interval_halfopen_count_by_depth;
41  carl::statistics::MultiCounter<std::size_t> m_interval_closed_count_by_depth;
42  carl::statistics::MultiCounter<std::size_t> m_interval_unbounded_count_by_depth;
43  carl::statistics::MultiCounter<std::size_t> m_interval_halfunbounded_count_by_depth;
44 
45  carl::statistics::MultiCounter<std::size_t> m_representation_equational_count_by_depth;
46 
47  carl::statistics::MultiCounter<std::size_t> m_rules_intersection_count_by_depth;
48 
49  carl::statistics::Timer m_proj_timer;
50 
51  boost::container::flat_map<ProjectionType, carl::statistics::Series> m_proj_x_total_degree;
52  boost::container::flat_map<ProjectionType, carl::statistics::Series> m_proj_x_degree;
53  boost::container::flat_map<ProjectionType, carl::statistics::Series> m_proj_x_level;
54 
55  carl::statistics::Series m_proj_realroots_num_roots;
56  std::size_t m_proj_realroots_nullified_count;
57 
58  carl::statistics::MultiCounter<std::size_t> m_filter_poly_count_by_depth;
59  carl::statistics::MultiCounter<std::pair<std::size_t, std::size_t>> m_filter_poly_count_by_depth_and_num_factors;
60  carl::statistics::MultiCounter<std::pair<std::size_t, std::size_t>> m_filter_poly_count_by_depth_and_num_roots;
61  carl::statistics::MultiCounter<std::size_t> m_filter_poly_count_independent_by_depth;
62 
63  std::size_t m_current_max_level;
64 
65  std::size_t m_filter_current_level;
66  bool m_filter_current_underlying_algebraic;
67  bool m_filter_current_indep;
68 
69  carl::statistics::Timer m_timer_filter_roots;
70  carl::statistics::Timer m_timer_filter_roots_callback;
71 
72  carl::statistics::MultiCounter<std::size_t> m_filter_root_by_depth;
73  carl::statistics::MultiCounter<std::size_t> m_filter_root_algebraic_by_depth;
74  carl::statistics::MultiCounter<std::size_t> m_filter_root_sample_algebraic_by_depth;
75  carl::statistics::MultiCounter<std::size_t> m_filter_root_optional_by_depth;
76  carl::statistics::MultiCounter<std::size_t> m_filter_root_inclusive_by_depth;
77 
78 public:
79  bool enabled() const {
80  return true;
81  }
82 
83  void collect() {
84  Statistics::addKeyValuePair("heuristics.section.common_zeros_count.by_depth", m_depth_section_common_zeros_count);
85 
86  Statistics::addKeyValuePair("heuristics.interval.point_count.by_depth", m_interval_point_count_by_depth);
87  Statistics::addKeyValuePair("heuristics.interval.open_count.by_depth", m_interval_open_count_by_depth);
88  Statistics::addKeyValuePair("heuristics.interval.halfopen_count.by_depth", m_interval_halfopen_count_by_depth);
89  Statistics::addKeyValuePair("heuristics.interval.closed_count.by_depth", m_interval_closed_count_by_depth);
90  Statistics::addKeyValuePair("heuristics.interval.unbounded_count.by_depth", m_interval_unbounded_count_by_depth);
91  Statistics::addKeyValuePair("heuristics.interval.halfunbounded_count.by_depth", m_interval_halfunbounded_count_by_depth);
92 
93  Statistics::addKeyValuePair("heuristics.representation.equational_count.by_depth", m_representation_equational_count_by_depth);
94 
95  Statistics::addKeyValuePair("heuristics.rules.intersection_count.by_depth", m_rules_intersection_count_by_depth);
96 
97  for (const auto& [k, v] : m_proj_x_total_degree) {
98  Statistics::addKeyValuePair("projections." + to_string(k) + ".total_degree", v);
99  }
100  for (const auto& [k, v] : m_proj_x_degree) {
101  Statistics::addKeyValuePair("projections." + to_string(k) + ".degree", v);
102  }
103  for (const auto& [k, v] : m_proj_x_level) {
104  Statistics::addKeyValuePair("projections." + to_string(k) + ".level", v);
105  }
106 
107  Statistics::addKeyValuePair("projections.real_roots.num_roots", m_proj_realroots_num_roots);
108  Statistics::addKeyValuePair("projections.real_roots.nullified.count", m_proj_realroots_nullified_count);
109 
110  Statistics::addKeyValuePair("projections.timer", m_proj_timer);
111 
112  Statistics::addKeyValuePair("filter.poly_count.by_depth", m_filter_poly_count_by_depth);
113  Statistics::addKeyValuePair("filter.poly_count.by_depth_and_num_factors", m_filter_poly_count_by_depth_and_num_factors);
114  Statistics::addKeyValuePair("filter.poly_count.by_depth_and_num_roots", m_filter_poly_count_by_depth_and_num_roots);
115  Statistics::addKeyValuePair("filter.poly_count.independent.by_depth", m_filter_poly_count_independent_by_depth);
116 
117  Statistics::addKeyValuePair("filter.timer.filter_roots", m_timer_filter_roots);
118  Statistics::addKeyValuePair("filter.timer.filter_roots_callback", m_timer_filter_roots_callback);
119 
120  Statistics::addKeyValuePair("filter.root.by_depth", m_filter_root_by_depth);
121  Statistics::addKeyValuePair("filter.root.algebraic.by_depth", m_filter_root_algebraic_by_depth);
122  Statistics::addKeyValuePair("filter.root.sample_algebraic.by_depth", m_filter_root_sample_algebraic_by_depth);
123  Statistics::addKeyValuePair("filter.root.optional.by_depth", m_filter_root_optional_by_depth);
124  Statistics::addKeyValuePair("filter.root.inclusive.by_depth", m_filter_root_inclusive_by_depth);
125  }
126 
127 
128  // projections
129 
130  void projection_start() {
131  m_proj_timer.start_this();
132  }
133  void projection_end() {
134  m_proj_timer.finish();
135  }
136 
137  void projection_poly(const ProjectionType& type, std::size_t total_degree, std::size_t degree, std::size_t level) {
138  m_proj_x_total_degree.try_emplace(type).first->second.add(total_degree);
139  m_proj_x_degree.try_emplace(type).first->second.add(degree);
140  m_proj_x_level.try_emplace(type).first->second.add(level);
141  }
142  void resultant (std::size_t total_degree, std::size_t degree, std::size_t level) { projection_poly(ProjectionType::resultant , total_degree, degree, level); }
143  void discriminant (std::size_t total_degree, std::size_t degree, std::size_t level) { projection_poly(ProjectionType::discriminant , total_degree, degree, level); }
144  void leading_coefficient(std::size_t total_degree, std::size_t degree, std::size_t level) { projection_poly(ProjectionType::leading_coefficient, total_degree, degree, level); }
145  void coefficient (std::size_t total_degree, std::size_t degree, std::size_t level) { projection_poly(ProjectionType::coefficient , total_degree, degree, level); }
146  void derivative (std::size_t total_degree, std::size_t degree, std::size_t level) { projection_poly(ProjectionType::derivative , total_degree, degree, level); }
147  void factor (std::size_t total_degree, std::size_t degree, std::size_t level) { projection_poly(ProjectionType::factor , total_degree, degree, level); }
148 
149  void real_roots_result(const carl::RealRootsResult<RAN>& result) {
150  if (result.is_nullified()) {
151  m_proj_realroots_nullified_count++;
152  }
153  m_proj_realroots_num_roots.add(result.is_nullified() ? 0 : result.roots().size());
154  }
155 
156 
157  // filter_roots
158 
159  void set_max_level(std::size_t level) {
160  m_current_max_level = level;
161  }
162  void filter_roots_start(std::size_t level, std::size_t num_factors, std::size_t num_roots, const cadcells::Assignment& ass) {
163  assert(m_current_max_level>=level);
164  m_filter_poly_count_by_depth.inc(m_current_max_level-level, 1);
165  m_filter_poly_count_by_depth_and_num_factors.inc(std::make_pair((std::size_t)m_current_max_level-level, num_factors), 1);
166  m_filter_poly_count_by_depth_and_num_roots.inc(std::make_pair((std::size_t)m_current_max_level-level, num_roots), 1);
167 
168  m_filter_current_level = level;
169  m_filter_current_underlying_algebraic = std::find_if(ass.begin(), ass.end(), [](const auto& m) { return !m.second.is_numeric(); }) != ass.end();
170  m_filter_current_indep = true;
171 
172  m_timer_filter_roots.start_this();
173  }
174  void filter_roots_end() {
175  if (m_filter_current_indep) {
176  m_filter_poly_count_independent_by_depth.inc(m_current_max_level-m_filter_current_level, 1);
177  }
178 
179  m_timer_filter_roots.finish();
180  }
181  void filter_roots_filter_start(const cadcells::RAN& ran) {
182  m_filter_root_by_depth.inc(m_current_max_level-m_filter_current_level, 1);
183  if (!ran.is_numeric()) {
184  m_filter_root_algebraic_by_depth.inc(m_current_max_level-m_filter_current_level, 1);
185  }
186  if (m_filter_current_underlying_algebraic || !ran.is_numeric()) {
187  m_filter_root_sample_algebraic_by_depth.inc(m_current_max_level-m_filter_current_level, 1);
188  }
189 
190  m_timer_filter_roots_callback.start_this();
191  }
192  void filter_roots_filter_end() {
193  m_timer_filter_roots.finish();
194  }
195 
196  void filter_roots_got_normal(const cadcells::RAN&) {
197  m_filter_current_indep = false;
198  }
199  void filter_roots_got_inclusive(const cadcells::RAN&) {
200  m_filter_root_inclusive_by_depth.inc(m_current_max_level-m_filter_current_level, 1);
201  m_filter_current_indep = false;
202  }
203  void filter_roots_got_optional(const cadcells::RAN&) {
204  m_filter_root_optional_by_depth.inc(m_current_max_level-m_filter_current_level, 1);
205  }
206  void filter_roots_got_inclusive_optional(const cadcells::RAN&) {
207  m_filter_root_optional_by_depth.inc(m_current_max_level-m_filter_current_level, 1);
208  m_filter_root_inclusive_by_depth.inc(m_current_max_level-m_filter_current_level, 1);
209  }
210 
211 
212  // heuristics
213 
214  void section_common_zeros(std::size_t depth, std::size_t num_common_eq_constr) {
215  m_depth_section_common_zeros_count.inc(std::make_pair(depth,num_common_eq_constr), 1);
216  }
217 
218  void got_bound(const datastructures::SymbolicInterval& interval) {
219  if (interval.is_section()) {
220  m_interval_point_count_by_depth.inc(m_current_max_level-m_filter_current_level, 1);
221  }
222  if(interval.lower().is_infty() && interval.upper().is_infty()) {
223  m_interval_unbounded_count_by_depth.inc(m_current_max_level-m_filter_current_level, 1);
224  } else if (interval.lower().is_infty() || interval.upper().is_infty()) {
225  m_interval_halfunbounded_count_by_depth.inc(m_current_max_level-m_filter_current_level, 1);
226  }
227  if(interval.lower().is_weak() && interval.upper().is_weak()) {
228  m_interval_closed_count_by_depth.inc(m_current_max_level-m_filter_current_level, 1);
229  } else if(interval.lower().is_strict() && interval.upper().is_strict()) {
230  m_interval_open_count_by_depth.inc(m_current_max_level-m_filter_current_level, 1);
231  } else {
232  m_interval_halfopen_count_by_depth.inc(m_current_max_level-m_filter_current_level, 1);
233  }
234  }
235 
236  void got_representation_equational(std::size_t num) {
237  m_representation_equational_count_by_depth.inc(m_current_max_level-m_filter_current_level, num);
238  }
239 
240 
241  /// rules
242 
243  void detect_intersection() {
244  m_rules_intersection_count_by_depth.inc(m_current_max_level-m_filter_current_level, 1);
245  }
246 };
247 
248 CADCellsStatistics &statistics();
249 
250 }
251 }
252 
253 #endif
Poly resultant(carl::Variable variable, const Poly &p, const Poly &q)
Computes the resultant of two polynomials.
Definition: utils.h:48
Poly discriminant(carl::Variable variable, const Poly &p)
Computes the discriminant of a polynomial.
Definition: utils.h:63
ProjectionType
Definition: Settings.h:9
Polynomial::RootType RAN
Definition: common.h:24
carl::Assignment< RAN > Assignment
Definition: common.h:25
QuantifierType type(const std::pair< QuantifierType, std::vector< carl::Variable >> &p)
Definition: QEQuery.h:39
Class to create the formulas for axioms.
carl::statistics::Statistics Statistics
Definition: Statistics.h:7