void context::display_watch_lists(std::ostream & out) const { unsigned s = m_watches.size(); for (unsigned l_idx = 0; l_idx < s; l_idx++) { literal l = to_literal(l_idx); display_watch_list(out, l); out << "\n"; } }
static void tst2() { ptr_vector<clause> clause_list; vector<literal> lit_list; watch_list wl; unsigned n = rand()%1000; for (unsigned i = 0; i < n; i++) { unsigned op = rand()%7; if (op <= 1) { clause * c = reinterpret_cast<clause*>(static_cast<size_t>(rand())); wl.insert_clause(c); clause_list.push_back(c); } else if (op <= 3) { literal l = to_literal(rand()); wl.insert_literal(l); lit_list.push_back(l); } else if (op <= 4) { if (!clause_list.empty()) { int idx = rand() % (clause_list.size()); clause * c = clause_list[idx]; wl.remove_clause(c); ptr_vector<clause>::iterator it = std::find(clause_list.begin(), clause_list.end(), c); SASSERT(it); clause_list.erase(it); } } else if (op <= 5) { ptr_vector<clause>::iterator it = clause_list.begin(); ptr_vector<clause>::iterator end = clause_list.end(); watch_list::clause_iterator it2 = wl.begin_clause(); watch_list::clause_iterator end2 = wl.end_clause(); for (; it != end; ++it, ++it2) { SASSERT(it2 != end2); SASSERT(*it == *it2); } } else if (op <= 6) { vector<literal>::iterator begin = lit_list.begin(); vector<literal>::iterator it = lit_list.end(); watch_list::literal_iterator it2 = wl.begin_literals(); watch_list::literal_iterator end2 = wl.end_literals(); while (it != begin) { --it; SASSERT(it2 != end2); SASSERT(*it == *it2); ++it2; } } } }
/** - Delete watch lists of assigned literals. - Delete satisfied binary watched binary clauses - Delete watched clauses (they will be reinserted after they are cleaned). */ void cleaner::cleanup_watches() { vector<watch_list>::iterator it = s.m_watches.begin(); vector<watch_list>::iterator end = s.m_watches.end(); unsigned l_idx = 0; for (; it != end; ++it, ++l_idx) { if (s.value(to_literal(l_idx)) != l_undef) { it->finalize(); SASSERT(it->empty()); continue; } TRACE("cleanup_bug", tout << "processing wlist of " << to_literal(l_idx) << "\n";); watch_list & wlist = *it; watch_list::iterator it2 = wlist.begin(); watch_list::iterator it_prev = it2; watch_list::iterator end2 = wlist.end(); for (; it2 != end2; ++it2) { switch (it2->get_kind()) { case watched::BINARY: SASSERT(s.value(it2->get_literal()) == l_true || s.value(it2->get_literal()) == l_undef); if (s.value(it2->get_literal()) == l_undef) { *it_prev = *it2; ++it_prev; } TRACE("cleanup_bug", tout << "keeping: " << ~to_literal(l_idx) << " " << it2->get_literal() << "\n";); break; case watched::TERNARY: case watched::CLAUSE: // skip break; case watched::EXT_CONSTRAINT: *it_prev = *it2; ++it_prev; break; default: UNREACHABLE(); break; } }
void context::display_literal_num_occs(std::ostream & out) const { unsigned num_lits = m_assignment.size(); unsigned_vector lit2num_occs; lit2num_occs.resize(num_lits, 0); acc_num_occs(m_aux_clauses, lit2num_occs); acc_num_occs(m_lemmas, lit2num_occs); for (unsigned lidx = 0; lidx < num_lits; lidx++) { literal l = to_literal(lidx); if (lit2num_occs[lidx] > 0) { out << lit2num_occs[lidx] << " "; // display_literal(out, l); out << l.sign() << " " << mk_pp(bool_var2expr(l.var()), m_manager); out << "\n"; } } }
void compiler::compile_literal(const std::string& token) { if ( islabel_ref(token) ) { compile_label(token.substr(1)); return; } int32_t literal = to_literal(token); // Literals are pushed on to the stack if ( literal != -1 ) { m.load(PUSH); m.load(literal); return; } // Unknown literals are treated as forward function calls compile_function_call(token); }
void context::display_binary_clauses(std::ostream & out) const { bool first = true; unsigned l_idx = 0; for (watch_list const& wl : m_watches) { literal l1 = to_literal(l_idx++); literal neg_l1 = ~l1; literal const * it2 = wl.begin_literals(); literal const * end2 = wl.end_literals(); for (; it2 != end2; ++it2) { literal l2 = *it2; if (l1.index() < l2.index()) { if (first) { out << "binary clauses:\n"; first = false; } out << "(clause "; display_literal(out, neg_l1); out << " "; display_literal(out, l2); out << ")\n"; } } } }