bool ClingoPropagator::simplify(Solver& s, bool) { if (!s.validVar(aux_.var())) { ClauseDB::size_type i, j, end = db_.size(); LitVec cc; Var last = s.numVars(); aux_ = lit_true(); for (i = j = 0; i != end; ++i) { db_[j++] = db_[i]; ClauseHead* c = db_[i]->clause(); if (c && c->aux()) { cc.clear(); c->toLits(cc); Literal x = *std::max_element(cc.begin(), cc.end()); if (x.var() > last) { c->destroy(&s, true); --j; } else if (aux_ < x) { aux_ = x; } } } db_.erase(db_.begin()+j, db_.end()); } simplifyDB(s, db_, false); return false; }
void Engine::topLevelCleanUp() { trail.clear(); if (so.fd_simplify && propagations >= next_simp_db) simplifyDB(); sat.topLevelCleanUp(); }
void SAT::topLevelCleanUp() { assert(decisionLevel() == 0); for (int i = rtrail[0].size(); i-- > 0; ) free(rtrail[0][i]); rtrail[0].clear(); if (so.sat_simplify && propagations >= next_simp_db) simplifyDB(); for (int i = 0; i < trail[0].size(); i++) { seen[var(trail[0][i])] = true; trailpos[var(trail[0][i])] = -1; } trail[0].clear(); qhead[0] = 0; }
void SAT::topLevelCleanUp() { assert(decisionLevel() == 0); for (int i = rtrail[0].size(); i-- > 0; ) free(rtrail[0][i]); rtrail[0].clear(); if (so.sat_simplify && propagations >= next_simp_db) simplifyDB(); for (int i = 0; i < trail[0].size(); i++) { if (so.debug) { std::cerr << "setting true at top-level: " << getLitString(toInt(trail[0][i])) << "\n"; } seen[var(trail[0][i])] = true; trailpos[var(trail[0][i])] = -1; } trail[0].clear(); qhead[0] = 0; }
//bool Solver::solve(const vec<Lit>& assumps) bool Solver::solve() { simplifyDB(); if (!ok) return false; SearchParams params(0.95, 0.999, 0.02); double nof_conflicts = 100; double nof_learnts = nConstrs() / 3; lbool status = l_Undef; // for (int i = 0; i < assumps.size(); i++) // if (!assume(assumps[i]) || propagate() != NULL){ // propQ.clear(); // cancelUntil(0); // return false; } root_level = decisionLevel; if (verbosity >= 1){ printf("==================================[MINISAT]===================================\n"); printf("| Conflicts | ORIGINAL | LEARNT | Progress |\n"); printf("| | Clauses Literals | Limit Clauses Literals Lit/Cl | |\n"); printf("==============================================================================\n"); } while (status == l_Undef){ if (verbosity >= 1){ printf("| %9d | %7d %8d | %7d %7d %8d %7.1f | %6.3f %% |\n", (int)stats.conflicts, nConstrs(), (int)stats.clauses_literals, (int)nof_learnts, nLearnts(), (int)stats.learnts_literals, (double)stats.learnts_literals/nLearnts(), progress_estimate*100); fflush(stdout); } status = search((int)nof_conflicts, (int)nof_learnts, params); nof_conflicts *= 1.5; nof_learnts *= 1.1; } if (verbosity >= 1) printf("==============================================================================\n"); cancelUntil(0); return status == l_True; }
/*_________________________________________________________________________________________________ | | search : (nof_conflicts : int) (nof_learnts : int) (params : const SearchParams&) -> [lbool] | | Description: | Search for a model the specified number of conflicts, keeping the number of learnt clauses | below the provided limit. NOTE! Use negative value for 'nof_conflicts' or 'nof_learnts' to | indicate infinity. | | Output: | 'l_True' if a partial assigment that is consistent with respect to the clauseset is found. If | all variables are decision variables, this means that the clause set is satisfiable. 'l_False' | if the clause set is unsatisfiable. 'l_Undef' if the bound on number of conflicts is reached. |________________________________________________________________________________________________@*/ lbool Solver::search(int nof_conflicts, int nof_learnts, const SearchParams& params) { if (!ok) return l_False; // GUARD (public method) assert(root_level == decisionLevel); stats.starts++; int conflictC = 0; var_decay = 1 / params.var_decay; cla_decay = 1 / params.clause_decay; model.clear(); for (;;){ Constr* confl = propagate(); if (confl != NULL){ // CONFLICT //if (verbosity >= 2) printf(L_IND"**CONFLICT**\n", L_ind); stats.conflicts++; conflictC++; vec<Lit> learnt_clause; int backtrack_level; if (decisionLevel == root_level) { if (doDeriv) { analyzeFinalDeriv(confl); } return l_False; } Deriv* deriv = new Deriv(); derivs.push_back(deriv); analyze(confl, learnt_clause, backtrack_level, deriv); cancelUntil(max(backtrack_level, root_level)); record(learnt_clause, deriv); varDecayActivity(); claDecayActivity(); }else{ // NO CONFLICT if (nof_conflicts >= 0 && conflictC >= nof_conflicts){ // Reached bound on number of conflicts: progress_estimate = progressEstimate(); propQ.clear(); cancelUntil(root_level); return l_Undef; } if (decisionLevel == 0) // Simplify the set of problem clauses: simplifyDB(), assert(ok); if (nof_learnts >= 0 && learnts.size()-nAssigns() >= nof_learnts) // Reduce the set of learnt clauses: reduceDB(); // New variable decision: stats.decisions++; Var next = order.select(params.random_var_freq); if (next == var_Undef){ // Model found: model.growTo(nVars); for (int i = 0; i < nVars; i++) model[i] = (value(i) == l_True); cancelUntil(root_level); return l_True; } // VERY important for the Y-variables to try positive polarity first // - follows the value ordering heuristic of aiming for solutions (as opposed to fail-first var order) check(assume(Lit(next))); //check(assume(~Lit(next))); } } }
bool simplify(Solver& s, bool) { EnumerationConstraint::simplify(s, false); simplifyDB(s, nogoods, false); return false; }
/*_________________________________________________________________________________________________ | | solve : (assumps : const vec<Lit>&) -> [bool] | | Description: | Top-level solve. If using assumptions (non-empty 'assumps' vector), you must call | 'simplifyDB()' first to see that no top-level conflict is present (which would put the solver | in an undefined state). |________________________________________________________________________________________________@*/ bool Solver::solve(const vec<Lit>& assumps) { simplifyDB(); if (!ok) return false; SearchParams params(default_params); double nof_conflicts = 100; double nof_learnts = nClauses() / 3; lbool status = l_Undef; // Perform assumptions: root_level = assumps.size(); for (int i = 0; i < assumps.size(); i++){ Lit p = assumps[i]; assert(var(p) < nVars()); if (!assume(p)){ GClause r = reason[var(p)]; if (r != GClause_NULL){ Clause* confl; if (r.isLit()){ confl = propagate_tmpbin; (*confl)[1] = ~p; (*confl)[0] = r.lit(); }else confl = r.clause(); analyzeFinal(confl, true); conflict.push(~p); }else conflict.clear(), conflict.push(~p); cancelUntil(0); return false; } Clause* confl = propagate(); if (confl != NULL){ analyzeFinal(confl), assert(conflict.size() > 0); cancelUntil(0); return false; } } assert(root_level == decisionLevel()); // Search: if (verbosity >= 1){ reportf("==================================[MINISAT]===================================\n", NULL); reportf("| Conflicts | ORIGINAL | LEARNT | Progress |\n", NULL); reportf("| | Clauses Literals | Limit Clauses Literals Lit/Cl | |\n", NULL); reportf("==============================================================================\n", NULL); } while (status == l_Undef){ if (verbosity >= 1) reportf("| %9d | %7d %8d | %7d %7d %8d %7.1f | %6.3f %% |\n", (int)stats.conflicts, nClauses(), (int)stats.clauses_literals, (int)nof_learnts, nLearnts(), (int)stats.learnts_literals, (double)stats.learnts_literals/nLearnts(), progress_estimate*100); status = search((int)nof_conflicts, (int)nof_learnts, params); nof_conflicts *= 1.5; nof_learnts *= 1.1; } if (verbosity >= 1) reportf("==============================================================================\n", NULL); cancelUntil(0); return status == l_True; }
/*_________________________________________________________________________________________________ | | search : (nof_conflicts : int) (nof_learnts : int) (params : const SearchParams&) -> [lbool] | | Description: | Search for a model the specified number of conflicts, keeping the number of learnt clauses | below the provided limit. NOTE! Use negative value for 'nof_conflicts' or 'nof_learnts' to | indicate infinity. | | Output: | 'l_True' if a partial assigment that is consistent with respect to the clauseset is found. If | all variables are decision variables, this means that the clause set is satisfiable. 'l_False' | if the clause set is unsatisfiable. 'l_Undef' if the bound on number of conflicts is reached. |________________________________________________________________________________________________@*/ lbool Solver::search(int nof_conflicts, int nof_learnts, const SearchParams& params) { if (!ok) return l_False; // GUARD (public method) assert(root_level == decisionLevel()); stats.starts++; int conflictC = 0; var_decay = 1 / params.var_decay; cla_decay = 1 / params.clause_decay; model.clear(); for (;;){ Clause* confl = propagate(); if (confl != NULL){ // CONFLICT stats.conflicts++; conflictC++; vec<Lit> learnt_clause; int backtrack_level; if (decisionLevel() == root_level){ // Contradiction found: analyzeFinal(confl); return l_False; } analyze(confl, learnt_clause, backtrack_level); cancelUntil(max(backtrack_level, root_level)); newClause(learnt_clause, true); if (learnt_clause.size() == 1) level[var(learnt_clause[0])] = 0; // (this is ugly (but needed for 'analyzeFinal()') -- in future versions, we will backtrack past the 'root_level' and redo the assumptions) varDecayActivity(); claDecayActivity(); }else{ // NO CONFLICT if (nof_conflicts >= 0 && conflictC >= nof_conflicts){ // Reached bound on number of conflicts: progress_estimate = progressEstimate(); cancelUntil(root_level); return l_Undef; } if (decisionLevel() == 0) // Simplify the set of problem clauses: simplifyDB(), assert(ok); if (nof_learnts >= 0 && learnts.size()-nAssigns() >= nof_learnts) // Reduce the set of learnt clauses: reduceDB(); // New variable decision: stats.decisions++; Var next = order.select(params.random_var_freq); if (next == var_Undef){ // Model found: model.growTo(nVars()); for (int i = 0; i < nVars(); i++) model[i] = value(i); cancelUntil(root_level); return l_True; } check(assume(~Lit(next))); } } }