void SAT::cEnqueue(Lit p, Reason r) { assert(value(p) != l_True); int v = var(p); if (value(p) == l_False) { if (so.lazy) { if (r == NULL) { assert(decisionLevel() == 0); setConfl(); } else { confl = getConfl(r, p); (*confl)[0] = p; } } else setConfl(); return; } assigns [v] = toInt(lbool(!sign(p))); trailpos[v] = engine.trailPos(); reason [v] = r; trail.last().push(p); }
void SAT::cEnqueue(Lit p, Reason r) { /* if (so.debug) { */ /* std::cerr << "c-enqueue literal " << getLitString(toInt(p)) << " because " << showReason(r) << "\n"; */ /* } */ assert(value(p) != l_True); int v = var(p); if (value(p) == l_False) { if (so.lazy) { if (r == NULL) { assert(decisionLevel() == 0); setConfl(); } else { confl = getConfl(r, p); (*confl)[0] = p; } } else setConfl(); return; } assigns [v] = toInt(lbool(!sign(p))); trailpos[v] = engine.trailPos(); reason [v] = r; trail.last().push(p); }
bool SAT::propagate() { int num_props = 0; int& qhead = this->qhead.last(); vec<Lit>& trail = this->trail.last(); while (qhead < trail.size()) { num_props++; Lit p = trail[qhead++]; // 'p' is enqueued fact to propagate. vec<WatchElem>& ws = watches[toInt(p)]; if (ws.size() == 0) continue; WatchElem *i, *j, *end; for (i = j = ws, end = i + ws.size(); i != end; ) { WatchElem& we = *i; switch (we.d.type) { case 1: { // absorbed binary clause *j++ = *i++; Lit q = toLit(we.d.d2); switch (toInt(value(q))) { case 0: enqueue(q, ~p); break; case -1: setConfl(q, ~p); qhead = trail.size(); while (i < end) *j++ = *i++; break; default:; } continue; } case 2: { // wake up FD propagator *j++ = *i++; engine.propagators[we.d.d2]->wakeup(we.d.d1, 0); continue; } default: Clause& c = *we.pt; i++; // Check if already satisfied if (value(c[0]) == l_True || value(c[1]) == l_True) { *j++ = &c; continue; } Lit false_lit = ~p; // Make sure the false literal is data[1]: if (c[0] == false_lit) c[0] = c[1], c[1] = false_lit; // Look for new watch: for (int k = 2; k < c.size(); k++) if (value(c[k]) != l_False) { c[1] = c[k]; c[k] = false_lit; watches[toInt(~c[1])].push(&c); goto FoundWatch; } // Did not find watch -- clause is unit under assignment: *j++ = &c; if (value(c[0]) == l_False) { confl = &c; qhead = trail.size(); while (i < end) *j++ = *i++; } else { enqueue(c[0], &c); } FoundWatch:; } } ws.shrink(i-j); } propagations += num_props; return (confl == NULL); }