SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
ConstraintCategorization.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include <smtrat-common/model.h>
5 
6 #include <carl-common/util/enum_util.h>
7 
8 #include <iostream>
9 
10 namespace smtrat {
11 namespace mcsat {
12 
13 /**
14  * This type categorizes constraints with respect to a given (partial) model and the next variable to be assigned.
15  * Note that `Constant` implies `Assigned`.
16  */
17 enum class ConstraintType {
18  Constant, /// The constraint contains no variables
19  Assigned, /// The constraint is fully assigned
20  Univariate, /// The constraint has a single unassigned variable being the next one.
21  Unassigned /// The constraint has an unassigned variable that is not the next one.
22 };
23 inline std::ostream& operator<<(std::ostream& os, ConstraintType ct) {
24  switch (ct) {
25  case ConstraintType::Constant: return os << "constant";
26  case ConstraintType::Assigned: return os << "assigned";
27  case ConstraintType::Univariate: return os << "univariate";
28  case ConstraintType::Unassigned: return os << "unassigned";
29  default:
30  assert(false && "Invalid enum value for ConstraintType");
31  return os << "ConstraintType(" << carl::underlying_enum_value(ct) << ")";
32  }
33 }
34 
35 namespace constraint_type {
36 
37  template<typename T>
38  ConstraintType categorize(const T& t, const Model& model, carl::Variable next) {
39  assert(model.find(next) == model.end());
40  carl::carlVariables vars;
41  carl::variables(t,vars);
42  if (vars.empty()) return ConstraintType::Constant;
43  bool foundNext = false;
44  for (const auto& var: vars) {
45  if (var == next) {
46  foundNext = true;
47  continue;
48  }
49  if (model.find(var) == model.end()) {
51  }
52  }
53  if (foundNext) return ConstraintType::Univariate;
55  }
56 
57  /**
58  * Checks whether the constraint is constant, i.e. whether it contains no variables.
59  */
60  template<typename T>
61  bool is_constant(const T& t) {
62  // Avoid unnecessary overhead of categorize()
63  carl::carlVariables vars;
64  carl::variables(t,vars);
65  return vars.empty();
66  }
67 
68  /**
69  * Checks whether all variables contained in the constraint are assigned in the model.
70  * In particular, a `Constant` constraint is also `Assigned`.
71  */
72  template<typename T>
73  bool isAssigned(const T& t, const Model& model) {
74  // Avoid unnecessary overhead of categorize()
75  carl::carlVariables vars;
76  carl::variables(t,vars);
77  for (const auto& var: vars) {
78  if (model.find(var) == model.end()) return false;
79  }
80  return true;
81  }
82 
83  /**
84  * Checks whether the constraint contains only a single unassigned variable, and this is the next one.
85  */
86  template<typename T>
87  bool is_univariate(const T& t, const Model& model, carl::Variable next) {
88  return categorize(t, model, next) == ConstraintType::Univariate;
89  }
90 
91  /**
92  * Checks whether the constraint contains an unassigned variable that is not the next one.
93  */
94  template<typename T>
95  bool isUnassigned(const T& t, const Model& model, carl::Variable next) {
96  return categorize(t, model, next) == ConstraintType::Unassigned;
97  }
98 }
99 
100 }
101 }
int var(Lit p)
Definition: SolverTypes.h:64
bool is_univariate(const T &t, const Model &model, carl::Variable next)
Checks whether the constraint contains only a single unassigned variable, and this is the next one.
bool isUnassigned(const T &t, const Model &model, carl::Variable next)
Checks whether the constraint contains an unassigned variable that is not the next one.
bool isAssigned(const T &t, const Model &model)
Checks whether all variables contained in the constraint are assigned in the model.
ConstraintType categorize(const T &t, const Model &model, carl::Variable next)
bool is_constant(const T &t)
Checks whether the constraint is constant, i.e.
std::ostream & operator<<(std::ostream &os, const Bookkeeping &bk)
Definition: Bookkeeping.h:107
ConstraintType
This type categorizes constraints with respect to a given (partial) model and the next variable to be...
@ Unassigned
The constraint has a single unassigned variable being the next one.
@ Univariate
The constraint is fully assigned.
@ Assigned
The constraint contains no variables.
std::vector< carl::Variable > vars(const std::pair< QuantifierType, std::vector< carl::Variable >> &p)
Definition: QEQuery.h:43
Class to create the formulas for axioms.
carl::Model< Rational, Poly > Model
Definition: model.h:13