SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
cad_projections.cpp
Go to the documentation of this file.
1 #include "variables.h"
2 #include "utils.h"
3 #include "../settings.h"
4 
5 #include <smtrat-cad/common.h>
6 #include <smtrat-cad/Settings.h>
11 
12 namespace smtrat::analyzer {
13 
14 template<typename Settings>
15 struct Projector {
18 
21  [&](const cad::UPoly& p, std::size_t cid, bool isBound){ mProjection.addPolynomial(cad::projection::normalize(p), cid, isBound); },
22  [&](const cad::UPoly& p, std::size_t cid, bool isBound){ mProjection.addEqConstraint(cad::projection::normalize(p), cid, isBound); },
23  [&](const cad::UPoly& p, std::size_t cid, bool isBound){ mProjection.removePolynomial(cad::projection::normalize(p), cid, isBound); }
24  ),
26  {}
27  void add(const ConstraintT& c) {
28  mConstraints.add(c);
29  }
30 };
31 
32 template<typename P>
33 void collect_projection_size(const std::string& prefix, const P& projection, AnalyzerStatistics& stats) {
34  std::size_t sum = 0;
35  DegreeCollector dc;
36  for (std::size_t level = 1; level <= projection.mProjection.dim(); ++level) {
37  sum += projection.mProjection.size(level);
38  for (std::size_t pid = 0; pid < projection.mProjection.size(level); ++pid) {
39  if (projection.mProjection.hasPolynomialById(level, pid)) {
40  const auto& p = projection.mProjection.getPolynomialById(level, pid);
41  dc(p);
42  }
43  }
44  }
45  stats.add(prefix + "_size", sum);
46  stats.add(prefix + "_deg_max", dc.degree_max);
47  stats.add(prefix + "_deg_sum", dc.degree_sum);
48  stats.add(prefix + "_tdeg_max", dc.tdegree_max);
49  stats.add(prefix + "_tdeg_sum", dc.tdegree_sum);
50 }
51 
52 template<typename Settings>
53 void perform_projection(const std::string& prefix, const std::set<ConstraintT>& constraints, AnalyzerStatistics& stats) {
55  std::vector<Poly> polys;
56  for (const auto& c: constraints) {
57  polys.emplace_back(c.lhs());
58  }
60  p.mProjection.reset();
61  for (const auto& c: constraints) {
62  p.add(c);
63  }
64 
66 }
67 
70 };
73 };
76 };
79 };
82 };
85 };
86 
88  if (settings_analyzer().analyze_projections == "none") return;
89 
90  std::set<ConstraintT> constraints;
91 
92  carl::visit(f, [&](const FormulaT& f){
93  if (f.type() == carl::FormulaType::CONSTRAINT) {
94  constraints.insert(f.constraint());
95  }
96  });
97 
98  bool all = (settings_analyzer().analyze_projections == "all");
99  if (all || settings_analyzer().analyze_projections == "collins") {
100  perform_projection<SettingsCollins>("cad_projection_collins", constraints, stats);
101  }
102  if (all || settings_analyzer().analyze_projections == "hong") {
103  perform_projection<SettingsHong>("cad_projection_hong", constraints, stats);
104  }
105  if (all || settings_analyzer().analyze_projections == "mccallum") {
106  perform_projection<SettingsMcCallum>("cad_projection_mccallum", constraints, stats);
107  }
108  if (all || settings_analyzer().analyze_projections == "mccallum_partial") {
109  perform_projection<SettingsMcCallumPartial>("cad_projection_mccallum_partial", constraints, stats);
110  }
111  if (all || settings_analyzer().analyze_projections == "lazard") {
112  perform_projection<SettingsLazard>("cad_projection_lazard", constraints, stats);
113  }
114  if (all || settings_analyzer().analyze_projections == "brown") {
115  perform_projection<SettingsBrown>("cad_projection_brown", constraints, stats);
116  }
117 }
118 
119 }
std::size_t add(const ConstraintT &c)
void reset(const std::vector< carl::Variable > &vars)
void analyze_cad_projections(const FormulaT &f, AnalyzerStatistics &stats)
void perform_projection(const std::string &prefix, const std::set< ConstraintT > &constraints, AnalyzerStatistics &stats)
void collect_projection_size(const std::string &prefix, const P &projection, AnalyzerStatistics &stats)
Poly normalize(const Poly &p)
Normalizes the given Poly by removing constant and duplicate factors.
Definition: utils.h:32
std::vector< carl::Variable > triangular_ordering(const std::vector< Poly > &polys)
carl::UnivariatePolynomial< Poly > UPoly
Definition: common.h:17
ProjectionType
Definition: Settings.h:9
std::vector< T > prefix(const std::vector< T > vars, std::size_t prefixSize)
Definition: utils.h:349
carl::Formula< Poly > FormulaT
Definition: types.h:37
carl::Constraint< Poly > ConstraintT
Definition: types.h:29
const auto & settings_analyzer()
Definition: settings.h:33
void add(const std::string &key, const T &value)
Definition: statistics.h:10
void add(const ConstraintT &c)
cad::CADConstraints< Settings::backtracking > mConstraints
cad::ProjectionT< Settings > mProjection
static constexpr cad::ProjectionType projectionOperator
static constexpr cad::ProjectionType projectionOperator
static constexpr cad::ProjectionType projectionOperator
static constexpr cad::ProjectionType projectionOperator
static constexpr cad::ProjectionType projectionOperator
static constexpr cad::ProjectionType projectionOperator