CaDiCaL: Clean up initialization on creation. (#4516)
authorAina Niemetz <aina.niemetz@gmail.com>
Fri, 22 May 2020 21:09:54 +0000 (14:09 -0700)
committerGitHub <noreply@github.com>
Fri, 22 May 2020 21:09:54 +0000 (16:09 -0500)
src/prop/cadical.cpp
src/prop/cadical.h
src/prop/sat_solver_factory.cpp

index f824f50751883b610e2f5cebc8c4920d22d63fcc..48116912b804c3657355d640da9bd24d87b40ea4 100644 (file)
@@ -63,6 +63,10 @@ CadicalSolver::CadicalSolver(StatisticsRegistry* registry,
       //       literals are represented as the negation of the index.
       d_nextVarIdx(1),
       d_statistics(registry, name)
+{
+}
+
+void CadicalSolver::init()
 {
   d_true = newVar();
   d_false = newVar();
index 6ab0c2850012f00c8b03c08f8d08a3bcd1dc3ab7..1adbfc2d1713c4658297e658530e955a39093461 100644 (file)
@@ -30,9 +30,9 @@ namespace prop {
 
 class CadicalSolver : public SatSolver
 {
- public:
-  CadicalSolver(StatisticsRegistry* registry, const std::string& name = "");
+  friend class SatSolverFactory;
 
+ public:
   ~CadicalSolver() override;
 
   ClauseId addClause(SatClause& clause, bool removable) override;
@@ -62,6 +62,17 @@ class CadicalSolver : public SatSolver
   bool ok() const override;
 
  private:
+  /**
+   * Private to disallow creation outside of SatSolverFactory.
+   * Function init() must be called after creation.
+   */
+  CadicalSolver(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<CaDiCaL::Solver> d_solver;
 
   unsigned d_nextVarIdx;
index 598ba454386330a45d98dff4733edf7c4d635867..4a8d616ba338c5b4da928a29bdf324ac43a5503b 100644 (file)
@@ -55,7 +55,9 @@ SatSolver* SatSolverFactory::createCadical(StatisticsRegistry* registry,
                                            const std::string& name)
 {
 #ifdef CVC4_USE_CADICAL
-  return new CadicalSolver(registry, name);
+  CadicalSolver* res = new CadicalSolver(registry, name);
+  res->init();
+  return res;
 #else
   Unreachable() << "CVC4 was not compiled with CaDiCaL support.";
 #endif