#ifdef CVC5_USE_CRYPTOMINISAT
+#include <cryptominisat5/cryptominisat.h>
+
#include "base/check.h"
+#include "util/resource_manager.h"
#include "util/statistics_registry.h"
-#include <cryptominisat5/cryptominisat.h>
-
namespace cvc5 {
namespace prop {
: d_solver(new CMSat::SATSolver()),
d_numVariables(0),
d_okay(true),
- d_statistics(registry, name)
+ d_statistics(registry, name),
+ d_resmgr(nullptr)
{
}
CryptoMinisatSolver::~CryptoMinisatSolver() {}
+void CryptoMinisatSolver::setTimeLimit(ResourceManager* resmgr)
+{
+ d_resmgr = resmgr;
+}
+
+void CryptoMinisatSolver::setMaxTime()
+{
+ if (d_resmgr)
+ {
+ // Set time limit to remaining number of seconds.
+ d_solver->set_max_time(d_resmgr->getRemainingTime() / 1000.0);
+ }
+}
+
ClauseId CryptoMinisatSolver::addXorClause(SatClause& clause,
bool rhs,
bool removable)
SatValue CryptoMinisatSolver::solve(){
TimerStat::CodeTimer codeTimer(d_statistics.d_solveTime);
++d_statistics.d_statCallsToSolve;
+ setMaxTime();
return toSatLiteralValue(d_solver->solve());
}
assumpts.push_back(toInternalLit(lit));
}
++d_statistics.d_statCallsToSolve;
+ setMaxTime();
return toSatLiteralValue(d_solver->solve(&assumpts));
}
*/
void init();
+ /**
+ * Set time limit per solve() call.
+ */
+ void setTimeLimit(ResourceManager* resmgr);
+
+ /**
+ * Set CryptoMiniSat's maximum time limit based on the already elapsed time
+ * of the --tlimit-per limit.
+ */
+ void setMaxTime();
+
std::unique_ptr<CMSat::SATSolver> d_solver;
unsigned d_numVariables;
bool d_okay;
SatVariable d_false;
Statistics d_statistics;
+ ResourceManager* d_resmgr;
};
} // namespace prop
}
SatSolver* SatSolverFactory::createCryptoMinisat(StatisticsRegistry& registry,
+ ResourceManager* resmgr,
const std::string& name)
{
#ifdef CVC5_USE_CRYPTOMINISAT
CryptoMinisatSolver* res = new CryptoMinisatSolver(registry, name);
res->init();
+ if (resmgr->limitOn())
+ {
+ res->setTimeLimit(resmgr);
+ }
return res;
#else
Unreachable() << "cvc5 was not compiled with Cryptominisat support.";
StatisticsRegistry& registry);
static SatSolver* createCryptoMinisat(StatisticsRegistry& registry,
+ ResourceManager* resmgr,
const std::string& name = "");
static SatSolver* createCadical(StatisticsRegistry& registry,
{
case options::SatSolverMode::CRYPTOMINISAT:
d_satSolver.reset(prop::SatSolverFactory::createCryptoMinisat(
- smtStatisticsRegistry(), "theory::bv::BVSolverBitblast::"));
+ smtStatisticsRegistry(),
+ d_env.getResourceManager(),
+ "theory::bv::BVSolverBitblast::"));
break;
default:
d_satSolver.reset(prop::SatSolverFactory::createCadical(
uint64_t ResourceManager::getTimeUsage() const { return d_cumulativeTimeUsed; }
+uint64_t ResourceManager::getRemainingTime() const
+{
+ return d_options.base.perCallMillisecondLimit - d_perCallTimer.elapsed();
+}
+
uint64_t ResourceManager::getResourceRemaining() const
{
if (d_options.base.cumulativeResourceLimit <= d_cumulativeResourceUsed)
uint64_t getResourceUsage() const;
/** Retrieves time used over all calls. */
uint64_t getTimeUsage() const;
+ /** Retrieves the remaining time until the time limit is reached. */
+ uint64_t getRemainingTime() const;
/** Retrieves the remaining number of cumulative resources. */
uint64_t getResourceRemaining() const;