SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
OCApproximationStatistics.h
Go to the documentation of this file.
1 #pragma once
2 
4 
5 #ifdef SMTRAT_DEVOPTION_Statistics
6 
7 namespace smtrat {
8 namespace cadcells {
9 
10 class OCApproximationStatistics : public Statistics {
11 private:
12  using Counter = std::map<std::size_t, std::size_t>;
13 
14  bool m_currently_approximated = false; // helper variable: is the current cell approximated?
15 
16  std::size_t m_considered_cells = 0; // #calls using the approximation heuristic
17  std::size_t m_approximated_cells = 0; // #calls actually approximating
18  std::size_t m_approximated_cells_success = 0; // #successful calls actually approximating
19 
20  Counter m_approximated_degree_counter; // Counts approximations for each degree
21 
22  std::vector<std::pair<std::size_t,std::size_t>> m_taylor_ignored; // For each taylor-approximated polynomial, #variables left out and # variables
23  std::size_t m_taylor_grad_zero = 0; // #times the taylor method fails because of gradient 0
24 
25  std::size_t m_unbounded_levels = 0; // #unbounded levels in the constructed cells
26  std::size_t m_half_unbounded_levels = 0; // #one side unbounded levels in the constructed cells
27  std::vector<std::size_t> m_cell_dimensions; // Dimension of the constructed cells
28 
29  std::size_t m_resultants = 0; // #computed resultants
30  std::size_t m_discriminants = 0; // #computed discriminants
31  std::size_t m_ldcfs = 0; // #computed leading coefficients
32  Counter m_constructed_degree_counter; // Counts the occuring degrees of all constructed polynomials
33 
34  std::size_t m_involved_too_often = 0; // #times a constraint was involved in too many conflicts
35  std::size_t m_apx_too_often = 0; // #times a poly was approximated too often
36  bool m_max_considered_reached = false; // flag whether the max number of apx considered is reached
37  bool m_max_apx_reached = false; // flag whether the max number of apx is reached
38 
39  void collectCounterStats(Counter c, const std::string& name) {
40  std::size_t max = 0;
41  std::size_t n = 0;
42  std::size_t sum = 0;
43  for (const auto& [key, value] : c) {
44  n += value;
45  sum += key * value;
46  if (key > max) max = key;
47  }
48  double mean = ((double) sum) / ((double) n);
49  Statistics::addKeyValuePair("total_"+name, n);
50  Statistics::addKeyValuePair("max_"+name, max);
51  Statistics::addKeyValuePair("mean_"+name, mean);
52  }
53 
54 public:
55  bool enabled() const {
56  return true;
57  }
58 
59  void collect() {
60  Statistics::addKeyValuePair("considered", m_considered_cells);
61  Statistics::addKeyValuePair("approximated", m_approximated_cells);
62  Statistics::addKeyValuePair("success", m_approximated_cells_success);
63 
64  collectCounterStats(m_approximated_degree_counter, "apx_degrees");
65 
66  Statistics::addKeyValuePair("unbounded_levels", m_unbounded_levels);
67  Statistics::addKeyValuePair("half_unbounded_levels", m_half_unbounded_levels);
68  std::size_t sumDimensions = 0;
69  for (const std::size_t d : m_cell_dimensions) sumDimensions += d;
70  Statistics::addKeyValuePair("mean_cell_dimension", ((double) sumDimensions) / ((double) m_cell_dimensions.size()));
71 
72  std::size_t maxIgnoredVars = 0;
73  double sum = 0.0;
74  std::size_t total = 0;
75  for (const auto& item : m_taylor_ignored) {
76  sum += ((double) item.first) / ((double) item.second);
77  total += item.first;
78  if (item.first > maxIgnoredVars) maxIgnoredVars = item.first;
79  }
80  double meanIgnoredVars = sum/((double) m_taylor_ignored.size());
81  Statistics::addKeyValuePair("max_taylor_ignored_vars", maxIgnoredVars);
82  Statistics::addKeyValuePair("total_taylor_ignored_vars", total);
83  Statistics::addKeyValuePair("mean_taylor_ignored_vars", meanIgnoredVars);
84  Statistics::addKeyValuePair("taylor_failure", m_taylor_grad_zero);
85 
86  Statistics::addKeyValuePair("resultants", m_resultants);
87  Statistics::addKeyValuePair("discriminants", m_discriminants);
88  Statistics::addKeyValuePair("leading_coefficients", m_ldcfs);
89  collectCounterStats(m_constructed_degree_counter, "construction_degrees");
90 
91  Statistics::addKeyValuePair("involved_too_often", m_involved_too_often);
92  Statistics::addKeyValuePair("apx_too_often", m_apx_too_often);
93  Statistics::addKeyValuePair("max_considered_reached", m_max_considered_reached);
94  Statistics::addKeyValuePair("max_apx_reached", m_max_apx_reached);
95  }
96 
97  void newCell() {
98  m_currently_approximated = false;
99  }
100 
101  void success(std::size_t d) {
102  if (m_currently_approximated) ++m_approximated_cells_success;
103  m_cell_dimensions.push_back(d);
104  }
105  void approximationConsidered() {++m_considered_cells;}
106  void approximated(std::size_t d) {
107  ++m_approximated_degree_counter[d];
108  if (!m_currently_approximated) {
109  ++m_approximated_cells;
110  m_currently_approximated = true;
111  }
112  }
113 
114  void taylorIgnoredVars(std::size_t ignored, std::size_t total) {m_taylor_ignored.emplace_back(ignored, total);}
115  void taylorFailure() {++m_taylor_grad_zero;}
116 
117  void unboundedLevel() {++m_unbounded_levels;}
118  void halfUnboundedLevel() {++m_half_unbounded_levels;}
119  void cellDimension(std::size_t d) {m_cell_dimensions.push_back(d);}
120 
121  void resultant() {++m_resultants;}
122  void discriminant() {++m_discriminants;}
123  void coefficient() {++m_ldcfs;}
124  void degree(std::size_t d) {++m_constructed_degree_counter[d];}
125 
126  void involvedTooOften() {++m_involved_too_often;}
127  void apxTooOften() {++m_apx_too_often;}
128  void maxConsideredReached() {m_max_considered_reached = true;}
129  void maxApxReached() {m_max_apx_reached = true;}
130 
131  static OCApproximationStatistics& get_instance() {
132  static OCApproximationStatistics& statistics = statistics_get<OCApproximationStatistics>("onecell-approximation");
133  return statistics;
134  }
135 };
136 
137 }
138 }
139 
140 #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
std::size_t cellDimension(const CADCell &cell, const std::size_t uptoLevel)
Definition: utils.h:438
Class to create the formulas for axioms.
carl::statistics::Statistics Statistics
Definition: Statistics.h:7