3 #include <carl-common/datastructures/carlTree.h>
8 #include "../utils/CADConstraints.h"
15 template<
typename Settings>
18 using Tree = carl::tree<Sample>;
31 std::size_t
dim()
const {
37 if (it.depth() <
dim()) {
45 auto removeIf = [&](
const auto& it){
return !
mTree.is_valid(it); };
53 if (samples.empty())
return false;
54 std::sort(samples.begin(), samples.end());
55 samples.erase(std::unique(samples.begin(), samples.end()), samples.end());
56 bool gotNewSamples =
false;
57 auto tbegin =
mTree.begin_children(parent);
59 auto tend =
mTree.end_children(parent);
61 for (
const auto& s: samples) {
62 while (tit != tend && *tit < s) tit++;
65 auto it =
mTree.append(parent, s);
68 }
else if (tit->value() == s.value()) {
70 if (!tit->isRoot()) gotNewSamples =
true;
74 auto it =
mTree.insert(tit, s);
87 if (
mTree.is_leaf(parent)) {
90 SMTRAT_LOG_TRACE(
"smtrat.cad.lifting",
"Inserting zero node for " <<
var <<
" from " << interval);
97 auto tbegin =
mTree.begin_children(parent);
98 auto tend =
mTree.end_children(parent);
99 auto tit = tbegin, tlast = tbegin;
100 if (tbegin->isRoot()) {
101 auto it =
mTree.insert(tbegin,
Sample(carl::sample_below(tlast->value())));
106 if (tit == tend)
break;
107 if (tlast->isRoot() && tit->isRoot()) {
108 auto it =
mTree.insert(tit,
Sample(carl::sample_between(tlast->value(), tit->value())));
113 if (tlast->isRoot()) {
114 auto it =
mTree.append(parent,
Sample(carl::sample_above(tlast->value())));
142 assert(
mTree.is_valid(it));
153 SMTRAT_LOG_DEBUG(
"smtrat.cad.lifting",
"Resetting samples of full dimension.");
155 for (
auto it =
mTree.begin_depth(
dim()); it !=
mTree.end_depth(); it++) {
181 std::vector<Sample> newSamples;
182 auto result = carl::real_roots(p, m, RationalInterval::unbounded_interval());
183 if (!ignore_nullifications &&
result.is_nullified())
return false;
184 if (!
result.is_univariate() ||
result.roots().empty()) {
186 newSamples.emplace_back(
RAN(0), pid);
188 for (
const auto& r:
result.roots()) {
190 newSamples.emplace_back(r, pid);
194 if (bounds.lower_bound_type() != carl::BoundType::INFTY) {
195 newSamples.emplace_back(
RAN(bounds.lower()),
true);
197 if (bounds.upper_bound_type() != carl::BoundType::INFTY) {
198 newSamples.emplace_back(
RAN(bounds.upper()),
true);
205 if (!
mTree.is_leaf(sample))
return false;
214 for (std::size_t i = 1; i < Settings::trivialSampleRadius; i++) {
215 auto itpos =
mTree.append(sample,
Sample(
RAN(center + i),
false));
217 auto itneg =
mTree.append(sample,
Sample(
RAN(center - i),
false));
226 auto cur =
mTree.begin_path(it);
227 while (cur !=
mTree.end_path() && !cur.isRoot()) {
228 res.emplace(
mVariables[cur.depth()-1], cur->value());
236 SMTRAT_LOG_DEBUG(
"smtrat.cad.lifting",
"Cleanup after removing " << mask <<
" from level " << level);
237 for (
auto it =
mTree.begin_depth(level - 1); it !=
mTree.end_depth(); it++) {
238 it->liftedWith() -= mask;
240 std::vector<Iterator> deleteQueue;
241 for (
auto it =
mTree.begin_depth(level); it !=
mTree.end_depth(); it++) {
242 if (!it->isRoot())
continue;
243 it->rootOf() -= mask;
244 if (it->rootOf().none()) {
245 deleteQueue.emplace_back(it);
249 for (
const auto& it: deleteQueue) {
257 for (
auto& s:
mTree) {
258 if (s.evaluatedWith().size() == 0)
continue;
259 SMTRAT_LOG_DEBUG(
"smtrat.cad.lifting",
"Purging " << s.evaluatedWith() <<
" by " << mask);
260 s.evaluatedWith() -= mask;
261 s.evaluationResult() -= mask;
272 std::vector<Sample> chunks(
mTree.begin_path(sample),
mTree.end_path());
273 std::stringstream ss;
274 for (std::size_t d = 0; d < sample.depth(); d++) {
275 if (d != 0) ss <<
" -> ";
276 ss <<
mVariables[d] <<
" = " << chunks[chunks.size()-2-d];
281 std::stringstream ss;
const auto & bounds() const
LiftingTree & operator=(const LiftingTree &)=delete
void reset(std::vector< carl::Variable > &&vars)
std::string printFullSamples() const
LiftingTree(const Constraints &c)
SampleIteratorQueue< Iterator, SC > mLiftingQueue
const auto & getTree() const
bool hasNextSample() const
const Constraints & mConstraints
LiftingTree(const LiftingTree &)=delete
carl::tree< Sample > Tree
bool liftSample(Iterator sample, const UPoly &p, std::size_t pid, bool ignore_nullifications)
const auto & getLiftingQueue() const
std::string printSample(Iterator sample) const
LiftingTree(LiftingTree &&)=delete
bool is_consistent() const
void cleanQueuesFromExpired()
bool addTrivialSample(Iterator sample)
Iterator getNextFullSample()
void restoreRemovedSamples()
LiftingTree & operator=(LiftingTree &&)=delete
void addToQueue(Iterator it)
std::vector< Iterator > mRemovedFromLiftingQueue
bool mergeRootSamples(Iterator parent, std::vector< Sample > &samples)
void removedConstraint(const carl::Bitset &mask)
std::vector< carl::Variable > mVariables
Assignment extractSampleMap(Iterator it) const
bool hasFullSamples() const
void removedPolynomialsFromLevel(std::size_t level, const carl::Bitset &mask)
SampleIteratorQueue< Iterator, FSC > mCheckingQueue
bool insertRootSamples(Iterator parent, std::vector< Sample > &samples)
void sort(T *array, int size, LessThan lt)
carl::UnivariatePolynomial< Poly > UPoly
std::map< carl::Variable, RAN > Assignment
std::vector< carl::Variable > vars(const std::pair< QuantifierType, std::vector< carl::Variable >> &p)
Class to create the formulas for axioms.
#define SMTRAT_LOG_TRACE(channel, msg)
#define SMTRAT_LOG_DEBUG(channel, msg)