From: Tim King Date: Wed, 3 Feb 2010 19:25:50 +0000 (+0000) Subject: I hacked in a temporary way to restart minisat for multiple queries. X-Git-Tag: cvc5-1.0.0~9304 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=14b035cd792b43ec1dc5655882378631235732ff;p=cvc5.git I hacked in a temporary way to restart minisat for multiple queries. --- diff --git a/src/prop/cnf_stream.h b/src/prop/cnf_stream.h index 131ac98dc..247a5b096 100644 --- a/src/prop/cnf_stream.h +++ b/src/prop/cnf_stream.h @@ -81,10 +81,6 @@ protected: */ minisat::Lit lookupInCache(const Node & n) const; - /** - * Empties the internal translation cache. - */ - void flushCache(); //negotiates the mapping of atoms to literals with PropEngine void registerMapping(const Node & node, minisat::Lit lit, bool atom = false); @@ -99,6 +95,12 @@ public: */ CnfStream(CVC4::PropEngine *pe); + + /** + * Empties the internal translation cache. + */ + void flushCache(); + /** * Converts and asserts a formula. * @param n node to convert and assert diff --git a/src/prop/prop_engine.cpp b/src/prop/prop_engine.cpp index 875d0cd16..b4df32f0f 100644 --- a/src/prop/prop_engine.cpp +++ b/src/prop/prop_engine.cpp @@ -33,12 +33,15 @@ namespace CVC4 { PropEngine::PropEngine(DecisionEngine& de, TheoryEngine& te) : d_de(de), - d_te(te){ + d_te(te), + d_restartMayBeNeeded(false){ + d_sat = new Solver(); d_cnfStream = new CVC4::prop::TseitinCnfStream(this); } PropEngine::~PropEngine(){ delete d_cnfStream; + delete d_sat; } @@ -47,7 +50,7 @@ void PropEngine::assertClause(vec & c){ *for restarting the sat solver */ //TODO assert that each lit has been mapped to an atom or requested - d_sat.addClause(c); + d_sat->addClause(c); } void PropEngine::registerAtom(const Node & n, Lit l){ @@ -56,21 +59,39 @@ void PropEngine::registerAtom(const Node & n, Lit l){ } Lit PropEngine::requestFreshLit(){ - Var v = d_sat.newVar(); + Var v = d_sat->newVar(); Lit l(v,false); return l; } void PropEngine::assertFormula(const Node& node) { d_cnfStream->convertAndAssert(node); + d_assertionList.push_back(node); +} + +void PropEngine::restart(){ + delete d_sat; + d_sat = new Solver(); + d_cnfStream->flushCache(); + d_atom2lit.clear(); + d_lit2atom.clear(); + + for(vector::iterator iter = d_assertionList.begin(); + iter != d_assertionList.end(); ++iter){ + d_cnfStream->convertAndAssert(*iter); + } } void PropEngine::solve() { + if(d_restartMayBeNeeded) + restart(); - //TODO: may need to restart if a previous query returned false + d_sat->verbosity = 1; + bool result = d_sat->solve(); - d_sat.verbosity = 1; - bool result = d_sat.solve(); + if(!result){ + d_restartMayBeNeeded = true; + } Notice() << "result is " << (result ? "sat/invalid" : "unsat/valid") << endl; } diff --git a/src/prop/prop_engine.h b/src/prop/prop_engine.h index f356c9e0b..9f5f9dac1 100644 --- a/src/prop/prop_engine.h +++ b/src/prop/prop_engine.h @@ -52,7 +52,7 @@ class PropEngine { * and to start from scratch everytime. (Avoid push/pop problems?) * Is this right? */ - CVC4::prop::minisat::SimpSolver d_sat; + CVC4::prop::minisat::Solver * d_sat; std::map d_atom2lit; @@ -64,6 +64,21 @@ class PropEngine { */ void registerAtom(const Node & n, CVC4::prop::minisat::Lit l); + /** + * Flags whether the solver may need to have its state reset before + * solving occurs + */ + bool d_restartMayBeNeeded; + + /** + * Cleans existing state in the PropEngine and reinitializes the state. + */ + void restart(); + + /** + * Keeps track of all of the assertions that need to be made. + */ + std::vector d_assertionList; CVC4::prop::minisat::Lit requestFreshLit();