Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the partition information of clauses more explicit. #222

Draft
wants to merge 1 commit into
base: partition-refactor
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions src/api/MainSolver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ MainSolver::pop()
for (int i = 0; i < partitionsToInvalidate.size(); ++i) {
PTRef part = partitionsToInvalidate[i];
auto index = pmanager.getPartitionIndex(part);
assert(index != -1);
opensmt::setbit(mask, static_cast<unsigned int>(index));
assert(index != PartIdx_Undef);
opensmt::setbit(mask, static_cast<unsigned int>(index.id));
}
pmanager.invalidatePartitions(mask);
}
Expand Down Expand Up @@ -121,7 +121,7 @@ MainSolver::insertFormula(PTRef root, char** msg)
// thus we need the old value of count. TODO: Find a good interface for this so it cannot be broken this easily
unsigned int partition_index = inserted_formulas_count++;
pmanager.assignTopLevelPartitionIndex(partition_index, root);
assert(pmanager.getPartitionIndex(root) != -1);
assert(pmanager.getPartitionIndex(root) != PartIdx_Undef);
}
else {
++inserted_formulas_count;
Expand Down Expand Up @@ -156,22 +156,21 @@ sstat MainSolver::simplifyFormulas(char** err_msg)
for (int j = 0; j < flas.size() && status != s_False; ++j) {
PTRef fla = flas[j];
if (fla == logic.getTerm_true()) { continue; }
assert(pmanager.getPartitionIndex(fla) != -1);
assert(pmanager.getPartitionIndex(fla) != PartIdx_Undef);
// Optimize the dag for cnfization
if (logic.isBooleanOperator(fla)) {
PTRef old = fla;
fla = rewriteMaxArity(fla);
pmanager.transferPartitionMembership(old, fla);
}
assert(pmanager.getPartitionIndex(fla) != -1);
assert(pmanager.getPartitionIndex(fla) != PartIdx_Undef);
pmanager.propagatePartitionMask(fla);
getSMTSolver().setPartition(pmanager.getPartitionIndex(fla));
status = giveToSolver(fla, frame.getId());
status = giveToSolver(fla, frame.getId(), pmanager.getPartitionIndex(fla));
}
} else {
PTRef root = frame.root;
if (logic.isFalse(root)) {
giveToSolver(getLogic().getTerm_false(), frame.getId());
giveToSolver(getLogic().getTerm_false(), frame.getId(), PartIdx_Undef);
status = s_False;
break;
}
Expand All @@ -180,7 +179,7 @@ sstat MainSolver::simplifyFormulas(char** err_msg)
root = rewriteMaxArity(root);
}
root_instance.setRoot(root);
status = giveToSolver(root, frame.getId());
status = giveToSolver(root, frame.getId(), PartIdx_Undef);
}
}
if (status == s_False) {
Expand Down
4 changes: 2 additions & 2 deletions src/api/MainSolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ class MainSolver
sstat simplifyFormulas(char** msg);
sstat solve ();

sstat giveToSolver(PTRef root, FrameId push_id) {
if (ts.cnfizeAndGiveToSolver(root, push_id) == l_False) return s_False;
sstat giveToSolver(PTRef root, FrameId push_id, PartIdx partitionIndex) {
if (ts.cnfizeAndGiveToSolver(root, push_id, partitionIndex) == l_False) return s_False;
return s_Undef; }

PTRef rewriteMaxArity(PTRef);
Expand Down
2 changes: 1 addition & 1 deletion src/api/PartitionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class PartitionManager {
partitionInfo.transferPartitionMembership(old, new_ptref);
}

int getPartitionIndex(PTRef ref) const {
PartIdx getPartitionIndex(PTRef ref) const {
return partitionInfo.getPartitionIndex(ref);
}
};
Expand Down
36 changes: 18 additions & 18 deletions src/cnfizers/Cnfizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ void Cnfizer::initialize()
vec<Lit> c;
Lit l = this->getOrCreateLiteralFor (logic.getTerm_true());
c.push (l);
addClause(c);
addClause(c, PartIdx_Default); // Check what's the "default" partition!
c.pop();
l = this->getOrCreateLiteralFor (logic.getTerm_false());
c.push (~l);
addClause(c);
addClause(c, PartIdx_Default); // Check what's the "default" partition!
}

lbool
Expand Down Expand Up @@ -132,7 +132,7 @@ void Cnfizer::setFrameTerm(FrameId frame_id)
//
// Main Routine. Examine formula and give it to the solver
//
lbool Cnfizer::cnfizeAndGiveToSolver(PTRef formula, FrameId frame_id)
lbool Cnfizer::cnfizeAndGiveToSolver(PTRef formula, FrameId frame_id, PartIdx partitionIndex)
{
// Get the variable for the incrementality.
setFrameTerm(frame_id);
Expand Down Expand Up @@ -174,7 +174,7 @@ lbool Cnfizer::cnfizeAndGiveToSolver(PTRef formula, FrameId frame_id)
#ifdef PEDANTIC_DEBUG
cerr << " => Already in CNF" << endl;
#endif
res = giveToSolver (f);
res = giveToSolver (f, partitionIndex);
}

// Check whether it can be rewritten using deMorgan laws
Expand All @@ -184,22 +184,22 @@ lbool Cnfizer::cnfizeAndGiveToSolver(PTRef formula, FrameId frame_id)
#ifdef PEDANTIC_DEBUG
cout << " => Will be de Morganized" << endl;
#endif
res = deMorganize (f);
res = deMorganize (f, partitionIndex);
}
else
{
#ifdef PEDANTIC_DEBUG
cout << " => proper cnfization" << endl;
#endif // PEDANTIC_DEBUG
res = cnfizeAndAssert (f); // Perform actual cnfization (implemented in subclasses)
res = cnfizeAndAssert (f, partitionIndex); // Perform actual cnfization (implemented in subclasses)
}
alreadyAsserted.insert(f, frame_term);
}
s_empty = false; // solver no longer empty
if (res) {
vec<PTRef> nestedBoolRoots = getNestedBoolRoots(formula);
for (int i = 0; i < nestedBoolRoots.size(); ++i) {
res &= cnfize(nestedBoolRoots[i]); // cnfize the formula without asserting the top level
res &= cnfize(nestedBoolRoots[i], partitionIndex); // cnfize the formula without asserting the top level
}
assert(res);
declareVars(logic.propFormulasAppearingInUF);
Expand All @@ -208,17 +208,17 @@ lbool Cnfizer::cnfizeAndGiveToSolver(PTRef formula, FrameId frame_id)
return res == false ? l_False : l_Undef;
}

