SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
PseudoBoolEncoder.cpp
Go to the documentation of this file.
1 #include "PseudoBoolEncoder.h"
2 
3 namespace smtrat {
4 
5  std::optional<FormulaT> PseudoBoolEncoder::encode(const ConstraintT& constraint) {
6  assert(constraint.isPseudoBoolean());
7  assert(constraint.relation() != carl::Relation::GEQ);
8  assert(constraint.relation() != carl::Relation::GREATER);
9  // since we are implicitly in an integer context, we can normalize the constraints
10  assert(constraint.relation() != carl::Relation::NEQ);
11  // However, we can still have LEQ, EQUAL
12 
13  // normalize constraint first if there is a LESS relation given
14  // We can do this since x \in {0, 1}.
15  if (constraint.relation() == carl::Relation::LESS) {
16  return doEncode(normalizeLessConstraint(constraint));
17  }
18 
19  assert(constraint.relation() != carl::Relation::LESS);
20  assert(this->canEncode(constraint));
21 
22  return doEncode(constraint);
23  }
24 
26  assert(constraint.relation() == carl::Relation::LESS);
27 
28  // e.g. -x1 -x2 - 2 < 0 iff x1 + x2 < 2 iff x1 + x2 <= 1
29  // This means we need to add(!!) 1 to lhs
30  return ConstraintT(constraint.lhs() + Rational(1), carl::Relation::LEQ);
31  }
32 
34  return Rational(std::numeric_limits<unsigned long>::max());
35  }
36 
37 
38  FormulaT PseudoBoolEncoder::generateVarChain(const std::set<carl::Variable>& vars, carl::FormulaType type) {
39  FormulasT newSubformulas;
40  for(const auto& var: vars){
41  FormulaT newFormula = FormulaT(var);
42  newSubformulas.push_back(newFormula);
43  }
44 
45  return FormulaT(type, std::move(newSubformulas));
46  }
47 }
virtual Rational encodingSize(const ConstraintT &constraint)
std::optional< FormulaT > encode(const ConstraintT &constraint)
Encodes an arbitrary constraint.
FormulaT generateVarChain(const std::set< carl::Variable > &vars, carl::FormulaType type)
virtual std::optional< FormulaT > doEncode(const ConstraintT &constraint)=0
virtual bool canEncode(const ConstraintT &constraint)=0
ConstraintT normalizeLessConstraint(const ConstraintT &constraint)
int var(Lit p)
Definition: SolverTypes.h:64
QuantifierType type(const std::pair< QuantifierType, std::vector< carl::Variable >> &p)
Definition: QEQuery.h:39
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::Formula< Poly > FormulaT
Definition: types.h:37
carl::Constraint< Poly > ConstraintT
Definition: types.h:29
carl::Formulas< Poly > FormulasT
Definition: types.h:39
mpq_class Rational
Definition: types.h:19