3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-08-25 20:46:01 +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

@ -16,47 +16,38 @@ Author:
namespace polysat {
/// Represents a conflict as core (~negation of clause).
///
/// TODO: can probably move some clause_builder functionality into this class.
/** Conflict state, represented as core (~negation of clause). */
class conflict_core {
// constraint_ref_vector m_constraints;
// TODO: core needs to own the constraint literals...
vector<constraint_literal> m_constraints;
bool m_needs_model = true; ///< True iff the conflict depends on the current variable assignment. (If so, additional constraints must be added to the final learned clause.)
/** True iff the conflict depends on the current variable assignment. (If so, additional constraints must be added to the final learned clause.) */
bool m_needs_model = false;
// NOTE: for now we keep this simple implementation.
// The drawback is that we may get weaker lemmas in some cases (but they are still correct).
// For example: if we have 4x+y=2 and y=0, then we have a conflict no matter the value of x, so we should drop x=? from the core.
public:
vector<constraint_literal> const& constraints() const {
return m_constraints;
}
vector<constraint_literal> const& constraints() const { return m_constraints; }
bool needs_model() const { return m_needs_model; }
bool empty() const {
return m_constraints.empty();
return m_constraints.empty() && !m_needs_model;
}
void reset() {
m_constraints.reset();
m_needs_model = true;
}
// for bailing out with a conflict at the base level
void set(std::nullptr_t) {
SASSERT(empty());
m_constraints.push_back({});
m_needs_model = false;
SASSERT(empty());
}
// void set(
// TODO: set core from conflicting units
// TODO: set clause
// TODO: use iterator instead (this method is needed for marking so duplicates don't necessarily have to be skipped)
unsigned_vector vars(constraint_manager const& cm) const {
unsigned_vector vars;
for (auto const& c : m_constraints)
vars.append(c->vars());
return vars;
}
/** for bailing out with a conflict at the base level */
void set(std::nullptr_t);
/** conflict because the constraint c is false under current variable assignment */
void set(constraint_literal c);
/** conflict because there is no viable value for the variable v */
void set(pvar v, vector<constraint_literal> const& cjust_v);
std::ostream& display(std::ostream& out) const;
};