SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
NewCoveringModule.h
Go to the documentation of this file.
1 /**
2  * @file NewCoveringModule.h
3  * @author Philip Kroll <Philip.Kroll@rwth-aachen.de>
4  *
5  * @version 2021-07-08
6  * Created on 2021-07-08.
7  */
8 
9 #pragma once
10 
15 #include "NewCoveringSettings.h"
16 #include <boost/container/flat_set.hpp>
17 #include <smtrat-solver/Module.h>
18 
19 #include <smtrat-cadcells/common.h>
21 
22 #include "Backend.h"
23 #include "LevelWiseInformation.h"
24 
25 #include "NewCoveringStatistics.h"
26 #include "Sampling.h"
27 
28 #include <carl-arith/ran/Conversion.h>
29 #include <carl-arith/poly/Conversion.h>
30 #include <carl-arith/ran/ran.h>
31 
32 
33 namespace smtrat {
34 
35 template<typename Settings>
36 class NewCoveringModule : public Module {
37 private:
38  // List of constraints that have not been passed to the backend
40 
41  // List of constraints that have to be removed from the backend (For Backtracking)
43 
44  // List of all constraints (Only used once for the initial variable ordering and then cleared)
45  std::vector<ConstraintT> mAllConstraints;
46 
47  // Variable Ordering, Initialized in checkCore
48  std::vector<carl::Variable> mVariableOrdering;
49 
50  // The Result of the last check, unkown if not run yet
52 
53  // Contains the last assignment which satisfied all the given known constraints (empty otherwise)
54  carl::Assignment<cadcells::RAN> mLastAssignment;
55 
56  // The actual algorithm
58 
59 public:
61 
62  NewCoveringModule(const ModuleInput* _formula, Conditionals& _conditionals, Manager* _manager = nullptr);
63 
65 
66  // Main interfaces.
67  /**
68  * Informs the module about the given constraint. It should be tried to inform this
69  * module about any constraint it could receive eventually before assertSubformula
70  * is called (preferably for the first time, but at least before adding a formula
71  * containing that constraint).
72  * @param _constraint The constraint to inform about.
73  * @return false, if it can be easily decided whether the given constraint is inconsistent;
74  * true, otherwise.
75  */
76  bool informCore(const FormulaT& _constraint);
77 
78  /**
79  * Informs all backends about the so far encountered constraints, which have not yet been communicated.
80  * This method must not and will not be called more than once and only before the first runBackends call.
81  */
82  void init();
83 
84  /**
85  * The module has to take the given sub-formula of the received formula into account.
86  *
87  * @param _subformula The sub-formula to take additionally into account.
88  * @return false, if it can be easily decided that this sub-formula causes a conflict with
89  * the already considered sub-formulas;
90  * true, otherwise.
91  */
93 
94  /**
95  * Removes the subformula of the received formula at the given position to the considered ones of this module.
96  * Note that this includes every stored calculation which depended on this subformula, but should keep the other
97  * stored calculation, if possible, untouched.
98  *
99  * @param _subformula The position of the subformula to remove.
100  */
102 
103  /**
104  * Updates the current assignment into the model.
105  * Note, that this is a unique but possibly symbolic assignment maybe containing newly introduced variables.
106  */
107  void updateModel() const;
108 
109  /**
110  * Checks the received formula for consistency.
111  * @return True, if the received formula is satisfiable;
112  * False, if the received formula is not satisfiable;
113  * Unknown, otherwise.
114  */
116 
117  /**
118  * Processes the current answer, i.e. computes a model or adds the infeasible subset.
119  *
120  */
122 
123  // ----Backend Interfaces for addition and removal of constraints if the previous call was SAT ----
124 
125  /**
126  * @brief Adds the given constraint to the backend
127  * @return the lowest level with an unsatisfied new constraint
128  * @note returns mVariableOrdering.size()+1 if all new constraints are satisfied
129  * @note If not all new constraints are satisfied the
130  */
132 
133  /**
134  * @brief Removes the given constraints from the backend
135  * @note This also removes all stored information about the removed constraints
136  */
138 
139  // ----Backend Interfaces for addition and removal of constraints if the previous call was UNSAT ----
140 
141  /**
142  * Adds the given constraint to the backend
143  *
144  */
146 
147  /**
148  * Removes the given constraints from the backend
149  * Also removes all stored information about the removed constraints
150  * @return True: If the model is still unsat after removing the constraints
151  * False: If the model might needs re-computation for the higher levels
152  */
154 
155  /**
156  * @brief The actual backtracking algorithm, which is called when we have constraints to add and no constraints to remove
157  *
158  * Removes all cells which were created as a rest of the constraints which are to be removed
159  * if level 0 is still fully covered after removing the constraints UNSAT is returned
160  * Otherwise std::nullopt is returned and level 1 is newly sampled and the algorithm starts again from level 1
161  *
162  * @return std::optional<Answer>, which contains the answer if it can be deduced directly
163  */
164  std::optional<Answer> doBacktracking();
165 
166  /**
167  * @brief The actual incremental algorithm, which is called when we have constraints to add and no constraints to remove
168  *
169  * Tests the new constraints with the last satisfying assignment, if the new constraints are also satisfied.
170  * If the new constraints are all satisfied SAT is returned accordingly
171  * Otherwise std::nullopt is returned and the stored information from the lowest level with an unsatisfied new constraint is removed
172  *
173  * @return std::optional<Answer>, which contains the answer if it can be deduced directly
174  */
175  std::optional<Answer> doIncremental();
176 
177  /**
178  * @brief Algorithms which contains backtracking and incremental checking, its called when we have constraints to add and constraints to remove
179  *
180  * @return std::optional<Answer>, which contains the answer if it can be deduced directly
181  */
182  std::optional<Answer> doIncrementalAndBacktracking();
183 };
184 } // namespace smtrat
Base class for solvers.
Definition: Manager.h:34
The input formula a module has to consider for it's satisfiability check.
Definition: ModuleInput.h:131
super::const_iterator const_iterator
Passing through the list::const_iterator.
Definition: ModuleInput.h:146
A base class for all kind of theory solving methods.
Definition: Module.h:70
void removeConstraintsSAT()
Removes the given constraints from the backend.
bool informCore(const FormulaT &_constraint)
Informs the module about the given constraint.
bool removeConstraintsUNSAT()
Removes the given constraints from the backend Also removes all stored information about the removed ...
void addConstraintsUNSAT()
Adds the given constraint to the backend.
Answer checkCore()
Checks the received formula for consistency.
carl::Assignment< cadcells::RAN > mLastAssignment
Backend< Settings > backend
std::vector< carl::Variable > mVariableOrdering
bool addCore(ModuleInput::const_iterator _subformula)
The module has to take the given sub-formula of the received formula into account.
void removeCore(ModuleInput::const_iterator _subformula)
Removes the subformula of the received formula at the given position to the considered ones of this m...
void processAnswer()
Processes the current answer, i.e.
size_t addConstraintsSAT()
Adds the given constraint to the backend.
void init()
Informs all backends about the so far encountered constraints, which have not yet been communicated.
void updateModel() const
Updates the current assignment into the model.
std::optional< Answer > doBacktracking()
The actual backtracking algorithm, which is called when we have constraints to add and no constraints...
std::optional< Answer > doIncremental()
The actual incremental algorithm, which is called when we have constraints to add and no constraints ...
std::optional< Answer > doIncrementalAndBacktracking()
Algorithms which contains backtracking and incremental checking, its called when we have constraints ...
NewCoveringModule(const ModuleInput *_formula, Conditionals &_conditionals, Manager *_manager=nullptr)
std::vector< ConstraintT > mAllConstraints
Class to create the formulas for axioms.
carl::Formula< Poly > FormulaT
Definition: types.h:37
const settings::Settings & Settings()
Definition: Settings.h:96
Answer
An enum with the possible answers a Module can give.
Definition: types.h:57
@ UNKNOWN
Definition: types.h:57
std::vector< std::atomic_bool * > Conditionals
A vector of atomic bool pointers.
Definition: types.h:17
carl::Formulas< Poly > FormulasT
Definition: types.h:39