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

Small refactoring of partition information #219

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions src/api/MainSolver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ sstat MainSolver::simplifyFormulas(char** err_msg)
}
assert(pmanager.getPartitionIndex(fla) != -1);
pmanager.propagatePartitionMask(fla);
getSMTSolver().setPartition(pmanager.getPartitionIndex(fla));
status = giveToSolver(fla, frame.getId());
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/api/MainSolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class MainSolver
pmanager(logic),
config(conf),
pfstore(getTheory().pfstore),
ts( config, logic, pmanager, term_mapper, *smt_solver ),
ts( config, logic, term_mapper, *smt_solver ),
solver_name {std::move(name)},
check_called(0),
status(s_Undef),
Expand Down
6 changes: 0 additions & 6 deletions src/api/PartitionManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,6 @@ PartitionManager::getPartition(const ipartitions_t& mask, PartitionManager::part
return A;
}

void
PartitionManager::addClauseClassMask(CRef c, const ipartitions_t& toadd)
{
partitionInfo.addClausePartition(c, toadd);
}

void
PartitionManager::invalidatePartitions(const ipartitions_t& toinvalidate) {
partitionInfo.invalidatePartitions(toinvalidate);
Expand Down
4 changes: 0 additions & 4 deletions src/api/PartitionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ class PartitionManager {

ipartitions_t computeAllowedPartitions(PTRef p);

const ipartitions_t & getClauseClassMask(CRef c) const { return partitionInfo.getClausePartitions(c); }

void addClauseClassMask(CRef c, const ipartitions_t & toadd);

void invalidatePartitions(const ipartitions_t & toinvalidate);

inline std::vector<PTRef> getPartitions() { return partitionInfo.getTopLevelFormulas(); }
Expand Down
22 changes: 1 addition & 21 deletions src/cnfizers/Cnfizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,12 @@ using namespace std;

Cnfizer::Cnfizer ( SMTConfig &config_
, Logic &logic_
, PartitionManager &pmanager_
, TermMapper &tmap
, SimpSMTSolver &solver_
) :
solver (solver_)
, config (config_ )
, logic (logic_)
, pmanager (pmanager_)
, tmap (tmap)
, s_empty (true)
, alreadyAsserted(logic.getTerm_true())
Expand All @@ -52,7 +50,6 @@ Cnfizer::Cnfizer ( SMTConfig &config_
void Cnfizer::initialize()
{
// TODO: MB: why is all this initialization necessary?
currentPartition = 0;
vec<Lit> c;
Lit l = this->getOrCreateLiteralFor (logic.getTerm_true());
c.push (l);
Expand All @@ -61,7 +58,6 @@ void Cnfizer::initialize()
l = this->getOrCreateLiteralFor (logic.getTerm_false());
c.push (~l);
addClause(c);
currentPartition = -1;
}

lbool
Expand Down Expand Up @@ -148,11 +144,6 @@ lbool Cnfizer::cnfizeAndGiveToSolver(PTRef formula, FrameId frame_id)
#ifdef PEDANTIC_DEBUG
cerr << "cnfizerAndGiveToSolver: " << logic.printTerm (formula) << endl;
#endif

if (keepPartitionInfo()) {
assert(pmanager.getPartitionIndex(formula) != -1);
currentPartition = pmanager.getPartitionIndex(formula);
}
vec<PTRef> top_level_formulae;
// Retrieve top-level formulae - this is a list constructed from a conjunction
retrieveTopLevelFormulae (formula, top_level_formulae);
Expand Down Expand Up @@ -214,7 +205,6 @@ lbool Cnfizer::cnfizeAndGiveToSolver(PTRef formula, FrameId frame_id)
declareVars(logic.propFormulasAppearingInUF);
}

currentPartition = -1;
return res == false ? l_False : l_Undef;
}

Expand Down Expand Up @@ -440,17 +430,7 @@ bool Cnfizer::addClause(const vec<Lit> & c_in)
}

