22 #include <minisat/core/Solver.h>
23 #include <minisat/simp/SimpSolver.h>
26 #error "Expected HAVE_MINISAT2"
29 void convert(
const bvt &bv, Minisat::vec<Minisat::Lit> &dest)
32 bv.size() <=
static_cast<std::size_t
>(std::numeric_limits<int>::max()));
33 dest.capacity(
static_cast<int>(bv.size()));
35 for(
const auto &literal : bv)
37 if(!literal.is_false())
38 dest.push(Minisat::mkLit(literal.var_no(), literal.sign()));
80 solver->setPolarity(a.
var_no(), value ? l_True : l_False);
82 catch(Minisat::OutOfMemoryException)
84 log.error() <<
"SAT checker ran out of memory" <<
messaget::eom;
85 status = statust::ERROR;
86 throw std::bad_alloc();
104 return "MiniSAT 2.2.1 without simplifier";
109 return "MiniSAT 2.2.1 with simplifier";
115 while((
unsigned)
solver->nVars()<no_variables())
126 for(
const auto &literal : bv)
128 if(literal.is_true())
130 else if(!literal.is_false())
133 literal.var_no() < (
unsigned)
solver->nVars(),
134 "variable not added yet");
138 Minisat::vec<Minisat::Lit> c;
155 static size_t cnf_clause_index = 0;
157 bool clause_removed = process_clause(bv, cnf);
162 solver_hardness->register_clause(
163 bv, cnf, cnf_clause_index, !clause_removed);
168 catch(
const Minisat::OutOfMemoryException &)
170 log.error() <<
"SAT checker ran out of memory" <<
messaget::eom;
171 status = statust::ERROR;
172 throw std::bad_alloc();
188 template <
typename T>
193 log.statistics() << (no_variables() - 1) <<
" variables, "
202 log.status() <<
"SAT checker inconsistent: instance is UNSATISFIABLE"
204 status = statust::UNSAT;
205 return resultt::P_UNSATISFIABLE;
209 for(
const auto &assumption : assumptions)
211 if(assumption.is_false())
213 log.status() <<
"got FALSE as assumption: instance is UNSATISFIABLE"
215 status = statust::UNSAT;
216 return resultt::P_UNSATISFIABLE;
220 Minisat::vec<Minisat::Lit> solver_assumptions;
221 convert(assumptions, solver_assumptions);
223 using Minisat::lbool;
227 void (*old_handler)(int) = SIG_ERR;
229 if(time_limit_seconds != 0)
233 if(old_handler == SIG_ERR)
234 log.warning() <<
"Failed to set solver time limit" <<
messaget::eom;
236 alarm(time_limit_seconds);
239 lbool solver_result =
solver->solveLimited(solver_assumptions);
241 if(old_handler != SIG_ERR)
244 signal(SIGALRM, old_handler);
250 if(time_limit_seconds != 0)
252 log.warning() <<
"Time limit ignored (not supported on Win32 yet)"
256 lbool solver_result =
solver->solve(solver_assumptions) ? l_True : l_False;
260 if(solver_result == l_True)
262 log.status() <<
"SAT checker: instance is SATISFIABLE" <<
messaget::eom;
264 status = statust::SAT;
265 return resultt::P_SATISFIABLE;
268 if(solver_result == l_False)
270 log.status() <<
"SAT checker: instance is UNSATISFIABLE" <<
messaget::eom;
271 status = statust::UNSAT;
272 return resultt::P_UNSATISFIABLE;
275 log.status() <<
"SAT checker: timed out or other error" <<
messaget::eom;
276 status = statust::ERROR;
277 return resultt::P_ERROR;
279 catch(
const Minisat::OutOfMemoryException &)
281 log.error() <<
"SAT checker ran out of memory" <<
messaget::eom;
282 status=statust::ERROR;
283 return resultt::P_ERROR;
295 bool sign = a.
sign();
298 solver->model.growTo(v + 1);
300 solver->model[v] = Minisat::lbool(value);
302 catch(
const Minisat::OutOfMemoryException &)
304 log.error() <<
"SAT checker ran out of memory" <<
messaget::eom;
305 status = statust::ERROR;
306 throw std::bad_alloc();
310 template <
typename T>
315 time_limit_seconds(0)
319 template <
typename T>
327 for(
int i=0; i<
solver->conflict.size(); i++)
328 if(var(
solver->conflict[i])==v)
340 for(
const auto &assumption : bv)
342 if(!assumption.is_true())
344 assumptions.push_back(assumption);
362 catch(
const Minisat::OutOfMemoryException &)
366 throw std::bad_alloc();