diff options
author | Morgan Deters <mdeters@cs.nyu.edu> | 2014-08-22 16:59:28 -0400 |
---|---|---|
committer | Morgan Deters <mdeters@cs.nyu.edu> | 2014-08-22 17:58:14 -0400 |
commit | 2dbe1f150d30f0fb0c8522f891104270ce09db4c (patch) | |
tree | 1305f3de890f4353c3b5695a93ab7e2419760617 /src/prop/minisat/core | |
parent | 4ec2c8eb8b8a50dc743119100767e101f19305f6 (diff) |
Unsat core infrastruture and API (SMT-LIB compliance to come).
Diffstat (limited to 'src/prop/minisat/core')
-rw-r--r-- | src/prop/minisat/core/Solver.cc | 32 | ||||
-rw-r--r-- | src/prop/minisat/core/Solver.h | 38 |
2 files changed, 42 insertions, 28 deletions
diff --git a/src/prop/minisat/core/Solver.cc b/src/prop/minisat/core/Solver.cc index b0d710d66..5403b992e 100644 --- a/src/prop/minisat/core/Solver.cc +++ b/src/prop/minisat/core/Solver.cc @@ -135,8 +135,8 @@ Solver::Solver(CVC4::prop::TheoryProxy* proxy, CVC4::context::Context* context, // Assert the constants uncheckedEnqueue(mkLit(varTrue, false)); uncheckedEnqueue(mkLit(varFalse, true)); - PROOF( ProofManager::getSatProof()->registerUnitClause(mkLit(varTrue, false), INPUT); ) - PROOF( ProofManager::getSatProof()->registerUnitClause(mkLit(varFalse, true), INPUT); ) + PROOF( ProofManager::getSatProof()->registerUnitClause(mkLit(varTrue, false), INPUT, uint64_t(-1)); ) + PROOF( ProofManager::getSatProof()->registerUnitClause(mkLit(varFalse, true), INPUT, uint64_t(-1)); ) } @@ -263,7 +263,7 @@ CRef Solver::reason(Var x) { // Construct the reason CRef real_reason = ca.alloc(explLevel, explanation, true); - PROOF (ProofManager::getSatProof()->registerClause(real_reason, THEORY_LEMMA); ); + PROOF (ProofManager::getSatProof()->registerClause(real_reason, THEORY_LEMMA, (uint64_t(RULE_CONFLICT) << 32)); ); vardata[x] = VarData(real_reason, level(x), user_level(x), intro_level(x), trail_index(x)); clauses_removable.push(real_reason); attachClause(real_reason); @@ -271,7 +271,7 @@ CRef Solver::reason(Var x) { return real_reason; } -bool Solver::addClause_(vec<Lit>& ps, bool removable) +bool Solver::addClause_(vec<Lit>& ps, bool removable, uint64_t proof_id) { if (!ok) return false; @@ -321,6 +321,8 @@ bool Solver::addClause_(vec<Lit>& ps, bool removable) lemmas.push(); ps.copyTo(lemmas.last()); lemmas_removable.push(removable); + Debug("cores") << "lemma push " << proof_id << " " << (proof_id & 0xffffffff) << std::endl; + lemmas_proof_id.push(proof_id); } else { // If all false, we're in conflict if (ps.size() == falseLiteralsCount) { @@ -329,7 +331,7 @@ bool Solver::addClause_(vec<Lit>& ps, bool removable) // construct the clause below to give to the proof manager // as the final conflict. if(falseLiteralsCount == 1) { - PROOF( ProofManager::getSatProof()->storeUnitConflict(ps[0], INPUT); ) + PROOF( ProofManager::getSatProof()->storeUnitConflict(ps[0], INPUT, proof_id); ) PROOF( ProofManager::getSatProof()->finalizeProof(::Minisat::CRef_Lazy); ) return ok = false; } @@ -351,7 +353,7 @@ bool Solver::addClause_(vec<Lit>& ps, bool removable) attachClause(cr); if(PROOF_ON()) { - PROOF( ProofManager::getSatProof()->registerClause(cr, INPUT); ) + PROOF( ProofManager::getSatProof()->registerClause(cr, INPUT, proof_id); ) if(ps.size() == falseLiteralsCount) { PROOF( ProofManager::getSatProof()->finalizeProof(cr); ) return ok = false; @@ -364,11 +366,12 @@ bool Solver::addClause_(vec<Lit>& ps, bool removable) if(assigns[var(ps[0])] == l_Undef) { assert(assigns[var(ps[0])] != l_False); uncheckedEnqueue(ps[0], cr); - PROOF( if(ps.size() == 1) { ProofManager::getSatProof()->registerUnitClause(ps[0], INPUT); } ); + Debug("cores") << "i'm registering a unit clause, input, proof id " << proof_id << std::endl; + PROOF( if(ps.size() == 1) { ProofManager::getSatProof()->registerUnitClause(ps[0], INPUT, proof_id); } ); CRef confl = propagate(CHECK_WITHOUT_THEORY); if(! (ok = (confl == CRef_Undef)) ) { if(ca[confl].size() == 1) { - PROOF( ProofManager::getSatProof()->storeUnitConflict(ca[confl][0], LEARNT); ); + PROOF( ProofManager::getSatProof()->storeUnitConflict(ca[confl][0], LEARNT, proof_id); ); PROOF( ProofManager::getSatProof()->finalizeProof(::Minisat::CRef_Lazy); ) } else { PROOF( ProofManager::getSatProof()->finalizeProof(confl); ); @@ -842,7 +845,7 @@ CRef Solver::propagate(TheoryCheckType type) propagateTheory(); // If there are lemmas (or conflicts) update them if (lemmas.size() > 0) { - confl = updateLemmas(); + confl = updateLemmas(); } } else { // Even though in conflict, we still need to discharge the lemmas @@ -891,7 +894,7 @@ void Solver::propagateTheory() { proxy->explainPropagation(MinisatSatSolver::toSatLiteral(p), explanation_cl); vec<Lit> explanation; MinisatSatSolver::toMinisatClause(explanation_cl, explanation); - addClause(explanation, true); + addClause(explanation, true, 0); } } } @@ -1645,6 +1648,8 @@ CRef Solver::updateLemmas() { // The current lemma vec<Lit>& lemma = lemmas[i]; bool removable = lemmas_removable[i]; + uint64_t proof_id = lemmas_proof_id[i]; + Debug("cores") << "pulled lemma proof id " << proof_id << " " << (proof_id & 0xffffffff) << std::endl; // Attach it if non-unit CRef lemma_ref = CRef_Undef; @@ -1659,7 +1664,7 @@ CRef Solver::updateLemmas() { } lemma_ref = ca.alloc(clauseLevel, lemma, removable); - PROOF( ProofManager::getSatProof()->registerClause(lemma_ref, THEORY_LEMMA); ); + PROOF( ProofManager::getSatProof()->registerClause(lemma_ref, THEORY_LEMMA, proof_id); ); if (removable) { clauses_removable.push(lemma_ref); } else { @@ -1667,7 +1672,7 @@ CRef Solver::updateLemmas() { } attachClause(lemma_ref); } else { - PROOF( ProofManager::getSatProof()->registerUnitClause(lemma[0], THEORY_LEMMA); ); + PROOF( ProofManager::getSatProof()->registerUnitClause(lemma[0], THEORY_LEMMA, proof_id); ); } // If the lemma is propagating enqueue its literal (or set the conflict) @@ -1681,7 +1686,7 @@ CRef Solver::updateLemmas() { } else { Debug("minisat::lemmas") << "Solver::updateLemmas(): unit conflict or empty clause" << std::endl; conflict = CRef_Lazy; - PROOF( ProofManager::getSatProof()->storeUnitConflict(lemma[0]); ); + PROOF( ProofManager::getSatProof()->storeUnitConflict(lemma[0], LEARNT, proof_id); ); } } else { Debug("minisat::lemmas") << "lemma size is " << lemma.size() << std::endl; @@ -1694,6 +1699,7 @@ CRef Solver::updateLemmas() { // Clear the lemmas lemmas.clear(); lemmas_removable.clear(); + lemmas_proof_id.clear(); if (conflict != CRef_Undef) { theoryConflict = true; diff --git a/src/prop/minisat/core/Solver.h b/src/prop/minisat/core/Solver.h index 7831f211b..2d70cfeef 100644 --- a/src/prop/minisat/core/Solver.h +++ b/src/prop/minisat/core/Solver.h @@ -37,12 +37,11 @@ OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWA #include "expr/command.h" namespace CVC4 { -class SatProof; - -namespace prop { - class TheoryProxy; -}/* CVC4::prop namespace */ + class SatProof; + namespace prop { + class TheoryProxy; + }/* CVC4::prop namespace */ }/* CVC4 namespace */ namespace Minisat { @@ -85,6 +84,9 @@ protected: /** Is the lemma removable */ vec<bool> lemmas_removable; + /** Proof IDs for lemmas */ + vec<uint64_t> lemmas_proof_id; + /** Do a another check if FULL_EFFORT was the last one */ bool recheck; @@ -154,12 +156,14 @@ public: void push (); void pop (); - bool addClause (const vec<Lit>& ps, bool removable); // Add a clause to the solver. + // CVC4 adds the "proof_id" here to refer to the input assertion/lemma + // that produced this clause + bool addClause (const vec<Lit>& ps, bool removable, uint64_t proof_id); // Add a clause to the solver. bool addEmptyClause(bool removable); // Add the empty clause, making the solver contradictory. - bool addClause (Lit p, bool removable); // Add a unit clause to the solver. - bool addClause (Lit p, Lit q, bool removable); // Add a binary clause to the solver. - bool addClause (Lit p, Lit q, Lit r, bool removable); // Add a ternary clause to the solver. - bool addClause_( vec<Lit>& ps, bool removable); // Add a clause to the solver without making superflous internal copy. Will + bool addClause (Lit p, bool removable, uint64_t proof_id); // Add a unit clause to the solver. + bool addClause (Lit p, Lit q, bool removable, uint64_t proof_id); // Add a binary clause to the solver. + bool addClause (Lit p, Lit q, Lit r, bool removable, uint64_t proof_id); // Add a ternary clause to the solver. + bool addClause_( vec<Lit>& ps, bool removable, uint64_t proof_id); // Add a clause to the solver without making superflous internal copy. Will // change the passed vector 'ps'. // Solving: @@ -489,11 +493,15 @@ inline void Solver::checkGarbage(double gf){ // NOTE: enqueue does not set the ok flag! (only public methods do) inline bool Solver::enqueue (Lit p, CRef from) { return value(p) != l_Undef ? value(p) != l_False : (uncheckedEnqueue(p, from), true); } -inline bool Solver::addClause (const vec<Lit>& ps, bool removable) { ps.copyTo(add_tmp); return addClause_(add_tmp, removable); } -inline bool Solver::addEmptyClause (bool removable) { add_tmp.clear(); return addClause_(add_tmp, removable); } -inline bool Solver::addClause (Lit p, bool removable) { add_tmp.clear(); add_tmp.push(p); return addClause_(add_tmp, removable); } -inline bool Solver::addClause (Lit p, Lit q, bool removable) { add_tmp.clear(); add_tmp.push(p); add_tmp.push(q); return addClause_(add_tmp, removable); } -inline bool Solver::addClause (Lit p, Lit q, Lit r, bool removable) { add_tmp.clear(); add_tmp.push(p); add_tmp.push(q); add_tmp.push(r); return addClause_(add_tmp, removable); } +inline bool Solver::addClause (const vec<Lit>& ps, bool removable, uint64_t proof_id) + { ps.copyTo(add_tmp); return addClause_(add_tmp, removable, proof_id); } +inline bool Solver::addEmptyClause (bool removable) { add_tmp.clear(); return addClause_(add_tmp, removable, uint64_t(-1)); } +inline bool Solver::addClause (Lit p, bool removable, uint64_t proof_id) + { add_tmp.clear(); add_tmp.push(p); return addClause_(add_tmp, removable, proof_id); } +inline bool Solver::addClause (Lit p, Lit q, bool removable, uint64_t proof_id) + { add_tmp.clear(); add_tmp.push(p); add_tmp.push(q); return addClause_(add_tmp, removable, proof_id); } +inline bool Solver::addClause (Lit p, Lit q, Lit r, bool removable, uint64_t proof_id) + { add_tmp.clear(); add_tmp.push(p); add_tmp.push(q); add_tmp.push(r); return addClause_(add_tmp, removable, proof_id); } inline bool Solver::locked (const Clause& c) const { return value(c[0]) == l_True && isPropagatedBy(var(c[0]), c); } inline void Solver::newDecisionLevel() { trail_lim.push(trail.size()); flipped.push(false); context->push(); if(Dump.isOn("state")) { Dump("state") << CVC4::PushCommand(); } } |