SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
PBPPModule.h
Go to the documentation of this file.
1 /**
2  *
3  * Supports optimization.
4  *
5  * @file PBPPModule.h
6  * @author YOUR NAME <YOUR EMAIL ADDRESS>
7  *
8  * @version 2016-11-23
9  * Created on 2016-11-23.
10  */
11 
12 #pragma once
13 
14 #include <carl-arith/numbers/PrimeFactory.h>
15 #include <boost/math/common_factor.hpp>
16 
20 #include "Encoders/RNSEncoder.h"
24 
25 #include <smtrat-solver/Module.h>
26 
27 #include "PBPPSettings.h"
28 #include "PBPPStatistics.h"
30 
31 
32 namespace smtrat
33 {
34  template<typename Settings>
35  class PBPPModule : public Module
36  {
37  private:
38 #ifdef SMTRAT_DEVOPTION_Statistics
39  PBPPStatistics mStatistics;
40 #endif
41  // Members.
42  std::map<carl::Variable, carl::Variable> mVariablesCache; // int, bool
43  std::vector<carl::Variable> mCheckedVars;
44  std::vector<carl::Variable> mConnectedVars;
45 
46  std::vector<ConstraintT> liaConstraints;
47  std::vector<ConstraintT> boolConstraints;
48  std::vector<ConstraintT> mConstraints;
49 
50  // the actual encodings by constraint. Does not contain any coupling. These are just substitutions.
51  std::map<ConstraintT, FormulaT> boolEncodings;
52  std::map<ConstraintT, FormulaT> liaConstraintFormula;
53 
54  std::map<ConstraintT, Rational> conversionSizeByConstraint;
55  std::map<ConstraintT, PseudoBoolEncoder*> encoderByConstraint;
56  std::map<ConstraintT, FormulaT> formulaByConstraint;
57 
65 
67 
68  std::vector<PseudoBoolEncoder*> mEncoders;
69 
70  public:
72  std::string moduleName() const {
73  return SettingsType::moduleName;
74  }
75  PBPPModule(const ModuleInput* _formula, Conditionals& _conditionals, Manager* _manager = nullptr);
76 
78 
79  // Main interfaces.
80  /**
81  * Informs the module about the given constraint. It should be tried to inform this
82  * module about any constraint it could receive eventually before assertSubformula
83  * is called (preferably for the first time, but at least before adding a formula
84  * containing that constraint).
85  * @param _constraint The constraint to inform about.
86  * @return false, if it can be easily decided whether the given constraint is inconsistent;
87  * true, otherwise.
88  */
89  bool informCore( const FormulaT& _constraint );
90 
91  /**
92  * Informs all backends about the so far encountered constraints, which have not yet been communicated.
93  * This method must not and will not be called more than once and only before the first runBackends call.
94  */
95  void init();
96 
97  /**
98  * The module has to take the given sub-formula of the received formula into account.
99  *
100  * @param _subformula The sub-formula to take additionally into account.
101  * @return false, if it can be easily decided that this sub-formula causes a conflict with
102  * the already considered sub-formulas;
103  * true, otherwise.
104  */
106 
107  /**
108  * Removes the subformula of the received formula at the given position to the considered ones of this module.
109  * Note that this includes every stored calculation which depended on this subformula, but should keep the other
110  * stored calculation, if possible, untouched.
111  *
112  * @param _subformula The position of the subformula to remove.
113  */
115 
116  /**
117  * Updates the current assignment into the model.
118  * Note, that this is a unique but possibly symbolic assignment maybe containing newly introduced variables.
119  */
120  void updateModel() const;
121 
122  /**
123  * Checks the received formula for consistency.
124  * @return True, if the received formula is satisfiable;
125  * False, if the received formula is not satisfiable;
126  * Unknown, otherwise.
127  */
129 
130  private:
131  bool isAllCoefficientsEqual(const ConstraintT& constraint);
134 
135  FormulaT forwardAsArithmetic(const ConstraintT& formula, const std::set<carl::Variable>& boolVariables);
136 
137  FormulaT generateVarChain(const std::set<carl::Variable>& vars, carl::FormulaType type);
138  FormulaT interconnectVariables(const std::set<carl::Variable>& variables);
139 
140  bool encodeAsBooleanFormula(const ConstraintT& constraint);
141  bool isTrivial(const ConstraintT& constraint);
142 
143  void extractConstraints(const FormulaT& formula);
144 
145  void addConstraints(const FormulaT& formula);
146 
148 
149 
150  };
151 }
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
ModuleStatistics & mStatistics
Definition: Module.h:192
void removeCore(ModuleInput::const_iterator _subformula)
Removes the subformula of the received formula at the given position to the considered ones of this m...
std::vector< ConstraintT > mConstraints
Definition: PBPPModule.h:48
std::map< ConstraintT, PseudoBoolEncoder * > encoderByConstraint
Definition: PBPPModule.h:55
LongFormulaEncoder mLongFormulaEncoder
Definition: PBPPModule.h:60
std::vector< PseudoBoolEncoder * > mEncoders
Definition: PBPPModule.h:68
std::map< ConstraintT, FormulaT > formulaByConstraint
Definition: PBPPModule.h:56
bool addCore(ModuleInput::const_iterator _subformula)
The module has to take the given sub-formula of the received formula into account.
std::map< ConstraintT, FormulaT > liaConstraintFormula
Definition: PBPPModule.h:52
FormulaT convertSmallFormula(const ConstraintT &formula)
std::map< ConstraintT, Rational > conversionSizeByConstraint
Definition: PBPPModule.h:54
std::vector< ConstraintT > liaConstraints
Definition: PBPPModule.h:46
FormulaT interconnectVariables(const std::set< carl::Variable > &variables)
void extractConstraints(const FormulaT &formula)
RNSEncoder mRNSEncoder
Definition: PBPPModule.h:58
TotalizerEncoder mTotalizerEncoder
Definition: PBPPModule.h:64
std::map< ConstraintT, FormulaT > boolEncodings
Definition: PBPPModule.h:51
PseudoBoolNormalizer mNormalizer
Definition: PBPPModule.h:66
std::map< carl::Variable, carl::Variable > mVariablesCache
Definition: PBPPModule.h:42
bool informCore(const FormulaT &_constraint)
Informs the module about the given constraint.
FormulaT forwardAsArithmetic(const ConstraintT &formula, const std::set< carl::Variable > &boolVariables)
void addConstraints(const FormulaT &formula)
std::vector< carl::Variable > mConnectedVars
Definition: PBPPModule.h:44
ShortFormulaEncoder mShortFormulaEncoder
Definition: PBPPModule.h:59
MixedSignEncoder mMixedSignEncoder
Definition: PBPPModule.h:62
bool isTrivial(const ConstraintT &constraint)
void init()
Informs all backends about the so far encountered constraints, which have not yet been communicated.
bool isAllCoefficientsEqual(const ConstraintT &constraint)
std::vector< carl::Variable > mCheckedVars
Definition: PBPPModule.h:43
Answer checkCore()
Checks the received formula for consistency.
CardinalityEncoder mCardinalityEncoder
Definition: PBPPModule.h:61
bool encodeAsBooleanFormula(const ConstraintT &constraint)
void updateModel() const
Updates the current assignment into the model.
std::vector< ConstraintT > boolConstraints
Definition: PBPPModule.h:47
std::string moduleName() const
Definition: PBPPModule.h:72
FormulaT convertBigFormula(const ConstraintT &formula)
PBPPModule(const ModuleInput *_formula, Conditionals &_conditionals, Manager *_manager=nullptr)
Settings SettingsType
Definition: PBPPModule.h:71
FormulaT generateVarChain(const std::set< carl::Variable > &vars, carl::FormulaType type)
ExactlyOneCommanderEncoder mExactlyOneCommanderEncoder
Definition: PBPPModule.h:63
FormulaT restoreFormula(const FormulaT &formula)
TotalizerEncoder implements the Totalizer encoding as described in "Incremental Cardinality Constrain...
QuantifierType type(const std::pair< QuantifierType, std::vector< carl::Variable >> &p)
Definition: QEQuery.h:39
std::vector< carl::Variable > vars(const std::pair< QuantifierType, std::vector< carl::Variable >> &p)
Definition: QEQuery.h:43
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
std::vector< std::atomic_bool * > Conditionals
A vector of atomic bool pointers.
Definition: types.h:17
carl::Constraint< Poly > ConstraintT
Definition: types.h:29