SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
ProjectionComparator.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "../common.h"
4 #include "../Settings.h"
5 
6 #include <tuple>
7 
8 namespace smtrat {
9 namespace cad {
10 
11 namespace projection_compare {
12 
13  template<typename Poly>
14  using Candidate = std::tuple<const Poly&, const Poly&, std::size_t>;
15  template<typename Poly>
16  std::ostream& operator<<(std::ostream& os, const Candidate<Poly>& c) {
17  return os << "(" << std::get<0>(c) << ", " << std::get<1>(c) << " on " << std::get<2>(c) << ")";
18  }
19 
20  struct level {};
21  struct degree {};
22  struct type {};
23 
24  template<typename Poly>
25  auto get(const Candidate<Poly>& c, level) {
26  return std::get<2>(c);
27  }
28  template<typename Poly>
29  auto get(const Candidate<Poly>& c, degree) {
30  return std::max(complexity(std::get<0>(c)), complexity(std::get<1>(c)));
31  }
32  template<typename Poly>
33  auto get(const Candidate<Poly>& c, type) {
34  if (&std::get<0>(c) == &std::get<1>(c)) return 0;
35  return 1;
36  }
37 
38  /**
39  * Compares the criterion given by `t` of two samples `lhs` and `rhs` using a comparator `f`.
40  * Returns `0` if the values are the same, `-1` if `lhs` should be used first and `1` if `rhs` should be used first.
41  */
42  template<typename Poly, typename tag, typename F>
43  int compareCriterion(const Candidate<Poly>& lhs, const Candidate<Poly>& rhs, tag t, F&& f) {
44  auto l = get(lhs, t);
45  auto r = get(rhs, t);
46  if (l == r) {
47  SMTRAT_LOG_TRACE("smtrat.cad.projectioncompare", "Comparing " << l << " < " << r << " -> 0");
48  return 0;
49  }
50  SMTRAT_LOG_TRACE("smtrat.cad.projectioncompare", "Comparing " << l << " < " << r << " ? " << (f(l, r) ? -1 : 1));
51  return f(l, r) ? -1 : 1;
52  }
53 
54  template<typename Poly>
55  bool compare(const Candidate<Poly>& lhs, const Candidate<Poly>& rhs) {
56  return lhs < rhs;
57  }
58  template<typename Poly, typename tag, typename F, typename... Tail>
59  bool compare(const Candidate<Poly>& lhs, const Candidate<Poly>& rhs) {
60  int res = compareCriterion(lhs, rhs, tag{}, F{});
61  if (res != 0) return res > 0;
62  return compare<Poly, Tail...>(lhs, rhs);
63  }
64 
65  template<typename... Args>
67  template<typename Poly>
68  bool operator()(const Candidate<Poly>& lhs, const Candidate<Poly>& rhs) const {
69  auto res = compare<Poly, Args...>(lhs, rhs);
70  SMTRAT_LOG_TRACE("smtrat.cad.projectioncompare", lhs << " < " << rhs << " ? " << res);
71  return res;
72  }
73  };
74 
75  using lt = std::less<>;
76  using gt = std::greater<>;
77 
78  template<ProjectionCompareStrategy Strategy>
80 
81  template<>
83  ProjectionComparator_impl<degree, lt> {};
84  template<>
86  ProjectionComparator_impl<type, gt, degree, lt> {};
87  template<>
89  ProjectionComparator_impl<type, lt, degree, lt> {};
90  template<>
92  ProjectionComparator_impl<level, lt, degree, lt> {};
93  template<>
95  ProjectionComparator_impl<level, gt, degree, lt> {};
96 
97 }
98 
100 
101  template<typename Poly>
102  projection_compare::Candidate<Poly> candidate(const Poly& p, const Poly& q, std::size_t level) {
103  return projection_compare::Candidate<Poly>(p, q, level);
104  }
105 }
106 }
std::size_t complexity(const std::vector< FormulaT > &origin)
std::tuple< const Poly &, const Poly &, std::size_t > Candidate
auto get(const Candidate< Poly > &c, level)
int compareCriterion(const Candidate< Poly > &lhs, const Candidate< Poly > &rhs, tag t, F &&f)
Compares the criterion given by t of two samples lhs and rhs using a comparator f.
bool compare(const Candidate< Poly > &lhs, const Candidate< Poly > &rhs)
std::ostream & operator<<(std::ostream &os, const Candidate< Poly > &c)
projection_compare::Candidate< Poly > candidate(const Poly &p, const Poly &q, std::size_t level)
ProjectionCompareStrategy
Definition: Settings.h:10
Class to create the formulas for axioms.
carl::MultivariatePolynomial< Rational > Poly
Definition: types.h:25
#define SMTRAT_LOG_TRACE(channel, msg)
Definition: logging.h:36
bool operator()(const Candidate< Poly > &lhs, const Candidate< Poly > &rhs) const