bool Cnfizer::cnfizeAndAssert(PTRef formula) {
bool Cnfizer::cnfizeAndAssert(PTRef formula, PartIdx partitionIndex) {
assert(formula != PTRef_Undef);
// Top level formula must not be and anymore
assert(!logic.isAnd(formula));
bool res = true;
// Add the top level literal as a unit to solver.
vec<Lit> clause;
clause.push(this->getOrCreateLiteralFor(formula));
res &= addClause(clause);
res &= addClause(clause, partitionIndex);

res &= cnfize(formula);
res &= cnfize(formula, partitionIndex);
return res;
}

Expand All @@ -234,7 +234,7 @@ void Cnfizer::declareVars(vec<PTRef>& vars)
// Apply simple de Morgan laws to the formula
//

bool Cnfizer::deMorganize ( PTRef formula )
bool Cnfizer::deMorganize ( PTRef formula, PartIdx partitionIndex )
{
assert (!logic.isAnd (formula));
Pterm &pt = logic.getPterm (formula);
Expand All @@ -259,7 +259,7 @@ bool Cnfizer::deMorganize ( PTRef formula )
#endif
}

rval = addClause(clause);
rval = addClause(clause, partitionIndex);
}

return rval;
Expand Down Expand Up @@ -408,7 +408,7 @@ bool Cnfizer::checkPureConj (PTRef e, Map<PTRef, bool, PTRefHash, Equal<PTRef> >
return true;
}

