SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
heuristics_covering.h
Go to the documentation of this file.
2  template<typename T>
3  std::vector<datastructures::SampledDerivationRef<T>> compute_min_derivs(const std::vector<datastructures::SampledDerivationRef<T>>& derivs) {
4  std::vector<datastructures::SampledDerivationRef<T>> sorted_derivs;
5  for (auto& der : derivs) sorted_derivs.emplace_back(der);
6 
7  std::sort(sorted_derivs.begin(), sorted_derivs.end(), [](const datastructures::SampledDerivationRef<T>& p_cell1, const datastructures::SampledDerivationRef<T>& p_cell2) { // cell1 < cell2
8  const auto& cell1 = p_cell1->cell();
9  const auto& cell2 = p_cell2->cell();
10  return lower_lt_lower(cell1, cell2) || (lower_eq_lower(cell1, cell2) && upper_lt_upper(cell2, cell1));
11  });
12 
13  std::vector<datastructures::SampledDerivationRef<T>> min_derivs;
14  auto iter = sorted_derivs.begin();
15  while (iter != sorted_derivs.end()) {
16  min_derivs.emplace_back(*iter);
17  auto& last_cell = (*iter)->cell();
18  iter++;
19  while (iter != sorted_derivs.end() && !upper_lt_upper(last_cell, (*iter)->cell())) iter++;
20  }
21 
22  return min_derivs;
23  }
24 
25  template<typename T>
28  for (auto it = cells.begin(); it != cells.end()-1; it++) {
29  if (enable_weak && (!std::next(it)->description.lower().is_strict() || !it->description.upper().is_strict())) {
30  ordering.add_leq(std::next(it)->description.lower().value(), it->description.upper().value());
31  } else {
32  if (std::next(it)->description.lower().value() == it->description.upper().value()) {
33  ordering.add_eq(std::next(it)->description.lower().value(), it->description.upper().value());
34  } else {
35  ordering.add_less(std::next(it)->description.lower().value(), it->description.upper().value());
36  }
37 
38  }
39  }
40  return ordering;
41  }
42 
43  template <>
45  template<typename T>
48  auto min_derivs = compute_min_derivs(derivs);
49  for (auto& iter : min_derivs) {
51  result.cells.emplace_back(cell_result);
52  }
53  result.ordering = compute_default_ordering(result.cells);
54  return result;
55  }
56  };
57 
58  template <>
60  template<typename T>
63  auto min_derivs = compute_min_derivs(derivs);
64  for (auto& iter : min_derivs) {
66  result.cells.emplace_back(cell_result);
67  result.ordering = cell_result.ordering;
68  }
69  result.ordering = compute_default_ordering(result.cells);
70  return result;
71  }
72  };
73 
74  template <>
76  template<typename T>
79  auto min_derivs = compute_min_derivs(derivs);
81  for (auto& iter : min_derivs) {
83  result.cells.emplace_back(cell_result);
84  tmp_ordering = cell_result.ordering;
85  }
86  result.ordering = compute_default_ordering(result.cells);
87  return result;
88  }
89  };
90 
91  template <>
93  template<typename T>
96  auto min_derivs = compute_min_derivs(derivs);
98  for (auto& iter : min_derivs) {
100  result.cells.emplace_back(cell_result);
101  tmp_ordering = cell_result.ordering;
102  }
103  result.ordering = compute_default_ordering(result.cells);
104  return result;
105  }
106  };
107 
108  template <>
110  template<typename T>
113  auto min_derivs = compute_min_derivs(derivs);
114  for (auto& iter : min_derivs) {
116  result.cells.emplace_back(cell_result);
117  }
118  result.ordering = compute_default_ordering(result.cells);
119  result.ordering.set_projective();
120  return result;
121  }
122  };
123 
124  template <>
126  template<typename T>
129  auto min_derivs = compute_min_derivs(derivs);
130  for (auto& iter : min_derivs) {
132  result.cells.emplace_back(cell_result);
133  }
134  result.ordering = compute_default_ordering(result.cells, true);
135  return result;
136  }
137  };
138 
139  template <>
141  template<typename T>
144  auto min_derivs = compute_min_derivs(derivs);
145  for (auto& iter : min_derivs) {
147  result.cells.emplace_back(cell_result);
148  }
149  result.ordering = compute_default_ordering(result.cells, true);
150  return result;
151  }
152  };
153 
154  namespace util {
155  template<typename T>
158  auto cell_a = a->cell();
159  auto cell_b = b->cell();
160  return datastructures::lower_lt_lower(cell_a, cell_b) || (datastructures::lower_eq_lower(cell_a, cell_b) && datastructures::upper_lt_upper(cell_b, cell_a));
161  }
162  };
163  template<typename T>
164  using DerivationSet = boost::container::flat_set<datastructures::SampledDerivationRef<T>, IntervalCompare<T>>;
165  template<typename T>
166  bool is_covering(const DerivationSet<T>& set) {
167  if (set.empty()) return false;
168  auto current_max = set.end();
169  for (auto iter = set.begin(); iter != set.end(); iter++) {
170  if (current_max == set.end()) {
171  if ((*iter)->cell().lower_unbounded()) {
172  current_max = iter;
173  } else {
174  return false;
175  }
176  } else {
177  if (!datastructures::upper_lt_lower((*current_max)->cell(), (*iter)->cell())) {
178  if (datastructures::upper_lt_upper((*current_max)->cell(), (*iter)->cell())) {
179  current_max = iter;
180  }
181  } else {
182  return false;
183  }
184  }
185  }
186  return (*current_max)->cell().upper_unbounded();
187  }
188  }
189 
190  template <>
192  template<typename T>
194  struct Data {
196  std::size_t tdeg;
197  bool nullified;
198  };
199  std::vector<Data> sorted_by_tdeg;
200  for (auto& deriv : derivs) {
201  std::size_t tdeg = 0;
202  for (const auto& e : deriv->delin().roots()) {
203  for (const auto& e2 : e.second) {
204  tdeg = std::max(tdeg, deriv->proj().total_degree(e2.root.poly));
205  }
206  }
207  bool nullified = deriv->cell().is_sector() && !deriv->delin().nullified().empty();
208  sorted_by_tdeg.push_back(Data{deriv, tdeg, nullified});
209  }
210  std::sort(sorted_by_tdeg.begin(), sorted_by_tdeg.end(), [](const Data& a, const Data& b) {
211  return (a.nullified && !b.nullified) || (a.nullified == b.nullified && a.tdeg > b.tdeg);
212  });
213  util::DerivationSet<T> set(derivs.begin(), derivs.end());
214  for (const auto& e : sorted_by_tdeg) {
215  set.erase(e.deriv);
216  if (!util::is_covering(set)) {
217  set.insert(e.deriv);
218  }
219  }
220  assert(util::is_covering(set));
222  for (auto& deriv : set) {
224  result.cells.emplace_back(cell_result);
225  }
226  result.ordering = compute_default_ordering(result.cells);
227  return result;
228  }
229  };
230 
231  template <>
233  template<typename T>
236 
237  auto min_derivs = compute_min_derivs(derivs);
238 
239  datastructures::Delineation delineation;
240  util::PolyDelineations poly_delins;
241  std::vector<std::size_t> ord_idx;
242  for (auto& iter : min_derivs) {
243  result.cells.emplace_back(iter);
244  auto& cell_result = result.cells.back();
245  cell_result.description = util::compute_simplest_cell((iter)->proj(), (iter)->cell());
246 
247  if ((iter)->cell().is_section()) {
248  handle_section_all_equational(iter, cell_result);
249  delineation.add_root((iter)->cell().lower()->first,datastructures::TaggedIndexedRoot {cell_result.description.section_defining() });
250  } else {
251  ord_idx.push_back(result.cells.size()-1);
252  datastructures::Delineation subdelin = (iter)->delin();
253  auto subdelin_int = subdelin.delineate_cell((iter)->main_var_sample());
254  util::decompose(subdelin, subdelin_int, poly_delins);
255  delineation.merge_with(subdelin);
256  }
257  }
258 
259  assert (ord_idx.size() > 0);
260  auto& proj = (*min_derivs.begin())->proj();
261  util::simplest_chain_ordering(proj, delineation, result.ordering);
262  for (const auto& poly_delin : poly_delins.data) {
263  chain_ordering(poly_delin.first, poly_delin.second, result.ordering);
264  }
265  for (std::size_t idx : ord_idx) {
266  result.cells[idx].ordering = result.ordering;
267  }
268  return result;
269  }
270  };
271 }
Represents the delineation of a set of polynomials (at a sample), that is.
Definition: delineation.h:118
void merge_with(const Delineation &other)
Definition: delineation.h:242
void add_root(RAN root, TaggedIndexedRoot tagged_root)
Definition: delineation.h:206
auto delineate_cell(const RAN &sample) const
Computes the bounds of the interval around the given sample w.r.t.
Definition: delineation.h:154
Describes an ordering of IndexedRoots.
Definition: roots.h:400
void add_eq(RootFunction first, RootFunction second)
Definition: roots.h:449
void add_leq(RootFunction first, RootFunction second)
Definition: roots.h:420
void add_less(RootFunction first, RootFunction second)
Definition: roots.h:435
void sort(T *array, int size, LessThan lt)
Definition: Sort.h:67
bool upper_lt_upper(const DelineationInterval &del1, const DelineationInterval &del2)
Compares the upper bounds of two DelineationIntervals.
Definition: delineation.h:286
bool lower_lt_lower(const DelineationInterval &del1, const DelineationInterval &del2)
Compares the lower bounds of two DelineationIntervals.
Definition: delineation.h:266
bool upper_lt_lower(const DelineationInterval &del1, const DelineationInterval &del2)
Compares an upper bound with a lower bound of DelineationIntervals.
Definition: delineation.h:296
bool lower_eq_lower(const DelineationInterval &del1, const DelineationInterval &del2)
Compares the lower bounds of two DelineationIntervals.
Definition: delineation.h:276
std::shared_ptr< SampledDerivation< Properties > > SampledDerivationRef
Definition: derivation.h:25
void chain_ordering(const datastructures::PolyRef poly, const PolyDelineation &poly_delin, datastructures::IndexedRootOrdering &ordering)
Definition: util.h:399
void simplest_chain_ordering(datastructures::Projections &proj, const datastructures::Delineation &delin, datastructures::IndexedRootOrdering &ordering, bool enable_weak=false)
Definition: util.h:139
bool is_covering(const DerivationSet< T > &set)
datastructures::SymbolicInterval compute_simplest_cell(datastructures::Projections &proj, const datastructures::DelineationInterval &del, bool enable_weak=false)
Definition: util.h:56
boost::container::flat_set< datastructures::SampledDerivationRef< T >, IntervalCompare< T > > DerivationSet
void decompose(datastructures::Delineation &delin, const datastructures::DelineationInterval &delin_interval, PolyDelineations &poly_delins)
Definition: util.h:361
Heuristics for computing representations.
std::vector< datastructures::SampledDerivationRef< T > > compute_min_derivs(const std::vector< datastructures::SampledDerivationRef< T >> &derivs)
void handle_section_all_equational(const datastructures::Delineation &delin, datastructures::CellRepresentation< T > &response)
datastructures::CellRepresentation< T > compute_cell_lowest_degree_barriers(datastructures::SampledDerivationRef< T > &der, LocalDelMode ldel_mode=LocalDelMode::NONE, bool enable_weak=false, bool use_global_cache=false, datastructures::IndexedRootOrdering global_ordering=datastructures::IndexedRootOrdering())
datastructures::IndexedRootOrdering compute_default_ordering(const std::vector< datastructures::CellRepresentation< T >> &cells, bool enable_weak=false)
IndexedRootOrdering ordering
An ordering on the roots that protects the cell.
Note: If connected(i) holds, then the indexed root ordering must contain an ordering between the inte...
Definition: heuristics.h:24
static datastructures::CellRepresentation< T > compute(datastructures::SampledDerivationRef< T > &der)
static datastructures::CoveringRepresentation< T > compute(const std::vector< datastructures::SampledDerivationRef< T >> &derivs)
static datastructures::CoveringRepresentation< T > compute(const std::vector< datastructures::SampledDerivationRef< T >> &derivs)
static datastructures::CoveringRepresentation< T > compute(const std::vector< datastructures::SampledDerivationRef< T >> &derivs)
static datastructures::CoveringRepresentation< T > compute(const std::vector< datastructures::SampledDerivationRef< T >> &derivs)
static datastructures::CoveringRepresentation< T > compute(const std::vector< datastructures::SampledDerivationRef< T >> &derivs)
static datastructures::CoveringRepresentation< T > compute(const std::vector< datastructures::SampledDerivationRef< T >> &derivs)
static datastructures::CoveringRepresentation< T > compute(const std::vector< datastructures::SampledDerivationRef< T >> &derivs)
static datastructures::CoveringRepresentation< T > compute(const std::vector< datastructures::SampledDerivationRef< T >> &derivs)
static datastructures::CoveringRepresentation< T > compute(const std::vector< datastructures::SampledDerivationRef< T >> &derivs)
constexpr bool operator()(const datastructures::SampledDerivationRef< T > &a, const datastructures::SampledDerivationRef< T > &b) const
boost::container::flat_map< datastructures::PolyRef, PolyDelineation > data
Definition: util.h:352