From: Aina Niemetz Date: Fri, 22 May 2020 21:09:54 +0000 (-0700) Subject: CaDiCaL: Clean up initialization on creation. (#4516) X-Git-Tag: cvc5-1.0.0~3297 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=5c8601e638fcbfcd29eceeea4f83a0c1ca578316;p=cvc5.git CaDiCaL: Clean up initialization on creation. (#4516) --- diff --git a/src/prop/cadical.cpp b/src/prop/cadical.cpp index f824f5075..48116912b 100644 --- a/src/prop/cadical.cpp +++ b/src/prop/cadical.cpp @@ -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(); diff --git a/src/prop/cadical.h b/src/prop/cadical.h index 6ab0c2850..1adbfc2d1 100644 --- a/src/prop/cadical.h +++ b/src/prop/cadical.h @@ -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 d_solver; unsigned d_nextVarIdx; diff --git a/src/prop/sat_solver_factory.cpp b/src/prop/sat_solver_factory.cpp index 598ba4543..4a8d616ba 100644 --- a/src/prop/sat_solver_factory.cpp +++ b/src/prop/sat_solver_factory.cpp @@ -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