SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
Module.h
Go to the documentation of this file.
1 /**
2  * @file Module.h
3  * @author Florian Corzilius
4  * @author Ulrich Loup
5  * @author Sebastian Junges
6  * @since 2012-01-18
7  * @version 2013-02-06
8  */
9 
10 #pragma once
11 
12 #include <vector>
13 #include <set>
14 #include <string>
15 #include <atomic>
16 #include <mutex>
19 #include "ModuleInput.h"
20 
21 namespace smtrat
22 {
23  class Manager; // forward declaration
24 
25  /// A vector of atomic bool pointers.
26  typedef std::vector<std::atomic_bool*> Conditionals;
27 
28  /**
29  * Stores all necessary information of an branch, which can be used to detect probable infinite loop of branchings.
30  */
31  struct Branching
32  {
33  /// The polynomial to branch at.
34 #ifdef __VS
35  Poly::PolyType mPolynomial;
36 #else
37  typename Poly::PolyType mPolynomial;
38 #endif
39  /// The value to branch the polynomial at.
41  /// The number of repetitions of the branching.
42  size_t mRepetitions;
43  /**
44  * Stores whether this the branching of the polynomial has been on an increasing sequence of values (>0),
45  * or on a decreasing sequence of values (<0). It is initially zero.
46  */
48 
49  /**
50  * Constructor.
51  * @param _polynomial The polynomial to branch at.
52  * @param _value The value to branch the polynomial at.
53  */
54 #ifdef __VS
55  Branching(const Poly::PolyType& _polynomial, const Rational& _value) :
56 #else
57  Branching( const typename Poly::PolyType& _polynomial, const Rational& _value ):
58 #endif
59  mPolynomial( _polynomial ),
60  mValue( _value ),
61  mRepetitions( 1 ),
62  mIncreasing( 0 )
63  {}
64  };
65 
66  /**
67  * A base class for all kind of theory solving methods.
68  */
69  class Module
70  {
71  friend Manager;
72  public:
73  struct ModuleStatistics: public Statistics {
74 #ifdef SMTRAT_DEVOPTION_Statistics
75  carl::statistics::timing::time_point timer_add_started;
76  carl::statistics::timing::time_point timer_check_started;
77  carl::statistics::timing::time_point timer_remove_started;
78  carl::statistics::timing::time_point timer_pause_started;
79  carl::statistics::timing::duration timer_add_total;
80  carl::statistics::timing::duration timer_check_total;
81  carl::statistics::timing::duration timer_remove_total;
82  bool timer_add_running;
83  bool timer_check_running;
84  bool timer_remove_running;
85  std::size_t check_count = 0;
86 
87  void collect() override {
88  addKeyValuePair("timer_add_total", timer_add_total.count());
89  addKeyValuePair("timer_check_total", timer_check_total.count());
90  addKeyValuePair("timer_remove_total", timer_remove_total.count());
91  addKeyValuePair("check_count", check_count);
92  }
93 
94  void start_add() { timer_add_started = carl::statistics::timing::now(); }
95  void start_check() { timer_check_started = carl::statistics::timing::now(); }
96  void start_remove() { timer_remove_started = carl::statistics::timing::now(); }
97  void pause_all() { timer_pause_started = carl::statistics::timing::now(); }
98  void continue_all() {
99  auto diff = carl::statistics::timing::since(timer_pause_started);
100  timer_add_started += diff;
101  timer_check_started += diff;
102  timer_remove_started += diff;
103  }
104  void stop_add() { timer_add_total += carl::statistics::timing::since(timer_add_started); }
105  void stop_check() { timer_check_total += carl::statistics::timing::since(timer_check_started); }
106  void stop_remove() { timer_remove_total += carl::statistics::timing::since(timer_remove_started); }
107 #else
108  void start_add() {}
109  void start_check() {}
110  void start_remove() {}
111  void pause_all() {}
112  void continue_all() {}
113  void stop_add() {}
114  void stop_check() {}
115  void stop_remove() {}
116 #endif
117  };
118 
119  /*
120  * The type of a lemma.
121  * PERMANENT = The lemma should not be forgotten.
122  */
123  enum class LemmaType: unsigned { NORMAL = 0, PERMANENT = 1 };
124 
125  struct Lemma
126  {
127  /// The lemma to learn.
129  /// The type of the lemma.
131  /// The formula within the lemma, which should be assigned to true in the next decision.
133 
134  /**
135  * Constructor.
136  * @param _lemma The lemma to learn.
137  * @param _lemmaType The type of the lemma.
138  * @param _preferredFormula The formula within the lemma, which should be assigned to true in the next decision.
139  */
140  Lemma( const FormulaT& _lemma, const LemmaType& _lemmaType, const FormulaT& _preferredFormula ):
141  mLemma( _lemma ),
142  mLemmaType( _lemmaType ),
143  mPreferredFormula( _preferredFormula )
144  {}
145  };
146 
148  {
149  /// The constraints under which the propagated constraint holds.
151  /// The propagated constraint.
153 
154  /**
155  * Constructor.
156  */
157  TheoryPropagation( FormulasT&& _premise, const FormulaT& _conclusion ):
158  mPremise( std::move( _premise ) ),
159  mConclusion( _conclusion )
160  {}
161 
162  TheoryPropagation() = delete;
165  mPremise( std::move( _toMove.mPremise ) ),
166  mConclusion( std::move(_toMove.mConclusion) )
167  {}
168 
169 
170  TheoryPropagation& operator=( const TheoryPropagation& _toMove ) = delete;
172  {
173  mPremise = std::move( _toMove.mPremise );
174  mConclusion = std::move( _toMove.mConclusion );
175  return *this;
176  }
177 
179  };
180 
181  // Members.
182  private:
183  /// A unique ID to identify this module instance. (Could be useful but currently nowhere used)
184  std::size_t mId;
185  /// The priority of this module to get a thread for running its check procedure.
187  /// The formula passed to this module.
189  /// The formula passed to the backends of this module.
191  std::string mModuleName;
192  ModuleStatistics& mStatistics = statistics_get<ModuleStatistics>(moduleName());
193  protected:
194  /// Stores the infeasible subsets.
195  std::vector<FormulaSetT> mInfeasibleSubsets;
196  /// A reference to the manager.
198  /// Stores the assignment of the current satisfiable result, if existent.
199  mutable Model mModel;
200  /// Stores all satisfying assignments
201  mutable std::vector<Model> mAllModels;
202  /// True, if the model has already been computed.
203  mutable bool mModelComputed;
204  /// true, if the check procedure should perform a final check which especially means not to postpone splitting decisions
206  /// false, if this module should avoid too expensive procedures and rather return unknown instead.
208  /// Objective variable to be minimized. If set to NO_VARIABLE, a normal sat check should be performed.
209  carl::Variable mObjectiveVariable;
210  ///
211  std::vector<TheoryPropagation> mTheoryPropagations;
212 
213  //private:
214  /// States whether the received formula is known to be satisfiable or unsatisfiable otherwise it is set to unknown.
215  std::atomic<Answer> mSolverState;
216  /// This flag is passed to any backend and if it determines an answer to a prior check call, this flag is fired.
217 #ifdef __VS
218  std::atomic<bool>* mBackendsFoundAnswer;
219 #else
220  std::atomic_bool* mBackendsFoundAnswer;
221 #endif
222  /// Vector of Booleans: If any of them is true, we have to terminate a running check procedure.
224  /// The backends of this module which are currently used (conditions to use this module are fulfilled for the passed formula).
225  std::vector<Module*> mUsedBackends;
226  /// The backends of this module which have been used.
227  std::vector<Module*> mAllBackends;
228  /// Stores the lemmas being valid formulas this module or its backends made.
229  std::vector<Lemma> mLemmas;
230  /// Stores the position of the first sub-formula in the passed formula, which has not yet been considered for a consistency check of the backends.
232  /// Stores the constraints which the backends must be informed about.
233  carl::FastSet<FormulaT> mConstraintsToInform;
234  /// Stores the position of the first constraint of which no backend has been informed about.
235  carl::FastSet<FormulaT> mInformedConstraints;
236  /// Stores the position of the first (by this module) unchecked sub-formula of the received formula.
238  /// Counter used for the generation of the smt2 files to check for smaller muses.
239  mutable unsigned mSmallerMusesCheckCounter;
240  /// Maps variables to the number of their occurrences
241  std::vector<std::size_t> mVariableCounters;
242 
243  public:
244  #ifdef SMTRAT_STRAT_PARALLEL_MODE
245  /// a mutex for exclusive access to the old splitting variables
246  static std::mutex mOldSplittingVarMutex;
247  #define OLD_SPLITTING_VARS_LOCK_GUARD std::lock_guard<std::mutex> lock( mOldSplittingVarMutex );
248  #define OLD_SPLITTING_VARS_LOCK mOldSplittingVarMutex.lock();
249  #define OLD_SPLITTING_VARS_UNLOCK mOldSplittingVarMutex.unlock();
250  #else
251  #define OLD_SPLITTING_VARS_LOCK_GUARD
252  #define OLD_SPLITTING_VARS_LOCK
253  #define OLD_SPLITTING_VARS_UNLOCK
254  #endif
255 
256  /**
257  * Constructs a module.
258  * @param _formula The formula passed to this module, called received formula.
259  * @param _foundAnswer Vector of Booleans: If any of them is true, we have to terminate a running check procedure.
260  * @param _manager A reference to the manager of the solver using this module.
261  * @param module_name Name of this module as string for printing.
262  */
263  Module( const ModuleInput* _formula, Conditionals& _foundAnswer, Manager* _manager = nullptr, std::string module_name = "Module" );
264 
265  /**
266  * Destructs a module.
267  */
268  virtual ~Module();
269 
270  /// The number of different variables to consider for a probable infinite loop of branchings.
271  static size_t mNumOfBranchVarsToStore;
272  /// Stores the last branches in a cycle buffer.
273  static std::vector<Branching> mLastBranches;
274  /// The beginning of the cyclic buffer storing the last branches.
275  static size_t mFirstPosInLastBranches;
276  /// Reusable splitting variables.
277  static std::vector<FormulaT> mOldSplittingVariables;
278 
279  // Main interfaces
280 
281  /**
282  * Informs the module about the given constraint. It should be tried to inform this
283  * module about any constraint it could receive eventually before assertSubformula
284  * is called (preferably for the first time, but at least before adding a formula
285  * containing that constraint).
286  * @param _constraint The constraint to inform about.
287  * @return false, if it can be easily decided whether the given constraint is inconsistent;
288  * true, otherwise.
289  */
290  bool inform( const FormulaT& _constraint );
291 
292  /**
293  * The inverse of informing about a constraint. All data structures which were kept regarding this
294  * constraint are going to be removed. Note, that this makes only sense if it is not likely enough
295  * that a formula with this constraint must be solved again.
296  * @param _constraint The constraint to remove from internal data structures.
297  */
298  void deinform( const FormulaT& _constraint );
299 
300  /**
301  * Informs all backends about the so far encountered constraints, which have not yet been communicated.
302  * This method must not be called twice and only before the first runBackends call.
303  */
304  virtual void init();
305 
306  /**
307  * The module has to take the given sub-formula of the received formula into account.
308  *
309  * @param _subformula The sub-formula to take additionally into account.
310  * @return false, if it can be easily decided that this sub-formula causes a conflict with
311  * the already considered sub-formulas;
312  * true, otherwise.
313  */
314  bool add( ModuleInput::const_iterator _subformula );
315 
316  /**
317  * Checks the received formula for consistency. Note, that this is an implementation of
318  * the satisfiability check of the conjunction of the so far received formulas, which does
319  * actually nothing but passing the problem to its backends. This implementation is only used
320  * internally and must be overwritten by any derived module.
321  * @param _final true, if this satisfiability check will be the last one (for a global sat-check), if its result is SAT
322  * @param _full false, if this module should avoid too expensive procedures and rather return unknown instead.
323  * @param _objective if not set to NO_VARIABLE, the module should find an assignment minimizing this objective variable; otherwise any assignment is good.
324  * @return True, if the received formula is satisfiable;
325  * False, if the received formula is not satisfiable;
326  * Unknown, otherwise.
327  */
328  virtual Answer check( bool _final = false, bool _full = true, carl::Variable _objective = carl::Variable::NO_VARIABLE );
329 
330  /**
331  * Removes everything related to the given sub-formula of the received formula. However,
332  * it is desired not to lose track of search spaces where no satisfying assignment can
333  * be found for the remaining sub-formulas.
334  *
335  * @param _subformula The sub formula of the received formula to remove.
336  */
337  virtual void remove( ModuleInput::const_iterator _subformula );
338 
339  /**
340  * Updates the model, if the solver has detected the consistency of the received formula, beforehand.
341  */
342  virtual void updateModel() const;
343 
344  /**
345  * Updates all satisfying models, if the solver has detected the consistency of the received formula, beforehand.
346  */
347  virtual void updateAllModels();
348 
349  /**
350  * Partition the variables from the current model into equivalence classes according to their assigned value.
351  *
352  * The result is a set of equivalence classes of variables where all variables within one class are assigned the same value.
353  * Note that the number of classes may not be minimal, i.e. two classes may actually be equivalent.
354  * @return Equivalence classes.
355  */
356  virtual std::list<std::vector<carl::Variable>> getModelEqualities() const;
357 
358  /**
359  * @return 0, if the given formula is conflicted by the current model;
360  * 1, if the given formula is satisfied by the current model;
361  * 2, otherwise
362  * 3, if we do not know anything (default)
363  */
364  unsigned currentlySatisfiedByBackend( const FormulaT& _formula ) const;
365 
366  /**
367  * @return 0, if the given formula is conflicted by the current model;
368  * 1, if the given formula is satisfied by the current model;
369  * 2, otherwise;
370  * 3, if we do not know anything (default)
371  */
372  virtual unsigned currentlySatisfied( const FormulaT& ) const
373  {
374  return 3;
375  }
376 
377  bool receivedVariable( carl::Variable::Arg _var ) const
378  {
379  return _var.id() < mVariableCounters.size() && mVariableCounters[_var.id()] > 0;
380  }
381 
382  // Methods to read and write on the members.
383  /**
384  * @return True, if this module is in a state, such that it has found a solution for its received formula;
385  * False, if this module is in a state, such that it has determined that there is no solution for its received formula;
386  * Unknown, otherwise.
387  */
388  inline Answer solverState() const
389  {
390  return mSolverState.load();
391  }
392 
393  /**
394  * @return A unique ID to identify this module instance.
395  */
396  inline std::size_t id() const
397  {
398  return mId;
399  }
400 
401  /**
402  * Sets this modules unique ID to identify itself.
403  * @param _id The id to set this module's id to.
404  */
405  void setId( std::size_t _id )
406  {
407  assert( mId == 0 && _id != 0 );
408  mId = _id;
409  }
410 
411  /**
412  * @return The priority of this module to get a thread for running its check procedure.
413  */
415  {
416  return mThreadPriority;
417  }
418 
419  /**
420  * Sets the priority of this module to get a thread for running its check procedure.
421  * @param _threadPriority The priority to set this module's thread priority to.
422  */
423  void setThreadPriority( thread_priority _threadPriority )
424  {
425  mThreadPriority = _threadPriority;
426  }
427 
428  /**
429  * @return A pointer to the formula passed to this module.
430  */
431  inline const ModuleInput* pReceivedFormula() const
432  {
433  return mpReceivedFormula;
434  }
435 
436  /**
437  * @return A reference to the formula passed to this module.
438  */
439  inline const ModuleInput& rReceivedFormula() const
440  {
441  return *mpReceivedFormula;
442  }
443 
444  /**
445  * @return A pointer to the formula passed to the backends of this module.
446  */
447  inline const ModuleInput* pPassedFormula() const
448  {
449  return mpPassedFormula;
450  }
451 
452  /**
453  * @return A reference to the formula passed to the backends of this module.
454  */
455  inline const ModuleInput& rPassedFormula() const
456  {
457  return *mpPassedFormula;
458  }
459 
460  /**
461  * @return The assignment of the current satisfiable result, if existent.
462  */
463  inline const Model& model() const
464  {
465  return mModel;
466  }
467 
468  /**
469  * @return All satisfying assignments, if existent.
470  */
471  inline const std::vector<Model>& allModels() const
472  {
473  return mAllModels;
474  }
475 
476  /**
477  * @return The infeasible subsets of the set of received formulas (empty, if this module has not
478  * detected unsatisfiability of the conjunction of received formulas.
479  */
480  inline const std::vector<FormulaSetT>& infeasibleSubsets() const
481  {
482  return mInfeasibleSubsets;
483  }
484 
485  /**
486  * @return The backends of this module which are currently used (conditions to use this module are fulfilled for the passed formula).
487  */
488  const std::vector<Module*>& usedBackends() const
489  {
490  return mUsedBackends;
491  }
492 
493  /**
494  * @return The constraints which the backends must be informed about.
495  */
496  const carl::FastSet<FormulaT>& constraintsToInform() const
497  {
498  return mConstraintsToInform;
499  }
500 
501  /**
502  * @return The position of the first constraint of which no backend has been informed about.
503  */
504  const carl::FastSet<FormulaT>& informedConstraints() const
505  {
506  return mInformedConstraints;
507  }
508 
509  static void freeSplittingVariable( const FormulaT& _splittingVariable )
510  {
512  mOldSplittingVariables.push_back( _splittingVariable );
513  }
514 
515  /**
516  * Stores a lemma being a valid formula.
517  * @param _lemma The eduction/lemma to store.
518  * @param _lt The type of the lemma.
519  * @param _preferredFormula Hint for the next decision, which formula should be assigned to true.
520  */
521  void addLemma( const FormulaT& _lemma, const LemmaType& _lt = LemmaType::NORMAL, const FormulaT& _preferredFormula = FormulaT( carl::FormulaType::TRUE ) )
522  {
523  #ifdef SMTRAT_DEVOPTION_Validation
524  SMTRAT_VALIDATION_ADD("smtrat.module.lemma",moduleName() + "_lemma",FormulaT( carl::FormulaType::NOT, _lemma ),false);
525  #endif
526  mLemmas.emplace_back( _lemma, _lt, _preferredFormula );
527  }
528 
529  /**
530  * Checks whether this module or any of its backends provides any lemmas.
531  */
532  bool hasLemmas()
533  {
534  if( !mLemmas.empty() )
535  return true;
536  if( mpManager != nullptr )
537  {
538  for( auto module = mAllBackends.begin(); module != mAllBackends.end(); ++module )
539  {
540  if( (*module)->hasLemmas() )
541  return true;
542  }
543  }
544  return false;
545  }
546 
547  /**
548  * Deletes all yet found lemmas.
549  */
550  void clearLemmas()
551  {
552  if( mpManager != nullptr )
553  {
554  for( auto module = mAllBackends.begin(); module != mAllBackends.end(); ++module )
555  {
556  (*module)->clearLemmas();
557  }
558  }
559  mLemmas.clear();
560  }
561 
562  /**
563  * @return A constant reference to the lemmas being valid formulas this module or its backends made.
564  */
565  const std::vector<Lemma>& lemmas() const
566  {
567  return mLemmas;
568  }
569 
570  /**
571  * @return The position of the first (by this module) unchecked sub-formula of the received formula.
572  */
574  {
576  }
577 
578  /**
579  * @return The position of the first sub-formula in the passed formula, which has not yet been considered for a consistency check of the backends.
580  */
582  {
583  return mFirstSubformulaToPass;
584  }
585 
586  /**
587  * Notifies that the received formulas has been checked.
588  */
590  {
592  }
593 
594  /**
595  * @return A vector of Booleans: If any of them is true, we have to terminate a running check procedure.
596  */
598  {
599  return mFoundAnswer;
600  }
601 
602  /**
603  * @return true, if this module is a preprocessor that is a module, which simplifies
604  * its received formula to an equisatisfiable formula being passed to its backends.
605  * The simplified formula can be obtained with getReceivedFormulaSimplified().
606  */
607  bool isPreprocessor() const
608  {
609  return false;
610  }
611 
612  /**
613  * @return The name of the given module type as name.
614  */
615  virtual std::string moduleName() const {
616  return mModuleName;
617  }
618 
619  carl::Variable objective() const {
620  return mObjectiveVariable;
621  }
622 
623  bool is_minimizing() const {
624  return mObjectiveVariable != carl::Variable::NO_VARIABLE;
625  }
626 
627  /**
628  * Excludes all variables from the current model, which do not occur in the received formula.
629  */
631 
632  /**
633  * Stores all lemmas of any backend of this module in its own lemma vector.
634  */
635  void updateLemmas();
637 
638  /**
639  * Collects the formulas in the given formula, which are part of the received formula. If the given formula directly
640  * occurs in the received formula, it is inserted into the given set. Otherwise, the given formula must be of
641  * type AND and all its sub-formulas part of the received formula. Hence, they will be added to the given set.
642  * @param _formula The formula from which to collect the formulas being sub-formulas of the received formula (origins).
643  * @param _origins The set in which to store the origins.
644  */
645  void collectOrigins( const FormulaT& _formula, FormulasT& _origins ) const;
646  void collectOrigins( const FormulaT& _formula, FormulaSetT& _origins ) const;
647 
648  // Methods for debugging purposes.
649 
650  /**
651  * @return true, if the module has at least one valid infeasible subset, that is all its
652  * elements are sub-formulas of the received formula (pointer must be equal).
653  */
654  bool hasValidInfeasibleSubset() const;
655 
656  /**
657  * Checks the given infeasible subset for minimality by storing all subsets of it, which have a smaller size
658  * which differs from the size of the infeasible subset not more than the given threshold.
659  * @param _infsubset The infeasible subset to check for minimality.
660  * @param _filename The name of the file to store the infeasible subsets in order to be able to check their infeasibility.
661  * @param _maxSizeDifference The maximal difference between the sizes of the subsets compared to the size of the infeasible subset.
662  */
663  void checkInfSubsetForMinimality( std::vector<FormulaSetT>::const_iterator _infsubset, const std::string& _filename = "smaller_muses", unsigned _maxSizeDifference = 1 ) const;
664 
665  /**
666  * @return A pair of a Boolean and a formula, where the Boolean is true, if the received formula
667  * could be simplified to an equisatisfiable formula. The formula is equisatisfiable to this
668  * module's reveived formula, if the Boolean is true.
669  */
670  virtual std::pair<bool,FormulaT> getReceivedFormulaSimplified();
671 
672  protected:
673 
674  // Internally used methods.
675  /**
676  * Informs the module about the given constraint. It should be tried to inform this
677  * module about any constraint it could receive eventually before assertSubformula
678  * is called (preferably for the first time, but at least before adding a formula
679  * containing that constraint).
680  * @param _constraint The constraint to inform about.
681  * @return false, if it can be easily decided whether the given constraint is inconsistent;
682  * true, otherwise.
683  */
684  virtual bool informCore( [[maybe_unused]] const FormulaT& _constraint )
685  {
686  return true;
687  }
688 
689  /**
690  * The inverse of informing about a constraint. All data structures which were kept regarding this
691  * constraint are going to be removed. Note, that this makes only sense if it is not likely enough
692  * that a formula with this constraint must be solved again.
693  * @param _constraint The constraint to remove from internal data structures.
694  */
695  virtual void deinformCore( [[maybe_unused]] const FormulaT& _constraint ) {
696  }
697 
698  /**
699  * The module has to take the given sub-formula of the received formula into account.
700  *
701  * @param formula The sub-formula to take additionally into account.
702  * @return false, if it can be easily decided that this sub-formula causes a conflict with
703  * the already considered sub-formulas;
704  * true, otherwise.
705  */
706  virtual bool addCore( [[maybe_unused]] ModuleInput::const_iterator formula)
707  {
708  return true;
709  }
710 
711  /**
712  * Checks the received formula for consistency. Note, that this is an implementation of
713  * the satisfiability check of the conjunction of the so far received formulas, which does
714  * actually nothing but passing the problem to its backends. This implementation is only used
715  * internally and must be overwritten by any derived module.
716  * @return True, if the received formula is satisfiable;
717  * False, if the received formula is not satisfiable;
718  * Unknown, otherwise.
719  */
720  virtual Answer checkCore();
721 
722  /**
723  * Removes everything related to the given sub-formula of the received formula. However,
724  * it is desired not to lose track of search spaces where no satisfying assignment can
725  * be found for the remaining sub-formulas.
726  *
727  * @param formula The sub formula of the received formula to remove.
728  */
729  virtual void removeCore( [[maybe_unused]] ModuleInput::const_iterator formula) {
730  }
731 
732  /**
733  * Checks for all antecedent modules and those which run in parallel with the same antecedent modules,
734  * whether one of them has determined a result.
735  * @return True, if one of them has determined a result.
736  */
737  bool anAnswerFound() const
738  {
739  for( auto iter = mFoundAnswer.begin(); iter != mFoundAnswer.end(); ++iter )
740  {
741  if( (*iter)->load() ) return true;
742  }
743  return false;
744  }
745 
746  /**
747  * Clears the assignment, if any was found
748  */
749  void clearModel() const
750  {
751  // the Assignments should not contain any values that must be deleted explicitly...
752  mModel.clear();
753  }
754 
755  /**
756  * Clears all assignments, if any was found
757  */
758  void clearModels() const
759  {
760  // the Assignments should not contain any values that must be deleted explicitly...
761  for ( Model model : mAllModels )
762  {
763  model.clear();
764  }
765  mAllModels.clear();
766  }
767 
768  /**
769  * Substitutes variable occurrences by its model value in the model values of other variables.
770  */
771  void cleanModel() const
772  {
773  mModel.clean();
774  }
775 
776  /**
777  * @return An iterator to the end of the passed formula.
778  * TODO: disable this method
779  */
781  {
782  return mpPassedFormula->begin();
783  }
784 
785  /**
786  * @return An iterator to the end of the passed formula.
787  */
789  {
790  return mpPassedFormula->end();
791  }
792 
793  /**
794  * Adds the given set of formulas in the received formula to the origins of the given passed formula.
795  * @param _formula The passed formula to set the origins for.
796  * @param _origin A set of formulas in the received formula of this module.
797  */
798  void addOrigin( ModuleInput::iterator _formula, const FormulaT& _origin )
799  {
800  mpPassedFormula->addOrigin( _formula, _origin );
801  }
802 
803  /**
804  * Gets the origins of the passed formula at the given position.
805  * @param _formula The position of a formula in the passed formulas.
806  * @return The origins of the passed formula at the given position.
807  */
809  {
810  assert( _formula != mpPassedFormula->end() );
811  return _formula->origins().front();
812  }
813 
814  std::pair<ModuleInput::iterator,bool> removeOrigin( ModuleInput::iterator _formula, const FormulaT& _origin )
815  {
816  if( mpPassedFormula->removeOrigin( _formula, _origin ) )
817  {
818  return std::make_pair( eraseSubformulaFromPassedFormula( _formula ), true );
819  }
820  return std::make_pair( _formula, false );
821  }
822 
823  std::pair<ModuleInput::iterator,bool> removeOrigins( ModuleInput::iterator _formula, const std::shared_ptr<std::vector<FormulaT>>& _origins )
824  {
825  if( mpPassedFormula->removeOrigins( _formula, _origins ) )
826  {
827  return std::make_pair( eraseSubformulaFromPassedFormula( _formula ), true );
828  }
829  return std::make_pair( _formula, false );
830  }
831 
832  /**
833  * Informs all backends of this module about the given constraint.
834  * @param _constraint The constraint to inform about.
835  */
836  void informBackends( const FormulaT& _constraint )
837  {
838  for( Module* module : mAllBackends )
839  {
840  module->inform( _constraint );
841  }
842  }
843 
844  /**
845  * Adds a constraint to the collection of constraints of this module, which are informed to a
846  * freshly generated backend.
847  * @param _constraint The constraint to add.
848  */
849  virtual void addConstraintToInform( const FormulaT& _constraint );
850 
851  /**
852  * Copies the given sub-formula of the received formula to the passed formula. Note, that
853  * there is always a link between sub-formulas of the passed formulas to sub-formulas of
854  * the received formulas, which are responsible for its occurrence.
855  * @param _subformula The sub-formula of the received formula to copy.
856  */
857  std::pair<ModuleInput::iterator,bool> addReceivedSubformulaToPassedFormula( ModuleInput::const_iterator _subformula )
858  {
859  assert( _subformula->formula().type() != carl::FormulaType::AND );
860  return addSubformulaToPassedFormula( _subformula->formula(), true, _subformula->formula(), nullptr, false );
861  }
862 
863  bool originInReceivedFormula( const FormulaT& _origin ) const;
864 
865  /**
866  * Adds the given formula to the passed formula with no origin. Note that in the next call of this module's removeSubformula,
867  * all formulas in the passed formula without origins will be removed.
868  * @param _formula The formula to add to the passed formula.
869  * @return A pair to the position where the formula to add has been inserted (or its first sub-formula
870  * which has not yet been in the passed formula, in case the formula to add is a conjunction),
871  * and a Boolean stating whether anything has been added to the passed formula.
872  */
873  std::pair<ModuleInput::iterator,bool> addSubformulaToPassedFormula( const FormulaT& _formula )
874  {
875  return addSubformulaToPassedFormula( _formula, false, FormulaT( carl::FormulaType::FALSE ), nullptr, true );
876  }
877 
878  /**
879  * Adds the given formula to the passed formula.
880  * @param _formula The formula to add to the passed formula.
881  * @param _origins The link of the formula to add to the passed formula to sub-formulas
882  * of the received formulas, which are responsible for its occurrence
883  * @return A pair to the position where the formula to add has been inserted (or its first sub-formula
884  * which has not yet been in the passed formula, in case the formula to add is a conjunction),
885  * and a Boolean stating whether anything has been added to the passed formula.
886  */
887  std::pair<ModuleInput::iterator,bool> addSubformulaToPassedFormula( const FormulaT& _formula, const std::shared_ptr<std::vector<FormulaT>>& _origins )
888  {
889  return addSubformulaToPassedFormula( _formula, false, FormulaT( carl::FormulaType::FALSE ), _origins, true );
890  }
891 
892  /**
893  * Adds the given formula to the passed formula.
894  * @param _formula The formula to add to the passed formula.
895  * @param _origin The sub-formula of the received formula being responsible for the
896  * occurrence of the formula to add to the passed formula.
897  * @return A pair to the position where the formula to add has been inserted (or its first sub-formula
898  * which has not yet been in the passed formula, in case the formula to add is a conjunction),
899  * and a Boolean stating whether anything has been added to the passed formula.
900  */
901  std::pair<ModuleInput::iterator,bool> addSubformulaToPassedFormula( const FormulaT& _formula, const FormulaT& _origin )
902  {
903  return addSubformulaToPassedFormula( _formula, true, _origin, nullptr, true );
904  }
905 
906  /**
907  * Stores the trivial infeasible subset being the set of received formulas.
908  */
910  {
911  FormulaSetT infeasibleSubset;
912  for( auto subformula = rReceivedFormula().begin(); subformula != rReceivedFormula().end(); ++subformula )
913  infeasibleSubset.insert( subformula->formula() );
914  mInfeasibleSubsets.push_back( std::move(infeasibleSubset) );
915  }
916 
917  /**
918  * Stores an infeasible subset consisting only of the given received formula.
919  */
921  {
922  FormulaSetT infeasibleSubset;
923  infeasibleSubset.insert( _subformula->formula() );
924  mInfeasibleSubsets.push_back( std::move(infeasibleSubset) );
925  }
926 
927  private:
928  /**
929  * This method actually implements the adding of a formula to the passed formula
930  * @param _formula The formula to add to the passed formula.
931  * @param _hasSingleOrigin true, if the next argument contains the formula being the single origin.
932  * @param _origin The sub-formula of the received formula being responsible for the
933  * occurrence of the formula to add to the passed formula.
934  * @param _origins The link of the formula to add to the passed formula to sub-formulas
935  * of the received formulas, which are responsible for its occurrence
936  * @param _mightBeConjunction true, if the formula to add might be a conjunction.
937  * @return A pair to the position where the formula to add has been inserted (or its first sub-formula
938  * which has not yet been in the passed formula, in case the formula to add is a conjunction),
939  * and a Boolean stating whether anything has been added to the passed formula.
940  */
941  std::pair<ModuleInput::iterator,bool> addSubformulaToPassedFormula( const FormulaT& _formula, bool _hasSingleOrigin, const FormulaT& _origin, const std::shared_ptr<std::vector<FormulaT>>& _origins, bool _mightBeConjunction );
942  protected:
943 
944  /**
945  * @param _origins
946  * @return
947  */
948  std::vector<FormulaT>::const_iterator findBestOrigin( const std::vector<FormulaT>& _origins ) const;
949 
950  /**
951  *
952  * @param _formula
953  * @param _origins
954  */
955  void getOrigins( const FormulaT& _formula, FormulasT& _origins ) const
956  {
957  ModuleInput::const_iterator posInReceived = mpPassedFormula->find( _formula );
958  assert( posInReceived != mpPassedFormula->end() );
959  if( posInReceived->hasOrigins() )
960  collectOrigins( *findBestOrigin( posInReceived->origins() ), _origins );
961  }
962 
963  /**
964  *
965  * @param _formula
966  * @param _origins
967  */
968  void getOrigins( const FormulaT& _formula, FormulaSetT& _origins ) const
969  {
970  ModuleInput::const_iterator posInReceived = mpPassedFormula->find( _formula );
971  assert( posInReceived != mpPassedFormula->end() );
972  if( posInReceived->hasOrigins() )
973  collectOrigins( *findBestOrigin( posInReceived->origins() ), _origins );
974  }
975 
976  /**
977  * Copies the infeasible subsets of the passed formula
978  */
979  void getInfeasibleSubsets();
980 
981  /**
982  * Checks whether there is no variable assigned by both models.
983  * @param _modelA The first model to check for.
984  * @param _modelB The second model to check for.
985  * @return true, if there is no variable assigned by both models;
986  * false, otherwise.
987  */
988  static bool modelsDisjoint( const Model& _modelA, const Model& _modelB );
989 
990  /**
991  * Stores the model of a backend which determined satisfiability of the passed
992  * formula in the model of this module.
993  */
994  const Model& backendsModel() const;
995  void getBackendsModel() const;
996 
997  /**
998  * Stores all models of a backend in the list of all models of this module.
999  */
1000  void getBackendsAllModels() const;
1001 
1002  /**
1003  * Runs the backend solvers on the passed formula.
1004  * @param _final true, if this satisfiability check will be the last one (for a global sat-check), if its result is SAT
1005  * @param _full false, if this module should avoid too expensive procedures and rather return unknown instead.
1006  * @param _objective if not set to NO_VARIABLE, the module should find an assignment minimizing this objective variable; otherwise any assignment is good.
1007  * @return True, if the passed formula is consistent;
1008  * False, if the passed formula is inconsistent;
1009  * Unknown, otherwise.
1010  */
1011  virtual Answer runBackends( bool _final, bool _full, carl::Variable _objective );
1013  {
1015  }
1016 
1017  /**
1018  * Removes everything related to the sub-formula to remove from the passed formula in the backends of this module.
1019  * Afterwards the sub-formula is removed from the passed formula.
1020  * @param _subformula The sub-formula to remove from the passed formula.
1021  * @param _ignoreOrigins True, if the sub-formula shall be removed regardless of its origins (should only be applied with expertise).
1022  * @return
1023  */
1024  virtual ModuleInput::iterator eraseSubformulaFromPassedFormula( ModuleInput::iterator _subformula, bool _ignoreOrigins = false );
1025 
1026  void clearPassedFormula();
1027 
1028  /**
1029  * Get the infeasible subsets the given backend provides. Note, that an infeasible subset
1030  * in a backend contains sub formulas of the passed formula and an infeasible subset of
1031  * this module contains sub formulas of the received formula. In this method the LATTER is
1032  * returned.
1033  * @param _backend The backend from which to obtain the infeasible subsets.
1034  * @return The infeasible subsets the given backend provides.
1035  */
1036  std::vector<FormulaSetT> getInfeasibleSubsets( const Module& _backend ) const;
1037 
1038  /**
1039  * Merges the two vectors of sets into the first one.
1040  *
1041  * ({a,b},{a,c}) and ({b,d},{b}) -> ({a,b,d},{a,b},{a,b,c,d},{a,b,c})
1042  *
1043  * @param _vecSetA A vector of sets of constraints.
1044  * @param _vecSetB A vector of sets of constraints.
1045  *
1046  * @result The vector being the two given vectors merged.
1047  */
1048  std::vector<FormulaT> merge( const std::vector<FormulaT>&, const std::vector<FormulaT>& ) const;
1049 
1050  /**
1051  * @param origins A vector of sets of origins.
1052  * @return The index of the smallest (regarding the size of the sets) element of origins
1053  */
1054  size_t determine_smallest_origin( const std::vector<FormulaT>& origins ) const;
1055 
1056  /**
1057  * Checks whether given the current branching value and branching variable/polynomial it is (highly) probable that
1058  * this branching is part of an infinite loop of branchings.
1059  * @param _branchingPolynomial The polynomial to branch at (in most branching strategies this is just a variable).
1060  * @param _branchingValue The value to branch at.
1061  * @return true, if this branching is probably part of an infinite loop of branchings;
1062  * false, otherwise.
1063  */
1064 #ifdef __VS
1065  bool probablyLooping( const Poly::PolyType& _branchingPolynomial, const Rational& _branchingValue ) const;
1066 #else
1067  bool probablyLooping( const typename Poly::PolyType& _branchingPolynomial, const Rational& _branchingValue ) const;
1068 #endif
1069 
1070  /**
1071  * Adds a lemmas which provoke a branching for the given variable at the given value,
1072  * if this module returns Unknown and there exists a preceding SATModule. Note that the
1073  * given value is rounded down and up, if the given variable is integer-valued.
1074  * @param _polynomial The variable to branch for.
1075  * @param _integral A flag being true, if all variables in the polynomial to branch for are integral.
1076  * @param _value The value to branch at.
1077  * @param _premise The sub-formulas of the received formula from which the branch is followed.
1078  * Note, that a premise is not necessary, as every branch is a valid formula.
1079  * But a premise can prevent from branching unnecessarily.
1080  * @param _leftCaseWeak true, if a branching in the form of (or (<= p b) (> p b)) is desired.
1081  * false, if a branching in the form of (or (< p b) (>= p b)) is desired.
1082  * @param _preferLeftCase true, if the left case (polynomial less(or equal) 0 shall be chosen first.
1083  * false, otherwise.
1084  * @param _useReceivedFormulaAsPremise true, if the whole received formula should be used as premise
1085  */
1086  bool branchAt( const Poly& _polynomial, bool _integral, const Rational& _value, std::vector<FormulaT>&& _premise, bool _leftCaseWeak = true, bool _preferLeftCase = true, bool _useReceivedFormulaAsPremise = false );
1087 
1088  bool branchAt( const Poly& _polynomial, bool _integral, const Rational& _value, bool _leftCaseWeak = true, bool _preferLeftCase = true, bool _useReceivedFormulaAsPremise = false, const std::vector<FormulaT>& _premise = std::vector<FormulaT>() )
1089  {
1090  return branchAt( _polynomial, _integral, _value, std::vector<FormulaT>( _premise ), _leftCaseWeak, _preferLeftCase, _useReceivedFormulaAsPremise );
1091  }
1092 
1093  bool branchAt( carl::Variable::Arg _var, const Rational& _value, std::vector<FormulaT>&& _premise, bool _leftCaseWeak = true, bool _preferLeftCase = true, bool _useReceivedFormulaAsPremise = false )
1094  {
1095  return branchAt( Poly( _var ), _var.type() == carl::VariableType::VT_INT, _value, std::move( _premise ), _leftCaseWeak, _preferLeftCase, _useReceivedFormulaAsPremise );
1096  }
1097 
1098  bool branchAt( carl::Variable::Arg _var, const Rational& _value, bool _leftCaseWeak = true, bool _preferLeftCase = true, bool _useReceivedFormulaAsPremise = false, const std::vector<FormulaT>& _premise = std::vector<FormulaT>() )
1099  {
1100  return branchAt( Poly( _var ), _var.type() == carl::VariableType::VT_INT, _value, std::vector<FormulaT>( _premise ), _leftCaseWeak, _preferLeftCase, _useReceivedFormulaAsPremise );
1101  }
1102 
1103  /**
1104  * Adds the following lemmas for the given constraint p!=0
1105  *
1106  * (p!=0 <-> (p<0 or p>0))
1107  * and not(p<0 and p>0)
1108  *
1109  * @param _unequalConstraint A constraint having the relation symbol !=.
1110  */
1111  void splitUnequalConstraint( const FormulaT& );
1112 
1113  /**
1114  * @return false, if the current model of this module does not satisfy the current given formula;
1115  * true, if it cannot be said whether the model satisfies the given formula.
1116  */
1117  unsigned checkModel() const;
1118 
1119  /**
1120  * Adds a formula to the InformationRelevantFormula
1121  * @param formula Formula to add
1122  */
1123  void addInformationRelevantFormula( const FormulaT& formula );
1124 
1125  /**
1126  * Gets all InformationRelevantFormulas
1127  * @return Set of all formulas
1128  */
1129  const std::set<FormulaT>& getInformationRelevantFormulas();
1130 
1131  /**
1132  * Checks if current lemma level is greater or equal to given level.
1133  * @param level Level to check.
1134  */
1135  bool isLemmaLevel(LemmaLevel level);
1136 
1137  public:
1138  // Printing methods.
1139 
1140  /**
1141  * Prints everything relevant of the solver.
1142  * @param _initiation The line initiation.
1143  */
1144  void print( const std::string& _initiation = "***" ) const;
1145 
1146  /**
1147  * Prints the vector of the received formula.
1148  * @param _initiation The line initiation.
1149  */
1150  void printReceivedFormula( const std::string& _initiation = "***" ) const;
1151 
1152  /**
1153  * Prints the vector of passed formula.
1154  * @param _initiation The line initiation.
1155  */
1156  void printPassedFormula( const std::string& _initiation = "***" ) const;
1157 
1158  /**
1159  * Prints the infeasible subsets.
1160  * @param _initiation The line initiation.
1161  */
1162  void printInfeasibleSubsets( const std::string& _initiation = "***" ) const;
1163 
1164  /**
1165  * Prints the assignment of this module satisfying its received formula if it satisfiable
1166  * and this module could find an assignment.
1167  * @param _out The stream to print the assignment on.
1168  */
1169  void printModel( std::ostream& _out = std::cout ) const;
1170 
1171  /**
1172  * Prints all assignments of this module satisfying its received formula if it satisfiable
1173  * and this module could find an assignment.
1174  * @param _out The stream to print the assignment on.
1175  */
1176  void printAllModels( std::ostream& _out = std::cout );
1177  private:
1178 
1179  /**
1180  * Sets the solver state to the given answer value. This method also fires the flag
1181  * given by the antecessor module of this module to true, if the given answer value is not Unknown.
1182  * @param _answer The found answer.
1183  */
1184  Answer foundAnswer( Answer _answer );
1185  };
1186 
1187  inline std::ostream& operator<<(std::ostream& os, Module::LemmaType lt) {
1188  switch (lt) {
1189  case Module::LemmaType::NORMAL: return os << "NORMAL";
1190  case Module::LemmaType::PERMANENT: return os << "PERMANENT";
1191  }
1192  return os << "???";
1193  }
1194 } // namespace smtrat
#define OLD_SPLITTING_VARS_LOCK_GUARD
Definition: Module.h:251
#define SMTRAT_VALIDATION_ADD(channel, name, formula, consistent)
Definition: Validation.h:26
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
void addOrigin(iterator _formula, const FormulaT &_origin)
Definition: ModuleInput.h:404
iterator find(const FormulaT &_formula)
Definition: ModuleInput.cpp:46
bool removeOrigins(iterator _formula, const std::shared_ptr< FormulasT > &_origins)
bool removeOrigin(iterator _formula, const FormulaT &_origin)
super::iterator iterator
Passing through the list::iterator.
Definition: ModuleInput.h:144
A base class for all kind of theory solving methods.
Definition: Module.h:70
std::pair< ModuleInput::iterator, bool > addSubformulaToPassedFormula(const FormulaT &_formula, const std::shared_ptr< std::vector< FormulaT >> &_origins)
Adds the given formula to the passed formula.
Definition: Module.h:887
void clearModel() const
Clears the assignment, if any was found.
Definition: Module.h:749
const std::vector< FormulaSetT > & infeasibleSubsets() const
Definition: Module.h:480
std::pair< ModuleInput::iterator, bool > addReceivedSubformulaToPassedFormula(ModuleInput::const_iterator _subformula)
Copies the given sub-formula of the received formula to the passed formula.
Definition: Module.h:857
ModuleInput::iterator passedFormulaEnd()
Definition: Module.h:788
virtual void init()
Informs all backends about the so far encountered constraints, which have not yet been communicated.
Definition: Module.cpp:234
std::vector< FormulaSetT > mInfeasibleSubsets
Stores the infeasible subsets.
Definition: Module.h:195
void printReceivedFormula(const std::string &_initiation="***") const
Prints the vector of the received formula.
Definition: Module.cpp:1105
void splitUnequalConstraint(const FormulaT &)
Adds the following lemmas for the given constraint p!=0.
Definition: Module.cpp:565
void addInformationRelevantFormula(const FormulaT &formula)
Adds a formula to the InformationRelevantFormula.
Definition: Module.cpp:1068
thread_priority threadPriority() const
Definition: Module.h:414
std::vector< Model > mAllModels
Stores all satisfying assignments.
Definition: Module.h:201
void receivedFormulasAsInfeasibleSubset(ModuleInput::const_iterator _subformula)
Stores an infeasible subset consisting only of the given received formula.
Definition: Module.h:920
void generateTrivialInfeasibleSubset()
Stores the trivial infeasible subset being the set of received formulas.
Definition: Module.h:909
void informBackends(const FormulaT &_constraint)
Informs all backends of this module about the given constraint.
Definition: Module.h:836
const std::vector< Module * > & usedBackends() const
Definition: Module.h:488
bool isPreprocessor() const
Definition: Module.h:607
bool anAnswerFound() const
Checks for all antecedent modules and those which run in parallel with the same antecedent modules,...
Definition: Module.h:737
std::vector< Module * > mAllBackends
The backends of this module which have been used.
Definition: Module.h:227
virtual bool addCore([[maybe_unused]] ModuleInput::const_iterator formula)
The module has to take the given sub-formula of the received formula into account.
Definition: Module.h:706
std::string mModuleName
Definition: Module.h:191
carl::FastSet< FormulaT > mConstraintsToInform
Stores the constraints which the backends must be informed about.
Definition: Module.h:233
void getOrigins(const FormulaT &_formula, FormulaSetT &_origins) const
Definition: Module.h:968
virtual std::string moduleName() const
Definition: Module.h:615
static size_t mFirstPosInLastBranches
The beginning of the cyclic buffer storing the last branches.
Definition: Module.h:275
ModuleInput::iterator mFirstSubformulaToPass
Stores the position of the first sub-formula in the passed formula, which has not yet been considered...
Definition: Module.h:231
const ModuleInput * pPassedFormula() const
Definition: Module.h:447
static void freeSplittingVariable(const FormulaT &_splittingVariable)
Definition: Module.h:509
const std::set< FormulaT > & getInformationRelevantFormulas()
Gets all InformationRelevantFormulas.
Definition: Module.cpp:1074
const Model & backendsModel() const
Stores the model of a backend which determined satisfiability of the passed formula in the model of t...
Definition: Module.cpp:630
Conditionals mFoundAnswer
Vector of Booleans: If any of them is true, we have to terminate a running check procedure.
Definition: Module.h:223
virtual void updateModel() const
Updates the model, if the solver has detected the consistency of the received formula,...
Definition: Module.cpp:250
std::size_t id() const
Definition: Module.h:396
virtual std::list< std::vector< carl::Variable > > getModelEqualities() const
Partition the variables from the current model into equivalence classes according to their assigned v...
Definition: Module.cpp:308
std::vector< std::size_t > mVariableCounters
Maps variables to the number of their occurrences.
Definition: Module.h:241
void deinform(const FormulaT &_constraint)
The inverse of informing about a constraint.
Definition: Module.cpp:124
bool originInReceivedFormula(const FormulaT &_origin) const
Definition: Module.cpp:352
unsigned currentlySatisfiedByBackend(const FormulaT &_formula) const
Definition: Module.cpp:296
virtual Answer runBackends()
Definition: Module.h:1012
std::pair< ModuleInput::iterator, bool > addSubformulaToPassedFormula(const FormulaT &_formula)
Adds the given formula to the passed formula with no origin.
Definition: Module.h:873
Answer foundAnswer(Answer _answer)
Sets the solver state to the given answer value.
Definition: Module.cpp:856
bool probablyLooping(const typename Poly::PolyType &_branchingPolynomial, const Rational &_branchingValue) const
Checks whether given the current branching value and branching variable/polynomial it is (highly) pro...
Definition: Module.cpp:426
ModuleInput::const_iterator firstSubformulaToPass() const
Definition: Module.h:581
virtual ~Module()
Destructs a module.
Definition: Module.cpp:76
virtual std::pair< bool, FormulaT > getReceivedFormulaSimplified()
Definition: Module.cpp:945
bool mFullCheck
false, if this module should avoid too expensive procedures and rather return unknown instead.
Definition: Module.h:207
unsigned mSmallerMusesCheckCounter
Counter used for the generation of the smt2 files to check for smaller muses.
Definition: Module.h:239
Manager *const mpManager
A reference to the manager.
Definition: Module.h:197
void setThreadPriority(thread_priority _threadPriority)
Sets the priority of this module to get a thread for running its check procedure.
Definition: Module.h:423
void addOrigin(ModuleInput::iterator _formula, const FormulaT &_origin)
Adds the given set of formulas in the received formula to the origins of the given passed formula.
Definition: Module.h:798
bool inform(const FormulaT &_constraint)
Informs the module about the given constraint.
Definition: Module.cpp:117
ModuleStatistics & mStatistics
Definition: Module.h:192
const carl::FastSet< FormulaT > & constraintsToInform() const
Definition: Module.h:496
void printInfeasibleSubsets(const std::string &_initiation="***") const
Prints the infeasible subsets.
Definition: Module.cpp:1136
bool branchAt(carl::Variable::Arg _var, const Rational &_value, bool _leftCaseWeak=true, bool _preferLeftCase=true, bool _useReceivedFormulaAsPremise=false, const std::vector< FormulaT > &_premise=std::vector< FormulaT >())
Definition: Module.h:1098
const std::vector< Lemma > & lemmas() const
Definition: Module.h:565
bool is_minimizing() const
Definition: Module.h:623
static size_t mNumOfBranchVarsToStore
The number of different variables to consider for a probable infinite loop of branchings.
Definition: Module.h:271
void cleanModel() const
Substitutes variable occurrences by its model value in the model values of other variables.
Definition: Module.h:771
virtual void updateAllModels()
Updates all satisfying models, if the solver has detected the consistency of the received formula,...
Definition: Module.cpp:261
void printAllModels(std::ostream &_out=std::cout)
Prints all assignments of this module satisfying its received formula if it satisfiable and this modu...
Definition: Module.cpp:1161
void setId(std::size_t _id)
Sets this modules unique ID to identify itself.
Definition: Module.h:405
void clearPassedFormula()
Definition: Module.cpp:850
carl::Variable objective() const
Definition: Module.h:619
std::vector< Lemma > mLemmas
Stores the lemmas being valid formulas this module or its backends made.
Definition: Module.h:229
const Model & model() const
Definition: Module.h:463
void checkInfSubsetForMinimality(std::vector< FormulaSetT >::const_iterator _infsubset, const std::string &_filename="smaller_muses", unsigned _maxSizeDifference=1) const
Checks the given infeasible subset for minimality by storing all subsets of it, which have a smaller ...
Definition: Module.cpp:1018
void getOrigins(const FormulaT &_formula, FormulasT &_origins) const
Definition: Module.h:955
bool isLemmaLevel(LemmaLevel level)
Checks if current lemma level is greater or equal to given level.
Definition: Module.cpp:1079
void updateLemmas()
Stores all lemmas of any backend of this module in its own lemma vector.
Definition: Module.cpp:919
const smtrat::Conditionals & answerFound() const
Definition: Module.h:597
Model mModel
Stores the assignment of the current satisfiable result, if existent.
Definition: Module.h:199
std::pair< ModuleInput::iterator, bool > removeOrigins(ModuleInput::iterator _formula, const std::shared_ptr< std::vector< FormulaT >> &_origins)
Definition: Module.h:823
thread_priority mThreadPriority
The priority of this module to get a thread for running its check procedure.
Definition: Module.h:186
std::pair< ModuleInput::iterator, bool > addSubformulaToPassedFormula(const FormulaT &_formula, const FormulaT &_origin)
Adds the given formula to the passed formula.
Definition: Module.h:901
virtual unsigned currentlySatisfied(const FormulaT &) const
Definition: Module.h:372
std::vector< FormulaT >::const_iterator findBestOrigin(const std::vector< FormulaT > &_origins) const
Definition: Module.cpp:691
Answer solverState() const
Definition: Module.h:388
virtual void removeCore([[maybe_unused]] ModuleInput::const_iterator formula)
Removes everything related to the given sub-formula of the received formula.
Definition: Module.h:729
bool hasLemmas()
Checks whether this module or any of its backends provides any lemmas.
Definition: Module.h:532
const FormulaT & getOrigins(ModuleInput::const_iterator _formula) const
Gets the origins of the passed formula at the given position.
Definition: Module.h:808
void excludeNotReceivedVariablesFromModel() const
Excludes all variables from the current model, which do not occur in the received formula.
Definition: Module.cpp:884
virtual void addConstraintToInform(const FormulaT &_constraint)
Adds a constraint to the collection of constraints of this module, which are informed to a freshly ge...
Definition: Module.cpp:877
virtual bool informCore([[maybe_unused]] const FormulaT &_constraint)
Informs the module about the given constraint.
Definition: Module.h:684
std::atomic< Answer > mSolverState
States whether the received formula is known to be satisfiable or unsatisfiable otherwise it is set t...
Definition: Module.h:215
void collectOrigins(const FormulaT &_formula, FormulasT &_origins) const
Collects the formulas in the given formula, which are part of the received formula.
Definition: Module.cpp:960
carl::FastSet< FormulaT > mInformedConstraints
Stores the position of the first constraint of which no backend has been informed about.
Definition: Module.h:235
bool hasValidInfeasibleSubset() const
Definition: Module.cpp:1000
const ModuleInput * pReceivedFormula() const
Definition: Module.h:431
ModuleInput::iterator passedFormulaBegin()
Definition: Module.h:780
virtual ModuleInput::iterator eraseSubformulaFromPassedFormula(ModuleInput::iterator _subformula, bool _ignoreOrigins=false)
Removes everything related to the sub-formula to remove from the passed formula in the backends of th...
Definition: Module.cpp:807
virtual Answer check(bool _final=false, bool _full=true, carl::Variable _objective=carl::Variable::NO_VARIABLE)
Checks the received formula for consistency.
Definition: Module.cpp:86
bool branchAt(carl::Variable::Arg _var, const Rational &_value, std::vector< FormulaT > &&_premise, bool _leftCaseWeak=true, bool _preferLeftCase=true, bool _useReceivedFormulaAsPremise=false)
Definition: Module.h:1093
unsigned checkModel() const
Definition: Module.cpp:588
friend Manager
Definition: Module.h:71
carl::Variable mObjectiveVariable
Objective variable to be minimized. If set to NO_VARIABLE, a normal sat check should be performed.
Definition: Module.h:209
const ModuleInput & rReceivedFormula() const
Definition: Module.h:439
Module(const ModuleInput *_formula, Conditionals &_foundAnswer, Manager *_manager=nullptr, std::string module_name="Module")
Constructs a module.
Definition: Module.cpp:42
size_t determine_smallest_origin(const std::vector< FormulaT > &origins) const
Definition: Module.cpp:403
std::vector< TheoryPropagation > mTheoryPropagations
Definition: Module.h:211
virtual Answer checkCore()
Checks the received formula for consistency.
Definition: Module.cpp:207
ModuleInput::const_iterator firstUncheckedReceivedSubformula() const
Definition: Module.h:573
bool receivedVariable(carl::Variable::Arg _var) const
Definition: Module.h:377
void print(const std::string &_initiation="***") const
Prints everything relevant of the solver.
Definition: Module.cpp:1085
void receivedFormulaChecked()
Notifies that the received formulas has been checked.
Definition: Module.h:589
void getBackendsModel() const
Definition: Module.cpp:652
void collectTheoryPropagations()
Definition: Module.cpp:928
std::atomic_bool * mBackendsFoundAnswer
This flag is passed to any backend and if it determines an answer to a prior check call,...
Definition: Module.h:220
virtual void remove(ModuleInput::const_iterator _subformula)
Removes everything related to the given sub-formula of the received formula.
Definition: Module.cpp:159
std::vector< Module * > mUsedBackends
The backends of this module which are currently used (conditions to use this module are fulfilled for...
Definition: Module.h:225
std::size_t mId
A unique ID to identify this module instance. (Could be useful but currently nowhere used)
Definition: Module.h:184
void clearModels() const
Clears all assignments, if any was found.
Definition: Module.h:758
bool branchAt(const Poly &_polynomial, bool _integral, const Rational &_value, std::vector< FormulaT > &&_premise, bool _leftCaseWeak=true, bool _preferLeftCase=true, bool _useReceivedFormulaAsPremise=false)
Adds a lemmas which provoke a branching for the given variable at the given value,...
Definition: Module.cpp:478
bool branchAt(const Poly &_polynomial, bool _integral, const Rational &_value, bool _leftCaseWeak=true, bool _preferLeftCase=true, bool _useReceivedFormulaAsPremise=false, const std::vector< FormulaT > &_premise=std::vector< FormulaT >())
Definition: Module.h:1088
const ModuleInput & rPassedFormula() const
Definition: Module.h:455
void printModel(std::ostream &_out=std::cout) const
Prints the assignment of this module satisfying its received formula if it satisfiable and this modul...
Definition: Module.cpp:1151
bool mModelComputed
True, if the model has already been computed.
Definition: Module.h:203
const carl::FastSet< FormulaT > & informedConstraints() const
Definition: Module.h:504
const std::vector< Model > & allModels() const
Definition: Module.h:471
std::vector< FormulaT > merge(const std::vector< FormulaT > &, const std::vector< FormulaT > &) const
Merges the two vectors of sets into the first one.
Definition: Module.cpp:377
void clearLemmas()
Deletes all yet found lemmas.
Definition: Module.h:550
bool add(ModuleInput::const_iterator _subformula)
The module has to take the given sub-formula of the received formula into account.
Definition: Module.cpp:138
const ModuleInput * mpReceivedFormula
The formula passed to this module.
Definition: Module.h:188
static std::vector< FormulaT > mOldSplittingVariables
Reusable splitting variables.
Definition: Module.h:277
static std::vector< Branching > mLastBranches
Stores the last branches in a cycle buffer.
Definition: Module.h:273
void getBackendsAllModels() const
Stores all models of a backend in the list of all models of this module.
Definition: Module.cpp:669
void getInfeasibleSubsets()
Copies the infeasible subsets of the passed formula.
Definition: Module.cpp:596
ModuleInput * mpPassedFormula
The formula passed to the backends of this module.
Definition: Module.h:190
virtual void deinformCore([[maybe_unused]] const FormulaT &_constraint)
The inverse of informing about a constraint.
Definition: Module.h:695
bool mFinalCheck
true, if the check procedure should perform a final check which especially means not to postpone spli...
Definition: Module.h:205
static bool modelsDisjoint(const Model &_modelA, const Model &_modelB)
Checks whether there is no variable assigned by both models.
Definition: Module.cpp:611
void printPassedFormula(const std::string &_initiation="***") const
Prints the vector of passed formula.
Definition: Module.cpp:1118
ModuleInput::const_iterator mFirstUncheckedReceivedSubformula
Stores the position of the first (by this module) unchecked sub-formula of the received formula.
Definition: Module.h:237
void addLemma(const FormulaT &_lemma, const LemmaType &_lt=LemmaType::NORMAL, const FormulaT &_preferredFormula=FormulaT(carl::FormulaType::TRUE))
Stores a lemma being a valid formula.
Definition: Module.h:521
std::pair< ModuleInput::iterator, bool > removeOrigin(ModuleInput::iterator _formula, const FormulaT &_origin)
Definition: Module.h:814
Class to create the formulas for axioms.
LemmaLevel
Definition: types.h:53
carl::FormulaSet< Poly > FormulaSetT
Definition: types.h:41
carl::Formula< Poly > FormulaT
Definition: types.h:37
carl::Model< Rational, Poly > Model
Definition: model.h:13
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
std::ostream & operator<<(std::ostream &os, CMakeOptionPrinter cmop)
carl::Formulas< Poly > FormulasT
Definition: types.h:39
mpq_class Rational
Definition: types.h:19
carl::statistics::Statistics Statistics
Definition: Statistics.h:7
std::pair< std::size_t, std::size_t > thread_priority
Definition: types.h:50
Stores all necessary information of an branch, which can be used to detect probable infinite loop of ...
Definition: Module.h:32
Poly::PolyType mPolynomial
The polynomial to branch at.
Definition: Module.h:37
Branching(const typename Poly::PolyType &_polynomial, const Rational &_value)
Constructor.
Definition: Module.h:57
Rational mValue
The value to branch the polynomial at.
Definition: Module.h:40
size_t mRepetitions
The number of repetitions of the branching.
Definition: Module.h:42
int mIncreasing
Stores whether this the branching of the polynomial has been on an increasing sequence of values (>0)...
Definition: Module.h:47
FormulaT mLemma
The lemma to learn.
Definition: Module.h:128
LemmaType mLemmaType
The type of the lemma.
Definition: Module.h:130
FormulaT mPreferredFormula
The formula within the lemma, which should be assigned to true in the next decision.
Definition: Module.h:132
Lemma(const FormulaT &_lemma, const LemmaType &_lemmaType, const FormulaT &_preferredFormula)
Constructor.
Definition: Module.h:140
TheoryPropagation(const TheoryPropagation &)=delete
TheoryPropagation & operator=(const TheoryPropagation &_toMove)=delete
TheoryPropagation & operator=(TheoryPropagation &&_toMove)
Definition: Module.h:171
FormulaT mConclusion
The propagated constraint.
Definition: Module.h:152
FormulasT mPremise
The constraints under which the propagated constraint holds.
Definition: Module.h:150
TheoryPropagation(TheoryPropagation &&_toMove)
Definition: Module.h:164
TheoryPropagation(FormulasT &&_premise, const FormulaT &_conclusion)
Constructor.
Definition: Module.h:157