Cryptominisat: Clean up initialization on creation. (#4515)
authorAina Niemetz <aina.niemetz@gmail.com>
Fri, 22 May 2020 16:47:55 +0000 (09:47 -0700)
committerGitHub <noreply@github.com>
Fri, 22 May 2020 16:47:55 +0000 (11:47 -0500)
src/prop/cryptominisat.cpp
src/prop/cryptominisat.h
src/prop/sat_solver_factory.cpp

index 9893f1d6c07b0c0223fcf2079e6d5260b9d1920a..6ad67de042ab5402f7461ad05db70ebd7c82b46a 100644 (file)
@@ -68,6 +68,10 @@ CryptoMinisatSolver::CryptoMinisatSolver(StatisticsRegistry* registry,
       d_numVariables(0),
       d_okay(true),
       d_statistics(registry, name)
+{
+}
+
+void CryptoMinisatSolver::init()
 {
   d_true = newVar();
   d_false = newVar();
@@ -75,12 +79,11 @@ CryptoMinisatSolver::CryptoMinisatSolver(StatisticsRegistry* registry,
   std::vector<CMSat::Lit> clause(1);
   clause[0] = CMSat::Lit(d_true, false);
   d_solver->add_clause(clause);
-  
+
   clause[0] = CMSat::Lit(d_false, true);
   d_solver->add_clause(clause);
 }
 
-
 CryptoMinisatSolver::~CryptoMinisatSolver() {}
 
 ClauseId CryptoMinisatSolver::addXorClause(SatClause& clause,
index d3c5aeb30c5d08baefdfc65e38057ebb270b4ea9..25d6cce02bcf53337dba754105b201f585025db2 100644 (file)
@@ -36,18 +36,11 @@ namespace CMSat {
 namespace CVC4 {
 namespace prop {
 
-class CryptoMinisatSolver : public SatSolver {
+class CryptoMinisatSolver : public SatSolver
+{
+  friend class SatSolverFactory;
 
-private:
-  std::unique_ptr<CMSat::SATSolver> d_solver;
-  proof::ClausalBitVectorProof* d_bvp;
-  unsigned d_numVariables;
-  bool d_okay;
-  SatVariable d_true;
-  SatVariable d_false;
-public:
-  CryptoMinisatSolver(StatisticsRegistry* registry,
-                      const std::string& name = "");
+ public:
   ~CryptoMinisatSolver() override;
 
   ClauseId addClause(SatClause& clause, bool removable) override;
@@ -55,7 +48,9 @@ public:
 
   bool nativeXor() override { return true; }
 
-  SatVariable newVar(bool isTheoryAtom = false, bool preRegister = false, bool canErase = true) override;
+  SatVariable newVar(bool isTheoryAtom = false,
+                     bool preRegister = false,
+                     bool canErase = true) override;
 
   SatVariable trueVar() override;
   SatVariable falseVar() override;
@@ -63,7 +58,7 @@ public:
   void markUnremovable(SatLiteral lit);
 
   void interrupt() override;
-  
+
   SatValue solve() override;
   SatValue solve(long unsigned int&) override;
   SatValue solve(const std::vector<SatLiteral>& assumptions) override;
@@ -75,19 +70,39 @@ public:
   unsigned getAssertionLevel() const override;
   void setClausalProofLog(proof::ClausalBitVectorProof* bvp) override;
 
-  class Statistics {
-  public:
+ private:
+  class Statistics
+  {
+   public:
     StatisticsRegistry* d_registry;
     IntStat d_statCallsToSolve;
     IntStat d_xorClausesAdded;
     IntStat d_clausesAdded;
     TimerStat d_solveTime;
     bool d_registerStats;
-    Statistics(StatisticsRegistry* registry,
-               const std::string& prefix);
+    Statistics(StatisticsRegistry* registry, const std::string& prefix);
     ~Statistics();
   };
 
+  /**
+   * Private to disallow creation outside of SatSolverFactory.
+   * Function init() must be called after creation.
+   */
+  CryptoMinisatSolver(StatisticsRegistry* registry,
+                      const std::string& name = "");
+  /**
+   * Initialize SAT solver instance.
+   * Note: Split out to not call virtual functions in constructor.
+   */
+  void init();
+
+  std::unique_ptr<CMSat::SATSolver> d_solver;
+  proof::ClausalBitVectorProof* d_bvp;
+  unsigned d_numVariables;
+  bool d_okay;
+  SatVariable d_true;
+  SatVariable d_false;
+
   Statistics d_statistics;
 };
 
index 8f18a605584a6307b46ec51b03edfb75baaad374..598ba454386330a45d98dff4733edf7c4d635867 100644 (file)
@@ -43,7 +43,9 @@ SatSolver* SatSolverFactory::createCryptoMinisat(StatisticsRegistry* registry,
                                                  const std::string& name)
 {
 #ifdef CVC4_USE_CRYPTOMINISAT
-  return new CryptoMinisatSolver(registry, name);
+  CryptoMinisatSolver* res = new CryptoMinisatSolver(registry, name);
+  res->init();
+  return res;
 #else
   Unreachable() << "CVC4 was not compiled with Cryptominisat support.";
 #endif