#endif
opensmt::pair<CRef, CRef> iorefs{CRef_Undef, CRef_Undef};
bool res = solver.addOriginalSMTClause(c, iorefs);
if (keepPartitionInfo()) {
CRef ref = iorefs.first;
if (ref != CRef_Undef) {
ipartitions_t parts = 0;
assert(currentPartition != -1);
setbit(parts, static_cast<unsigned int>(currentPartition));
pmanager.addClauseClassMask(ref, parts);
}
}
bool res = solver.addOriginalSMTClause(c);
return res;
}
//
Expand Down
6 changes: 0 additions & 6 deletions src/cnfizers/Cnfizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,11 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "Global.h"
#include "Theory.h"
#include "Logic.h"
#include "PartitionManager.h"
#include "TermMapper.h"

#include <unordered_set>

class SimpSMTSolver;
class CnfState;
class THandler;
struct SMTConfig;

Expand All @@ -50,7 +48,6 @@ class Cnfizer
protected:
SMTConfig& config;
Logic& logic;
PartitionManager& pmanager;
TermMapper& tmap;
bool s_empty;

Expand All @@ -70,7 +67,6 @@ class Cnfizer

Cnfizer( SMTConfig & config_
, Logic& logic_
, PartitionManager& pmanager_
, TermMapper& tmap_
, SimpSMTSolver& solver_
);
Expand Down Expand Up @@ -121,8 +117,6 @@ class Cnfizer

bool keepPartitionInfo() const { return config.produce_inter(); }

int currentPartition = -1;

PTRef frame_term;
vec<PTRef> frame_terms;
void setFrameTerm(FrameId frame_id);
Expand Down
2 changes: 0 additions & 2 deletions src/cnfizers/Tseitin.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,11 @@ class Tseitin : public Cnfizer

Tseitin( SMTConfig& config_
, Logic& logic_
, PartitionManager &pmanager_
, TermMapper& tmap_
, SimpSMTSolver& solver_
)
: Cnfizer( config_
, logic_
, pmanager_
, tmap_
, solver_ )
, alreadyCnfized(logic_.getTerm_true())
Expand Down
8 changes: 0 additions & 8 deletions src/common/PartitionInfo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,6 @@ PartitionInfo::addIPartitions(SymRef _s, const ipartitions_t& _p) {
sym_partitions[_s] |= _p;
}

const ipartitions_t & PartitionInfo::getClausePartitions(CRef c) const {
return clause_class.at(c);
}

void PartitionInfo::addClausePartition(CRef c, const ipartitions_t & p) {
// opensmt::orbit(clause_class[c], clause_class[c], p);
clause_class[c] |= p;
}

