9 #include <carl-formula/formula/functions/Negations.h>
10 #include <carl-arith/ran/Conversion.h>
11 #include <carl-arith/poly/Conversion.h>
12 #include <carl-arith/constraint/Conversion.h>
13 #include <carl-arith/extended/Conversion.h>
15 #include "../../utils/RootExpr.h"
88 template<
typename Settings = DefaultSettings>
90 #ifdef SMTRAT_DEVOPTION_Statistics
91 OCStatistics& mStatistics = statistics_get<OCStatistics>(
"mcsat-explanation-onecell");
95 #ifdef SMTRAT_DEVOPTION_Statistics
96 mStatistics.explanationCalled();
102 cadcells::Polynomial::ContextType context(
vars);
105 for (
const auto& [key, value] : trail.
model()) {
107 ass.emplace(key.asVariable(), carl::convert<cadcells::RAN>(value.asRAN()));
109 assert(value.isRational());
110 ass.emplace(key.asVariable(),
cadcells::RAN(value.asRational()));
117 carl::carlVariables reason_vars;
118 for (
const auto& r : reason) carl::variables(r,reason_vars);
119 for (
const auto v : reason_vars) {
120 if (ass.find(v) == ass.end() && v !=
var) {
121 SMTRAT_LOG_DEBUG(
"smtrat.mcsat.onecell",
"Conflict reasons are of higher level than the current one.");
126 std::vector<cadcells::Atom> constr;
127 for (
const auto& r : reason) {
128 if (r.type() == carl::FormulaType::CONSTRAINT) {
129 constr.emplace_back(carl::convert<cadcells::Polynomial>(context, r.constraint().constr()));
130 }
else if (r.type() == carl::FormulaType::VARCOMPARE) {
131 constr.emplace_back(carl::convert<cadcells::Polynomial>(context, r.variable_comparison()));
134 SMTRAT_LOG_DEBUG(
"smtrat.mcsat.onecell",
"Explain conflict " << constr <<
" with " <<
vars <<
" and " << ass);
135 #ifdef SMTRAT_DEVOPTION_Statistics
138 auto result = onecell<Settings>(constr, context, ass);
139 #ifdef SMTRAT_DEVOPTION_Statistics
148 #ifdef SMTRAT_DEVOPTION_Statistics
149 mStatistics.explanationSuccess();
151 SMTRAT_LOG_DEBUG(
"smtrat.mcsat.onecell",
"Got unsat cell " <<
result <<
" of constraints " << constr <<
" wrt " <<
vars <<
" and " << ass);
153 for (
const auto& f : reason) {
154 expl.push_back(f.negated());
156 bool is_clause =
true;
157 for (
const auto& disjunction : *
result) {
158 std::vector<FormulaT> tmp;
159 for (
const auto& f : disjunction) {
160 if (std::holds_alternative<cadcells::Constraint>(f)) {
161 tmp.push_back(
FormulaT(
ConstraintT(carl::convert<Poly>(std::get<cadcells::Constraint>(f)))).negated());
162 }
else if (std::holds_alternative<cadcells::VariableComparison>(f)) {
163 auto transf =
constr_from_vc(std::get<cadcells::VariableComparison>(f), ass, Settings::enforce_tarski);
164 if (transf.empty()) {
165 tmp.push_back(
FormulaT(carl::convert<Poly>(std::get<cadcells::VariableComparison>(f))).negated());
167 std::vector<FormulaT> tmp2;
168 for (
const auto& c : transf) {
177 if (tmp.size() > 1) is_clause =
false;
Represent the trail, i.e.
const auto & assignedVariables() const
const auto & model() const
static ClauseChain from_formula(const FormulaT &f, const Model &model, bool with_equivalence)
Transforms a given Boolean conjunction over AND and OR to CNF via Tseitin-Transformation so that,...
@ LOWEST_DEGREE_BARRIERS_CACHE_GLOBAL
@ LDB_COVERING_CACHE_GLOBAL
std::vector< carl::Variable > VariableOrdering
carl::Assignment< RAN > Assignment
std::vector< carl::BasicConstraint< P > > constr_from_vc(const carl::VariableComparison< P > &vc, const carl::Assignment< typename P::RootType > assignment, bool tarski=false)
std::variant< FormulaT, ClauseChain > Explanation
std::vector< carl::Variable > vars(const std::pair< QuantifierType, std::vector< carl::Variable >> &p)
carl::Formula< Poly > FormulaT
carl::Constraint< Poly > ConstraintT
carl::Formulas< Poly > FormulasT
#define SMTRAT_LOG_DEBUG(channel, msg)
#define SMTRAT_STATISTICS_CALL(function)
#define SMTRAT_TIME_START(variable)
#define SMTRAT_TIME_FINISH(timer, start)
constexpr static bool exploit_strict_constraints
constexpr static bool use_approximation
static constexpr bool clause_chain_with_equivalences
static constexpr bool enforce_tarski
constexpr static auto covering_heuristic
constexpr static bool exploit_strict_constraints
constexpr static auto cell_heuristic
std::optional< mcsat::Explanation > operator()(const mcsat::Bookkeeping &trail, carl::Variable var, const FormulasT &reason, bool) const