3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-05-13 02:34:43 +00:00

Polysat: use constraint_literal and begin move to core-based conflict representation (#5489)

* Rename solver_scope for fixplex tests

(otherwise the wrong constructor is called for polysat's solver_scope)

* Update conflict_core

* simplify

* Be clearer about constraint_literal lifetime

* remove old comment

* Remove status (positive/negative) from constraint

* Use constraint_literal in the solver

* Fix build (constraint -> get_constraint)
This commit is contained in:
Jakob Rath 2021-08-18 20:02:46 +02:00 committed by GitHub
parent 30e9f24fa3
commit ebaea2159e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 933 additions and 1004 deletions

View file

@ -22,8 +22,8 @@ namespace polysat {
struct fi_record {
eval_interval interval;
constraint_literal neg_cond; // could be multiple constraints later
constraint* src;
constraint_literal_ref neg_cond; // could be multiple constraints later
constraint_literal src;
};
/**
@ -64,24 +64,20 @@ namespace polysat {
return true;
}
bool forbidden_intervals::explain(solver& s, constraint_ref_vector const& conflict, pvar v, clause_ref& out_lemma) {
bool forbidden_intervals::explain(solver& s, vector<constraint_literal> const& conflict, pvar v, clause_ref& out_lemma) {
// Extract forbidden intervals from conflicting constraints
vector<fi_record> records;
bool has_full = false;
rational longest_len;
unsigned longest_i = UINT_MAX;
for (constraint* c : conflict) {
LOG_H3("Computing forbidden interval for: " << *c);
if (c->is_undef()) {
LOG("TODO: undef constraint in conflict... what does this mean???");
continue;
}
for (constraint_literal c : conflict) {
LOG_H3("Computing forbidden interval for: " << c);
eval_interval interval = eval_interval::full();
constraint_literal neg_cond;
if (c->forbidden_interval(s, v, interval, neg_cond)) {
constraint_literal_ref neg_cond;
if (c->forbidden_interval(s, c.is_positive(), v, interval, neg_cond)) {
LOG("interval: " << interval);
LOG("neg_cond: " << show_deref(neg_cond));
LOG("neg_cond: " << neg_cond);
if (interval.is_currently_empty())
continue;
if (interval.is_full())
@ -106,7 +102,7 @@ namespace polysat {
auto& full_record = records.back();
SASSERT(full_record.interval.is_full());
clause_builder clause(s);
clause.push_literal(~full_record.src->blit());
clause.push_literal(~full_record.src.literal());
if (full_record.neg_cond)
clause.push_new_constraint(std::move(full_record.neg_cond));
out_lemma = clause.build();
@ -134,7 +130,7 @@ namespace polysat {
unsigned lemma_lvl = 0;
for (unsigned i : seq) {
constraint* c = records[i].src;
constraint_literal const& c = records[i].src;
lemma_lvl = std::max(lemma_lvl, c->level());
}
@ -149,7 +145,7 @@ namespace polysat {
clause_builder clause(s);
// Add negation of src constraints as antecedents (may be resolved during backtracking)
for (unsigned const i : seq) {
sat::literal src_lit = records[i].src->blit();
sat::literal src_lit = records[i].src.literal();
clause.push_literal(~src_lit);
}
// Add side conditions and interval constraints
@ -163,12 +159,12 @@ namespace polysat {
auto const& next_hi = records[next_i].interval.hi();
auto const& lhs = hi - next_lo;
auto const& rhs = next_hi - next_lo;
constraint_literal c = ~s.m_constraints.ult(lemma_lvl, lhs, rhs);
LOG("constraint: " << *c);
constraint_literal_ref c = ~s.m_constraints.ult(lemma_lvl, lhs, rhs);
LOG("constraint: " << c);
clause.push_new_constraint(std::move(c));
// Side conditions
// TODO: check whether the condition is subsumed by c? maybe at the end do a "lemma reduction" step, to try and reduce branching?
constraint_literal& neg_cond = records[i].neg_cond;
constraint_literal_ref& neg_cond = records[i].neg_cond;
if (neg_cond)
clause.push_new_constraint(std::move(neg_cond));
}