1 #include "../VarScheduler.h"
22 template<
typename BaseModule>
27 minisatVar([&baseModule](carl::Variable v){
return baseModule.mMCSAT.minisatVar(v); }),
28 currentModel([&baseModule](){
return baseModule.mMCSAT.model(); })
38 template<mcsat::VariableOrdering vot>
46 template<
typename BaseModule>
86 std::cout <<
"Theory variable ordering: " <<
ordering << std::endl;
89 template<
typename Constra
ints>
93 std::vector<carl::Variable> tordering = mcsat::calculate_variable_order<vot>(c);
94 assert(tordering.size() ==
ordering.size());
96 for (
const auto& tvar : tordering) {
119 auto vars = carl::arithmetic_variables(reabstraction);
122 for (std::size_t i =
ordering.size(); i > 0; i--) {
136 template<mcsat::VariableOrdering vot>
142 template<
typename BaseModule>
219 template<
typename Constra
ints>
230 template<
typename TheoryScheduler>
237 template<
typename BaseModule>
318 template<
typename Constra
ints>
328 template<
int lookahead, mcsat::VariableOrdering vot>
340 static_assert(lookahead >= 1);
345 template<
typename BaseModule>
349 theory_ordering( baseModule )
357 if (isTheoryVar(
var)) {
380 if (!boolean_ordering.
empty()) {
381 if (varDecidable(boolean_ordering.
top())) {
383 return boolean_ordering.
pop();
385 SMTRAT_LOG_DEBUG(
"smtrat.sat.mcsat.scheduler",
"Decision of next Boolean variable is deferred");
386 assert(!theory_ordering.
empty());
389 if (!theory_ordering.
empty()) {
391 return theory_ordering.
pop();
398 return boolean_ordering.
empty() && theory_ordering.
empty();
412 boolean_ordering.
print();
413 theory_ordering.
print();
430 template<
typename Constra
ints>
442 template<
typename TheoryScheduler,
bool respectActivities>
446 const auto& x = mTheoryLevels.back().variable;
448 for (
int i = 0; i < getClause(cl).size(); i++) {
449 const auto& l = getClause(cl)[i];
451 const auto& reabstraction = reabstractLiteral(l);
455 auto vars = carl::arithmetic_variables(substituted);
457 auto size =
vars.size();
458 for (
auto iter = mTheoryLevels.begin(); iter != std::prev(mTheoryLevels.end()); iter++) {
459 if (
vars.has(iter->variable)){
466 if (size > 1 || !
vars.has(x)) {
477 for (
int i = 0; i < getClause(cl).size(); i++) {
478 const auto& l = getClause(cl)[i];
480 const auto& eval =
carl::evaluate(reabstractLiteral(l), currentModel());
481 if (!eval.isBool()) {
493 for (
int i = 0; i < getClause(cl).size(); i++) {
494 auto lit = getClause(cl)[i];
495 if (getBoolLitValue(lit) ==
l_Undef) {
496 if (!respectActivities) {
519 assert(mTheoryLevels.back().variable != carl::Variable::NO_VARIABLE);
521 for (
const auto& cl : mTheoryLevels.back().clauses) {
522 auto lit = undefLitIn(cl);
524 if (!respectActivities) {
537 assert(mTheoryLevels.back().variable == carl::Variable::NO_VARIABLE);
539 for (
const auto& cl : mUndecidedClauses) {
540 auto lit = undefLitIn(cl);
542 if (!respectActivities) {
556 assert(mTheoryLevels.back().variable != carl::Variable::NO_VARIABLE);
557 carl::Variable& v = mTheoryLevels.back().variable;
558 mTheoryLevels.emplace_back();
564 assert(mTheoryLevels.back().variable == carl::Variable::NO_VARIABLE);
565 for (
auto cl = mUndecidedClauses.begin(); cl != mUndecidedClauses.end();) {
566 if (decidedByTheory(*cl)) {
567 mTheoryLevels[mTheoryLevels.size()-2].clauses.push_back(*cl);
568 cl = mUndecidedClauses.erase(cl);
573 auto lit = theory_ordering.pop();
577 mTheoryLevels.back().variable = carlVar(
Minisat::var(lit));
578 for (
auto cl = mUndecidedClauses.begin(); cl != mUndecidedClauses.end();) {
579 if (univariate(*cl)) {
580 mTheoryLevels.back().clauses.push_back(*cl);
581 cl = mUndecidedClauses.erase(cl);
590 assert(mTheoryLevels.size() > 1);
592 if (mTheoryLevels.back().variable != carl::Variable::NO_VARIABLE) {
593 auto v = mTheoryLevels.back().variable;
594 theory_ordering.insert(minisatVar(v));
597 mUndecidedClauses.insert(mUndecidedClauses.end(), mTheoryLevels.back().clauses.begin(), mTheoryLevels.back().clauses.end());
598 mTheoryLevels.pop_back();
600 assert(mTheoryLevels.back().variable != carl::Variable::NO_VARIABLE);
608 if (univariate(cl)) {
609 mTheoryLevels.back().clauses.push_back(cl);
611 assert(!decidedByTheory(cl));
612 mUndecidedClauses.push_back(cl);
617 mUndecidedClauses.erase(
std::remove(mUndecidedClauses.begin(), mUndecidedClauses.end(), cl), mUndecidedClauses.end());
618 for (
auto& level : mTheoryLevels) {
619 level.clauses.erase(
std::remove(level.clauses.begin(), level.clauses.end(), cl), level.clauses.end());
624 for (
auto& level : mTheoryLevels) {
625 for (
auto& clause : level.clauses) {
629 for (
auto& clause : mUndecidedClauses) {
636 template<
typename BaseModule>
639 theory_ordering( baseModule )
641 mTheoryLevels.emplace_back();
645 theory_ordering.rebuild();
649 if (isTheoryVar(
var)) {
650 if (mTheoryLevels.back().variable != carl::Variable::NO_VARIABLE || mTheoryLevels.size() > 1) {
652 assert(mTheoryLevels.back().variable == carlVar(
var));
654 theory_ordering.insert(
var);
662 if (mTheoryLevels.back().variable == carl::Variable::NO_VARIABLE) {
663 if (!pickNextTheoryVar()) {
665 return pickBooleanVarFromUndecided();
668 auto res = pickBooleanVarFromCurrentLevel();
672 auto x = theoryDecision();
678 return theory_ordering.empty() && pickBooleanVarFromCurrentLevel() ==
Minisat::lit_Undef;
682 theory_ordering.print();
683 for (
const auto& level: mTheoryLevels) {
684 std::cout <<
"Clauses in " << level.variable <<
": " << level.clauses << std::endl;
686 std::cout <<
"Undecided clauses: " << mUndecidedClauses << std::endl;
692 theory_ordering.increaseActivity(
var);
696 theory_ordering.decreaseActivity(
var);
700 theory_ordering.rebuild();
703 template<
typename Constra
ints>
705 assert(mTheoryLevels.size() == 1 && mTheoryLevels.back().variable == carl::Variable::NO_VARIABLE);
706 theory_ordering.rebuildTheoryVars(c);
715 template<mcsat::VariableOrdering vot>
717 bool initialized =
false;
722 if (getActivity(x) != getActivity(y)) {
723 return getActivity(x) > getActivity(y);
724 }
else if (isTheoryVar(x) && !isTheoryVar(y)) {
726 }
else if (!isTheoryVar(x) && isTheoryVar(y)) {
728 }
else if (isTheoryVar(x) && isTheoryVar(y)) {
729 auto ypos =
std::find(theory_ordering.begin(), theory_ordering.end(), y);
730 assert(!initialized || ypos != theory_ordering.end());
731 return std::find(theory_ordering.begin(), ypos, x) != theory_ordering.end();
739 template<
typename BaseModule>
742 ordering( baseModule, [this](
Minisat::
Var x,
Minisat::
Var y) -> bool { return compareVars(x, y); } )
760 return ordering.
pop();
764 return ordering.
empty();
791 template<
typename Constra
ints>
793 assert(!initialized);
794 std::vector<carl::Variable> tordering = mcsat::calculate_variable_order<vot>(c);
795 theory_ordering.clear();
796 for (
const auto& tvar : tordering) {
797 theory_ordering.push_back(minisatVar(tvar));
Schedules theory variables statically.
TheoryVarSchedulerStatic(BaseModule &baseModule)
void rebuildTheoryVars(const Constraints &c)
std::vector< Minisat::Var > ordering
size_t level()
Level of the next theory variable.
size_t univariateLevel(Minisat::Var v)
Returns the level in which the given constraint is univariate.
std::vector< Minisat::Var >::const_iterator nextTheoryVar
void insert(Minisat::Var var)
Base class for variable schedulers.
std::function< bool(Minisat::Var)> isTheoryAbstraction
std::function< const FormulaT &(Minisat::Var)> reabstractVariable
std::function< double(Minisat::Var)> getActivity
Activity-based scheduler preferring initially theory variables.
auto compareVars(Minisat::Var x, Minisat::Var y)
VarSchedulerMcsatActivityPreferTheory(BaseModule &baseModule)
void increaseActivity(Minisat::Var var)
std::vector< Minisat::Var > theory_ordering
void insert(Minisat::Var var)
void rebuildTheoryVars(const Constraints &c)
void decreaseActivity(Minisat::Var var)
VarSchedulerMinisat ordering
Base class for all MCSAT variable scheduler.
std::function< carl::Variable(Minisat::Var)> carlVar
std::function< bool(Minisat::Var)> isTheoryVar
std::function< Model()> currentModel
VarSchedulerMcsatBase(BaseModule &baseModule)
std::function< Minisat::Var(carl::Variable)> minisatVar
Variable scheduling that all decides Boolean variables first before deciding any theory variable.
void increaseActivity(Minisat::Var var)
void decreaseActivity(Minisat::Var var)
void insert(Minisat::Var var)
TheoryVarSchedulerStatic< vot > theory_ordering
VarSchedulerMcsatBooleanFirst(BaseModule &baseModule)
void rebuildTheoryVars(const Constraints &c)
VarSchedulerMinisat boolean_ordering
Variable scheduling that all decides theory variables first before deciding any Boolean variable.
VarSchedulerMinisat boolean_ordering
VarSchedulerMcsatTheoryFirst(BaseModule &baseModule)
void increaseActivity(Minisat::Var var)
void rebuildTheoryVars(const Constraints &c)
void decreaseActivity(Minisat::Var var)
void insert(Minisat::Var var)
TheoryScheduler theory_ordering
Decides only Constraints occuring in clauses that are univariate in the current theory variable while...
void detachClause(Minisat::CRef cl)
void rebuildTheoryVars(const Constraints &c)
Minisat::Lit undefLitIn(Minisat::CRef cl)
carl::Variable theoryDecision()
std::vector< TheoryLevel > mTheoryLevels
void attachClause(Minisat::CRef cl)
Minisat::Lit pickBooleanVarFromUndecided()
void relocateClauses(std::function< void(Minisat::CRef &)> relocate)
VarSchedulerMcsatUnivariateClausesOnly(BaseModule &baseModule)
void decreaseActivity(Minisat::Var var)
void insert(Minisat::Var var)
std::vector< Minisat::CRef > mUndecidedClauses
void increaseActivity(Minisat::Var var)
bool univariate(Minisat::CRef cl)
Minisat::Lit pickBooleanVarFromCurrentLevel()
bool decidedByTheory(Minisat::CRef cl)
TheoryScheduler theory_ordering
Decides only Constraints univariate in the current theory variable while the theory ordering is stati...
bool varDecidable(Minisat::Var x)
VarSchedulerMinisat boolean_ordering
void increaseActivity(Minisat::Var var)
void insert(Minisat::Var var)
TheoryVarSchedulerStatic< vot > theory_ordering
void rebuildTheoryVars(const Constraints &c)
void decreaseActivity(Minisat::Var var)
bool varCmp(Minisat::Var x, Minisat::Var y)
VarSchedulerMcsatUnivariateConstraintsOnly(BaseModule &baseModule)
Minisat's activity-based variable scheduling.
void increaseActivity(Minisat::Var var)
void insert(Minisat::Var var)
void decreaseActivity(Minisat::Var var)
static bool find(V &ts, const T &t)
RegionAllocator< uint32_t >::Ref CRef
Lit mkLit(Var var, bool sign=false)
static void remove(V &ts, const T &t)
Rational evaluate(carl::Variable v, const Poly &p, const Rational &r)
bool substitute(const FormulaT &constr, const carl::Variable var, const carl::vs::Term< Poly > &term, FormulaT &result)
std::vector< carl::Variable > vars(const std::pair< QuantifierType, std::vector< carl::Variable >> &p)
Class to create the formulas for axioms.
carl::Model< Rational, Poly > Model
#define SMTRAT_LOG_DEBUG(channel, msg)
std::vector< Minisat::CRef > clauses