SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
VSModule.h
Go to the documentation of this file.
1 /**
2  * @file VSModule.h
3  * @author Florian Corzilius <corzilius@cs.rwth-aachen.de>
4  *
5  * Created on January 18, 2012, 3:45 PM
6  */
7 
8 #pragma once
9 
10 //#define VS_PRINT_ANSWERS
11 //#define VS_LOG_INTERMEDIATE_STEPS
12 
14 #include <smtrat-common/model.h>
15 #include "Substitute.h"
16 #include "State.h"
17 #include "VSStatistics.h"
18 #include <carl-common/memory/IDPool.h>
19 #include <smtrat-solver/Module.h>
20 
21 namespace smtrat
22 {
23  template<class Settings>
24  class VSModule: public Module
25  {
26  private:
27 
28  /// A map from constraints represented by carl::formulas to vs::conditions.
29  typedef std::map<FormulaT, const vs::Condition*> FormulaConditionMap;
30  /// A vector of carl::variable pairs.
31  typedef std::vector<std::pair<carl::Variable,carl::Variable>> VarPairVector;
32 
33  // Members.
34 
35  /// A flag being true, if a condition in the root state has been changed after the last consistency check.
37  /// A flag, which is true if the last check was a full one.
39  /// A flag being true, if it is known that a constraint has been added to the root state, which is inconsistent itself.
41  ///
42  bool mLazyMode;
43  /// For the allocation of unique ids for the states.
44  size_t mIDCounter;
45  ///
47  /// Id allocator for the conditions.
48  carl::IDPool* mpConditionIdAllocator;
49  ///
51  ///
52  carl::Variables mAllVariables;
53  ///
55  /// The order for all states, in which they shall be processed. The first state in this map is processed first.
57  /**
58  * Stores for each depth in the state tree (hence, for the variable eliminated in that state) a
59  * variable for minus infinity (the first) and epsilon (the second).
60  */
62 
63  #ifdef SMTRAT_DEVOPTION_Statistics
64  /// Stores all collected statistics during solving.
65  VSStatistics& mStatistics = statistics_get<VSStatistics>(moduleName() + "_" + std::to_string(id()));
66  #endif
67 
68  public:
70  std::string moduleName() const {
71  return SettingsType::moduleName;
72  }
73 
74  // Constructors.
75  VSModule( const ModuleInput*, Conditionals&, Manager* const = NULL );
76 
77  // Destructor.
79 
80  // Interfaces.
82 
83  /**
84  * Checks the received formula for consistency.
85  * @param _final true, if this satisfiability check will be the last one (for a global sat-check), if its result is SAT.
86  * @param _full false, if this module should avoid too expensive procedures and rather return unknown instead.
87  * @param _objective if not set to NO_VARIABLE, the module should find an assignment minimizing this objective variable; otherwise any assignment is good.
88  * @return SAT, if the received formula is satisfiable;
89  * UNSAT, if the received formula is not satisfiable;
90  * Unknown, otherwise.
91  */
94  void updateModel() const;
95 
96  private:
97 
98  /// A pair of a substitution and the states which belong to this substitution.
99  typedef std::pair<vs::Substitution, std::list< vs::State* >> ChildrenGroup;
100  /// A vector of pairs of a substitution and the states which belong to this substitution.
101  typedef std::vector<ChildrenGroup> ChildrenGroups;
102 
103  /**
104  * Increase the counter for id allocation.
105  */
107  {
108  assert( mIDCounter < UINT_MAX );
109  mIDCounter++;
110  }
111 
112  /**
113  * @return
114  */
116 
117  /**
118  * Eliminates the given variable by finding test candidates of the constraint of the given
119  * condition. All this happens in the state _currentState.
120  * @param _currentState The currently considered state.
121  * @param _eliminationVar The substitution to apply.
122  * @param _condition The condition with the constraint, in which should be substituted.
123  * @sideeffect: For each test candidate a new child of the currently considered state
124  * is generated. The solved constraint in the currently considered
125  * state is now labeled by true, which means, that the constraint
126  * already served to eliminate for the respective variable in this
127  * state.
128  */
129  void eliminate( vs::State* _currentState, const carl::Variable& _eliminationVar, const vs::Condition* _condition );
130 
131  /**
132  * Applies the substitution of _currentState to the given conditions.
133  * @param _currentState The currently considered state.
134  * @param _conditions The conditions to which the substitution in this state
135  * shall be applied. Note that these conditions are always
136  * a subset of the condition vector in the father of this
137  * state.
138  * @sideeffect: The result is stored in the substitution result of the given state.
139  */
140  bool substituteAll( vs::State* _currentState, vs::ConditionList& _conditions );
141 
142  /**
143  * Applies the substitution of the given state to all conditions, which were recently added to it.
144  * @param _currentState The currently considered state.
145  */
146  void propagateNewConditions( vs::State* _currentState );
147 
148  /**
149  * Inserts a state in the ranking.
150  * @param _state The states, which will be inserted.
151  */
152  void addStateToRanking( vs::State* _state );
153 
154  /**
155  * Inserts a state and all its successors in the ranking.
156  * @param _state The root of the states, which will be inserted.
157  */
158  void addStatesToRanking( vs::State* _state );
159 
160  /**
161  * Inserts all states with too high degree conditions being the given state or any of its successors in the ranking.
162  * @param _state The root of the states, which will be inserted if they have too high degree conditions.
163  */
165 
166  /**
167  * Removes a state from the ranking.
168  * @param _state The states, which will be erased of the ranking.
169  * @return SAT, if the state was in the ranking.
170  */
172 
173  /**
174  * Removes a state and its successors from the ranking.
175  * @param _state The root of the states, which will be erased of the ranking.
176  */
178 
179  bool checkRanking() const;
180 
181  FormulaSetT getReasons( const carl::PointerSet<vs::Condition>& _conditions ) const;
182  std::vector<FormulaT> getReasonsAsVector( const carl::PointerSet<vs::Condition>& _conditions ) const;
183 
184  /**
185  *
186  * @param _includeInconsistentTestCandidates
187  */
188  void updateInfeasibleSubset( bool _includeInconsistentTestCandidates = false );
189 
191 
192  /**
193  * Finds all minimum covering sets of a vector of sets of sets. A minimum covering set
194  * fulfills the following properties:
195  * 1.) It covers in each set of sets at least one of its sets.
196  * 2.) If you delete any element of the minimum covering set, the
197  * first property does not hold anymore.
198  * @param _conflictSets The vector of sets of sets, for which the method finds all minimum covering sets.
199  * @param _minCovSets The resulting minimum covering sets.
200  */
201  static void allMinimumCoveringSets( const vs::ConditionSetSetSet& _conflictSets, vs::ConditionSetSet& _minCovSets );
202 
203  /**
204  * Adapts the passed formula according to the conditions of the currently considered state.
205  * @param _state
206  * @param _formulaCondMap
207  * @return true, if the passed formula has been changed;
208  * false, otherwise.
209  */
210  bool adaptPassedFormula( const vs::State& _state, FormulaConditionMap& _formulaCondMap );
211 
212  /**
213  * Run the backend solvers on the conditions of the given state.
214  * @param _state The state to check the conditions of.
215  * @return SAT, if the conditions are consistent and there is no unfinished ancestor;
216  * UNSAT, if the conditions are inconsistent;
217  * Unknown, if the theory solver cannot give an answer for these conditons.
218  */
220 
221  /**
222  * Checks the correctness of the symbolic assignment given by the path from the root
223  * state to the satisfying state.
224  */
225  void checkAnswer() const;
226 
227  /**
228  * Checks whether the set of conditions is is consistent/inconsistent.
229  * @param _state
230  * @param _assumption
231  * @param _description
232  */
233  void logConditions( const vs::State& _state, bool _assumption, const std::string& _description, bool _logAsDeduction = true ) const;
234 
235  public:
236 
237  /**
238  * Prints the history to the output stream.
239  * @param _init The beginning of each row.
240  * @param _out The output stream where the history should be printed.
241  */
242  void printAll( const std::string& _init = "", std::ostream& _out = std::cout ) const;
243 
244  /**
245  * Prints the history to the output stream.
246  * @param _init The beginning of each row.
247  * @param _out The output stream where the history should be printed.
248  */
249  void printFormulaConditionMap( const std::string& _init = "", std::ostream& _out = std::cout ) const;
250 
251  /**
252  * Prints the history to the output stream.
253  * @param _init The beginning of each row.
254  * @param _out The output stream where the history should be printed.
255  */
256  void printRanking( const std::string& _init = "", std::ostream& _out = std::cout ) const;
257 
258  /**
259  * Prints the answer if existent.
260  * @param _init The beginning of each row.
261  * @param _out The output stream where the answer should be printed.
262  */
263  void printAnswer( const std::string& _init = "", std::ostream& _out = std::cout ) const;
264  };
265 
266 } // end 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
ModuleStatistics & mStatistics
Definition: Module.h:192
Answer checkCore()
Checks the received formula for consistency.
void checkAnswer() const
Checks the correctness of the symbolic assignment given by the path from the root state to the satisf...
std::string moduleName() const
Definition: VSModule.h:70
static void allMinimumCoveringSets(const vs::ConditionSetSetSet &_conflictSets, vs::ConditionSetSet &_minCovSets)
Finds all minimum covering sets of a vector of sets of sets.
VarPairVector mVariableVector
Stores for each depth in the state tree (hence, for the variable eliminated in that state) a variable...
Definition: VSModule.h:61
void removeStatesFromRanking(vs::State &_state)
Removes a state and its successors from the ranking.
void addStatesToRanking(vs::State *_state)
Inserts a state and all its successors in the ranking.
std::pair< vs::Substitution, std::list< vs::State * > > ChildrenGroup
A pair of a substitution and the states which belong to this substitution.
Definition: VSModule.h:99
void propagateNewConditions(vs::State *_currentState)
Applies the substitution of the given state to all conditions, which were recently added to it.
Answer consistencyTrue()
void printFormulaConditionMap(const std::string &_init="", std::ostream &_out=std::cout) const
Prints the history to the output stream.
std::map< FormulaT, const vs::Condition * > FormulaConditionMap
A map from constraints represented by carl::formulas to vs::conditions.
Definition: VSModule.h:29
bool mLastCheckFull
A flag, which is true if the last check was a full one.
Definition: VSModule.h:38
vs::ValuationMap mRanking
The order for all states, in which they shall be processed. The first state in this map is processed ...
Definition: VSModule.h:56
Settings SettingsType
Definition: VSModule.h:69
void removeCore(ModuleInput::const_iterator)
void printRanking(const std::string &_init="", std::ostream &_out=std::cout) const
Prints the history to the output stream.
void addStateToRanking(vs::State *_state)
Inserts a state in the ranking.
void insertTooHighDegreeStatesInRanking(vs::State *_state)
Inserts all states with too high degree conditions being the given state or any of its successors in ...
bool solutionInDomain()
size_t mIDCounter
For the allocation of unique ids for the states.
Definition: VSModule.h:44
std::vector< FormulaT > getReasonsAsVector(const carl::PointerSet< vs::Condition > &_conditions) const
bool checkRanking() const
vs::State * mpStateTree
Definition: VSModule.h:50
void logConditions(const vs::State &_state, bool _assumption, const std::string &_description, bool _logAsDeduction=true) const
Checks whether the set of conditions is is consistent/inconsistent.
std::vector< std::pair< carl::Variable, carl::Variable > > VarPairVector
A vector of carl::variable pairs.
Definition: VSModule.h:31
bool mConditionsChanged
A flag being true, if a condition in the root state has been changed after the last consistency check...
Definition: VSModule.h:36
bool mInconsistentConstraintAdded
A flag being true, if it is known that a constraint has been added to the root state,...
Definition: VSModule.h:40
Answer runBackendSolvers(vs::State *_state)
Run the backend solvers on the conditions of the given state.
FormulaSetT getReasons(const carl::PointerSet< vs::Condition > &_conditions) const
bool adaptPassedFormula(const vs::State &_state, FormulaConditionMap &_formulaCondMap)
Adapts the passed formula according to the conditions of the currently considered state.
void printAll(const std::string &_init="", std::ostream &_out=std::cout) const
Prints the history to the output stream.
bool substituteAll(vs::State *_currentState, vs::ConditionList &_conditions)
Applies the substitution of _currentState to the given conditions.
void increaseIDCounter()
Increase the counter for id allocation.
Definition: VSModule.h:106
VSModule(const ModuleInput *, Conditionals &, Manager *const =NULL)
carl::Variables mAllVariables
Definition: VSModule.h:52
carl::IDPool * mpConditionIdAllocator
Id allocator for the conditions.
Definition: VSModule.h:48
bool removeStateFromRanking(vs::State &_state)
Removes a state from the ranking.
void updateInfeasibleSubset(bool _includeInconsistentTestCandidates=false)
bool addCore(ModuleInput::const_iterator)
void printAnswer(const std::string &_init="", std::ostream &_out=std::cout) const
Prints the answer if existent.
std::vector< ChildrenGroup > ChildrenGroups
A vector of pairs of a substitution and the states which belong to this substitution.
Definition: VSModule.h:101
FormulaConditionMap mFormulaConditionMap
Definition: VSModule.h:54
void updateModel() const
Updates the model, if the solver has detected the consistency of the received formula,...
size_t mLazyCheckThreshold
Definition: VSModule.h:46
void eliminate(vs::State *_currentState, const carl::Variable &_eliminationVar, const vs::Condition *_condition)
Eliminates the given variable by finding test candidates of the constraint of the given condition.
std::set< ConditionSetSet > ConditionSetSetSet
Definition: State.h:29
std::list< const Condition * > ConditionList
Definition: State.h:30
std::set< carl::PointerSet< Condition > > ConditionSetSet
Definition: State.h:28
std::map< UnsignedTriple, vs::State *, unsignedTripleCmp > ValuationMap
Definition: State.h:62
Class to create the formulas for axioms.
carl::FormulaSet< Poly > FormulaSetT
Definition: types.h:41
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