SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
SATModule.h
Go to the documentation of this file.
1 /*
2  * ***************************************************************************************[Solver.h]
3  * Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson
4  * Copyright (c) 2007-2010, Niklas Sorensson
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
7  * associated documentation files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9  * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
10  * furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in all copies or
13  * substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
16  * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
19  * OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20  */
21 /**
22  * @file SATModule.h
23  * @author Florian Corzilius <corzilius@cs.rwth-aachen.de>
24  * @since 2012-01-18
25  * @version 2014-10-02
26  *
27  * Supports optimization.
28  *
29  */
30 
31 #pragma once
32 
34 #include "mcsat/MCSATMixin.h"
35 #include "SATSettings.h"
36 #include "Vec.h"
37 #include "Heap.h"
38 #include "Alg.h"
39 #include "Options.h"
40 #include "SolverTypes.h"
41 #include "Sort.h"
42 #include <math.h>
43 #include <smtrat-solver/Module.h>
44 
45 #include "VarScheduler.h"
47 
48 #ifdef SMTRAT_DEVOPTION_Statistics
49 #include "SATModuleStatistics.h"
50 #include "mcsat/MCSATStatistics.h"
51 #endif
52 
53 namespace smtrat
54 {
55  /**
56  * Implements a module performing DPLL style SAT checking. It is mainly based on Minisat 2.0 and
57  * extends it by enabling the SMT-RAT module interfaces and some optimizations.
58  */
59  template<class Settings>
60  class SATModule:
61  public Module
62  {
64  //friend struct VarSchedulingDefault;
65  //template<int num> friend struct VarSchedulingMcsat;
66  //template<int num, int num2> friend struct VarSchedulingMcsatPreferLowDegrees;
67  //template<int num, int num2> friend struct VarSchedulingMcsatLowerFirstPerLevel;
68  friend class VarSchedulerBase;
69  friend class VarSchedulerMcsatBase;
70 
71  private:
72 
73  /**
74  * Stores information about a Minisat variable.
75  */
76  struct VarData
77  {
78  /**
79  * A reference to the clause, which implied the current assignment of this variable.
80  * It is not defined, if the assignment of the variable follows from a clause of size 0
81  * or if the variable is unassigned.
82  */
84 
85  /// The level in which the variable has been assigned, if it is not unassigned.
86  int level;
87 
88  /// The index in the trail.
90 
91  /// Position of explanation.
92  int mExpPos;
93 
94  VarData( Minisat::CRef _reason, int _level, int _trailIndex ):
95  reason( _reason ),
96  level( _level ),
97  mTrailIndex( _trailIndex ),
98  mExpPos( -1 )
99  {}
100  };
101 
102  /**
103  * Stores all information regarding a Boolean abstraction of a constraint.
104  */
105  struct Abstraction
106  {
107  /**
108  * A flag, which is set to false, if the constraint corresponding to the abstraction does
109  * not occur in the received formula and, hence, does not need to be part of a consistency check.
110  */
112 
113  /**
114  * A flag, which is set to false, if the constraint corresponding to the abstraction is redundant
115  * and hence there is no need to include it to a consistency check. (NOT YET USED)
116  */
118 
119  /**
120  * <0, if the corresponding constraint must still be added to the passed formula;
121  * >0, if the corresponding constraint must still be removed to the passed formula;
122  * 0, otherwise.
123  */
125 
127 
128  /**
129  * The position of the corresponding constraint in the passed formula. It points to the end
130  * if the constraint is not part of the passed formula.
131  */
133 
134  /**
135  * The constraint corresponding to this abstraction. It is NULL, if the literal for which we
136  * store this abstraction does actually not belong to an abstraction.
137  */
139 
140  // The origins of this constraint. Usually it is its own origin, but the origins can be extended during solving.
141  std::shared_ptr<std::vector<FormulaT>> origins;
142 
143  /**
144  * Constructs abstraction information, for a literal which does actually not belong to an abstraction.
145  * @param _position The end of the passed formula of this module.
146  * @param _constraint The constraint to abstract.
147  */
148  Abstraction( ModuleInput::iterator _position, const FormulaT& _reabstraction ):
149  consistencyRelevant( false ),
150  isDeduction( true ),
151  updateInfo( 0 ),
152  updatedReabstraction( false ),
153  position( _position ),
154  reabstraction( _reabstraction ),
155  origins( nullptr )
156  {}
157 
158  Abstraction( const Abstraction& ) = delete;
159  };
160 
162  {
165  std::vector<FormulaT> mOrigins;
166 
167  ClauseInformation() = delete;
168  ClauseInformation( int _position ):
169  mStoredInSatisfied( false ),
170  mPosition( _position ),
171  mOrigins()
172  {}
176 
177  void addOrigin( const FormulaT& _formula )
178  {
179  mOrigins.push_back( _formula );
180  }
181 
182  void removeOrigin( const FormulaT& _formula )
183  {
184  auto iter = std::find( mOrigins.begin(), mOrigins.end(), _formula );
185  if( iter != mOrigins.end() )
186  {
187  if( iter != --mOrigins.end() )
188  {
189  *iter = mOrigins.back();
190  mOrigins.pop_back();
191  }
192  else
193  {
194  mOrigins.pop_back();
195  }
196  }
197  }
198  };
199 
200  /// [Minisat related code]
202  {
203  /// [Minisat related code]
205 
206  /// [Minisat related code]
208  ca( _ca )
209  {}
210 
211  /// [Minisat related code]
212  bool operator ()( const Minisat::Watcher& w ) const
213  {
214  return ca[w.cref].mark() == 1;
215  }
216  };
217 
218  using VarScheduler = typename Settings::VarScheduler;
219 
220  struct VarOrderLt
221  {
223 
225  {
226  return activity[x] > activity[y];
227  }
228 
231  {}
232  };
233 
234  struct CNFInfos
235  {
236  carl::uint mCounter;
238  std::vector<Minisat::CRef> mClauses;
239 
241  mCounter( 1 ),
243  mClauses()
244  {}
245  };
246 
247  // Less than for literals in a lemma
248  struct lemma_lt
249  {
253  if (solver.bool_value(v) != l_Undef) {
254  SMTRAT_LOG_TRACE("smtrat.sat.lemma_lt", "Level of " << v << ": " << solver.trailIndex(v) << " (trail index from boolean assignment)");
255  return solver.trailIndex(v);
256  } else {
257  assert(Settings::mc_sat);
258  auto res = solver.mMCSAT.assignedAtTrailIndex(v);
259  SMTRAT_LOG_TRACE("smtrat.sat.lemma_lt", "Index of " << v << ": " << res);
260  return res;
261  }
262  }
264  SMTRAT_LOG_TRACE("smtrat.sat.lemma_lt", "Doing comparison " << x << " < " << y << "?");
265  if (x == y) return false;
266 
267  /* We want the following order:
268  * First: Undef < True < False
269  * Second: Larger level < Smaller level
270  */
271  Minisat::lbool x_value = solver.value(x);
272  Minisat::lbool y_value = solver.value(y);
273  if (x_value == l_Undef) {
274  if (y_value == l_Undef) {
275  // arbitrary
276  SMTRAT_LOG_TRACE("smtrat.sat.lemma_lt", "Both unassigned, using arbitrary order: " << (x < y));
277  return x < y;
278  } else {
279  // x < y
280  SMTRAT_LOG_TRACE("smtrat.sat.lemma_lt", x << " unassigned but " << y << " assigned, hence true");
281  return true;
282  }
283  }
284  if (y_value == l_Undef) {
285  // y < x
286  SMTRAT_LOG_TRACE("smtrat.sat.lemma_lt", x << " assigned but " << y << " unassigned, hence false");
287  return false;
288  }
289  assert(x_value != l_Undef && y_value != l_Undef);
290  if (x_value != y_value) {
291  return x_value == l_True;
292  SMTRAT_LOG_TRACE("smtrat.sat.lemma_lt", "Both assigned but differently: " << (x_value == l_True));
293  }
294  assert(x_value == y_value);
295  int x_level = levelOf(var(x));
296  SMTRAT_LOG_TRACE("smtrat.sat.lemma_lt", "Level of " << x << ": " << x_level);
297  int y_level = levelOf(var(y));
298  SMTRAT_LOG_TRACE("smtrat.sat.lemma_lt", "Level of " << y << ": " << y_level);
299  SMTRAT_LOG_TRACE("smtrat.sat.lemma_lt", "Comparing levels: " << (x_level > y_level));
300  return x_level > y_level;
301  }
302  };
303 
304  /**
305  * Maps the constraints occurring in the SAT module to their abstractions. We store a vector of literals
306  * for each constraints, which is only used in the optimization, which applies valid substitutions.
307  */
308  typedef carl::FastMap<FormulaT, std::vector<Minisat::Lit>> ConstraintLiteralsMap;
309 
310  /// Maps the Boolean variables to their corresponding Minisat variable.
311  typedef carl::FastMap<carl::Variable, Minisat::Var> BooleanVarMap;
312 
313  /// Maps the Minisat variables to their corresponding boolean variable.
314  typedef std::unordered_map<int,FormulaT> MinisatVarMap;
315 
316  /**
317  * Maps each Minisat variable to a pair of Abstractions, one contains the abstraction information of the literal
318  * being the variable and one contains the abstraction information of the literal being the variables negation.
319  */
321 
322  /// Maps the clauses in the received formula to the corresponding Minisat clause.
323  typedef carl::FastMap<FormulaT, CNFInfos> FormulaCNFInfosMap;
324 
325  /// Maps the minisat variable to the formulas which influence its value
326  typedef std::map<Minisat::Var, FormulasT> VarLemmaMap;
327 
328  /// A vector of vectors of literals representing a vector of clauses.
329  typedef std::vector<std::vector<Minisat::Lit>> ClauseVector;
330 
331  /// A set of vectors of integer representing a set of clauses.
332  typedef std::set<std::vector<int>> ClauseSet;
333 
334  ///
335  typedef carl::FastMap<signed,std::vector<signed>> TseitinVarShadows;
336 
337  ///
339  {
340  private:
341  std::vector<Minisat::CRef> mPositives;
342  std::vector<Minisat::CRef> mNegatives;
343 
344  public:
345 
347  LiteralClauses( const LiteralClauses& ) = delete;
349  mPositives( std::move(_toMove.mPositives) ),
350  mNegatives( std::move(_toMove.mNegatives) )
351  {}
353 
354  const std::vector<Minisat::CRef>& positives() const
355  {
356  return mPositives;
357  }
358 
359  const std::vector<Minisat::CRef>& negatives() const
360  {
361  return mNegatives;
362  }
363 
365  {
366  mPositives.push_back( _cref );
367  }
368 
370  {
371  mNegatives.push_back( _cref );
372  }
373 
375  {
376  auto iter = std::find( mPositives.begin(), mPositives.end(), _cref );
377  if( iter != mPositives.end() )
378  {
379  *iter = mPositives.back();
380  mPositives.pop_back();
381  }
382  }
383 
385  {
386  auto iter = std::find( mNegatives.begin(), mNegatives.end(), _cref );
387  if( iter != mNegatives.end() )
388  {
389  *iter = mNegatives.back();
390  mNegatives.pop_back();
391  }
392  }
393 
395  {
396  for( Minisat::CRef& cr : mPositives )
397  _ca.reloc( cr, _to );
398  for( Minisat::CRef& cr : mNegatives )
399  _ca.reloc( cr, _to );
400  }
401 
402  size_t numOfNegatives() const
403  {
404  return mNegatives.size();
405  }
406 
407  size_t numOfPositives() const
408  {
409  return mPositives.size();
410  }
411  };
412 
413  // Minisat related members.
414 
415  // Mode of operation:
416  /// [Minisat related code]
418  /// [Minisat related code]
419  double var_decay;
420  /// [Minisat related code]
421  double clause_decay;
422  /// [Minisat related code]
424  /// [Minisat related code]
425  double random_seed;
426  /// [Minisat related code]
428  /// Controls conflict clause minimization (0=none, 1=basic, 2=deep).
430  /// Controls the level of phase saving (0=none, 1=limited, 2=full).
432  /// Use random polarities for branching heuristics.
433  bool rnd_pol;
434  /// Initialize variable activities with a small random value.
436  /// The fraction of wasted memory allowed before a garbage collection is triggered.
437  double garbage_frac;
438  /// The initial restart limit. (default 100)
440  /// The factor with which the restart limit is multiplied in each restart. (default 1.5)
441  double restart_inc;
442  /// The initial limit for learned clauses is a factor of the original clauses.(default 1 / 3)
444  /// The limit for learned clauses is multiplied with this factor each restart.(default 1.1)
446  /// [Minisat related code]
448  /// [Minisat related code]
450 
451  // Statistics: (read-only member variable)
452  /// [Minisat related code]
454  /// [Minisat related code]
456 
457  // Solver state:
458  /// If FALSE, the constraints are already unsatisfiable. No part of the solver state may be used!
459  bool ok;
460  /// List of problem clauses.
462  /// List of problem clauses.
464  /// List of learned clauses.
466  /// List of clauses which exclude a call resulted in unknown.
468  /// Amount to bump next clause with.
469  double cla_inc;
470  /// A heuristic measurement of the activity of a variable.
472  /// Amount to bump next variable with.
473  double var_inc;
474  /// 'watches[lit]' is a list of constraints watching 'lit' (will go there if literal becomes true).
476  /// The current assignments.
478  /// The preferred polarity of each variable.
480  /// Declares if a variable is eligible for selection in the decision heuristic.
482  /// Assignment stack; stores all assignments made in the order they were made.
484  /// Separator indices for different decision levels in 'trail'.
486  /// Stores reason and level for each variable.
488  /// Head of queue (as index into the trail -- no more explicit propagation queue in MiniSat).
489  int qhead;
490  /// Number of top-level assignments since last execution of 'simplify()'.
492  /// Remaining number of propagations that must be made before next execution of 'simplify()'.
493  int64_t simpDB_props;
494  /// Current set of assumptions provided to solve by the user.
496  /// A priority queue of variables.
498  /// Set by 'search()'.
500  /// Indicates whether possibly inefficient linear scan for satisfied clauses should be performed in 'simplify'.
502  /// [Minisat related code]
504 
505  // Temporaries (to reduce allocation overhead).
506  /// Each variable is prefixed by the method in which it is used, except 'seen' which is used in several places.
508  /// [Minisat related code]
510  /// [Minisat related code]
512  /// [Minisat related code]
514  /// [Minisat related code]
515  double max_learnts;
516  /// [Minisat related code]
518  /// [Minisat related code]
520 
521  // Resource constraints:
522  /// -1 means no budget.
524  /// -1 means no budget.
526  /// [Minisat related code]
528  /// For temporary usage.
530  /// Variable representing true.
532 
533  // Module related members.
534  /// A flag, which is set to true, if anything has been changed in the passed formula between now and the last consistency check.
536  /// A flag, which is set to true, if all satisfying assignments should be computed.
538  ///
540  ///
542  ///
543  bool mBusy;
544  ///
546  /**
547  * Stores gained information about the current assignment's consistency. If we know from the last consistency check, whether the
548  * current assignment is consistent, this member is SAT, if we know that it is inconsistent it is UNSAT, otherwise Unknown.
549  */
551  /// The number of full laze calls made.
553  /// The number of restarts made.
555  /// The number of theory calls made.
557  ///
559  /**
560  * Maps each Minisat variable to a pair of Abstractions, one contains the abstraction information of the literal
561  * being the variable and one contains the abstraction information of the literal being the variables negation.
562  */
564  /**
565  * Maps the constraints occurring in the SAT module to their abstractions. We store a vector of literals
566  * for each constraints, which is only used in the optimization, which applies valid substitutions.
567  */
569  /// Maps the Boolean variables to their corresponding Minisat variable.
571  /// Maps the Minisat variables to their corresponding boolean variable.
573  ///
574  carl::FastMap<FormulaT, Minisat::Lit> mFormulaAssumptionMap;
575  /// Maps the clauses in the received formula to the corresponding Minisat clause and Minisat literal.
577  /// If problem is unsatisfiable (possibly under assumptions), this vector represent the final conflict clause expressed in the assumptions.
579  ///
580  carl::FastMap<Minisat::CRef,ClauseInformation> mClauseInformation;
581  ///
582  std::unordered_map<int,std::unordered_set<Minisat::CRef>> mLiteralClausesMap;
583  ///
585  /// Stores all Literals for which the abstraction information might be changed.
586  std::vector<signed> mChangedBooleans;
587  /// Is true, if we have to communicate all activities to the backends. (This might be the case after rescaling the activities.)
589  /// Stores all clauses in which the activities have been changed.
590  std::vector<signed> mChangedActivities;
591 
592  /// Stores for each variable the corresponding formulas which control its value
594  /// Stores Minisat indexes of all relevant variables
595  std::vector<int> mRelevantVariables;
596  ///
598  ///
600  ///
601  carl::FastMap<int, FormulaT> mTseitinVarFormulaMap;
602  /// Stores whether a given variable is a tseitin variable.
603  carl::Bitset mTseitinVariable;
604  /// Stores whether a given tseitin variable was already added to the assumptions.
606  /// Stores whether a given tseitin variable was not yet added to the assumptions, but represents a top-level clause.
607  /// Tseitin variables for top-level clauses are only assumed lazily if they occur in another clause.
609  ///
610  std::vector<Minisat::vec<Minisat::Lit>> mCurrentTheoryConflicts;
611  ///
612  std::vector<unsigned> mCurrentTheoryConflictTypes;
613  ///
614  std::map<std::pair<size_t,size_t>,size_t> mCurrentTheoryConflictEvaluations;
615  ///
616  std::unordered_set<int> mLevelCounter;
617  ///
619  ///
621  ///
622  std::vector<LiteralClauses> mLiteralsClausesMap;
623  ///
624  std::vector<std::pair<size_t,size_t>> mLiteralsActivOccurrences;
625  ///
626  std::vector<Minisat::Lit> mPropagationFreeDecisions;
627  /// literals propagated by lemmas
629  /// is the lemma removable
631  /*
632  * MC-SAT related members.
633  */
634  #ifdef SMTRAT_DEVOPTION_Statistics
635  mcsat::MCSATStatistics& mMCSATStatistics = statistics_get<mcsat::MCSATStatistics>("SATModule_" + std::to_string(id()) + "_mcsat");
636  #endif
638  std::map<carl::Variable, std::vector<signed>> mFutureChangedBooleans;
639 
640  #ifdef SMTRAT_DEVOPTION_Statistics
641  /// Stores all collected statistics during solving.
642  SATModuleStatistics& mStatistics = statistics_get<SATModuleStatistics>("SATModule_" + std::to_string(id()));
643  #endif
644 
645  // learnt clause set for duplicate checks
648  std::size_t operator() (const std::vector<Minisat::Lit>& cl) const {
649  return std::accumulate(cl.begin(), cl.end(), static_cast<std::size_t>(0),
650  [](std::size_t a, Minisat::Lit b){ return a ^ static_cast<std::size_t>(b.x); }
651  );
652  }
653  };
654  /// Stores all clauses as sets to quickly check for duplicates.
655  std::unordered_set<std::vector<Minisat::Lit>, UnorderedClauseHasher> mData;
656 
657  void preprocess(std::vector<Minisat::Lit>& cl) const {
658  std::sort(cl.begin(), cl.end());
659  }
660  bool contains(const std::vector<Minisat::Lit>& cl) const {
661  return mData.find(cl) != mData.end();
662  }
663  void insert(const std::vector<Minisat::Lit>& cl) {
664  mData.insert(cl);
665  }
666  void clear() {
667  mData.clear();
668  }
669  };
671 
672  public:
674 
675  /**
676  * Constructs a SATModule.
677  * @param _type The type of this module being SATModule.
678  * @param _formula The formula passed to this module, called received formula.
679  * @param _settings [Not yet used.]
680  * @param _foundAnswer Vector of Booleans: If any of them is true, we have to terminate a running check procedure.
681  * @param _manager A reference to the manager of the solver using this module.
682  */
683  SATModule( const ModuleInput* _formula, Conditionals& _foundAnswer, Manager* const _manager = nullptr );
684 
685  /**
686  * Destructs this SATModule.
687  */
689 
690  // Interfaces.
691 
692  /**
693  * The module has to take the given sub-formula of the received formula into account.
694  * @param _subformula The sub-formula to take additionally into account.
695  * @return false, if it can be easily decided that this sub-formula causes a conflict with
696  * the already considered sub-formulas;
697  * true, otherwise.
698  */
700 
701  /**
702  * Checks the received formula for consistency.
703  * @return SAT, if the received formula is satisfiable;
704  * UNSAT, if the received formula is not satisfiable;
705  * Unknown, otherwise.
706  */
708 
709  /**
710  * Removes everything related to the given sub-formula of the received formula.
711  * @param _subformula The sub formula of the received formula to remove.
712  */
714 
715  /**
716  * Updates the model, if the solver has detected the consistency of the received formula, beforehand.
717  */
718  void updateModel() const;
719 
720  /**
721  * Updates all satisfying models, if the solver has detected the consistency of the received formula, beforehand.
722  */
724 
725  /**
726  * Updates the infeasible subset found by the SATModule, if the received formula is unsatisfiable.
727  */
729 
730  void cleanUpAfterOptimizing( const std::vector<Minisat::CRef>& _excludedAssignments );
731 
733 
734  void addConstraintToInform( const FormulaT& ) {}
735  void addConstraintToInform_( const FormulaT& _formula )
736  {
737  Module::addConstraintToInform( _formula );
738  }
739 
740  /**
741  * Adds the Boolean assignments to the given assignments, which were determined by the Minisat procedure.
742  * Note: Assignments in the given map are not overwritten.
743  * @param _rationalAssignment The assignments to add the Boolean assignments to.
744  */
745  void addBooleanAssignments( RationalAssignment& _rationalAssignment ) const;
746 
747  /**
748  * Prints everything.
749  * @param _out The output stream where the answer should be printed.
750  * @param _init The line initiation.
751  */
752  void print( std::ostream& _out = std::cout, const std::string& _init = "" ) const;
753 
754  /**
755  * Prints the current assignment of the SAT solver.
756  * @param _out The output stream where the answer should be printed.
757  * @param _init The line initiation.
758  */
759  void printCurrentAssignment( std::ostream& = std::cout, const std::string& = "" ) const;
760 
761  /**
762  * Prints the constraints to literal map.
763  * @param _out The output stream where the answer should be printed.
764  * @param _init The line initiation.
765  */
766  void printConstraintLiteralMap( std::ostream& _out = std::cout, const std::string& _init = "" ) const;
767 
768  /**
769  * Prints the formulas to clauses map.
770  * @param _out The output stream where the answer should be printed.
771  * @param _init The line initiation.
772  */
773  void printFormulaCNFInfosMap( std::ostream& _out = std::cout, const std::string& _init = "" ) const;
774 
775  /**
776  * Prints the clause information.
777  * @param _out The output stream where the answer should be printed.
778  * @param _init The line initiation.
779  */
780  void printClauseInformation( std::ostream& _out = std::cout, const std::string& _init = "" ) const;
781 
782  /**
783  * Prints map of the Boolean within the SAT solver to the given Booleans.
784  * @param _out The output stream where the answer should be printed.
785  * @param _init The line initiation.
786  */
787  void printBooleanVarMap( std::ostream& _out = std::cout, const std::string& _init = "" ) const;
788 
789  /**
790  * Prints the literal to constraint map.
791  * @param _out The output stream where the answer should be printed.
792  * @param _init The line initiation.
793  */
794  void printBooleanConstraintMap( std::ostream& _out = std::cout, const std::string& _init = "" ) const;
795 
796  /**
797  * Prints the clause at the given reference.
798  * @param _clause The reference of the clause.
799  * @param _withAssignment A flag indicating if true, that the assignments should be printed too.
800  * @param _out The output stream where the answer should be printed.
801  * @param _init The prefix of each printed line.
802  */
803  void printClause( Minisat::CRef _clause, bool _withAssignment = false, std::ostream& _out = std::cout, const std::string& _init = "" ) const;
804 
805  /**
806  * Prints the clause resulting from the given vector of literals.
807  * @param _clause The reference of the clause.
808  * @param _withAssignment A flag indicating if true, that the assignments should be printed too.
809  * @param _out The output stream where the answer should be printed.
810  * @param _init The prefix of each printed line.
811  */
812  void printClause( const Minisat::vec<Minisat::Lit>&, bool _withAssignment = false, std::ostream& _out = std::cout, const std::string& _init = "" ) const;
813 
814  /**
815  * Prints all given clauses.
816  * @param _clauses The clauses to print.
817  * @param _name The name of the clauses to print. (e.g. learnts, clauses, ..)
818  * @param _out The output stream where the answer should be printed.
819  * @param _init The prefix of each printed line.
820  * @param _from The position of the first clause to print within the given vector of clauses.
821  * @param _withAssignment A flag indicating if true, that the assignments should be printed too.
822  */
823  void printClauses( const Minisat::vec<Minisat::CRef>& _clauses, const std::string _name, std::ostream& _out = std::cout, const std::string& _init = "", int = 0, bool _withAssignment = false, bool _onlyNotSatisfied = false ) const;
824 
825  /**
826  * Prints the decisions the SAT solver has made.
827  * @param _out The output stream where the answer should be printed.
828  * @param _init The line initiation.
829  */
830  void printDecisions( std::ostream& _out = std::cout, const std::string& _init = "" ) const;
831 
832  /**
833  * Prints the propagated lemmas for each variables which influence its value.
834  * @param _out The output stream where the answer should be printed.
835  * @param _init The line initiation.
836  */
837  void printPropagatedLemmas( std::ostream& _out = std::cout, const std::string& _init = "" ) const;
838 
839  /**
840  * Prints the literals' active occurrences in all clauses.
841  * @param _out The output stream where the answer should be printed.
842  * @param _init The line initiation.
843  */
844  void printLiteralsActiveOccurrences( std::ostream& _out = std::cout, const std::string& _init = "" ) const;
845 
846  /**
847  * Collects the taken statistics.
848  */
849  void collectStats();
850 
851  private:
852  // Problem specification:
853 
854  /**
855  * Creates a new SAT variable in the solver. If 'decision' is cleared, variable will not be
856  * used as a decision variable (NOTE! This has effects on the meaning of a SATISFIABLE result).
857  * @param polarity A flag, which is true, if the variable preferably is assigned to false.
858  * @param dvar A flag, which is true, if the variable to create needs to considered in the solving.
859  * @param _activity The initial activity of the variable to create.
860  * @param _tseitinShadowed A flag, which is true, if the variable to create is a sub-formula of a formula represented by a Tseitin variable.
861  * @return The created Minisat variable.
862  */
863  Minisat::Var newVar( bool polarity = true, bool dvar = true, double _activity = 0, bool insertIntoHeap = true );
864 
865  // Solving:
866 
867  /**
868  * Removes already satisfied clauses and performs simplifications on all clauses.
869  */
870  void simplify();
871 
872  /**
873  * Adds the clause of the given type with the given literals to the clauses managed by Minisat.
874  * @param _clause The clause to add.
875  * @param _type The type of the clause (NORMAL_CLAUSE, LEMMA_CLAUSE or CONFLICT_CLAUSE).
876  * @param _force If true backtracking won't stop at the first assumption-decision-level.
877  * @return true, if a clause has been added;
878  * false, otherwise.
879  */
880  bool addClause( const Minisat::vec<Minisat::Lit>& _clause, unsigned _type = 0 );
881 
882  void removeLiteralOrigin( Minisat::Lit _litToRemove, const FormulaT& _origin );
883 
884  /**
885  * @return FALSE means solver is in a conflicting state
886  */
887  inline bool okay() const
888  {
889  return ok;
890  }
891 
892  // Variable mode:
893 
894  /**
895  * Declare which polarity the decision heuristic should use for a variable. Requires mode 'polarity_user'.
896  * @param v The variable to set the polarity for.
897  * @param b true, if the variables should be preferably assigned to false.
898  */
899  inline void setPolarity( Minisat::Var v, bool b )
900  {
901  polarity[v] = b;
902  }
903 
904  /**
905  * Declare if a variable should be eligible for selection in the decision heuristic.
906  * @param v The variable to change the eligibility for selection in the decision heuristic.
907  * @param b true, if the variable should be eligible for selection in the decision heuristic.
908  */
909  inline void setDecisionVar( Minisat::Var v, bool b, bool insertIntoHeap = true )
910  {
911  if( b &&!decision[v] )
912  dec_vars++;
913  else if( !b && decision[v] )
914  dec_vars--;
915  decision[v] = b;
916  if (insertIntoHeap) insertVarOrder( v );
917  }
918 
919  // Read state:
921  {
922  return assigns[x];
923  }
924  /**
925  * @param x The variable to get its value for.
926  * @return The current value of a variable.
927  */
929  {
930  if (Settings::mc_sat) {
931  return theoryValue(x);
932  }
933  return assigns[x];
934  }
935 
937  // MCSAT-specific:
938  // There are currently two ways of propagating literals evaluating in the theory
939  // to the Boolean level: Semantic propagations inserted as decisions explicitly
940  // in the search loop and this value function. This value function should have no
941  // effect most of the times as semantic propagations handle most cases. The only case
942  // where theoryValue is neccessary is during backtracking, when semantic propagations
943  // which are not inserted at the earliest possible point are already backtracked but
944  // the corerspondiong literals still evaluate to a value.
945  // Since the trail is left inconsistent after an theory decision, it is important for
946  // the correctness of the procedure that the Boolean level is considered first here,
947  // as Boolean conflict resolution (which will fix those inconsistencies) relies on that.
948  // Note that the inconsistency mentioned here is not between semantic propagations and
949  // Boolean decisions/propagations but between theory values and Boolean decisions/propagations.
950  // In this sense, the trail is kept consistent throughout the procedure.
951  Minisat::lbool res = assigns[x];
952  if (res == l_Undef) {
953  if (mBooleanConstraintMap.size() <= x) return l_Undef;
954  if (mBooleanConstraintMap[x].first == nullptr) return l_Undef;
955  res = mMCSAT.evaluateLiteral(Minisat::mkLit(x, false));
956  }
957  //SMTRAT_LOG_DEBUG("smtrat.sat", x << " -> " << res);
958  return res;
959  }
960 
961  bool addClauseIfNew(const FormulasT& clause) {
962  SMTRAT_LOG_DEBUG("smtrat.sat", "Add theory conflict clause " << clause << " if new");
963 
964  sat::detail::validateClause(clause, Settings::validate_clauses);
965  Minisat::vec<Minisat::Lit> explanation;
966  std::vector<Minisat::Lit> explanation_set;
967  for (const auto& c: clause) {
968  auto lit = createLiteral(c);
969  explanation.push(lit);
970  explanation_set.push_back(lit);
971  SMTRAT_LOG_DEBUG("smtrat.sat", "Created literal from " << c << " -> " << explanation.last());
972  }
973 
974  mUnorderedClauseLookup.preprocess(explanation_set);
975  if (mUnorderedClauseLookup.contains(explanation_set)) {
976  SMTRAT_LOG_DEBUG("smtrat.sat", "Skipping duplicate clause " << explanation);
977  return false;
978  }
979  else {
980  SMTRAT_LOG_DEBUG("smtrat.sat", "Adding clause " << explanation);
981  mUnorderedClauseLookup.insert(explanation_set);
982  addClause(explanation, Minisat::LEMMA_CLAUSE);
983  return true;
984  }
985  }
986 
987  void handleTheoryConflict(const mcsat::Explanation& explanation) {
988  #ifdef DEBUG_SATMODULE
989  print(std::cout, "###");
990  #endif
991  SMTRAT_LOG_DEBUG("smtrat.sat", "Handling theory conflict explanation " << explanation);
992 
993  if (std::holds_alternative<FormulaT>(explanation)) {
994  // add conflict clause
995  const auto& clause = std::get<FormulaT>(explanation);
996  bool added = addClauseIfNew(clause.is_nary() ? clause.subformulas() : FormulasT({clause}));
997  assert(added);
998  } else {
999  const auto& chain = std::get<mcsat::ClauseChain>(explanation);
1000  if (Settings::mcsat_resolve_clause_chains) {
1001  FormulaT clause = chain.resolve();
1002  SMTRAT_LOG_DEBUG("smtrat.sat", "Resolved clause chain to " << clause);
1003  bool added = addClauseIfNew(clause.is_nary() ? clause.subformulas() : FormulasT({clause}));
1004  assert(added);
1005  } else {
1006  // add propagations
1007  bool added = false;
1008  for (const auto& link : chain) {
1009  added |= addClauseIfNew(link.clause().is_nary() ? link.clause().subformulas() : FormulasT({link.clause()}));
1010  }
1011  assert(added);
1012  }
1013  }
1014 
1015  Minisat::CRef confl = storeLemmas();
1016  if (confl != Minisat::CRef_Undef) {
1017  handleConflict(confl);
1018  }
1019 
1020  SMTRAT_LOG_DEBUG("smtrat.sat", "Handled theory conflict explanation");
1021  }
1022 
1024  {
1026  }
1027  /**
1028  * @param p The literal to get its value for.
1029  * @return The current value of a literal.
1030  */
1032  {
1033  return value(Minisat::var(p)) == l_Undef ? l_Undef : value(Minisat::var(p)) ^ Minisat::sign(p);
1034  }
1037  }
1038 
1039  /**
1040  * @return The current number of assigned literals.
1041  */
1042  inline int nAssigns() const
1043  {
1044  return trail.size();
1045  }
1046 
1047  /**
1048  * @return The current number of original clauses.
1049  */
1050  inline int nClauses() const
1051  {
1052  return clauses.size();
1053  }
1054 
1055  /**
1056  * @return The current number of learned clauses.
1057  */
1058  inline int nLearnts() const
1059  {
1060  return learnts.size();
1061  }
1062 
1063  /**
1064  * @return The current number of variables.
1065  */
1066  inline int nVars() const
1067  {
1068  return vardata.size();
1069  }
1070 
1071  /**
1072  * @return [Minisat related code]
1073  */
1074  inline int nFreeVars() const
1075  {
1076  return (int)dec_vars - (trail_lim.size() == 0 ? trail.size() : trail_lim[0]);
1077  }
1078 
1079  // Resource constraints:
1080 
1081  /**
1082  * [Minisat related code]
1083  * @param x [Minisat related code]
1084  */
1085  inline void setConfBudget( int64_t x )
1086  {
1087  conflict_budget = (int64_t)conflicts + x;
1088  }
1089 
1090  /**
1091  * [Minisat related code]
1092  * @param x [Minisat related code]
1093  */
1094  inline void setPropBudget( int64_t x )
1095  {
1096  propagation_budget = (int64_t)propagations + x;
1097  }
1098 
1099  /**
1100  * [Minisat related code]
1101  */
1102  inline void budgetOff()
1103  {
1105  }
1106 
1107  /**
1108  * Trigger a (potentially asynchronous) interruption of the solver.
1109  */
1110  inline void interrupt()
1111  {
1112  asynch_interrupt = true;
1113  }
1114 
1115  /**
1116  * Clear interrupt indicator flag.
1117  */
1118  inline void clearInterrupt()
1119  {
1120  asynch_interrupt = false;
1121  }
1122 
1123  // Memory management:
1124 
1125  /**
1126  * [Minisat related code]
1127  */
1129 
1130  /**
1131  * [Minisat related code]
1132  * @param gf [Minisat related code]
1133  */
1134  inline void checkGarbage( double gf )
1135  {
1136  if( ca.wasted() > ca.size() * gf )
1137  garbageCollect();
1138  }
1139 
1140  /**
1141  * [Minisat related code]
1142  */
1143  void checkGarbage( void )
1144  {
1145  return checkGarbage( garbage_frac );
1146  }
1147 
1148  /**
1149  * [Minisat related code]
1150  * @param std::cout [Minisat related code]
1151  * @param [Minisat related code]
1152  */
1153  void printSatState( std::ostream& = std::cout, const std::string = "" );
1154 
1155  // Main internal methods:
1156 
1157  /**
1158  * Insert a variable in the decision order priority queue.
1159  * @param x [Minisat related code]
1160  */
1161  inline void insertVarOrder( Minisat::Var x )
1162  {
1163  SMTRAT_LOG_TRACE("smtrat.sat", "Insert " << x << " into order heap");
1164 
1165  if (Settings::mc_sat) {
1166  // Note: insertVarOrder should never be called with a VARASSIGN when it's created
1167  if (mBooleanConstraintMap.size() > x && mBooleanConstraintMap[x].first != nullptr) {
1168  const auto& reabstr = mBooleanConstraintMap[x].first->reabstraction;
1169  if (reabstr.type() == carl::FormulaType::VARASSIGN) {
1170  SMTRAT_LOG_DEBUG("smtrat.sat", "Converting " << x << " (" << reabstr << ")...")
1171  const carl::Variable tvar = reabstr.variable_assignment().var();
1172  x = mMCSAT.minisatVar(tvar);
1173  SMTRAT_LOG_DEBUG("smtrat.sat", "..to " << x << " (" << tvar << ")");
1174  }
1175  }
1176  }
1177 
1178  var_scheduler.insert(x);
1179  }
1180 
1181  /**
1182  * [Minisat related code]
1183  */
1185 
1186  /**
1187  * @return true, if the current assignment is a full one.
1188  */
1190 
1191  /**
1192  * @return The next decision variable.
1193  */
1195 
1197  for (int i = 0; i < mBooleanConstraintMap.size(); i++) {
1198  auto ptr1 = mBooleanConstraintMap[i].first;
1199  auto ptr2 = mBooleanConstraintMap[i].second;
1200  if (ptr1 == nullptr) continue;
1201  assert(ptr2 != nullptr);
1202  if (ptr1->updateInfo * ptr2->updateInfo > 0) {
1203  SMTRAT_LOG_WARN("smtrat.sat.mcsat", "Consistency error for " << ptr1->reabstraction << " / " << ptr2->reabstraction);
1204  std::exit(24);
1205  }
1206  assert(ptr1->updateInfo * ptr2->updateInfo <= 0);
1207  }
1208  }
1209 
1210  /**
1211  * Begins a new decision level.
1212  */
1213  inline void newDecisionLevel()
1214  {
1215  trail_lim.push( trail.size() );
1216  }
1217 
1219  {
1220  unsigned& ntso = mNonTseitinShadowedOccurrences[_var];
1221  assert( ntso > 0 );
1222  --ntso;
1223  if( ntso == 0 )
1224  {
1225  setDecisionVar( _var, false );
1226  }
1227  }
1228 
1230  {
1231  unsigned& ntso = mNonTseitinShadowedOccurrences[_var];
1232  if( ntso == 0 )
1233  {
1234  setDecisionVar( _var, true );
1235  }
1236  ++ntso;
1237  }
1238 
1239  /**
1240  * Enqueue a literal. Assumes value of literal is undefined.
1241  * @param p The literal to enqueue. (The variable in the literal is set to true, if the literal is positive,
1242  * and to false, if the literal is negative).s
1243  * @param from A reference to the clause, which implied this assignment.
1244  */
1246 
1247  /**
1248  * Test if fact 'p' contradicts current state, enqueue otherwise.
1249  * NOTE: enqueue does not set the ok flag! (only public methods do)
1250  * @param p [Minisat related code]
1251  * @param from [Minisat related code]
1252  * @return [Minisat related code]
1253  */
1255  {
1256  return value( p ) != l_Undef ? value( p ) != l_False : (uncheckedEnqueue( p, from ), true);
1257  }
1258 
1259  /**
1260  * propagate : [void] -> [Clause*]
1261  *
1262  * Description:
1263  * Propagates all enqueued facts. If a conflict arises, the conflicting clause is returned,
1264  * otherwise CRef_Undef.
1265  *
1266  * Post-conditions:
1267  * - the propagation queue is empty, even if there was a conflict.
1268  *
1269  * @return A reference to the conflicting clause, if a conflict has been detected.
1270  */
1272 
1273  /**
1274  * Revert to the state at given level (keeping all assignments at 'level' but not beyond).
1275  *
1276  * @param level The level to backtrack to.
1277  */
1278  void cancelUntil( int level, bool force = false );
1279 
1281 
1282  /**
1283  * Revert the variables assignment until a given level (keeping all assignments at 'level')
1284  *
1285  * @param level The level to backtrack to
1286  */
1289 
1290  /**
1291  * analyze : (confl : Clause*) (out_learnt : vec<Lit>&) (out_btlevel : int&) -> [void]
1292  *
1293  * Description:
1294  * Analyze conflict and produce a reason clause.
1295  *
1296  * Pre-conditions:
1297  * - 'out_learnt' is assumed to be cleared.
1298  * - Current decision level must be greater than root level.
1299  *
1300  * Post-conditions:
1301  * - 'out_learnt[0]' is the asserting literal at level 'out_btlevel'.
1302  * - If out_learnt.size() > 1 then 'out_learnt[1]' has the greatest decision level of the
1303  * rest of literals. There may be others from the same level though.
1304  *
1305  * @param confl A reference to the conflicting clause.
1306  * @param out_learnt The asserting clause derived by this method.
1307  * @param out_btlevel The level to backtrack to according the analysis of this method.
1308  * @return true, if the asserting clause does not equal the conflict clause given by confl
1309  */
1310  bool analyze( Minisat::CRef confl, Minisat::vec<Minisat::Lit>& out_learnt, int& out_btlevel );
1311 
1312 
1313  /**
1314  * Check if 'p' can be removed. 'abstract_levels' is used to abort early if the algorithm is
1315  * visiting literals at levels that cannot be removed later.
1316  * @param p [Minisat related code]
1317  * @param abstract_levels [Minisat related code]
1318  * @return [Minisat related code]
1319  */
1320  bool litRedundant( Minisat::Lit p, uint32_t abstract_levels );
1321 
1322  /**
1323  * Adds clauses representing the lemmas which should be added to this SATModule. This may provoke backtracking.
1324  * @return true, if any clause has been added.
1325  */
1327 
1328  /**
1329  * Adds the clauses representing all conflicts generated by all backends.
1330  * @return A reference to the clause representing the best infeasible subset.
1331  */
1333 
1334  void adaptConflictEvaluation( size_t& _clauseEvaluation, Minisat::Lit _lit, bool _firstLiteral );
1335 
1336  /**
1337  * Propagate and check the consistency of the constraints, whose abstraction literals have been assigned to true.
1338  * @param _madeTheoryCall A flag which is set to true, if at least one theory call has been made within this method.
1339  * @return A reference to a conflicting clause, if a clause has been added.
1340  */
1341  Minisat::CRef propagateConsistently( bool _checkWithTheory = true );
1343  void theoryCall();
1345  bool expPositionsCorrect() const;
1346 
1347  /**
1348  * Checks the received formula for consistency.
1349  * @return l_True, if the received formula is satisfiable;
1350  * l_False, if the received formula is not satisfiable;
1351  * l_Undef, otherwise.
1352  */
1354 
1356 
1357  /**
1358  * search : (nof_conflicts : int) (params : const SearchParams&) -> [lbool]
1359  *
1360  * Description:
1361  * Search for a model the specified number of conflicts.
1362  * NOTE! Use negative value for 'nof_conflicts' indicate infinity.
1363  *
1364  * Output:
1365  * 'l_True' if a partial assignment that is consistent with respect to the clause set is found. If
1366  * all variables are decision variables, this means that the clause set is satisfiable. 'l_False'
1367  * if the clause set is unsatisfiable. 'l_Undef' if the bound on number of conflicts is reached.
1368  *
1369  * @param nof_conflicts The number of conflicts after which a restart is forced.
1370  * @return l_True, if the considered clauses are satisfiable;
1371  * l_False, if the considered clauses are unsatisfiable;
1372  * l_Undef, if it could not been detected whether the given set of clauses is satisfiable or not.
1373  */
1374  Minisat::lbool search( int nof_conflicts = 100 );
1375 
1376  /**
1377  * Handles conflict
1378  * @param conf conflict clause
1379  * @return if return is not l_True, search can be aborted
1380  */
1382 
1383  /**
1384  * reduceDB : () -> [void]
1385  *
1386  * Description:
1387  * Remove half of the learnt clauses, minus the clauses locked by the current assignment. Locked
1388  * clauses are clauses that are reason to some assignment. Binary clauses are never removed.
1389  */
1390  void reduceDB();
1391 
1392  void clearLearnts( int n );
1393 
1394  // Shrink 'cs' to contain only non-satisfied clauses.
1395 
1396  /**
1397  * Removes all satisfied clauses from the given vector of clauses, which should only be performed in decision level 0.
1398  * @param cs The vector of clauses wherein to remove all satisfied clauses.
1399  */
1401 
1402  /**
1403  * [Minisat related code]
1404  */
1406 
1407  // Maintaining Variable/Clause activity:
1408 
1409  /**
1410  * @return The maximum of all activities of the occurring literals.
1411  */
1412  inline double maxActivity() const
1413  {
1414  double result = 0;
1415  for( int i = 0; i < activity.size(); ++i )
1416  {
1417  if( result < activity[i] )
1418  result = activity[i];
1419  }
1420  return result;
1421  }
1422 
1423  /**
1424  * Decay all variables with the specified factor. Implemented by increasing the 'bump' value instead.
1425  */
1426  inline void varDecayActivity()
1427  {
1428  var_inc *= (1 / var_decay);
1429  }
1430 
1431  /**
1432  * Increase a variable with the current 'bump' value.
1433  * @param v [Minisat related code]
1434  * @param inc [Minisat related code]
1435  */
1436  inline void varBumpActivity( Minisat::Var v, double inc )
1437  {
1438  bool rescale = false;
1439 
1440  /*
1441  if (Settings::mc_sat) {
1442  for (auto tvar : mMCSAT.theoryVars(v)) {
1443  if ((activity[tvar] += inc) > 1e100) {
1444  rescale = true;
1445  }
1446  var_scheduler.increaseActivity(tvar);
1447  }
1448  }
1449  */
1450 
1451  if ((activity[v] += inc) > 1e100) {
1452  rescale = true;
1453  }
1454  var_scheduler.increaseActivity(v);
1455 
1456  if( rescale )
1457  {
1458  // Rescale:
1459  for( int i = 0; i < nVars(); i++ )
1460  activity[i] *= 1e-100;
1461  var_inc *= 1e-100;
1463  mAllActivitiesChanged = true;
1464  }
1466  {
1467  mChangedActivities.push_back( (signed) v );
1468  }
1469  }
1470 
1471  /**
1472  * Increase a variable with the current 'bump' value.
1473  * @param v [Minisat related code]
1474  */
1476  {
1477  varBumpActivity( v, var_inc );
1478  }
1479 
1480  /**
1481  * Decay all clauses with the specified factor. Implemented by increasing the 'bump' value instead.
1482  */
1483  inline void claDecayActivity()
1484  {
1485  cla_inc *= (1 / clause_decay);
1486  }
1487 
1488  /**
1489  * Increase a clause with the current 'bump' value.
1490  * @param c [Minisat related code]
1491  */
1493  {
1494  if( (c.activity() += (float)cla_inc) > 1e20 )
1495  {
1496  // Rescale:
1497  for( int i = 0; i < learnts.size(); i++ )
1498  {
1499  ca[learnts[i]].activity() *= (float)1e-20;
1500  }
1501  cla_inc *= 1e-20;
1502  }
1503  }
1504 
1505  // Operations on clauses:
1506 
1507  /**
1508  * Attach a clause to watcher lists.
1509  * @param cr [Minisat related code]
1510  */
1512 
1513  /**
1514  * Detach a clause to watcher lists.
1515  * @param cr [Minisat related code]
1516  * @param strict [Minisat related code]
1517  */
1518  void detachClause( Minisat::CRef cr, bool strict = false );
1519 
1520  /**
1521  * Detach and free a clause.
1522  * @param cr [Minisat related code]
1523  */
1525 
1527  return ca[cr];
1528  }
1529 
1530  /**
1531  * @param c [Minisat related code]
1532  * @return TRUE if a clause is a reason for some implication in the current state.
1533  */
1534  inline bool locked( const Minisat::Clause& c )
1535  {
1536  return value( c[0] ) == l_True && reason( Minisat::var( c[0] ) ) != Minisat::CRef_Undef && ca.lea( reason( Minisat::var( c[0] ) ) ) == &c;
1537  }
1538 
1539  /**
1540  * @param c [Minisat related code]
1541  * @return TRUE if a clause is satisfied in the current state.
1542  */
1543  bool satisfied( const Minisat::Clause& c ) const;
1544  bool bool_satisfied( const Minisat::Clause& c ) const;
1545 
1546  /**
1547  * [Minisat related code]
1548  * @param x [Minisat related code]
1549  * @param map [Minisat related code]
1550  * @param max [Minisat related code]
1551  * @return [Minisat related code]
1552  */
1554 
1555  /**
1556  * Finite subsequences of the Luby-sequence:
1557  *
1558  * 0: 1
1559  * 1: 1 1 2
1560  * 2: 1 1 2 1 1 2 4
1561  * 3: 1 1 2 1 1 2 4 1 1 2 1 1 2 4 8
1562  * ...
1563  *
1564  * @param y
1565  * @param x
1566  *
1567  * @return
1568  */
1569  static double luby( double y, int x );
1570 
1571  /**
1572  * [Minisat related code]
1573  * @param to [Minisat related code]
1574  */
1576 
1577  // Misc:
1578 
1579  /**
1580  * @return The current decision level.
1581  */
1582  inline int decisionLevel() const
1583  {
1584  return trail_lim.size();
1585  }
1586 
1587  /**
1588  * Used to represent an abstraction of sets of decision levels.
1589  * @param x [Minisat related code]
1590  * @return [Minisat related code]
1591  */
1592  inline uint32_t abstractLevel( Minisat::Var x ) const
1593  {
1594  return 1 << (level( x ) & 31);
1595  }
1596 
1597  /**
1598  * @param x The variable to get the reason for it's assignment.
1599  * @return A reference to the clause, which implied the current assignment of this variable.
1600  * It is not defined, if the assignment of the variable follows from a clause of size 0
1601  * or if the variable is unassigned.
1602  */
1604 
1605  void removeTheoryPropagation( int _position );
1606 
1607  /**
1608  * @param x The variable for which we to get the level in which it has been assigned to a value.
1609  * @return The level in which the variable has been assigned, if it is not unassigned.
1610  */
1611  int level( Minisat::Var x ) const
1612  {
1613  return vardata[x].level;
1614  }
1616  {
1617  if (level(x) >= 0) return level(x);
1618  return mMCSAT.decisionLevel(x);
1619  }
1621  if (Settings::mc_sat) {
1622  int tl = mMCSAT.decisionLevel(x);
1623  SMTRAT_LOG_DEBUG("smtrat.sat", "Theory level of " << x << " is " << tl);
1624  if (bool_value(x) != l_Undef && level(x) >= 0) return std::min(level(x), tl);
1625  return tl;
1626  } else {
1627  return level(x);
1628  }
1629  }
1630 
1631  inline int trailIndex( Minisat::Var _var ) const
1632  {
1633  assert( _var < vardata.size() );
1634  assert( var(trail[vardata[_var].mTrailIndex]) == _var );
1635  return vardata[_var].mTrailIndex;
1636  }
1637 
1638  /**
1639  * @param _clause The clause to get the highest decision level in which assigned one of its literals has been assigned.
1640  * @return The highest decision level which assigned a literal of the given clause.
1641  */
1643 
1645 
1646  /**
1647  * @return An estimation of the progress the SAT solver has been made, depending on how many assignments have been excluded
1648  * and how many assignments are in general possible. The calculated value is between 0 and 1.
1649  */
1650  double progressEstimate() const;
1651 
1652  /**
1653  * @return [Minisat related code]
1654  */
1655  inline bool withinBudget() const
1656  {
1657  return !asynch_interrupt && (conflict_budget < 0 || conflicts < (uint64_t)conflict_budget)
1658  && (propagation_budget < 0 || propagations < (uint64_t)propagation_budget);
1659  }
1660 
1661  // Static helpers:
1662 
1663  /**
1664  * @param seed [Minisat related code]
1665  * @return A random float 0 <= x < 1. Seed must never be 0.
1666  */
1667  static inline double drand( double& seed )
1668  {
1669  seed *= 1389796;
1670  int q = (int)(seed / 2147483647);
1671  seed -= (double)q * 2147483647;
1672  return seed / 2147483647;
1673  }
1674 
1675  /**
1676  * @param seed [Minisat related code]
1677  * @param size [Minisat related code]
1678  * @return A random integer 0 <= x < size. Seed must never be 0.
1679  */
1680  static inline int irand( double& seed, int size )
1681  {
1682  return (int)(drand( seed ) * size);
1683  }
1684 
1685  void updateCNFInfoCounter( typename FormulaCNFInfosMap::iterator _iter, const FormulaT& _origin, bool _increment );
1686 
1687  void addClause_( const Minisat::vec<Minisat::Lit>& _clause, unsigned _type, const FormulaT& _original, typename FormulaCNFInfosMap::iterator _formulaCNFInfoIter )
1688  {
1689  if( addClause( _clause, _type ) && _type == Minisat::NORMAL_CLAUSE )
1690  {
1691  assert( _formulaCNFInfoIter != mFormulaCNFInfosMap.end() );
1692  assert( clauses.size() > 0 );
1693  _formulaCNFInfoIter->second.mClauses.push_back( clauses.last() );
1694  auto cfRet = mClauseInformation.emplace( clauses.last(), ClauseInformation( clauses.size()-1 ) );
1695  assert( cfRet.second );
1696  cfRet.first->second.addOrigin( _original );
1697  }
1698  }
1699 
1700  Minisat::Lit addClauses( const FormulaT& _formula, unsigned _type, unsigned _depth = 0, const FormulaT& _original = FormulaT( carl::FormulaType::TRUE ) );
1701  void addXorClauses( const Minisat::vec<Minisat::Lit>& _literals, const Minisat::vec<Minisat::Lit>& _negLiterals, int _from, bool _numOfNegatedLitsEven, unsigned _type, Minisat::vec<Minisat::Lit>& _clause, const FormulaT& _original, typename FormulaCNFInfosMap::iterator _formulaCNFInfoIter );
1702 
1703  bool supportedConstraintType( const FormulaT& _formula ) const
1704  {
1705  return
1706  _formula.type() == carl::FormulaType::CONSTRAINT ||
1707  _formula.type() == carl::FormulaType::VARCOMPARE ||
1708  _formula.type() == carl::FormulaType::VARASSIGN ||
1709  _formula.type() == carl::FormulaType::UEQ ||
1710  _formula.type() == carl::FormulaType::BITVECTOR;
1711  }
1712 
1713  /**
1714  * Creates or simply returns the literal belonging to the formula being the first argument.
1715  * @param _formula The formula to get the literal for.
1716  * @param _origin The origin of the formula to get the literal for.
1717  * @param _decisionRelevant true, if the variable of the literal needs to be involved in the decision process of the SAT solving.
1718  * @return The corresponding literal.
1719  */
1720  Minisat::Lit createLiteral( const FormulaT& _formula, const FormulaT& _origin = FormulaT( carl::FormulaType::TRUE ), bool _decisionRelevant = true );
1721  Minisat::Lit getLiteral( const FormulaT& _formula ) const;
1722 
1723  /**
1724  * Adapts the passed formula according to the current assignment within the SAT solver.
1725  * @return true, if the passed formula has been changed;
1726  * false, otherwise.
1727  */
1729 
1730  /**
1731  * Adapts the passed formula according to the given abstraction information.
1732  * @param _abstr The information of a Boolean abstraction of a constraint (contains no
1733  * information, if the Boolean does not correspond to a constraint's abstraction).
1734  */
1736 
1737 
1738  /**
1739  * @return true, if the passed formula coincides with the constraints whose abstractions (literals)
1740  * are assigned to true.
1741  */
1742  bool passedFormulaCorrect() const;
1743 
1744  /**
1745  * Updates the model, if the solver has detected the consistency of the received formula, beforehand.
1746  * @param model The model to update with the current assignment
1747  * @param only_relevant_variables If true, only variables in mRelevantVariables are part of the model
1748  */
1749  void updateModel( Model& model, bool only_relevant_variables = false ) const;
1750  };
1751 } // namespace smtrat
Class to create a settings object for the SATModule.
#define l_True
Definition: SolverTypes.h:97
#define l_Undef
Definition: SolverTypes.h:99
#define l_False
Definition: SolverTypes.h:98
#define BITVECTOR(...)
Definition: TheoryTypes.h:24
void reloc(CRef &cr, ClauseAllocator &to)
Definition: SolverTypes.h:289
Clause * lea(Ref r)
Definition: SolverTypes.h:279
float & activity()
Definition: SolverTypes.h:224
uint32_t size() const
Definition: Alloc.h:63
uint32_t wasted() const
Definition: Alloc.h:68
int size(void) const
Definition: Vec.h:118
const T & last(void) const
Definition: Vec.h:178
void push(void)
Definition: Vec.h:147
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
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
ModuleStatistics & mStatistics
Definition: Module.h:192
const Model & model() const
Definition: Module.h:463
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
Implements a module performing DPLL style SAT checking.
Definition: SATModule.h:62
void print(std::ostream &_out=std::cout, const std::string &_init="") const
Prints everything.
bool remove_satisfied
Indicates whether possibly inefficient linear scan for satisfied clauses should be performed in 'simp...
Definition: SATModule.h:501
std::map< Minisat::Var, FormulasT > VarLemmaMap
Maps the minisat variable to the formulas which influence its value.
Definition: SATModule.h:326
Minisat::CRef propagateConsistently(bool _checkWithTheory=true)
Propagate and check the consistency of the constraints, whose abstraction literals have been assigned...
Minisat::vec< Minisat::Lit > analyze_stack
[Minisat related code]
Definition: SATModule.h:509
std::set< std::vector< int > > ClauseSet
A set of vectors of integer representing a set of clauses.
Definition: SATModule.h:332
size_t mNumberOfSatisfiedClauses
Definition: SATModule.h:584
carl::FastMap< FormulaT, std::vector< Minisat::Lit > > ConstraintLiteralsMap
Maps the constraints occurring in the SAT module to their abstractions.
Definition: SATModule.h:308
int level(Minisat::Var x) const
Definition: SATModule.h:1611
bool mFullAssignmentCheckedForConsistency
Definition: SATModule.h:539
bool luby_restart
[Minisat related code]
Definition: SATModule.h:427
void varBumpActivity(Minisat::Var v, double inc)
Increase a variable with the current 'bump' value.
Definition: SATModule.h:1436
static int irand(double &seed, int size)
Definition: SATModule.h:1680
int min_theory_level(Minisat::Var x) const
Definition: SATModule.h:1620
std::vector< signed > mChangedBooleans
Stores all Literals for which the abstraction information might be changed.
Definition: SATModule.h:586
double random_var_freq
[Minisat related code]
Definition: SATModule.h:423
void claDecayActivity()
Decay all clauses with the specified factor.
Definition: SATModule.h:1483
void newDecisionLevel()
Begins a new decision level.
Definition: SATModule.h:1213
Minisat::lbool bool_value(Minisat::Lit p) const
Definition: SATModule.h:1023
Minisat::lbool bool_value(Minisat::Var x) const
Definition: SATModule.h:920
void printConstraintLiteralMap(std::ostream &_out=std::cout, const std::string &_init="") const
Prints the constraints to literal map.
std::vector< Minisat::Lit > mPropagationFreeDecisions
Definition: SATModule.h:626
void addConstraintToInform_(const FormulaT &_formula)
Definition: SATModule.h:735
carl::FastMap< Minisat::CRef, ClauseInformation > mClauseInformation
Definition: SATModule.h:580
int64_t propagation_budget
-1 means no budget.
Definition: SATModule.h:525
void cleanUpAfterOptimizing(const std::vector< Minisat::CRef > &_excludedAssignments)
void setPropBudget(int64_t x)
[Minisat related code]
Definition: SATModule.h:1094
uint64_t tot_literals
Definition: SATModule.h:455
Minisat::vec< Minisat::CRef > clauses
List of problem clauses.
Definition: SATModule.h:461
bool mReceivedFormulaPurelyPropositional
Definition: SATModule.h:558
Minisat::Lit getLiteral(const FormulaT &_formula) const
Minisat::lbool value(Minisat::Var x) const
Definition: SATModule.h:928
void printClauseInformation(std::ostream &_out=std::cout, const std::string &_init="") const
Prints the clause information.
double maxActivity() const
Definition: SATModule.h:1412
uint64_t rnd_decisions
Definition: SATModule.h:453
uint64_t learnts_literals
Definition: SATModule.h:455
Minisat::Var mTrueVar
Variable representing true.
Definition: SATModule.h:531
int trailIndex(Minisat::Var _var) const
Definition: SATModule.h:1631
int simpDB_assigns
Number of top-level assignments since last execution of 'simplify()'.
Definition: SATModule.h:491
void decrementTseitinShadowOccurrences(signed _var)
Definition: SATModule.h:1218
double learntsize_adjust_confl
[Minisat related code]
Definition: SATModule.h:517
void printClause(const Minisat::vec< Minisat::Lit > &, bool _withAssignment=false, std::ostream &_out=std::cout, const std::string &_init="") const
Prints the clause resulting from the given vector of literals.
bool mComputeAllSAT
A flag, which is set to true, if all satisfying assignments should be computed.
Definition: SATModule.h:537
Minisat::Lit createLiteral(const FormulaT &_formula, const FormulaT &_origin=FormulaT(carl::FormulaType::TRUE), bool _decisionRelevant=true)
Creates or simply returns the literal belonging to the formula being the first argument.
uint64_t propagations
Definition: SATModule.h:453
Minisat::vec< std::pair< Abstraction *, Abstraction * > > BooleanConstraintMap
Maps each Minisat variable to a pair of Abstractions, one contains the abstraction information of the...
Definition: SATModule.h:320
void learnTheoryConflicts()
Adds the clauses representing all conflicts generated by all backends.
void insertVarOrder(Minisat::Var x)
Insert a variable in the decision order priority queue.
Definition: SATModule.h:1161
static double drand(double &seed)
Definition: SATModule.h:1667
void cancelAssignmentUntil(int level)
Revert the variables assignment until a given level (keeping all assignments at 'level')
typename Settings::VarScheduler VarScheduler
Definition: SATModule.h:218
double learntsize_inc
The limit for learned clauses is multiplied with this factor each restart.(default 1....
Definition: SATModule.h:445
double clause_decay
[Minisat related code]
Definition: SATModule.h:421
void setPolarity(Minisat::Var v, bool b)
Declare which polarity the decision heuristic should use for a variable.
Definition: SATModule.h:899
int theory_level(Minisat::Var x) const
Definition: SATModule.h:1615
void reduceDB()
reduceDB : () -> [void]
void resetVariableAssignment(Minisat::Var _var)
Minisat::lbool theoryValue(Minisat::Lit p) const
Definition: SATModule.h:1035
carl::Bitset mNonassumedTseitinVariable
Stores whether a given tseitin variable was not yet added to the assumptions, but represents a top-le...
Definition: SATModule.h:608
void printFormulaCNFInfosMap(std::ostream &_out=std::cout, const std::string &_init="") const
Prints the formulas to clauses map.
std::unordered_map< int, std::unordered_set< Minisat::CRef > > mLiteralClausesMap
Definition: SATModule.h:582
int nAssigns() const
Definition: SATModule.h:1042
void decrementLearntSizeAdjustCnt()
[Minisat related code]
void removeUpperBoundOnMinimal()
bool ok
If FALSE, the constraints are already unsatisfiable. No part of the solver state may be used!
Definition: SATModule.h:459
carl::Bitset mAssumedTseitinVariable
Stores whether a given tseitin variable was already added to the assumptions.
Definition: SATModule.h:605
void printLiteralsActiveOccurrences(std::ostream &_out=std::cout, const std::string &_init="") const
Prints the literals' active occurrences in all clauses.
void garbageCollect()
[Minisat related code]
void checkGarbage(double gf)
[Minisat related code]
Definition: SATModule.h:1134
Minisat::vec< VarData > vardata
Stores reason and level for each variable.
Definition: SATModule.h:487
Minisat::Var newVar(bool polarity=true, bool dvar=true, double _activity=0, bool insertIntoHeap=true)
Creates a new SAT variable in the solver.
void rebuildOrderHeap()
[Minisat related code]
bool rnd_pol
Use random polarities for branching heuristics.
Definition: SATModule.h:433
Minisat::vec< char > polarity
The preferred polarity of each variable.
Definition: SATModule.h:479
bool addClauseIfNew(const FormulasT &clause)
Definition: SATModule.h:961
bool withinBudget() const
Definition: SATModule.h:1655
bool okay() const
Definition: SATModule.h:887
std::vector< LiteralClauses > mLiteralsClausesMap
Definition: SATModule.h:622
void adaptPassedFormula(Abstraction &_abstr)
Adapts the passed formula according to the given abstraction information.
std::vector< signed > mChangedActivities
Stores all clauses in which the activities have been changed.
Definition: SATModule.h:590
void adaptConflictEvaluation(size_t &_clauseEvaluation, Minisat::Lit _lit, bool _firstLiteral)
bool analyze(Minisat::CRef confl, Minisat::vec< Minisat::Lit > &out_learnt, int &out_btlevel)
analyze : (confl : Clause*) (out_learnt : vec<Lit>&) (out_btlevel : int&) -> [void]
uint64_t starts
Definition: SATModule.h:453
Minisat::vec< Minisat::lbool > assigns
The current assignments.
Definition: SATModule.h:477
void clearLearnts(int n)
Minisat::lbool value(Minisat::Lit p) const
Definition: SATModule.h:1031
Minisat::vec< char > seen
Each variable is prefixed by the method in which it is used, except 'seen' which is used in several p...
Definition: SATModule.h:507
double progress_estimate
Set by 'search()'.
Definition: SATModule.h:499
Minisat::vec< Minisat::CRef > learnts
List of learned clauses.
Definition: SATModule.h:465
std::map< std::pair< size_t, size_t >, size_t > mCurrentTheoryConflictEvaluations
Definition: SATModule.h:614
bool mAllActivitiesChanged
Is true, if we have to communicate all activities to the backends. (This might be the case after resc...
Definition: SATModule.h:588
void removeLiteralOrigin(Minisat::Lit _litToRemove, const FormulaT &_origin)
double cla_inc
Amount to bump next clause with.
Definition: SATModule.h:469
void updateCNFInfoCounter(typename FormulaCNFInfosMap::iterator _iter, const FormulaT &_origin, bool _increment)
uint64_t solves
[Minisat related code]
Definition: SATModule.h:453
double garbage_frac
The fraction of wasted memory allowed before a garbage collection is triggered.
Definition: SATModule.h:437
void printBooleanConstraintMap(std::ostream &_out=std::cout, const std::string &_init="") const
Prints the literal to constraint map.
void addXorClauses(const Minisat::vec< Minisat::Lit > &_literals, const Minisat::vec< Minisat::Lit > &_negLiterals, int _from, bool _numOfNegatedLitsEven, unsigned _type, Minisat::vec< Minisat::Lit > &_clause, const FormulaT &_original, typename FormulaCNFInfosMap::iterator _formulaCNFInfoIter)
void updateAllModels()
Updates all satisfying models, if the solver has detected the consistency of the received formula,...
mcsat::MCSATMixin< typename Settings::MCSATSettings > mMCSAT
Definition: SATModule.h:637
carl::FastMap< FormulaT, CNFInfos > FormulaCNFInfosMap
Maps the clauses in the received formula to the corresponding Minisat clause.
Definition: SATModule.h:323
void clearInterrupt()
Clear interrupt indicator flag.
Definition: SATModule.h:1118
Minisat::Lit addClauses(const FormulaT &_formula, unsigned _type, unsigned _depth=0, const FormulaT &_original=FormulaT(carl::FormulaType::TRUE))
bool locked(const Minisat::Clause &c)
Definition: SATModule.h:1534
void uncheckedEnqueue(Minisat::Lit p, Minisat::CRef from=Minisat::CRef_Undef)
Enqueue a literal.
Minisat::vec< Minisat::Lit > add_tmp
[Minisat related code]
Definition: SATModule.h:513
Minisat::vec< Minisat::Lit > learnt_clause
For temporary usage.
Definition: SATModule.h:529
Minisat::OccLists< Minisat::Lit, Minisat::vec< Minisat::Watcher >, WatcherDeleted > watches
'watches[lit]' is a list of constraints watching 'lit' (will go there if literal becomes true).
Definition: SATModule.h:475
void updateModel(Model &model, bool only_relevant_variables=false) const
Updates the model, if the solver has detected the consistency of the received formula,...
double random_seed
[Minisat related code]
Definition: SATModule.h:425
double var_inc
Amount to bump next variable with.
Definition: SATModule.h:473
std::unordered_map< int, FormulaT > MinisatVarMap
Maps the Minisat variables to their corresponding boolean variable.
Definition: SATModule.h:314
int64_t conflict_budget
-1 means no budget.
Definition: SATModule.h:523
int verbosity
[Minisat related code]
Definition: SATModule.h:417
double learntsize_adjust_inc
[Minisat related code]
Definition: SATModule.h:449
Settings SettingsType
Definition: SATModule.h:673
std::vector< std::vector< Minisat::Lit > > ClauseVector
A vector of vectors of literals representing a vector of clauses.
Definition: SATModule.h:329
UnorderedClauseLookup mUnorderedClauseLookup
Definition: SATModule.h:670
std::vector< Minisat::vec< Minisat::Lit > > mCurrentTheoryConflicts
Definition: SATModule.h:610
void cancelIncludingLiteral(Minisat::Lit lit)
bool rnd_init_act
Initialize variable activities with a small random value.
Definition: SATModule.h:435
carl::FastMap< int, FormulaT > mTseitinVarFormulaMap
Definition: SATModule.h:601
void updateModel() const
Updates the model, if the solver has detected the consistency of the received formula,...
void handleTheoryConflict(const mcsat::Explanation &explanation)
Definition: SATModule.h:987
void printClause(Minisat::CRef _clause, bool _withAssignment=false, std::ostream &_out=std::cout, const std::string &_init="") const
Prints the clause at the given reference.
void removeClause(Minisat::CRef cr)
Detach and free a clause.
Minisat::ClauseAllocator ca
[Minisat related code]
Definition: SATModule.h:503
void setDecisionVar(Minisat::Var v, bool b, bool insertIntoHeap=true)
Declare if a variable should be eligible for selection in the decision heuristic.
Definition: SATModule.h:909
Minisat::lbool theoryValue(Minisat::Var x) const
Definition: SATModule.h:936
bool asynch_interrupt
[Minisat related code]
Definition: SATModule.h:527
bool addCore(ModuleInput::const_iterator)
The module has to take the given sub-formula of the received formula into account.
int learntsize_adjust_start_confl
[Minisat related code]
Definition: SATModule.h:447
std::map< carl::Variable, std::vector< signed > > mFutureChangedBooleans
Definition: SATModule.h:638
std::vector< int > mRelevantVariables
Stores Minisat indexes of all relevant variables.
Definition: SATModule.h:595
Minisat::lbool checkFormula()
Checks the received formula for consistency.
void varBumpActivity(Minisat::Var v)
Increase a variable with the current 'bump' value.
Definition: SATModule.h:1475
uint64_t decisions
Definition: SATModule.h:453
int nFreeVars() const
Definition: SATModule.h:1074
BooleanVarMap mBooleanVarMap
Maps the Boolean variables to their corresponding Minisat variable.
Definition: SATModule.h:570
Minisat::vec< Minisat::Lit > trail
Assignment stack; stores all assignments made in the order they were made.
Definition: SATModule.h:483
std::unordered_set< int > mLevelCounter
Definition: SATModule.h:616
void computeAdvancedLemmas()
static Minisat::Var mapVar(Minisat::Var x, Minisat::vec< Minisat::Var > &map, Minisat::Var &max)
[Minisat related code]
VarLemmaMap mPropagatedLemmas
Stores for each variable the corresponding formulas which control its value.
Definition: SATModule.h:593
int64_t simpDB_props
Remaining number of propagations that must be made before next execution of 'simplify()'.
Definition: SATModule.h:493
double learntsize_factor
The initial limit for learned clauses is a factor of the original clauses.(default 1 / 3)
Definition: SATModule.h:443
int ccmin_mode
Controls conflict clause minimization (0=none, 1=basic, 2=deep).
Definition: SATModule.h:429
void updateInfeasibleSubset()
Updates the infeasible subset found by the SATModule, if the received formula is unsatisfiable.
bool litRedundant(Minisat::Lit p, uint32_t abstract_levels)
Check if 'p' can be removed.
bool mChangedPassedFormula
A flag, which is set to true, if anything has been changed in the passed formula between now and the ...
Definition: SATModule.h:535
void printCurrentAssignment(std::ostream &=std::cout, const std::string &="") const
Prints the current assignment of the SAT solver.
bool supportedConstraintType(const FormulaT &_formula) const
Definition: SATModule.h:1703
void claBumpActivity(Minisat::Clause &c)
Increase a clause with the current 'bump' value.
Definition: SATModule.h:1492
Minisat::vec< double > activity
A heuristic measurement of the activity of a variable.
Definition: SATModule.h:471
TseitinVarShadows mTseitinVarShadows
Definition: SATModule.h:599
std::vector< std::pair< size_t, size_t > > mLiteralsActivOccurrences
Definition: SATModule.h:624
int level(const Minisat::vec< Minisat::Lit > &) const
void printPropagatedLemmas(std::ostream &_out=std::cout, const std::string &_init="") const
Prints the propagated lemmas for each variables which influence its value.
carl::FastMap< FormulaT, Minisat::Lit > mFormulaAssumptionMap
Definition: SATModule.h:574
carl::Bitset mTseitinVariable
Stores whether a given variable is a tseitin variable.
Definition: SATModule.h:603
static double luby(double y, int x)
Finite subsequences of the Luby-sequence:
int nClauses() const
Definition: SATModule.h:1050
void adaptPassedFormula()
Adapts the passed formula according to the current assignment within the SAT solver.
void cancelUntil(int level, bool force=false)
Revert to the state at given level (keeping all assignments at 'level' but not beyond).
size_t mNumberOfFullLazyCalls
The number of full laze calls made.
Definition: SATModule.h:552
Answer mCurrentAssignmentConsistent
Stores gained information about the current assignment's consistency.
Definition: SATModule.h:550
void simplify()
Removes already satisfied clauses and performs simplifications on all clauses.
void printClauses(const Minisat::vec< Minisat::CRef > &_clauses, const std::string _name, std::ostream &_out=std::cout, const std::string &_init="", int=0, bool _withAssignment=false, bool _onlyNotSatisfied=false) const
Prints all given clauses.
uint64_t conflicts
Definition: SATModule.h:453
uint64_t max_literals
Definition: SATModule.h:455
void collectStats()
Collects the taken statistics.
Minisat::vec< Minisat::CRef > satisfiedClauses
List of problem clauses.
Definition: SATModule.h:463
void interrupt()
Trigger a (potentially asynchronous) interruption of the solver.
Definition: SATModule.h:1110
Minisat::vec< Minisat::CRef > unknown_excludes
List of clauses which exclude a call resulted in unknown.
Definition: SATModule.h:467
int learntsize_adjust_cnt
[Minisat related code]
Definition: SATModule.h:519
void attachClause(Minisat::CRef cr)
Attach a clause to watcher lists.
ModuleInput::iterator mUpperBoundOnMinimal
Definition: SATModule.h:620
void removeTheoryPropagation(int _position)
BooleanConstraintMap mBooleanConstraintMap
Maps each Minisat variable to a pair of Abstractions, one contains the abstraction information of the...
Definition: SATModule.h:563
Minisat::vec< bool > mLemmasRemovable
is the lemma removable
Definition: SATModule.h:630
int qhead
Head of queue (as index into the trail – no more explicit propagation queue in MiniSat).
Definition: SATModule.h:489
~SATModule()
Destructs this SATModule.
double restart_inc
The factor with which the restart limit is multiplied in each restart. (default 1....
Definition: SATModule.h:441
void handleConflict(Minisat::CRef _confl)
Handles conflict.
bool expPositionsCorrect() const
ClauseSet mLearntDeductions
If problem is unsatisfiable (possibly under assumptions), this vector represent the final conflict cl...
Definition: SATModule.h:578
Minisat::Clause & getClause(Minisat::CRef cr)
Definition: SATModule.h:1526
Minisat::CRef propagate()
propagate : [void] -> [Clause*]
void checkAbstractionsConsistency()
Definition: SATModule.h:1196
void removeSatisfied(Minisat::vec< Minisat::CRef > &cs)
Removes all satisfied clauses from the given vector of clauses, which should only be performed in dec...
Minisat::vec< unsigned > mNonTseitinShadowedOccurrences
Definition: SATModule.h:597
ConstraintLiteralsMap mConstraintLiteralMap
Maps the constraints occurring in the SAT module to their abstractions.
Definition: SATModule.h:568
Minisat::vec< int > trail_lim
Separator indices for different decision levels in 'trail'.
Definition: SATModule.h:485
Answer checkCore()
Checks the received formula for consistency.
carl::FastMap< signed, std::vector< signed > > TseitinVarShadows
Definition: SATModule.h:335
void checkGarbage(void)
[Minisat related code]
Definition: SATModule.h:1143
Minisat::vec< Minisat::Lit > analyze_toclear
[Minisat related code]
Definition: SATModule.h:511
double progressEstimate() const
int mCurr_Restarts
The number of restarts made.
Definition: SATModule.h:554
void printDecisions(std::ostream &_out=std::cout, const std::string &_init="") const
Prints the decisions the SAT solver has made.
int decisionLevel() const
Definition: SATModule.h:1582
void relocAll(Minisat::ClauseAllocator &to)
[Minisat related code]
void setConfBudget(int64_t x)
[Minisat related code]
Definition: SATModule.h:1085
SATModule(const ModuleInput *_formula, Conditionals &_foundAnswer, Manager *const _manager=nullptr)
Constructs a SATModule.
uint64_t dec_vars
[Minisat related code]
Definition: SATModule.h:455
Minisat::Lit pickBranchLit()
bool bool_satisfied(const Minisat::Clause &c) const
void printBooleanVarMap(std::ostream &_out=std::cout, const std::string &_init="") const
Prints map of the Boolean within the SAT solver to the given Booleans.
bool processLemmas()
Adds clauses representing the lemmas which should be added to this SATModule.
Minisat::vec< Minisat::Lit > assumptions
Current set of assumptions provided to solve by the user.
Definition: SATModule.h:495
std::vector< unsigned > mCurrentTheoryConflictTypes
Definition: SATModule.h:612
void addConstraintToInform(const FormulaT &)
Adds a constraint to the collection of constraints of this module, which are informed to a freshly ge...
Definition: SATModule.h:734
double max_learnts
[Minisat related code]
Definition: SATModule.h:515
unsigned mNumberOfTheoryCalls
The number of theory calls made.
Definition: SATModule.h:556
Minisat::vec< Minisat::vec< Minisat::Lit > > mLemmas
literals propagated by lemmas
Definition: SATModule.h:628
Minisat::lbool search(int nof_conflicts=100)
search : (nof_conflicts : int) (params : const SearchParams&) -> [lbool]
int restart_first
The initial restart limit. (default 100)
Definition: SATModule.h:439
MinisatVarMap mMinisatVarMap
Maps the Minisat variables to their corresponding boolean variable.
Definition: SATModule.h:572
bool addClause(const Minisat::vec< Minisat::Lit > &_clause, unsigned _type=0)
Adds the clause of the given type with the given literals to the clauses managed by Minisat.
size_t mTheoryConflictIdCounter
Definition: SATModule.h:618
void removeCore(ModuleInput::const_iterator)
Removes everything related to the given sub-formula of the received formula.
uint64_t clauses_literals
Definition: SATModule.h:455
Minisat::CRef reason(Minisat::Var x)
Minisat::CRef storeLemmas()
void budgetOff()
[Minisat related code]
Definition: SATModule.h:1102
bool mExcludedAssignments
Definition: SATModule.h:545
bool enqueue(Minisat::Lit p, Minisat::CRef from=Minisat::CRef_Undef)
Test if fact 'p' contradicts current state, enqueue otherwise.
Definition: SATModule.h:1254
bool passedFormulaCorrect() const
VarScheduler var_scheduler
A priority queue of variables.
Definition: SATModule.h:497
void incrementTseitinShadowOccurrences(signed _var)
Definition: SATModule.h:1229
Minisat::vec< char > decision
Declares if a variable is eligible for selection in the decision heuristic.
Definition: SATModule.h:481
uint32_t abstractLevel(Minisat::Var x) const
Used to represent an abstraction of sets of decision levels.
Definition: SATModule.h:1592
int nVars() const
Definition: SATModule.h:1066
double var_decay
[Minisat related code]
Definition: SATModule.h:419
carl::FastMap< carl::Variable, Minisat::Var > BooleanVarMap
Maps the Boolean variables to their corresponding Minisat variable.
Definition: SATModule.h:311
void detachClause(Minisat::CRef cr, bool strict=false)
Detach a clause to watcher lists.
int phase_saving
Controls the level of phase saving (0=none, 1=limited, 2=full).
Definition: SATModule.h:431
FormulaCNFInfosMap mFormulaCNFInfosMap
Maps the clauses in the received formula to the corresponding Minisat clause and Minisat literal.
Definition: SATModule.h:576
void printSatState(std::ostream &=std::cout, const std::string="")
[Minisat related code]
void varDecayActivity()
Decay all variables with the specified factor.
Definition: SATModule.h:1426
bool satisfied(const Minisat::Clause &c) const
void addBooleanAssignments(RationalAssignment &_rationalAssignment) const
Adds the Boolean assignments to the given assignments, which were determined by the Minisat procedure...
void addClause_(const Minisat::vec< Minisat::Lit > &_clause, unsigned _type, const FormulaT &_original, typename FormulaCNFInfosMap::iterator _formulaCNFInfoIter)
Definition: SATModule.h:1687
int nLearnts() const
Definition: SATModule.h:1058
Base class for variable schedulers.
Definition: VarScheduler.h:15
Base class for all MCSAT variable scheduler.
Minisat::lbool evaluateLiteral(Minisat::Lit lit) const
Evaluate a literal in the theory, set lastReason to last theory decision involved.
int assignedAtTrailIndex(Minisat::Var variable) const
Definition: MCSATMixin.h:581
int decisionLevel(Minisat::Var v) const
Definition: MCSATMixin.h:590
Minisat::Var minisatVar(const carl::Variable &v) const
Definition: MCSATMixin.h:498
Definition: Alg.h:27
const CRef CRef_Undef
Definition: SolverTypes.h:246
void sort(T *array, int size, LessThan lt)
Definition: Sort.h:67
int Var
Definition: SolverTypes.h:42
int var(Lit p)
Definition: SolverTypes.h:64
static bool find(V &ts, const T &t)
Definition: Alg.h:47
RegionAllocator< uint32_t >::Ref CRef
Definition: SolverTypes.h:142
static const unsigned NORMAL_CLAUSE
Definition: SolverTypes.h:145
Lit mkLit(Var var, bool sign=false)
Definition: SolverTypes.h:60
bool sign(Lit p)
Definition: SolverTypes.h:63
const Lit lit_Undef
Definition: SolverTypes.h:72
static const unsigned LEMMA_CLAUSE
Definition: SolverTypes.h:146
std::variant< FormulaT, ClauseChain > Explanation
Definition: smtrat-mcsat.h:14
void validateClause(const T &t, bool enabled)
Definition: ClauseChecker.h:69
Class to create the formulas for axioms.
carl::Formula< Poly > FormulaT
Definition: types.h:37
carl::Assignment< Rational > RationalAssignment
Definition: types.h:45
const settings::Settings & Settings()
Definition: Settings.h:96
carl::Model< Rational, Poly > Model
Definition: model.h:13
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::Formulas< Poly > FormulasT
Definition: types.h:39
#define SMTRAT_LOG_TRACE(channel, msg)
Definition: logging.h:36
#define SMTRAT_LOG_WARN(channel, msg)
Definition: logging.h:33
#define SMTRAT_LOG_DEBUG(channel, msg)
Definition: logging.h:35
[Minisat related code]
Definition: SolverTypes.h:463
Minisat::CRef cref
[Minisat related code]
Definition: SolverTypes.h:465
Stores all information regarding a Boolean abstraction of a constraint.
Definition: SATModule.h:106
std::shared_ptr< std::vector< FormulaT > > origins
Definition: SATModule.h:141
bool isDeduction
A flag, which is set to false, if the constraint corresponding to the abstraction is redundant and he...
Definition: SATModule.h:117
bool consistencyRelevant
A flag, which is set to false, if the constraint corresponding to the abstraction does not occur in t...
Definition: SATModule.h:111
FormulaT reabstraction
The constraint corresponding to this abstraction.
Definition: SATModule.h:138
ModuleInput::iterator position
The position of the corresponding constraint in the passed formula.
Definition: SATModule.h:132
int updateInfo
<0, if the corresponding constraint must still be added to the passed formula; >0,...
Definition: SATModule.h:124
Abstraction(ModuleInput::iterator _position, const FormulaT &_reabstraction)
Constructs abstraction information, for a literal which does actually not belong to an abstraction.
Definition: SATModule.h:148
Abstraction(const Abstraction &)=delete
std::vector< Minisat::CRef > mClauses
Definition: SATModule.h:238
ClauseInformation(const ClauseInformation &)=default
ClauseInformation(ClauseInformation &&)=default
void removeOrigin(const FormulaT &_formula)
Definition: SATModule.h:182
std::vector< FormulaT > mOrigins
Definition: SATModule.h:165
void addOrigin(const FormulaT &_formula)
Definition: SATModule.h:177
void addPositive(Minisat::CRef _cref)
Definition: SATModule.h:364
void reloc(Minisat::ClauseAllocator &_ca, Minisat::ClauseAllocator &_to)
Definition: SATModule.h:394
std::vector< Minisat::CRef > mNegatives
Definition: SATModule.h:342
const std::vector< Minisat::CRef > & negatives() const
Definition: SATModule.h:359
LiteralClauses(LiteralClauses &&_toMove)
Definition: SATModule.h:348
void addNegative(Minisat::CRef _cref)
Definition: SATModule.h:369
void removeNegative(Minisat::CRef _cref)
Definition: SATModule.h:384
void removePositive(Minisat::CRef _cref)
Definition: SATModule.h:374
LiteralClauses(const LiteralClauses &)=delete
const std::vector< Minisat::CRef > & positives() const
Definition: SATModule.h:354
std::vector< Minisat::CRef > mPositives
Definition: SATModule.h:341
std::size_t operator()(const std::vector< Minisat::Lit > &cl) const
Definition: SATModule.h:648
void insert(const std::vector< Minisat::Lit > &cl)
Definition: SATModule.h:663
std::unordered_set< std::vector< Minisat::Lit >, UnorderedClauseHasher > mData
Stores all clauses as sets to quickly check for duplicates.
Definition: SATModule.h:655
void preprocess(std::vector< Minisat::Lit > &cl) const
Definition: SATModule.h:657
bool contains(const std::vector< Minisat::Lit > &cl) const
Definition: SATModule.h:660
Stores information about a Minisat variable.
Definition: SATModule.h:77
Minisat::CRef reason
A reference to the clause, which implied the current assignment of this variable.
Definition: SATModule.h:83
int mTrailIndex
The index in the trail.
Definition: SATModule.h:89
VarData(Minisat::CRef _reason, int _level, int _trailIndex)
Definition: SATModule.h:94
int level
The level in which the variable has been assigned, if it is not unassigned.
Definition: SATModule.h:86
int mExpPos
Position of explanation.
Definition: SATModule.h:92
VarOrderLt(Minisat::vec< double > &activity)
Definition: SATModule.h:229
Minisat::vec< double > & activity
Definition: SATModule.h:222
bool operator()(Minisat::Var x, Minisat::Var y)
Definition: SATModule.h:224
[Minisat related code]
Definition: SATModule.h:202
WatcherDeleted(const Minisat::ClauseAllocator &_ca)
[Minisat related code]
Definition: SATModule.h:207
bool operator()(const Minisat::Watcher &w) const
[Minisat related code]
Definition: SATModule.h:212
const Minisat::ClauseAllocator & ca
[Minisat related code]
Definition: SATModule.h:204
bool operator()(Minisat::Lit x, Minisat::Lit y)
Definition: SATModule.h:263
int levelOf(Minisat::Var v)
Definition: SATModule.h:252
lemma_lt(SATModule &solver)
Definition: SATModule.h:251