SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
RootIndexer.h
Go to the documentation of this file.
1 #pragma once
2 
4 
5 #include <algorithm>
6 #include <list>
7 #include <map>
8 #include <vector>
9 
10 namespace smtrat {
11 namespace mcsat {
12 namespace arithmetic {
13 
14 template<typename RANT>
15 class RootIndexer {
16 private:
17  std::vector<RANT> mRoots;
18  std::map<RANT, std::size_t> mMap;
19  std::vector<RANT> mSamples;
20 public:
21  void add(const std::vector<RANT>& list) {
22  mRoots.insert(mRoots.end(), list.begin(), list.end());
23  }
24  void process() {
25  std::sort(mRoots.begin(), mRoots.end());
26  mRoots.erase(std::unique(mRoots.begin(), mRoots.end()), mRoots.end());
27  SMTRAT_LOG_DEBUG("smtrat.mcsat.rootindexer", "Roots: " << mRoots);
28  for (std::size_t i = 0; i < mRoots.size(); i++) {
29  mMap.emplace(mRoots[i], i);
30  }
31  mSamples.reserve(2 * mRoots.size() + 1);
32  for (std::size_t n = 0; n < mRoots.size(); n++) {
33  if (n == 0) mSamples.emplace_back(carl::sample_below(mRoots.front()));
34  else mSamples.emplace_back(carl::sample_between(mRoots[n-1], mRoots[n]));
35  mSamples.emplace_back(mRoots[n]);
36  }
37  if (mRoots.empty()) mSamples.emplace_back(RANT(0));
38  else mSamples.emplace_back(carl::sample_above(mRoots.back()));
39  SMTRAT_LOG_DEBUG("smtrat.mcsat.rootindexer", "Samples: " << mSamples);
40  }
41  std::size_t size() const {
42  return mRoots.size();
43  }
44  std::size_t operator[](const RANT& ran) const {
45  auto it = mMap.find(ran);
46  assert(it != mMap.end());
47  return it->second;
48  }
49  const RANT& operator[](std::size_t n) const {
50  assert(n < mRoots.size());
51  return mRoots[n];
52  }
53  const RANT& sampleFrom(std::size_t n) const {
54  return mSamples[n];
55  }
56  bool is_root(std::size_t n) const {
57  return (n % 2) == 1;
58  }
59 };
60 template<typename RANT>
61 inline std::ostream& operator<<(std::ostream& os, const RootIndexer<RANT>& ri) {
62  os << "Roots:" << std::endl;
63  for (std::size_t i = 0; i < ri.size(); i++) {
64  os << "\t" << i << ": " << ri[i] << std::endl;
65  }
66  os << "Samples:" << std::endl;
67  for (std::size_t i = 0; i < ri.size()*2+1; i++) {
68  os << "\t" << i << ": " << ri.sampleFrom(i) << std::endl;;
69  }
70  return os;
71 }
72 
73 
74 }
75 }
76 }
std::map< RANT, std::size_t > mMap
Definition: RootIndexer.h:18
void add(const std::vector< RANT > &list)
Definition: RootIndexer.h:21
bool is_root(std::size_t n) const
Definition: RootIndexer.h:56
const RANT & operator[](std::size_t n) const
Definition: RootIndexer.h:49
const RANT & sampleFrom(std::size_t n) const
Definition: RootIndexer.h:53
std::size_t operator[](const RANT &ran) const
Definition: RootIndexer.h:44
void sort(T *array, int size, LessThan lt)
Definition: Sort.h:67
std::ostream & operator<<(std::ostream &os, const Covering &ri)
Definition: Covering.h:59
Class to create the formulas for axioms.
#define SMTRAT_LOG_DEBUG(channel, msg)
Definition: logging.h:35