#include "prop/prop_engine.h"
#include "expr/node.h"
#include "util/Assert.h"
+#include "util/output.h"
#include <queue>
namespace CVC4 {
namespace prop {
+bool atomic(const Node & n);
+
CnfStream::CnfStream(PropEngine *pe) :
d_propEngine(pe) {
}
CnfStream(pe) {
}
+static void printLit(ostream & out, Lit l) {
+ const char * s = (sign(l))?"~":" ";
+ out << s << var(l);
+
+}
+
+static void printClause(ostream & out, vec<Lit> & c) {
+ out << "clause :";
+ for(int i=0;i<c.size();i++){
+ out << " ";
+ printLit(out, c[i]) ;
+ }
+ out << ";" << endl;
+}
+
void CnfStream::insertClauseIntoStream(vec<Lit> & c) {
+ Debug("cnf") << "Inserting into stream ";
+ printClause(Debug("cnf"),c);
+
d_propEngine->assertClause(c);
}
}
Lit CnfStream::lookupInCache(const Node & n) const {
- Assert(isCached(n));
+ Assert(isCached(n),
+ "Node is not in cnf translation cache");
return d_translationCache.find(n)->second;
}
void CnfStream::flushCache() {
+ Debug("cnf") << "flushing the translation cache" << endl;
d_translationCache.clear();
}
void CnfStream::registerMapping(const Node & node, Lit lit, bool atom) {
+
+ Debug("cnf") << "Mapping Node "<< node << " to ";
+ printLit(Debug("cnf"),lit);
+ Debug("cnf") << endl;
+
//Prop engine does not need to know this mapping
d_translationCache.insert(make_pair(node, lit));
if(atom)
/***********************************************/
Lit TseitinCnfStream::handleAtom(const Node & n) {
+ Assert(atomic(n), "handleAtom(n) expects n to be an atom");
+
+ Debug("cnf") << "handling atom" << endl;
+
Lit l = aquireAndRegister(n, true);
switch(n.getKind()) { /* TRUE and FALSE are handled specially. */
case TRUE:
*/
void TseitinCnfStream::mapRecTransformOverChildren(const Node& n,
vec<Lit> & target) {
- Assert(target.size() == n.getNumChildren());
+ Assert(target.size() == n.getNumChildren(),
+ "Size of the children must be the same the constructed clause");
int i = 0;
Node::iterator subExprIter = n.begin();
* : (e | ~a1) & (e |~a2) & (e & ~a3) & ...
*/
- vec<Lit> c;
- c.push(~e);
+ vec<Lit> c(1 + lits.size());
+
for(int index = 0; index < lits.size(); ++index) {
Lit a = lits[index];
- c.push(a);
+ c[index] = a;
insertClauseIntoStream(e, ~a);
}
+ c[lits.size()] = ~e;
insertClauseIntoStream(c);
return e;
* : e | ~a1 | ~a2 | ~a3 | ...
*/
- vec<Lit> c;
- c.push(e);
+ vec<Lit> c(lits.size()+1);
for(int index = 0; index < lits.size(); ++index) {
Lit a = lits[index];
- c.push(~a);
+ c[index] = (~a);
insertClauseIntoStream(~e, a);
}
+ c[lits.size()] = e;
+
insertClauseIntoStream(c);
return e;
Node m = n[0];
Lit equivM = recTransform(m);
- registerMapping(n, ~equivM, false);
+ Lit equivN = ~equivM;
+
+ registerMapping(n, equivN, false);
- return equivM;
+ return equivN;
}
//FIXME: This function is a major hack! Should be changed ASAP
case XOR:
case ITE:
case IFF:
+ case IMPLIES:
case OR:
case AND:
return false;
return handleIte(n);
case IFF:
return handleIff(n);
+ case IMPLIES:
+ return handleImplies(n);
case OR:
return handleOr(n);
case AND:
}
void PropEngine::assertFormula(const Node& node) {
+
+ Debug("prop") << "Asserting ";
+ node.printAst(Debug("prop"));
+ Debug("prop") << endl;
+
d_cnfStream->convertAndAssert(node);
d_assertionList.push_back(node);
}
}
}
+static void printLit(ostream & out, Lit l) {
+ const char * s = (sign(l))?"~":" ";
+ out << s << var(l);
+
+}
+
Result PropEngine::solve() {
if(d_restartMayBeNeeded)
restart();
d_restartMayBeNeeded = true;
}
- Notice() << "result is " << (result ? "sat/invalid" : "unsat/valid") << endl;
+ Message() << "result is " << (result ? "sat/invalid" : "unsat/valid") << endl;
+
+ if(result){
+ for(map<Node,Lit>::iterator atomIter = d_atom2lit.begin();
+ atomIter != d_atom2lit.end();
+ ++atomIter){
+ Node n = (*atomIter).first;
+ Lit l = (*atomIter).second;
+
+ lbool lb = d_sat->modelValue(l);
+
+ Notice() << n << "->" << lb.toInt() << endl;
+ }
+ }else{
+ // unsat case
+ Notice() << "Conflict {";
+ for(int i=0; i< d_sat->conflict.size(); i++){
+ Notice() << endl << " ";
+ printLit(Notice(), d_sat->conflict[i]);
+ }
+ Notice() << endl << "}" << endl;
+ }
return Result(result ? Result::SAT : Result::UNSAT);
}