SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
Bookkeeping.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include <smtrat-common/model.h>
5 
6 #include <vector>
7 
8 namespace smtrat {
9 namespace mcsat {
10 
11 /**
12  * Represent the trail, i.e. the assignment/model state, of a MCSAT run in different
13  * representations (kept in sync) for a fast access.
14  * Most notably, we store literals, i.e. a polynomial (in)equality-atom or its negation,
15  * which we assert to be true. Since the negation can be represented by an atom by
16  * flipping the (in)equality, it suffices to store only atoms. Here we call atomic formulas
17  * over the theory of real arithmetic "constraints".
18  */
19 class Bookkeeping {
20  /** Current (partial) model. */
22  /** Stack of (algebraic) variables being assigned. */
23  std::vector<carl::Variable> mAssignedVariables;
24  /** Stack of theory assignments, i.e. the values for the variables. */
25  std::vector<FormulaT> mAssignments;
26  /** Stack of asserted constraints/literals. */
27  std::vector<FormulaT> mConstraints;
28  /** Stack of asserted multivariate root bounds. */
29  std::vector<FormulaT> mMVBounds;
30  /** Set of theory variables. */
31  carl::Variables mVariables;
32 public:
33 
34  const auto& model() const {
35  return mModel;
36  }
37  const auto& assignedVariables() const {
38  return mAssignedVariables;
39  }
40  const auto& assignments() const {
41  return mAssignments;
42  }
43  const auto& constraints() const {
44  return mConstraints;
45  }
46  const auto& mvBounds() const {
47  return mMVBounds;
48  }
49  const auto& variables() const {
50  return mVariables;
51  }
52 
53  void updateVariables(const carl::Variables& variables) {
55  }
56 
57  /** Assert a constraint/literal */
58  void pushConstraint(const FormulaT& f) {
59  SMTRAT_LOG_TRACE("smtrat.nlsat", "Adding " << f);
60  switch (f.type()) {
61  case carl::FormulaType::CONSTRAINT:
62  mConstraints.emplace_back(f);
63  break;
64  case carl::FormulaType::VARCOMPARE:
65  mMVBounds.emplace_back(f);
66  break;
67  default:
68  SMTRAT_LOG_ERROR("smtrat.nlsat", "Invalid formula type for a constraint: " << f);
69  assert(false);
70  }
71  }
72 
73  void popConstraint(const FormulaT& f) {
74  SMTRAT_LOG_TRACE("smtrat.nlsat", "Removing " << f);
75  switch (f.type()) {
76  case carl::FormulaType::CONSTRAINT:
77  assert(mConstraints.back() == f);
78  mConstraints.pop_back();
79  break;
80  case carl::FormulaType::VARCOMPARE:
81  assert(mMVBounds.back() == f);
82  mMVBounds.pop_back();
83  break;
84  default:
85  SMTRAT_LOG_ERROR("smtrat.nlsat", "Invalid formula type for a constraint: " << f);
86  assert(false);
87  }
88  }
89 
90  void pushAssignment(carl::Variable v, const ModelValue& mv, const FormulaT& f) {
91  SMTRAT_LOG_TRACE("smtrat.nlsat", "Adding " << v << " = " << mv);
92  assert(mModel.find(v) == mModel.end());
93  mModel.emplace(v, mv);
94  mAssignedVariables.emplace_back(v);
95  mAssignments.emplace_back(f);
96  }
97 
98  void popAssignment(carl::Variable v) {
99  SMTRAT_LOG_TRACE("smtrat.nlsat", "Removing " << v << " = " << mModel.evaluated(v));
100  assert(!mAssignedVariables.empty() && mAssignedVariables.back() == v);
101  mModel.erase(v);
102  mAssignedVariables.pop_back();
103  mAssignments.pop_back();
104  }
105 };
106 
107 inline std::ostream& operator<<(std::ostream& os, const Bookkeeping& bk) {
108  os << "MCSAT trail:\n";
109  os << "- Raw model: " << bk.model() << "\n";
110  os << "- Assigned Vars: " << bk.assignedVariables() << "\n";
111  os << "- Theory-assignments: " << bk.assignments() << "\n";
112  os << "- Asserted literals: " << bk.constraints() << "\n";
113  os << "- Bounds: " << bk.mvBounds() << "\n";
114  return os;
115 }
116 
117 }
118 }
Represent the trail, i.e.
Definition: Bookkeeping.h:19
carl::Variables mVariables
Set of theory variables.
Definition: Bookkeeping.h:31
const auto & assignedVariables() const
Definition: Bookkeeping.h:37
void popConstraint(const FormulaT &f)
Definition: Bookkeeping.h:73
void popAssignment(carl::Variable v)
Definition: Bookkeeping.h:98
std::vector< FormulaT > mConstraints
Stack of asserted constraints/literals.
Definition: Bookkeeping.h:27
const auto & constraints() const
Definition: Bookkeeping.h:43
Model mModel
Current (partial) model.
Definition: Bookkeeping.h:21
const auto & variables() const
Definition: Bookkeeping.h:49
const auto & model() const
Definition: Bookkeeping.h:34
const auto & assignments() const
Definition: Bookkeeping.h:40
void pushConstraint(const FormulaT &f)
Assert a constraint/literal.
Definition: Bookkeeping.h:58
const auto & mvBounds() const
Definition: Bookkeeping.h:46
std::vector< FormulaT > mAssignments
Stack of theory assignments, i.e.
Definition: Bookkeeping.h:25
std::vector< FormulaT > mMVBounds
Stack of asserted multivariate root bounds.
Definition: Bookkeeping.h:29
void updateVariables(const carl::Variables &variables)
Definition: Bookkeeping.h:53
void pushAssignment(carl::Variable v, const ModelValue &mv, const FormulaT &f)
Definition: Bookkeeping.h:90
std::vector< carl::Variable > mAssignedVariables
Stack of (algebraic) variables being assigned.
Definition: Bookkeeping.h:23
std::ostream & operator<<(std::ostream &os, const Bookkeeping &bk)
Definition: Bookkeeping.h:107
Class to create the formulas for axioms.
carl::ModelValue< Rational, Poly > ModelValue
Definition: model.h:12
carl::Formula< Poly > FormulaT
Definition: types.h:37
carl::Model< Rational, Poly > Model
Definition: model.h:13
#define SMTRAT_LOG_TRACE(channel, msg)
Definition: logging.h:36
#define SMTRAT_LOG_ERROR(channel, msg)
Definition: logging.h:32