6 template<
typename Solver>
13 for (
const auto& f : mSolver.formula()) fs.push_back(f.formula());
16 for (
const auto& f : fs) tmpSolver.add(f);
22 for (
auto it = mSolver.formulaBegin(); it != mSolver.formulaEnd(); ++it) {
23 if (it->formula() == formula) {
27 assert(
false &&
"Formula was not added correctly to backend. Expected to find formula.");
28 return mSolver.formulaEnd();
32 MaxSMTBackend(Solver& solver,
const std::vector<FormulaT>& softClauses) : mSolver(solver), softClauses(softClauses) {}
35 std::map<FormulaT, carl::Variable> blockingVars;
36 std::map<FormulaT, ModuleInput::iterator> formulaPositionMap;
39 std::map<carl::Variable, FormulaT> assignments;
40 std::map<FormulaT, FormulaT> extendedClauses;
42 std::vector<FormulaT> newSoftClauses;
47 for (
const FormulaT& clause : softClauses) {
48 carl::Variable blockingVar = carl::fresh_boolean_variable();
51 blockingVars[clause] = blockingVar;
55 extendedClauses[clauseWithBlockingVar] = clause;
56 mSolver.add(clauseWithBlockingVar);
58 newSoftClauses.push_back(clauseWithBlockingVar);
61 assignments[blockingVar] = !
FormulaT(blockingVar);
62 formulaPositionMap[assignments[blockingVar]] = addToSolver(assignments[blockingVar]);
67 std::vector<carl::Variable> relaxationVars;
69 Answer ans = mSolver.check();
70 SMTRAT_LOG_DEBUG(
"smtrat.maxsmt.fumalik",
"Checked satisfiability of current soft/hardclause mixture got... " << ans);
73 auto core = computeUnsatCore();
78 for (
auto it : core.second) {
80 if (
std::find(softClauses.begin(), softClauses.end(), it) == softClauses.end() &&
81 std::find(newSoftClauses.begin(), newSoftClauses.end(), it) == newSoftClauses.end() )
continue;
83 relaxationVars.push_back(carl::fresh_boolean_variable());
84 carl::Variable blockingRelaxationVar = carl::fresh_boolean_variable();
87 assert(extendedClauses.find(it) != extendedClauses.end());
89 newSoftClauses.push_back(replacementClause);
91 extendedClauses[replacementClause] = it;
92 blockingVars[replacementClause] = blockingRelaxationVar;
93 assignments[blockingRelaxationVar] = !
FormulaT(blockingRelaxationVar);
95 SMTRAT_LOG_DEBUG(
"smtrat.maxsat.fumalik",
"adding clause to backend: " << replacementClause);
96 mSolver.add(replacementClause);
97 formulaPositionMap[assignments[blockingRelaxationVar]] = addToSolver(assignments[blockingRelaxationVar]);
100 carl::Variable prevBlockingVar = blockingVars[extendedClauses[it]];
101 const auto& prevAssignment = assignments.find(prevBlockingVar);
102 assert(prevAssignment != assignments.end() &&
"Could not find an assignment which we must have made before.");
104 mSolver.remove(formulaPositionMap[prevAssignment->second]);
105 assignments.erase(prevAssignment);
108 mSolver.add(
FormulaT(prevBlockingVar));
113 for (carl::Variable&
var : relaxationVars) {
114 relaxationPoly = relaxationPoly +
var;
119 mSolver.add(pbEncoding);
121 SMTRAT_LOG_DEBUG(
"smtrat.maxsmt.fumalik",
"Adding cardinality constraint to solver: " << pbEncoding);
std::pair< Answer, FormulasT > compute_core(const FormulasT &formulas)
const std::vector< FormulaT > & softClauses
MaxSMTBackend(Solver &solver, const std::vector< FormulaT > &softClauses)
ModuleInput::iterator addToSolver(const FormulaT &formula)
static bool find(V &ts, const T &t)
Class to create the formulas for axioms.
carl::Formula< Poly > FormulaT
carl::MultivariatePolynomial< Rational > Poly
Answer
An enum with the possible answers a Module can give.
carl::Constraint< Poly > ConstraintT
carl::Formulas< Poly > FormulasT
#define SMTRAT_LOG_DEBUG(channel, msg)