static lbool core_chunking(sat::solver& s, sat::bool_var_vector& vars, sat::literal_vector const& asms, vector<sat::literal_vector>& conseq, unsigned K) { lbool r = s.check(asms.size(), asms.c_ptr()); if (r != l_true) { return r; } sat::model const & m = s.get_model(); sat::literal_vector lambda, backbones; for (unsigned i = 0; i < vars.size(); i++) { lambda.push_back(sat::literal(vars[i], m[vars[i]] == l_false)); } while (!lambda.empty()) { IF_VERBOSE(1, verbose_stream() << "(sat-backbone-core " << lambda.size() << " " << backbones.size() << ")\n";); unsigned k = std::min(K, lambda.size()); sat::literal_vector gamma, omegaN; for (unsigned i = 0; i < k; ++i) { sat::literal l = lambda[lambda.size() - i - 1]; gamma.push_back(l); omegaN.push_back(~l); } while (true) { sat::literal_vector asms1(asms); asms1.append(omegaN); r = s.check(asms1.size(), asms1.c_ptr()); if (r == l_true) { IF_VERBOSE(1, verbose_stream() << "(sat) " << omegaN << "\n";); prune_unfixed(lambda, s.get_model()); break; }
static void prune_unfixed(sat::literal_vector& lambda, sat::model const& m) { for (unsigned i = 0; i < lambda.size(); ++i) { if ((m[lambda[i].var()] == l_false) != lambda[i].sign()) { lambda[i] = lambda.back(); lambda.pop_back(); --i; } } }
static void track_clause(sat::solver& dst, sat::literal_vector& lits, sat::literal_vector& assumptions, vector<sat::literal_vector>& tracking_clauses) { sat::literal lit = sat::literal(dst.mk_var(true, false), false); tracking_clauses.set(lit.var(), lits); lits.push_back(~lit); dst.mk_clause(lits.size(), lits.c_ptr()); assumptions.push_back(lit); }
static void brute_force_consequences(sat::solver& s, sat::literal_vector const& asms, sat::literal_vector const& gamma, sat::literal_vector& backbones) { for (unsigned i = 0; i < gamma.size(); ++i) { sat::literal nlit = ~gamma[i]; sat::literal_vector asms1(asms); asms1.push_back(nlit); lbool r = s.check(asms1.size(), asms1.c_ptr()); if (r == l_false) { backbones.push_back(gamma[i]); } } }
static void back_remove(sat::literal_vector& lits, sat::literal l) { for (unsigned i = lits.size(); i > 0; ) { --i; if (lits[i] == l) { lits[i] = lits.back(); lits.pop_back(); return; } } std::cout << "UNREACHABLE\n"; }
void read_clause(Buffer & in, std::ostream& err, sat::solver & solver, sat::literal_vector & lits) { int parsed_lit; int var; lits.reset(); while (true) { parsed_lit = parse_int(in, err); if (parsed_lit == 0) break; var = abs(parsed_lit); SASSERT(var > 0); while (static_cast<unsigned>(var) >= solver.num_vars()) solver.mk_var(); lits.push_back(sat::literal(var, parsed_lit < 0)); } }