Skip to content

Commit

Permalink
Storing clause partitioning directly in Proof
Browse files Browse the repository at this point in the history
This cleans up Cnfizer a bit, because it does not need to know about the
partitioning anymore.
  • Loading branch information
Martin Blicha committed Jan 23, 2021
1 parent 8d0a77e commit 6bbfd27
Show file tree
Hide file tree
Showing 14 changed files with 25 additions and 51 deletions.
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
19 changes: 0 additions & 19 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 @@ -442,15 +432,6 @@ 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);
}
}
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
6 changes: 6 additions & 0 deletions src/smtsolvers/CoreSMTSolver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,12 @@ void CoreSMTSolver::finalizeProof(CRef finalConflict) {
proof->endChain(CRef_Undef);
}

void CoreSMTSolver::setPartition(std::size_t partitionIndex) {
if (proof) {
proof->setPartition(partitionIndex);
}
}

/*_________________________________________________________________________________________________
|
| analyzeFinal : (p : Lit) -> [void]
Expand Down
1 change: 1 addition & 0 deletions src/smtsolvers/CoreSMTSolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,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

0 comments on commit 6bbfd27

Please sign in to comment.