6 #include <carl-common/config.h>
10 namespace onecellcad {
18 template<
class Setting1,
class Setting2>
21 const FormulasT& trailLiterals,
bool)
const {
25 #ifdef SMTRAT_DEVOPTION_Statistics
26 getStatistic().explanationCalled();
29 #if not (defined USE_COCOA || defined USE_GINAC)
31 #warning OneCellCAD may be incorrect as USE_COCOA is disabled
36 varOrder.push_back(
var);
38 if (
std::find(varOrder.begin(), varOrder.end(), v) == varOrder.end()) {
39 varOrder.push_back(v);
46 SMTRAT_LOG_DEBUG(
"smtrat.mcsat.nlsat",
" OneCellExplanation called with 0 theory-assignment");
48 for (
const auto& trailLiteral : trailLiterals)
49 explainLiterals.emplace_back(trailLiteral.negated());
58 SMTRAT_LOG_DEBUG(
"smtrat.mcsat.nlsat",
"Ascending variable order: " << varOrder
59 <<
" and eliminate down from: " <<
var);
62 std::vector<carl::Variable> fullProjectionVarOrder = varOrder;
63 std::vector<carl::Variable> oneCellCADVarOrder;
64 for (std::size_t i = 0; i < trailVariables.size(); i++)
65 oneCellCADVarOrder.emplace_back(fullProjectionVarOrder[i]);
67 SMTRAT_LOG_DEBUG(
"smtrat.mcsat.nlsat",
"Ascending OneCellVarOrder: " << oneCellCADVarOrder);
69 std::size_t oneCellMaxLvl = trail.
model().size() - 1;
70 std::vector<std::vector<TagPoly>> projectionLevels(fullProjectionVarOrder.size());
72 std::vector<Poly> polys;
74 polys.emplace_back(constraint.lhs());
77 for(
const auto& poly : polys){
83 auto maxLevel = fullProjectionVarOrder.size() - 1;
84 while (projectionLevels[maxLevel].empty() && maxLevel > 0) {
85 projectionLevels.erase(projectionLevels.begin() + maxLevel);
88 assert(maxLevel > 0 || !projectionLevels[0].empty());
90 SMTRAT_LOG_DEBUG(
"smtrat.mcsat.nlsat",
"Polys at levels before full CAD projection:\n"
94 for (std::size_t currentLvl = maxLevel; currentLvl > oneCellMaxLvl; currentLvl--) {
95 auto currentVar = fullProjectionVarOrder[currentLvl];
96 assert(currentLvl >= 1);
98 if(currentLvl == oneCellMaxLvl+1){
108 projectionLevels.erase(projectionLevels.begin() + currentLvl);
109 SMTRAT_LOG_DEBUG(
"smtrat.mcsat.nlsat",
"Polys at levels after a CAD projection at level: " << currentLvl <<
":\n" << projectionLevels);
112 if(Setting2::heuristic == 1){
114 for (
int i = (
int)projectionLevels.size()-1; i >= 0; i--){
115 for(
auto & tpoly : projectionLevels[i]){
116 tpoly.deg =
getDegree(tpoly, fullProjectionVarOrder[i]);
119 std::sort(projectionLevels[i].begin(), projectionLevels[i].end(), [](
auto const &t1,
auto const &t2) {
120 return t1.deg < t2.deg;
123 }
else if(Setting2::heuristic == 2){
125 for (
int i = (
int)projectionLevels.size()-1; i >= 0; i--){
126 for(
auto & tpoly : projectionLevels[i]){
127 tpoly.deg =
getDegree(tpoly, fullProjectionVarOrder[i]);
130 std::sort(projectionLevels[i].begin(), projectionLevels[i].end(), [](
auto const &t1,
auto const &t2) {
131 return t1.deg > t2.deg;
134 }
else if(Setting2::heuristic != 0){
137 SMTRAT_LOG_DEBUG(
"smtrat.mcsat.nlsat",
"Polys after possible reordering: \n" << projectionLevels);
146 auto cell = *cellOpt;
157 for (
const auto& trailLiteral : trailLiterals)
158 explainLiterals.emplace_back(trailLiteral.negated());
160 for (std::size_t i = 0; i < cell.size(); i++) {
161 auto& cellComponent = cell[i];
162 auto cellVariable = oneCellCADVarOrder[i];
163 if (std::holds_alternative<Section>(cellComponent)) {
164 auto section = std::get<Section>(cellComponent).boundFunction;
165 auto param = std::make_pair(section.poly(), section.k());
168 auto sectorLowBound = std::get<Sector>(cellComponent).lowBound;
169 if (sectorLowBound) {
170 auto param = std::make_pair(sectorLowBound->boundFunction.poly(), sectorLowBound->boundFunction.k());
173 auto sectorHighBound = std::get<Sector>(cellComponent).highBound;
174 if (sectorHighBound) {
175 auto param = std::make_pair(sectorHighBound->boundFunction.poly(), sectorHighBound->boundFunction.k());
184 SMTRAT_LOG_DEBUG(
"smtrat.mcsat.nlsat",
"Explain literals: " << explainLiterals);
185 #ifdef SMTRAT_DEVOPTION_Statistics
186 getStatistic().explanationSuccess();
Represent the trail, i.e.
const auto & assignedVariables() const
const auto & variables() const
const auto & model() const
std::optional< CADCell > pointEnclosingCADCell(const std::vector< std::vector< onecellcad::TagPoly >> &polys)
Construct a single CADCell that contains the given 'point' and is sign-invariant for the given polyno...
void sort(T *array, int size, LessThan lt)
static bool find(V &ts, const T &t)
FormulaT buildEquality(carl::Variable var, const MVRootParams &mvp)
Construct an atomic formula representing a variable being equal to the given multivariate root.
std::set< ConstraintT > convertToConstraints(std::vector< FormulaT > constraintAtoms)
Transform constraints represented as atomic formualas into the easier to use objects of the Constrain...
FormulaT buildBelow(carl::Variable var, const MVRootParams &mvp)
Construct an atomic formula representing a variable being less than the given multivariate root.
FormulaT buildAbove(carl::Variable var, const MVRootParams &mvp)
Construct an atomic formula representing a variable being greater than the given multivariate root.
void setNullification(bool n)
void appendOnCorrectLevel(const Poly &poly, InvarianceType tag, std::vector< std::vector< TagPoly >> &polys, std::vector< carl::Variable > variableOrder)
std::size_t getDegree(TagPoly p, carl::Variable v)
RealAlgebraicPoint< smtrat::Rational > asRANPoint(const mcsat::Bookkeeping &data)
void singleLevelFullProjection(std::vector< carl::Variable > &variableOrder, carl::Variable mainVar, size_t currentLevel, std::vector< std::vector< TagPoly >> &projectionLevels)
bool optimized_singleLevelFullProjection(carl::Variable mainVar, size_t currentLevel, std::vector< std::vector< TagPoly >> &projectionLevels, OneCellCAD &cad)
Class to create the formulas for axioms.
carl::Formula< Poly > FormulaT
carl::Formulas< Poly > FormulasT
Construct a single open CAD Cell around a given point that is sign-invariant on a given set of polyno...
#define SMTRAT_LOG_WARN(channel, msg)
#define SMTRAT_LOG_DEBUG(channel, msg)
std::optional< mcsat::Explanation > operator()(const mcsat::Bookkeeping &trail, carl::Variable var, const FormulasT &trailLiterals, bool) const