void PartitionInfo::invalidatePartitions(const ipartitions_t& toinvalidate) {
auto negated = ~toinvalidate;
Expand Down
3 changes: 0 additions & 3 deletions src/common/PartitionInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
class PartitionInfo {
std::unordered_map<SymRef, ipartitions_t, SymRefHash> sym_partitions;
std::unordered_map<PTRef, ipartitions_t, PTRefHash> term_partitions;
std::unordered_map<CRef, ipartitions_t> clause_class;
FlaPartitionMap flaPartitionMap;

public:
Expand All @@ -26,8 +25,6 @@ class PartitionInfo {
void addIPartitions(PTRef t, const ipartitions_t& p);
ipartitions_t& getIPartitions(SymRef _s);
void addIPartitions(SymRef s, const ipartitions_t& p);
const ipartitions_t& getClausePartitions(CRef) const;
void addClausePartition(CRef c, const ipartitions_t& p);

inline std::vector<PTRef> getTopLevelFormulas() const { return flaPartitionMap.get_top_level_flas(); }
inline unsigned int getNoOfPartitions() const {return flaPartitionMap.getNoOfPartitions(); }
Expand Down
2 changes: 1 addition & 1 deletion src/proof/PGBuild.cc
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ void ProofGraph::buildProofGraph( int nVars )
if (_ctype == clause_type::CLA_ORIG) {
n->initClause(proof.getClause(clause));
n->setClauseRef(clause);
n->setInterpPartitionMask(pmanager.getClauseClassMask(clause));
n->setInterpPartitionMask(proof.getClauseClassMask(clause));
//Sort clause literals
std::sort(n->getClause().begin(),n->getClause().end());
if (n->getClauseSize() >= max_leaf_size) {
Expand Down
25 changes: 11 additions & 14 deletions src/smtsolvers/CoreSMTSolver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -269,17 +269,9 @@ Var CoreSMTSolver::newVar(bool sign, bool dvar)
return v;
}


bool CoreSMTSolver::addOriginalClause_(const vec<Lit> & _ps)
{
opensmt::pair<CRef, CRef> fake;
return addOriginalClause_(_ps, fake);
}

bool CoreSMTSolver::addOriginalClause_(const vec<Lit> & _ps, opensmt::pair<CRef, CRef> & inOutCRefs)
{
assert(decisionLevel() == 0);
inOutCRefs = {CRef_Undef, CRef_Undef};
if (!isOK()) { return false; }
bool logsProofForInterpolation = this->logsProofForInterpolation();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This old code seems a little redundant. Maybe we could fix it on this commit as well.

vec<Lit> ps;
Expand Down Expand Up @@ -307,16 +299,16 @@ bool CoreSMTSolver::addOriginalClause_(const vec<Lit> & _ps, opensmt::pair<CRef,
}
}
ps.shrink(i - j);
CRef clauseToInsert = CRef_Undef;
if (logsProofForInterpolation) {
vec<Lit> original;
ps.copyTo(original);
for(Lit l : resolvedUnits) {
original.push(l);
}
CRef inputClause = ca.alloc(original, false);
CRef outputClause = resolvedUnits.empty() ? inputClause :
clauseToInsert = resolvedUnits.empty() ? inputClause :
ps.size() == 0 ? CRef_Undef : ca.alloc(ps, false);
inOutCRefs = {inputClause, outputClause};
proof->newOriginalClause(inputClause);
if (!resolvedUnits.empty()) {
proof->beginChain( inputClause );
Expand All @@ -325,7 +317,7 @@ bool CoreSMTSolver::addOriginalClause_(const vec<Lit> & _ps, opensmt::pair<CRef,
assert(reason(v) != CRef_Undef);
proof->addResolutionStep(reason(v), v);
}
proof->endChain(outputClause);
proof->endChain(clauseToInsert);
}
}
if (ps.size() == 0) {
Expand All @@ -334,7 +326,7 @@ bool CoreSMTSolver::addOriginalClause_(const vec<Lit> & _ps, opensmt::pair<CRef,
if (ps.size() == 1)
{
assert(value(ps[0]) == l_Undef);
CRef reasonForAssignment = inOutCRefs.second;
CRef reasonForAssignment = clauseToInsert;
assert((logsProofForInterpolation && reasonForAssignment != CRef_Undef) || (!logsProofForInterpolation && reasonForAssignment == CRef_Undef));
uncheckedEnqueue(ps[0], reasonForAssignment);
CRef confl = propagate();
Expand All @@ -343,8 +335,7 @@ bool CoreSMTSolver::addOriginalClause_(const vec<Lit> & _ps, opensmt::pair<CRef,
}
else
{
CRef clauseToAttach = logsProofForInterpolation ? inOutCRefs.second : ca.alloc(ps, false);
inOutCRefs.second = clauseToAttach;
CRef clauseToAttach = logsProofForInterpolation ? clauseToInsert : ca.alloc(ps, false);
clauses.push(clauseToAttach);
attachClause(clauseToAttach);
// MB: TODO: remove this undo_stack
Expand Down Expand Up @@ -1044,6 +1035,12 @@ void CoreSMTSolver::finalizeProof(CRef finalConflict) {
proof->endChain(CRef_Undef);
}

void CoreSMTSolver::setPartition(std::size_t partitionIndex) {
if (proof) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to logsProofForInterpolation()?

proof->setPartition(partitionIndex);
}
}

/*_________________________________________________________________________________________________
|
| analyzeFinal : (p : Lit) -> [void]
Expand Down
2 changes: 1 addition & 1 deletion src/smtsolvers/CoreSMTSolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ class CoreSMTSolver
bool addOriginalClause(Lit p, Lit q, Lit r); // Add a ternary clause to the solver.
protected:
bool addOriginalClause_(const vec<Lit> & _ps); // Add a clause to the solver
bool addOriginalClause_(const vec<Lit> & _ps, opensmt::pair<CRef, CRef> & inOutCRefs); // Add a clause to the solver without making superflous internal copy. Will change the passed vector 'ps'. Write the new clause to cr
public:
// Solving:
//
Expand Down Expand Up @@ -755,6 +754,7 @@ class CoreSMTSolver
public:

void printTrace() const;
void setPartition(std::size_t partitionIndex);

protected:
virtual inline void clausesPublish() {};
Expand Down
8 changes: 8 additions & 0 deletions src/smtsolvers/Proof.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
, cl_al ( cl )
{ }

void Proof::newOriginalClause(CRef c) {
assert(currentPartition != static_cast<std::size_t>(-1));
newLeafClause(c, clause_type::CLA_ORIG);
ipartitions_t partition = 0;
setbit(partition, currentPartition);
clause_class[c] |= partition;
}

void Proof::newLeafClause(CRef c, clause_type t)
{
assert(c != CRef_Undef);
Expand Down
8 changes: 7 additions & 1 deletion src/smtsolvers/Proof.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,20 @@ class Proof
std::unordered_map< CRef, ProofDer> clause_to_proof_der;
ClauseAllocator& cl_al;
std::unordered_map<Lit, CRef, LitHash> assumed_literals;
std::unordered_map<CRef, ipartitions_t> clause_class;
std::size_t currentPartition = 0;

public:

Proof ( ClauseAllocator& cl );
~Proof( ) = default;

void setPartition(std::size_t partition) { currentPartition = partition; }

ipartitions_t getClauseClassMask(CRef c) const { assert(clause_class.count(c) != 0); return clause_class.at(c); }

// Notifies the proof about a new original clause.
void newOriginalClause(CRef c) { newLeafClause(c, clause_type::CLA_ORIG); }
void newOriginalClause(CRef c);

// Notifies the proof about a new T-clause.
void newTheoryClause(CRef c) { newLeafClause(c, clause_type::CLA_THEORY); }
Expand Down
11 changes: 4 additions & 7 deletions src/smtsolvers/SimpSMTSolver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,8 @@ lbool SimpSMTSolver::solve_(bool do_simp, bool turn_off_simp)
//=================================================================================================
// Added code

bool SimpSMTSolver::addOriginalSMTClause(const vec<Lit> & smt_clause, opensmt::pair<CRef, CRef> & inOutCRefs)
bool SimpSMTSolver::addOriginalSMTClause(const vec<Lit> & smt_clause)
{
inOutCRefs = {CRef_Undef, CRef_Undef};
assert( config.sat_preprocess_theory == 0 );

// Check that the variables exist in the solver
Expand All @@ -213,7 +212,7 @@ bool SimpSMTSolver::addOriginalSMTClause(const vec<Lit> & smt_clause, opensmt::p
cerr << "XXX skipped handling of unary theory literal?" << endl;
}
int nclauses = clauses.size();
if (!CoreSMTSolver::addOriginalClause_(smt_clause, inOutCRefs))
if (!CoreSMTSolver::addOriginalClause_(smt_clause))
return false;

if (use_simplification && clauses.size() == nclauses + 1)
Expand Down Expand Up @@ -622,8 +621,7 @@ bool SimpSMTSolver::eliminateVar(Var v)
vec<Lit>& resolvent = add_tmp;
for (int i = 0; i < pos.size(); i++) {
for (int j = 0; j < neg.size(); j++) {
opensmt::pair<CRef,CRef> dummy {CRef_Undef, CRef_Undef};
if (merge(ca[pos[i]], ca[neg[j]], v, resolvent) && !addOriginalSMTClause(resolvent, dummy))
if (merge(ca[pos[i]], ca[neg[j]], v, resolvent) && !addOriginalSMTClause(resolvent))
return false;
}
}
Expand Down Expand Up @@ -665,8 +663,7 @@ bool SimpSMTSolver::substitute(Var v, Lit x)

removeClause(cls[i]);

opensmt::pair<CRef,CRef> dummy {CRef_Undef, CRef_Undef};
if (!addOriginalSMTClause(subst_clause, dummy))
if (!addOriginalSMTClause(subst_clause))
return ok = false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/smtsolvers/SimpSMTSolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class SimpSMTSolver : public CoreSMTSolver
//
Var newVar (bool polarity = true, bool dvar = true) override;

bool addOriginalSMTClause(const vec<Lit> & smt_clause, opensmt::pair<CRef, CRef> & inOutCRefs);
bool addOriginalSMTClause(const vec<Lit> & smt_clause);
public:

bool substitute(Var v, Lit x); // Replace all occurences of v with x (may cause a contradiction).
Expand Down