SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
MISGeneration.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "ConflictGraph.h"
4 #include "../common.h"
5 
6 #include <carl-covering/carl-covering.h>
7 #include <carl-arith/constraint/Complexity.h>
8 
9 namespace smtrat {
10 namespace cad {
11 
12  template<MISHeuristic heuristic>
13  class MISGeneration {
14  public:
15  template<typename CAD>
16  void operator()(const CAD& cad, std::vector<FormulaSetT>& mis);
17  };
18 
19  template<>
20  template<typename CAD>
21  void MISGeneration<MISHeuristic::TRIVIAL>::operator()(const CAD& cad, std::vector<FormulaSetT>& mis) {
22  mis.emplace_back();
23  for (const auto& it: cad.getConstraintMap()) mis.back().emplace(it.first);
24  }
25 
26  template<>
27  template<typename CAD>
28  void MISGeneration<MISHeuristic::GREEDY>::operator()(const CAD& cad, std::vector<FormulaSetT>& mis) {
29  auto covering = cad.generateCovering().get_cover(carl::covering::heuristic::greedy);
30  mis.emplace_back();
31  for (const auto& c: covering) {
32  mis.back().emplace(c);
33  }
34  }
35 
36  template<>
37  template<typename CAD>
38  void MISGeneration<MISHeuristic::GREEDY_PRE>::operator()(const CAD& cad, std::vector<FormulaSetT>& mis) {
39  auto covering = cad.generateCovering().get_cover([](auto& sc) {
40  carl::Bitset res;
41  res |= carl::covering::heuristic::remove_duplicates(sc);
42  res |= carl::covering::heuristic::select_essential(sc);
43  res |= carl::covering::heuristic::greedy(sc);
44  return res;
45  });
46  mis.emplace_back();
47  for (const auto& c: covering) {
48  mis.back().emplace(c);
49  }
50  }
51 
52  template<>
53  template<typename CAD>
54  void MISGeneration<MISHeuristic::EXACT>::operator()(const CAD& cad, std::vector<FormulaSetT>& mis) {
55  auto covering = cad.generateCovering().get_cover(carl::covering::heuristic::exact);
56  mis.emplace_back();
57  for (const auto& c: covering) {
58  mis.back().emplace(c);
59  }
60  }
61 
62  template<>
63  template<typename CAD>
64  void MISGeneration<MISHeuristic::HYBRID>::operator()(const CAD& cad, std::vector<FormulaSetT>& mis) {
65  auto cov = cad.generateCovering();
66  carl::Bitset covering;
67 
68  covering |= carl::covering::heuristic::remove_duplicates(cov.set_cover());
69  SMTRAT_LOG_DEBUG("smtrat.mis", "After removing duplicates: " << covering << std::endl << cov);
70 
71  covering |= carl::covering::heuristic::select_essential(cov.set_cover());
72  cov.set_cover().prune_sets();
73 
74  if (cov.set_cover().active_set_count() == 0) {
75  mis.emplace_back();
76  for (const auto& c: covering) {
77  mis.back().emplace(cov.get_set(c));
78  }
79  SMTRAT_LOG_DEBUG("smtrat.mis", "returning after preconditioning");
80  return;
81  }
82  SMTRAT_LOG_DEBUG("smtrat.mis", "After preconditioning: " << covering << std::endl << cov);
83 
84  covering |= carl::covering::heuristic::greedy_weighted(cov,
85  [](const ConstraintT& c){
86  constexpr double constant_weight = 10.0;
87  constexpr double complexity_weight = 0.1;
88  return constant_weight + complexity_weight * (double)complexity(c.constr());
89  }, 12
90  );
91  SMTRAT_LOG_DEBUG("smtrat.mis", "After greedy: " << covering << std::endl << cov);
92 
93  cov.set_cover().prune_sets();
94  if (cov.set_cover().active_set_count() == 0) {
95  mis.emplace_back();
96  for (const auto& c: covering) {
97  mis.back().emplace(cov.get_set(c));
98  }
99  SMTRAT_LOG_DEBUG("smtrat.mis", "returning after greedy");
100  return;
101  }
102 
103  SMTRAT_LOG_DEBUG("smtrat.mis", "Computing exact solution for " << cov);
104  covering |= carl::covering::heuristic::exact(cov.set_cover());
105 
106  assert(cov.set_cover().active_set_count() == 0);
107  mis.emplace_back();
108  for (const auto& c: covering) {
109  mis.back().emplace(cov.get_set(c));
110  }
111  SMTRAT_LOG_DEBUG("smtrat.mis", "returning exact solution");
112  }
113 
114  template<>
115  template<typename CAD>
116  void MISGeneration<MISHeuristic::GREEDY_WEIGHTED>::operator()(const CAD& cad, std::vector<FormulaSetT>& mis) {
117  auto cov = cad.generateCovering();
118  auto covering = carl::covering::heuristic::select_essential(cov.set_cover());
119  cov.set_cover().prune_sets();
120 
121  if (cov.set_cover().active_set_count() == 0) {
122  mis.emplace_back();
123  for (const auto& c: covering) {
124  mis.back().emplace(cov.get_set(c));
125  }
126  SMTRAT_LOG_DEBUG("smtrat.mis", "returning after preconditioning");
127  return;
128  }
129 
130  covering |= carl::covering::heuristic::remove_duplicates(cov.set_cover());
131  covering |= carl::covering::heuristic::greedy_weighted(cov,
132  [](const ConstraintT& c){
133  constexpr double constant_weight = 5.0;
134  constexpr double complexity_weight = 0.1;
135  return constant_weight + complexity_weight * (double)complexity(c.constr());
136  }
137  );
138 
139  mis.emplace_back();
140  for (const auto& c: covering) {
141  mis.back().emplace(cov.get_set(c));
142  }
143  }
144 }
145 }
const auto & getConstraintMap() const
Definition: CAD.h:83
auto generateCovering() const
Definition: CAD.h:234
void operator()(const CAD &cad, std::vector< FormulaSetT > &mis)
std::size_t complexity(const std::vector< FormulaT > &origin)
Class to create the formulas for axioms.
carl::Constraint< Poly > ConstraintT
Definition: types.h:29
#define SMTRAT_LOG_DEBUG(channel, msg)
Definition: logging.h:35