Unsat core printing.
authorMorgan Deters <mdeters@cs.nyu.edu>
Sat, 23 Aug 2014 05:50:02 +0000 (01:50 -0400)
committerMorgan Deters <mdeters@cs.nyu.edu>
Sat, 23 Aug 2014 05:50:02 +0000 (01:50 -0400)
src/main/command_executor.cpp
src/main/command_executor_portfolio.cpp
src/printer/printer.cpp
src/printer/printer.h
src/printer/smt2/smt2_printer.cpp
src/printer/smt2/smt2_printer.h
src/smt/smt_engine.cpp
src/util/unsat_core.cpp
src/util/unsat_core.h

index 8f51c6d0d9ddc296deb4cb9317625169c555249b..950728fabdcca3e1053dfaf6a6c6569bc2c8cfc0 100644 (file)
@@ -119,9 +119,9 @@ bool CommandExecutor::doCommandSingleton(Command* cmd)
     d_lastStatistics = ossCurStats.str();
   }
 
-  // dump the model/proof if option is set
+  // dump the model/proof/unsat core if option is set
   if(status) {
-    Command * g = NULL;
+    Command* g = NULL;
     if( d_options[options::produceModels] &&
         d_options[options::dumpModels] &&
         ( res.asSatisfiabilityResult() == Result::SAT ||
@@ -138,8 +138,8 @@ bool CommandExecutor::doCommandSingleton(Command* cmd)
                res.asSatisfiabilityResult() == Result::UNSAT ) {
       g = new GetUnsatCoreCommand();
     }
-    if( g ){
-      //set no time limit during dumping if applicable
+    if(g != NULL) {
+      // set no time limit during dumping if applicable
       if( d_options[options::forceNoLimitCpuWhileDump] ){
         setNoLimitCPU();
       }
index 4c3c7b6bd4e03c5b00726303d4249ae222666ccd..8af0c452aaafca58fe44d04095f9aec1da11bec1 100644 (file)
@@ -357,7 +357,7 @@ bool CommandExecutorPortfolio::doCommandSingleton(Command* cmd)
 
     bool status = portfolioReturn.second;
 
-    // dump the model/proof if option is set
+    // dump the model/proof/unsat core if option is set
     if(status) {
       if( d_options[options::produceModels] &&
           d_options[options::dumpModels] &&
index 8f0f50daa08df3d41a6cfe97b5ca84f9047c9679..7a90f5a498363e5306187426d169e93cd9f728b2 100644 (file)
@@ -153,4 +153,11 @@ void Printer::toStream(std::ostream& out, const Model& m) const throw() {
   }
 }/* Printer::toStream(Model) */
 
+void Printer::toStream(std::ostream& out, const UnsatCore& core) const throw() {
+  for(UnsatCore::iterator i = core.begin(); i != core.end(); ++i) {
+    toStream(out, Node::fromExpr(*i), -1, false, -1);
+    out << std::endl;
+  }
+}/* Printer::toStream(UnsatCore) */
+
 }/* CVC4 namespace */
index beb2438e2b0251510efa5dd1ac4c0e00a0124378..9a9ee19d1dd2e062b63c9d11e533193eec77773d 100644 (file)
@@ -103,6 +103,9 @@ public:
   /** Write a Model out to a stream with this Printer. */
   virtual void toStream(std::ostream& out, const Model& m) const throw();
 
+  /** Write an UnsatCore out to a stream with this Printer. */
+  virtual void toStream(std::ostream& out, const UnsatCore& core) const throw();
+
 };/* class Printer */
 
 /**
index 766db729a80f122fcbc3d7a064705ccb60d2c093..543079576236b22b1f5eb612b09525ccfc6defdc 100644 (file)
@@ -771,6 +771,13 @@ void Smt2Printer::toStream(std::ostream& out, const CommandStatus* s) const thro
 }/* Smt2Printer::toStream(CommandStatus*) */
 
 
+void Smt2Printer::toStream(std::ostream& out, const UnsatCore& core) const throw() {
+  out << "(" << endl;
+  this->Printer::toStream(out, core);
+  out << ")" << endl;
+}
+
+
 void Smt2Printer::toStream(std::ostream& out, const Model& m) const throw() {
   out << "(model" << endl;
   this->Printer::toStream(out, m);
index e86b3cb2b53034071037914a504b0a97e6d6b5a3..e825d3f4c65dad5b180a524061b63ed751216304 100644 (file)
@@ -37,7 +37,6 @@ class Smt2Printer : public CVC4::Printer {
 
   void toStream(std::ostream& out, TNode n, int toDepth, bool types) const throw();
   void toStream(std::ostream& out, const Model& m, const Command* c) const throw();
-  void toStream(std::ostream& out, const Model& m) const throw();
 public:
   Smt2Printer(Variant variant = no_variant) : d_variant(variant) { }
   using CVC4::Printer::toStream;
@@ -46,6 +45,8 @@ public:
   void toStream(std::ostream& out, const CommandStatus* s) const throw();
   void toStream(std::ostream& out, const Result& r) const throw();
   void toStream(std::ostream& out, const SExpr& sexpr) const throw();
+  void toStream(std::ostream& out, const Model& m) const throw();
+  void toStream(std::ostream& out, const UnsatCore& core) const throw();
 };/* class Smt2Printer */
 
 }/* CVC4::printer::smt2 namespace */
index 90caa1fb18b411c0c5d2a5049c25ef69ee9933b0..98ae6d3ce402a71c3e19099e91666acc09cd8ef1 100644 (file)
@@ -3969,7 +3969,7 @@ UnsatCore SmtEngine::getUnsatCore() throw(ModalException) {
   }
 
   d_proofManager->getProof(this);// just to trigger core creation
-  return UnsatCore(d_proofManager->begin_unsat_core(), d_proofManager->end_unsat_core());
+  return UnsatCore(this, d_proofManager->begin_unsat_core(), d_proofManager->end_unsat_core());
 #else /* CVC4_PROOF */
   throw ModalException("This build of CVC4 doesn't have proof support (required for unsat cores).");
 #endif /* CVC4_PROOF */
index 27261635de762bc182cb87467d8a1b13063b14ec..6344b3eda8889132474e153ba3cfb8d901a59315 100644 (file)
@@ -16,6 +16,8 @@
 
 #include "util/unsat_core.h"
 #include "expr/command.h"
+#include "smt/smt_engine_scope.h"
+#include "printer/printer.h"
 
 namespace CVC4 {
 
@@ -34,7 +36,9 @@ void UnsatCore::toStream(std::ostream& out) const {
 }
 
 std::ostream& operator<<(std::ostream& out, const UnsatCore& core) {
-  core.toStream(out);
+  smt::SmtScope smts(core.d_smt);
+  Expr::dag::Scope scope(out, false);
+  Printer::getPrinter(options::outputLanguage())->toStream(out, core);
   return out;
 }
 
index 51724b33be8b47c5c2f0c5a6943277b4fd97a20c..c67a6e4489056aacb28a8019c54a60f5da1942cc 100644 (file)
 
 namespace CVC4 {
 
+class SmtEngine;
+class UnsatCore;
+
+std::ostream& operator<<(std::ostream& out, const UnsatCore& core) CVC4_PUBLIC;
+
 class CVC4_PUBLIC UnsatCore {
+  friend std::ostream& operator<<(std::ostream&, const UnsatCore&);
+
+  /** The SmtEngine we're associated with */
+  SmtEngine* d_smt;
+
   std::vector<Expr> d_core;
 
 public:
-  UnsatCore() {}
+  UnsatCore() : d_smt(NULL) {}
 
   template <class T>
-  UnsatCore(T begin, T end) : d_core(begin, end) {}
+  UnsatCore(SmtEngine* smt, T begin, T end) : d_smt(smt), d_core(begin, end) {}
 
   ~UnsatCore() {}
 
+  /** get the smt engine that this unsat core is hooked up to */
+  SmtEngine* getSmtEngine() { return d_smt; }
+
   typedef std::vector<Expr>::const_iterator iterator;
   typedef std::vector<Expr>::const_iterator const_iterator;
 
@@ -47,8 +60,6 @@ public:
 
 };/* class UnsatCore */
 
-std::ostream& operator<<(std::ostream& out, const UnsatCore& core) CVC4_PUBLIC;
-
 }/* CVC4 namespace */
 
 #endif /* __CVC4__UNSAT_CORE_H */