This commit adds --tlimit-per support for CaDiCaL via CaDiCaL's Terminator class.
Fixes #8049
#include "prop/cadical.h"
#include "base/check.h"
+#include "util/resource_manager.h"
#include "util/statistics_registry.h"
namespace cvc5 {
CadicalSolver::~CadicalSolver() {}
+/**
+ * Terminator class that notifies CaDiCaL to terminate when time limit is
+ * reached (used for time limits specified via --tlimit-per).
+ */
+class TimeLimitTerminator : public CaDiCaL::Terminator
+{
+ public:
+ TimeLimitTerminator(ResourceManager& resmgr) : d_resmgr(resmgr){};
+
+ bool terminate() override { return d_resmgr.outOfTime(); }
+
+ private:
+ ResourceManager& d_resmgr;
+};
+
+void CadicalSolver::setTimeLimit(ResourceManager* resmgr)
+{
+ d_terminator.reset(new TimeLimitTerminator(*resmgr));
+ d_solver->connect_terminator(d_terminator.get());
+}
+
ClauseId CadicalSolver::addClause(SatClause& clause, bool removable)
{
for (const SatLiteral& lit : clause)
*/
void init();
+ /**
+ * Set time limit per solve() call.
+ */
+ void setTimeLimit(ResourceManager* resmgr);
+
std::unique_ptr<CaDiCaL::Solver> d_solver;
+ std::unique_ptr<CaDiCaL::Terminator> d_terminator;
+
/**
* Stores the current set of assumptions provided via solve() and is used to
* query the solver if a given assumption is false.
}
SatSolver* SatSolverFactory::createCadical(StatisticsRegistry& registry,
+ ResourceManager* resmgr,
const std::string& name)
{
CadicalSolver* res = new CadicalSolver(registry, name);
res->init();
+ if (resmgr->limitOn())
+ {
+ res->setTimeLimit(resmgr);
+ }
return res;
}
const std::string& name = "");
static SatSolver* createCadical(StatisticsRegistry& registry,
+ ResourceManager* resmgr,
const std::string& name = "");
static SatSolver* createKissat(StatisticsRegistry& registry,
break;
default:
d_satSolver.reset(prop::SatSolverFactory::createCadical(
- smtStatisticsRegistry(), "theory::bv::BVSolverBitblast::"));
+ smtStatisticsRegistry(),
+ d_env.getResourceManager(),
+ "theory::bv::BVSolverBitblast::"));
}
d_cnfStream.reset(new prop::CnfStream(d_satSolver.get(),
d_bbRegistrar.get(),