SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
criteria.h
Go to the documentation of this file.
1 #pragma once
2 #include <carl-common/memory/Singleton.h>
3 
5 
6 using IR = datastructures::IndexedRoot;
7 
8 class ApxCriteria : public carl::Singleton<ApxCriteria> {
10  private:
11  std::size_t m_considered_count = 0;
12  std::size_t m_apx_count = 0;
13  bool m_curr_apx = false;
14  std::unordered_map<Atom, std::size_t> m_constraint_involved_counter;
15  std::map<std::pair<Polynomial, std::size_t>, std::size_t> m_poly_apx_counter;
16  std::vector<Atom> m_curr_constraints;
17 
19  if (!apx_settings().crit_considered_count_enabled) return true;
20  if (m_considered_count < apx_settings().crit_max_considered) return true;
21  #ifdef SMTRAT_DEVOPTION_Statistics
22  OCApproximationStatistics::get_instance().maxConsideredReached();
23  #endif
24  return false;
25  }
26 
27  bool crit_apx_count() {
28  if (!apx_settings().crit_apx_count_enabled) return true;
29  if (m_apx_count < apx_settings().crit_max_apx) return true;
30  #ifdef SMTRAT_DEVOPTION_Statistics
31  OCApproximationStatistics::get_instance().maxApxReached();
32  #endif
33  return false;
34  }
35 
37  if (!apx_settings().crit_single_degree_enabled) return true;
38  return proj.degree(ir.poly) >= apx_settings().crit_degree_threshold;
39  }
40 
41  bool crit_pair_degree(datastructures::Projections& proj, const IR& ir_l, const IR& ir_u) {
42  if (!apx_settings().crit_pair_degree_enabled) return true;
43  std::size_t deg_l = proj.degree(ir_l.poly);
44  if (deg_l <= apx_settings().taylor_deg) return false;
45  std::size_t deg_u = proj.degree(ir_u.poly);
46  if (deg_u <= apx_settings().taylor_deg) return false;
47  return deg_l * deg_u >= 2*apx_settings().crit_degree_threshold;
48  }
49 
51  if (!apx_settings().crit_poly_apx_count_enabled) return true;
52  auto p = std::make_pair(proj.polys()(ir.poly), ir.index);
53  if (m_poly_apx_counter[p] < apx_settings().crit_max_apx_per_poly) return true;
54  #ifdef SMTRAT_DEVOPTION_Statistics
55  if (m_poly_apx_counter[p] == apx_settings().crit_max_apx_per_poly)
56  OCApproximationStatistics::get_instance().apxTooOften();
57  #endif
58  return false;
59  }
60 
61  bool crit_involved_count(const std::vector<Atom>& constraints) {
62  if (!apx_settings().crit_involved_count_enabled) return true;
63  bool res = true;
64  for (const auto& c : constraints) {
65  //++m_constraint_involved_counter[c];
66  if (m_constraint_involved_counter[c] >= apx_settings().crit_max_constraint_involved) {
67  res = false;
68  /*#ifdef SMTRAT_DEVOPTION_Statistics
69  if (m_constraint_involved_counter[c] == apx_settings().crit_max_constraint_involved)
70  OCApproximationStatistics::get_instance().involvedTooOften();
71  #endif*/
72  }
73  }
74  return res;
75  }
76 
77  bool crit_side_degree(datastructures::Projections& proj, const IR& ir, datastructures::RootMap::const_iterator start, datastructures::RootMap::const_iterator end) {
78  if (!apx_settings().crit_side_degree_enabled) return false;
79  for(auto it = start; it != end; it++) {
80  for (const auto& ir_outer : it->second) {
81  if (ir.poly == ir_outer.root.poly) continue;
82  if (crit_pair_degree(proj, ir, ir_outer.root)) return true;
83  }
84  }
85  return false;
86  }
87 
88  void new_cell(const std::vector<Atom>& constraints) {
89  m_curr_constraints = constraints;
90  m_curr_apx = false;
91  }
92 
93 
94  public:
95  static void inform(const Polynomial& p, std::size_t root_index) {
96  ApxCriteria& ac = getInstance();
97  auto pr = std::make_pair(p, root_index);
98  ++(ac.m_poly_apx_counter[pr]);
99  if (!ac.m_curr_apx) {
100  ++ac.m_apx_count;
101  ac.m_curr_apx = true;
102  for (const auto& c : ac.m_curr_constraints) {
104  #ifdef SMTRAT_DEVOPTION_Statistics
106  OCApproximationStatistics::get_instance().involvedTooOften();
107  #endif
108  }
109  }
110  }
111 
112  static bool cell(const std::vector<Atom>& constraints) {
113  ApxCriteria& ac = getInstance();
114  ac.new_cell(constraints);
115  return ac.crit_considered_count() && ac.crit_apx_count() && ac.crit_involved_count(constraints);
116  }
117 
118  static bool level(std::size_t lvl) {
119  if (!apx_settings().crit_level_enabled) return true;
120  return lvl > 1;
121  }
122 
123  static bool poly(datastructures::Projections& proj, const IR& ir) {
124  ApxCriteria& ac = getInstance();
125  return ac.crit_single_degree(proj, ir) && ac.crit_poly_apx_count(proj, ir);
126  }
127 
128  static bool poly_pair(datastructures::Projections& proj, const IR& ir_l, const IR& ir_u) {
129  ApxCriteria& ac = getInstance();
130  return ac.crit_pair_degree(proj, ir_l, ir_u) && ac.crit_poly_apx_count(proj, ir_l) && ac.crit_poly_apx_count(proj, ir_u);
131  }
132 
133  static bool side(datastructures::Projections& proj, const IR& ir, datastructures::RootMap::const_iterator start, datastructures::RootMap::const_iterator end){
134  if (poly(proj, ir)) return true;
135  ApxCriteria& ac = getInstance();
136  return ac.crit_side_degree(proj, ir, start, end);
137  }
138 };
139 
140 }
Encapsulates all computations on polynomials.
Definition: projections.h:46
std::size_t degree(PolyRef p) const
Definition: projections.h:403
static bool cell(const std::vector< Atom > &constraints)
Definition: criteria.h:112
std::map< std::pair< Polynomial, std::size_t >, std::size_t > m_poly_apx_counter
Definition: criteria.h:15
void new_cell(const std::vector< Atom > &constraints)
Definition: criteria.h:88
bool crit_pair_degree(datastructures::Projections &proj, const IR &ir_l, const IR &ir_u)
Definition: criteria.h:41
bool crit_single_degree(datastructures::Projections &proj, const IR &ir)
Definition: criteria.h:36
bool crit_poly_apx_count(datastructures::Projections &proj, const IR &ir)
Definition: criteria.h:50
static bool side(datastructures::Projections &proj, const IR &ir, datastructures::RootMap::const_iterator start, datastructures::RootMap::const_iterator end)
Definition: criteria.h:133
static void inform(const Polynomial &p, std::size_t root_index)
Definition: criteria.h:95
static bool poly_pair(datastructures::Projections &proj, const IR &ir_l, const IR &ir_u)
Definition: criteria.h:128
bool crit_side_degree(datastructures::Projections &proj, const IR &ir, datastructures::RootMap::const_iterator start, datastructures::RootMap::const_iterator end)
Definition: criteria.h:77
bool crit_involved_count(const std::vector< Atom > &constraints)
Definition: criteria.h:61
std::unordered_map< Atom, std::size_t > m_constraint_involved_counter
Definition: criteria.h:14
static bool poly(datastructures::Projections &proj, const IR &ir)
Definition: criteria.h:123
carl::ContextPolynomial< Rational > Polynomial
Definition: common.h:16
Represents the i-th root of a multivariate polynomial at its main variable (given an appropriate samp...
Definition: roots.h:15
PolyRef poly
A multivariate polynomial.
Definition: roots.h:17
size_t index
The index, must be > 0.
Definition: roots.h:19