bool Cnfizer::addClause(const vec<Lit> & c_in)
bool Cnfizer::addClause(const vec<Lit> & c_in, PartIdx partitionIndex)
{
vec<Lit> c;
c_in.copyTo(c);
Expand All @@ -430,14 +430,14 @@ bool Cnfizer::addClause(const vec<Lit> & c_in)
}

#endif
bool res = solver.addOriginalSMTClause(c);
bool res = solver.addOriginalSMTClause(c, partitionIndex);
return res;
}
//
// Give the formula to the solver
//

bool Cnfizer::giveToSolver ( PTRef f )
bool Cnfizer::giveToSolver ( PTRef f, PartIdx partitionIndex )
{
vec<Lit> clause;

Expand All @@ -447,7 +447,7 @@ bool Cnfizer::giveToSolver ( PTRef f )
if (logic.isLit (f))
{
clause.push (this->getOrCreateLiteralFor (f));
return addClause(clause);
return addClause(clause, partitionIndex);
}

//
Expand All @@ -462,7 +462,7 @@ bool Cnfizer::giveToSolver ( PTRef f )
for (int i = 0; i < lits.size(); i++)
clause.push (this->getOrCreateLiteralFor (lits[i]));

return addClause(clause);
return addClause(clause, partitionIndex);
}

//
Expand All @@ -474,7 +474,7 @@ bool Cnfizer::giveToSolver ( PTRef f )
bool result = true;

for (unsigned i = 0; i < conj.size_( ) && result; i++)
result = giveToSolver (conj[i]);
result = giveToSolver (conj[i], partitionIndex);
return result;
}

Expand Down
12 changes: 6 additions & 6 deletions src/cnfizers/Cnfizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class Cnfizer

virtual ~Cnfizer( ) { }

lbool cnfizeAndGiveToSolver (PTRef, FrameId frame_id); // Main routine
lbool cnfizeAndGiveToSolver (PTRef, FrameId frame_id, PartIdx partitionIndex); // Main routine

lbool getTermValue(PTRef) const;

Expand All @@ -86,9 +86,9 @@ class Cnfizer

protected:

virtual bool cnfizeAndAssert ( PTRef ); // Cnfize and assert the top-level.
virtual bool cnfize ( PTRef ) = 0; // Actual cnfization. To be implemented in derived classes
bool deMorganize ( PTRef ); // Apply deMorgan rules whenever feasible
virtual bool cnfizeAndAssert ( PTRef, PartIdx partitionIndex ); // Cnfize and assert the top-level.
virtual bool cnfize ( PTRef, PartIdx partitionIndex ) = 0; // Actual cnfization. To be implemented in derived classes
bool deMorganize ( PTRef, PartIdx partitionIndex ); // Apply deMorgan rules whenever feasible
void declareVars (vec<PTRef>&); // Declare a set of Boolean atoms to the solver (without asserting them)

public:
Expand All @@ -98,10 +98,10 @@ class Cnfizer
void retrieveTopLevelFormulae ( PTRef, vec<PTRef> & ); // Retrieves the list of top-level formulae
protected:

bool giveToSolver ( PTRef ); // Gives formula to the SAT solver
bool giveToSolver ( PTRef, PartIdx partitionIndex ); // Gives formula to the SAT solver


bool addClause(const vec<Lit> &);
bool addClause(const vec<Lit> &, PartIdx partitionIndex);

void retrieveClause ( PTRef, vec<PTRef> & ); // Retrieve a clause from a formula
void retrieveConjuncts ( PTRef, vec<PTRef> & ); // Retrieve the list of conjuncts
Expand Down
Loading