SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
CSplitModule.h
Go to the documentation of this file.
1 /**
2  * @file CSplitModule.h
3  * @author Ă–mer Sali <oemer.sali@rwth-aachen.de>
4  *
5  * @version 2018-04-04
6  * Created on 2017-11-01.
7  */
8 
9 #pragma once
10 
11 #include <optional>
13 #include <smtrat-solver/Manager.h>
14 #include <smtrat-solver/Module.h>
15 #include "../SATModule/SATModule.h"
16 #include "../LRAModule/LRAModule.h"
17 #include "Bimap.h"
18 #include "CSplitSettings.h"
19 
20 namespace smtrat
21 {
22  template<typename Settings>
23  class CSplitModule : public Module
24  {
25  private:
26  /**
27  * Represents the substitution variables of a nonlinear monomial
28  * in a positional notation to the basis Settings::expansionBase.
29  */
30  struct Purification
31  {
32  /// Variable sequence used for the virtual positional notation
33  std::vector<carl::Variable> mSubstitutions;
34  /// Variable that is eliminated from the monomial during reduction
35  carl::Variable mReduction;
36  /// Number of active constraints in which the monomial is included
37  size_t mUsage;
38  /// Flag that indicates whether this purification is used for linearization
39  bool mActive;
40 
42  : mSubstitutions()
43  , mReduction(carl::Variable::NO_VARIABLE)
44  , mUsage(0)
45  , mActive(false)
46  {
47  mSubstitutions.emplace_back(carl::fresh_integer_variable());
48  }
49  };
50 
51  /// Maps a monomial to its purification information
52  std::map<carl::Monomial::Arg, Purification> mPurifications;
53 
54  /// Subdivides the size of a variable domain into three classes:
55  /// - SMALL, if domain size <= Settings::maxDomainSize
56  /// - LARGE, if Settings::maxDomainSize < domain size < infinity
57  /// - UNBOUNDED, if domain size = infinity
58  enum class DomainSize{SMALL = 0, LARGE = 1, UNBOUNDED = 2};
59 
60  /**
61  * Represents the quotients and remainders of a variable in
62  * a positional notation to the basis Settings::expansionBase.
63  */
64  struct Expansion
65  {
66  /// Original variable to which this expansion is dedicated to and its discrete substitute
67  const carl::Variable mRationalization, mDiscretization;
68  /// Center point of the domain where the search starts
70  /// Size of the maximal domain
72  /// Maximal domain deduced from received constraints and the currently active domain
74  /// Sequences of quotients and remainders used for the virtual positional notation
75  std::vector<carl::Variable> mQuotients, mRemainders;
76  /// Active purifications of monomials that contain the rationalization variable
77  std::vector<Purification *> mPurifications;
78  /// Flag that indicates whether the variable bounds changed since last check call
80 
81  Expansion(const carl::Variable& rationalization)
82  : mRationalization(rationalization)
83  , mDiscretization(rationalization.type() == carl::VariableType::VT_INT ? rationalization : carl::fresh_integer_variable())
84  , mNucleus(0)
85  , mMaximalDomainSize(DomainSize::UNBOUNDED)
86  , mMaximalDomain(RationalInterval::unbounded_interval())
87  , mActiveDomain(RationalInterval::empty_interval())
88  , mChangedBounds(false)
89  {
90  mQuotients.emplace_back(mDiscretization);
91  }
92  };
93 
95 
96  /**
97  * Represents the class of all original constraints with the same
98  * left hand side after a normalization. Here, the set of all received
99  * relations of constraints with the same left hand side is stored.
100  */
102  {
103  /// Normalization of the original constraint to which this linearization is dedicated to
105  /// Purifications of the original nonlinear monomials
106  const std::vector<Purification *> mPurifications;
107  /// Flag that indicates whether the original constraint contains real variables
108  const bool mHasRealVariables;
109  /// Relations of constraints with the same left hand side
110  std::unordered_set<carl::Relation> mRelations;
111 
112  Linearization(const Poly& normalization, Poly&& linearization, std::vector<Purification *>&& purifications, bool hasRealVariables)
113  : mNormalization(normalization)
114  , mLinearization(std::move(linearization))
115  , mPurifications(std::move(purifications))
116  , mHasRealVariables(std::move(hasRealVariables))
117  {}
118  };
119 
121 
122  /// Helper class that extracts the variable domains
124  /// Stores the last model for the linearization that was found by the LRA solver
126  /// Stores whether the last consistency check was done by the backends
128 
129  /**
130  * Linear arithmetic module to call for the linearized formula.
131  */
132  struct LAModule : public Manager
133  {
135  {
136  setStrategy({
137  addBackend<SATModule<SATSettings1>>({
138  addBackend<LRAModule<LRASettings1>>()
139  })
140  });
141  }
142  };
143 
144  /// Handle to the linear arithmetic module
146 
147  public:
149 
150  std::string moduleName() const
151  {
152  return SettingsType::moduleName;
153  }
154 
155  CSplitModule(const ModuleInput* _formula, Conditionals& _conditionals, Manager* _manager = nullptr);
156 
157  /**
158  * The module has to take the given sub-formula of the received formula into account.
159  * @param _subformula The sub-formula to take additionally into account.
160  * @return False, if it can be easily decided that this sub-formula causes a conflict with
161  * the already considered sub-formulas;
162  * True, otherwise.
163  */
165 
166  /**
167  * Removes the subformula of the received formula at the given position to the considered ones of this module.
168  * Note that this includes every stored calculation which depended on this subformula, but should keep the other
169  * stored calculation, if possible, untouched.
170  * @param _subformula The position of the subformula to remove.
171  */
173 
174  /**
175  * Updates the current assignment into the model.
176  * Note, that this is a unique but possibly symbolic assignment maybe containing newly introduced variables.
177  */
178  void updateModel() const;
179 
180  /**
181  * Checks the received formula for consistency.
182  * @return SAT, if the received formula is satisfiable;
183  * UNSAT, if the received formula is not satisfiable;
184  * UNKNOWN, otherwise.
185  */
187 
188  private:
189  /**
190  * Resets all expansions to the center points of the variable domains and
191  * constructs a new tree of reductions for the currently active monomials.
192  * @return True, if there exists a maximal domain with no integral points;
193  * False, otherwise.
194  */
196 
197  /**
198  * Bloats the active domains of a subset of variables that are part of the LRA solvers
199  * infeasible subset, and indicates if no active domain could be bloated, because the
200  * maximal domain of all variables were reached.
201  * @param LRAConflict Infeasible subset of the LRA solver
202  * @return True, if no active domain was bloated;
203  * False, otherwise.
204  */
205  bool bloatDomains(const FormulaSetT& LRAConflict);
206 
207  /**
208  * Analyzes the infeasible subset of the LRA solver and constructs an infeasible
209  * subset of the received constraints. The unsatisfiability cannot be deduced if
210  * the corresponding original constraints contain real valued variables.
211  * @param LRAConflict Infeasible subset of the LRA solver
212  * @return UNSAT, if an infeasible subset of the received constraints could be constructed;
213  * UNKNOWN, otherwise.
214  */
215  Answer analyzeConflict(const FormulaSetT& LRAConflict);
216 
217  /**
218  * Changes the active domain of a variable and adapts its positional notation
219  * to the basis Settings::expansionBase.
220  * @param expansion Expansion data structure thats keeps all needed informations.
221  * @param domain The new domain that shall be active afterwards. Note, that the new
222  * domain has to contain the currently active interval.
223  */
224  void changeActiveDomain(Expansion& expansion, RationalInterval&& domain);
225 
226  /**
227  * Asserts/Removes the given formula to/from the LRA solver.
228  * @param formula The formula to assert/remove to the LRA solver.
229  * @param assert True, if formula shall be asserted;
230  * False, if formula shall be removed.
231  */
232  inline void propagateFormula(const FormulaT& formula, bool assert);
233  };
234 }
Container that stores expensive to construct objects and allows the fast lookup with respect to two i...
Definition: Bimap.h:22
void updateModel() const
Updates the current assignment into the model.
std::map< carl::Monomial::Arg, Purification > mPurifications
Maps a monomial to its purification information.
Definition: CSplitModule.h:52
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 changeActiveDomain(Expansion &expansion, RationalInterval &&domain)
Changes the active domain of a variable and adapts its positional notation to the basis Settings::exp...
Answer analyzeConflict(const FormulaSetT &LRAConflict)
Analyzes the infeasible subset of the LRA solver and constructs an infeasible subset of the received ...
bool mCheckedWithBackends
Stores whether the last consistency check was done by the backends.
Definition: CSplitModule.h:127
Model mLRAModel
Stores the last model for the linearization that was found by the LRA solver.
Definition: CSplitModule.h:125
Answer checkCore()
Checks the received formula for consistency.
Bimap< Linearization, const Poly, &Linearization::mNormalization, const Poly, &Linearization::mLinearization > mLinearizations
Definition: CSplitModule.h:120
DomainSize
Subdivides the size of a variable domain into three classes:
Definition: CSplitModule.h:58
LAModule mLRAModule
Handle to the linear arithmetic module.
Definition: CSplitModule.h:145
CSplitModule(const ModuleInput *_formula, Conditionals &_conditionals, Manager *_manager=nullptr)
bool bloatDomains(const FormulaSetT &LRAConflict)
Bloats the active domains of a subset of variables that are part of the LRA solvers infeasible subset...
Bimap< Expansion, const carl::Variable, &Expansion::mRationalization, const carl::Variable, &Expansion::mDiscretization > mExpansions
Definition: CSplitModule.h:94
void propagateFormula(const FormulaT &formula, bool assert)
Asserts/Removes the given formula to/from the LRA solver.
vb::VariableBounds< FormulaT > mVariableBounds
Helper class that extracts the variable domains.
Definition: CSplitModule.h:123
bool addCore(ModuleInput::const_iterator _subformula)
The module has to take the given sub-formula of the received formula into account.
bool resetExpansions()
Resets all expansions to the center points of the variable domains and constructs a new tree of reduc...
std::string moduleName() const
Definition: CSplitModule.h:150
Base class for solvers.
Definition: Manager.h:34
void setStrategy(const std::initializer_list< BackendLink > &backends)
Definition: Manager.h:385
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
carl::mpl_variant_of< VariableTypes >::type VariableType
Variant type for all variables.
Definition: TheoryTypes.h:132
QuantifierType type(const std::pair< QuantifierType, std::vector< carl::Variable >> &p)
Definition: QEQuery.h:39
Class to create the formulas for axioms.
carl::FormulaSet< Poly > FormulaSetT
Definition: types.h:41
carl::Formula< Poly > FormulaT
Definition: types.h:37
const settings::Settings & Settings()
Definition: Settings.h:96
carl::Model< Rational, Poly > Model
Definition: model.h:13
carl::Interval< Rational > RationalInterval
Definition: model.h:27
carl::MultivariatePolynomial< Rational > Poly
Definition: types.h:25
Answer
An enum with the possible answers a Module can give.
Definition: types.h:57
std::vector< std::atomic_bool * > Conditionals
A vector of atomic bool pointers.
Definition: types.h:17
mpq_class Rational
Definition: types.h:19
Represents the quotients and remainders of a variable in a positional notation to the basis Settings:...
Definition: CSplitModule.h:65
bool mChangedBounds
Flag that indicates whether the variable bounds changed since last check call.
Definition: CSplitModule.h:79
const carl::Variable mRationalization
Original variable to which this expansion is dedicated to and its discrete substitute.
Definition: CSplitModule.h:67
std::vector< carl::Variable > mRemainders
Definition: CSplitModule.h:75
const carl::Variable mDiscretization
Definition: CSplitModule.h:67
DomainSize mMaximalDomainSize
Size of the maximal domain.
Definition: CSplitModule.h:71
Expansion(const carl::Variable &rationalization)
Definition: CSplitModule.h:81
Rational mNucleus
Center point of the domain where the search starts.
Definition: CSplitModule.h:69
std::vector< carl::Variable > mQuotients
Sequences of quotients and remainders used for the virtual positional notation.
Definition: CSplitModule.h:75
RationalInterval mActiveDomain
Definition: CSplitModule.h:73
RationalInterval mMaximalDomain
Maximal domain deduced from received constraints and the currently active domain.
Definition: CSplitModule.h:73
std::vector< Purification * > mPurifications
Active purifications of monomials that contain the rationalization variable.
Definition: CSplitModule.h:77
Linear arithmetic module to call for the linearized formula.
Definition: CSplitModule.h:133
Represents the class of all original constraints with the same left hand side after a normalization.
Definition: CSplitModule.h:102
std::unordered_set< carl::Relation > mRelations
Relations of constraints with the same left hand side.
Definition: CSplitModule.h:110
Linearization(const Poly &normalization, Poly &&linearization, std::vector< Purification * > &&purifications, bool hasRealVariables)
Definition: CSplitModule.h:112
const std::vector< Purification * > mPurifications
Purifications of the original nonlinear monomials.
Definition: CSplitModule.h:106
const Poly mNormalization
Normalization of the original constraint to which this linearization is dedicated to.
Definition: CSplitModule.h:104
const bool mHasRealVariables
Flag that indicates whether the original constraint contains real variables.
Definition: CSplitModule.h:108
Represents the substitution variables of a nonlinear monomial in a positional notation to the basis S...
Definition: CSplitModule.h:31
bool mActive
Flag that indicates whether this purification is used for linearization.
Definition: CSplitModule.h:39
size_t mUsage
Number of active constraints in which the monomial is included.
Definition: CSplitModule.h:37
std::vector< carl::Variable > mSubstitutions
Variable sequence used for the virtual positional notation.
Definition: CSplitModule.h:33
carl::Variable mReduction
Variable that is eliminated from the monomial during reduction.
Definition: CSplitModule.h:35