5 assert(
canEncode(constraint) &&
"Input must be <=-cardinality constraint.");
7 auto treeIt =
mTreeCache.find(constraint.variables().as_set());
10 mTreeCache.insert(std::map<carl::Variables, TotalizerTree*>::value_type(constraint.variables().as_set(), tree));
27 std::vector<carl::Variable> leftVars = tree.
left().
variables();
30 SMTRAT_LOG_TRACE(
"smtrat.pbpp.total",
"Having rootVars = " << tree.
variables() <<
", leftVars = " << leftVars <<
", rightVars = " << rightVars);
33 for (
size_t alpha = 0; alpha <= leftVars.size(); alpha++) {
34 for (
size_t beta = 0; beta <= rightVars.size(); beta++) {
35 size_t sigma = alpha + beta;
41 leftNode = !
FormulaT(leftVars[alpha - 1]);
45 rightNode = !
FormulaT(rightVars[beta - 1]);
49 rootNode =
FormulaT(carl::FormulaType::TRUE);
55 SMTRAT_LOG_TRACE(
"smtrat.pbpp.total",
"Adding for alpha =" << alpha <<
", beta = " << beta <<
", sigma = " << sigma <<
": " << nodeSum);
56 encoding.push_back(nodeSum);
73 for (
size_t i =
vars.size() - 1; i >= 0; i--) {
74 if (
Rational(i) < constantPart)
break;
75 SMTRAT_LOG_TRACE(
"smtrat.pbpp.total",
"Forcing variable " <<
vars[i] <<
" at index " << i <<
" to false");
81 SMTRAT_LOG_TRACE(
"smtrat.pbpp.total",
"Those literals are added to assure cardinality: " << encoding);
86 bool encodable =
true;
87 bool allCoeffPositive =
true;
88 bool allCoeffNegative =
true;
90 for (
const auto& it : constraint.lhs()) {
91 if (it.is_constant())
continue;
93 encodable = encodable && (it.coeff() == 1 || it.coeff() == -1);
94 if (it.coeff() < 0) allCoeffPositive =
false;
95 if (it.coeff() > 0) allCoeffNegative =
false;
98 encodable = encodable && allCoeffNegative != allCoeffPositive;
99 encodable = encodable && constraint.relation() == carl::Relation::LEQ;
105 std::size_t nVars = constraint.variables().size();
119 for (
size_t i = 0; i <
variables.size(); i++) {
126 std::set<carl::Variable> leftVariables;
127 std::set<carl::Variable> rightVariables;
131 auto separator = std::partition(varVector.begin(), varVector.end(), [&](
const carl::Variable&){
136 for (
auto it = varVector.begin(); it != separator; it++) {
137 rightVariables.insert(*it);
140 for (
auto it = separator; it != varVector.end(); it++) {
141 leftVariables.insert(*it);
144 assert(leftVariables.size() != 0);
145 assert(rightVariables.size() != 0);
148 SMTRAT_LOG_TRACE(
"smtrat.pbpp.total",
"Adding child left " << leftVariables);
149 SMTRAT_LOG_TRACE(
"smtrat.pbpp.total",
"Adding child right " << rightVariables);
std::optional< FormulaT > doEncode(const ConstraintT &constraint)
Rational encodingSize(const ConstraintT &constraint)
FormulaT encodeCardinalityRestriction(TotalizerTree &tree, Rational constantPart)
std::map< carl::Variables, FormulaT > mSumPropagationFormulaCache
FormulaT encodeSumPropagation(TotalizerTree &tree)
std::map< carl::Variables, TotalizerTree * > mTreeCache
bool canEncode(const ConstraintT &constraint)
std::vector< carl::Variable > mNodeVariables
std::vector< carl::Variable > variables()
TotalizerTree(const std::set< carl::Variable > &variables)
Numeric abs(const Numeric &_value)
Calculates the absolute value of the given Numeric.
std::vector< carl::Variable > vars(const std::pair< QuantifierType, std::vector< carl::Variable >> &p)
Class to create the formulas for axioms.
carl::Formula< Poly > FormulaT
carl::Constraint< Poly > ConstraintT
carl::Formulas< Poly > FormulasT
#define SMTRAT_LOG_TRACE(channel, msg)