mirror of
https://github.com/Z3Prover/z3
synced 2025-04-24 09:35:32 +00:00
inequality
This commit is contained in:
parent
e6c9e13848
commit
7468b2326c
7 changed files with 28 additions and 29 deletions
|
@ -37,8 +37,13 @@ namespace polysat {
|
|||
return m_constraint->to_ule().lhs();
|
||||
}
|
||||
|
||||
signed_constraint inequality::as_signed_constraint() const {
|
||||
return signed_constraint(const_cast<constraint*>(src), !is_strict);
|
||||
inequality inequality::from_ule(signed_constraint src)
|
||||
{
|
||||
ule_constraint& c = src->to_ule();
|
||||
if (src.is_positive())
|
||||
return inequality(c.lhs(), c.rhs(), src);
|
||||
else
|
||||
return inequality(c.rhs(), c.lhs(), src);
|
||||
}
|
||||
|
||||
ule_constraint& constraint::to_ule() {
|
||||
|
|
|
@ -34,19 +34,6 @@ namespace polysat {
|
|||
using constraints = ptr_vector<constraint>;
|
||||
using signed_constraints = vector<signed_constraint>;
|
||||
|
||||
/// Normalized inequality:
|
||||
/// lhs <= rhs, if !is_strict
|
||||
/// lhs < rhs, otherwise
|
||||
struct inequality {
|
||||
pdd lhs;
|
||||
pdd rhs;
|
||||
bool is_strict;
|
||||
constraint const* src; // TODO: should be signed_constraint now
|
||||
inequality(pdd const & lhs, pdd const & rhs, bool is_strict, constraint const* src):
|
||||
lhs(lhs), rhs(rhs), is_strict(is_strict), src(src) {}
|
||||
signed_constraint as_signed_constraint() const;
|
||||
};
|
||||
|
||||
class constraint {
|
||||
friend class constraint_manager;
|
||||
friend class signed_constraint;
|
||||
|
@ -97,7 +84,6 @@ namespace polysat {
|
|||
bool is_currently_false(solver const& s, bool is_positive) const { return is_currently_true(s, !is_positive); }
|
||||
|
||||
virtual void narrow(solver& s, bool is_positive, bool first) = 0;
|
||||
virtual inequality as_inequality(bool is_positive) const = 0;
|
||||
|
||||
ule_constraint& to_ule();
|
||||
ule_constraint const& to_ule() const;
|
||||
|
@ -167,7 +153,6 @@ namespace polysat {
|
|||
bool is_currently_true(solver const& s) const { return get()->is_currently_true(s, is_positive()); }
|
||||
lbool bvalue(solver& s) const;
|
||||
void narrow(solver& s, bool first) { get()->narrow(s, is_positive(), first); }
|
||||
inequality as_inequality() const { return get()->as_inequality(is_positive()); }
|
||||
|
||||
void add_to_univariate_solver(solver& s, univariate_solver& us, unsigned dep) const { get()->add_to_univariate_solver(s, us, dep, is_positive()); }
|
||||
|
||||
|
@ -196,7 +181,8 @@ namespace polysat {
|
|||
return combine_hash(get_ptr_hash(get()), bool_hash()(is_positive()));
|
||||
}
|
||||
bool operator==(signed_constraint const& other) const {
|
||||
return get() == other.get() && is_positive() == other.is_positive();
|
||||
SASSERT_EQ(blit() == other.blit(), get() == other.get() && is_positive() == other.is_positive());
|
||||
return blit() == other.blit();
|
||||
}
|
||||
bool operator!=(signed_constraint const& other) const { return !operator==(other); }
|
||||
|
||||
|
@ -212,6 +198,25 @@ namespace polysat {
|
|||
return c.display(out);
|
||||
}
|
||||
|
||||
/// Normalized inequality:
|
||||
/// lhs <= rhs, if !is_strict
|
||||
/// lhs < rhs, otherwise
|
||||
class inequality {
|
||||
pdd m_lhs;
|
||||
pdd m_rhs;
|
||||
signed_constraint m_src;
|
||||
|
||||
inequality(pdd lhs, pdd rhs, signed_constraint src):
|
||||
m_lhs(std::move(lhs)), m_rhs(std::move(rhs)), m_src(std::move(src)) {}
|
||||
|
||||
public:
|
||||
static inequality from_ule(signed_constraint src);
|
||||
pdd const& lhs() const { return m_lhs; }
|
||||
pdd const& rhs() const { return m_rhs; }
|
||||
bool is_strict() const { return m_src.is_negative(); }
|
||||
signed_constraint as_signed_constraint() const { return m_src; }
|
||||
};
|
||||
|
||||
class constraint_pp {
|
||||
constraint const* c;
|
||||
lbool status;
|
||||
|
|
|
@ -59,7 +59,6 @@ namespace polysat {
|
|||
lbool eval() const override;
|
||||
lbool eval(assignment const& a) const override;
|
||||
void narrow(solver& s, bool is_positive, bool first) override;
|
||||
inequality as_inequality(bool is_positive) const override { throw default_exception("is not an inequality"); }
|
||||
unsigned hash() const override;
|
||||
bool operator==(constraint const& other) const override;
|
||||
bool is_eq() const override { return false; }
|
||||
|
|
|
@ -38,7 +38,6 @@ namespace polysat {
|
|||
lbool eval(assignment const& a) const override { return l_undef; } // TODO
|
||||
void narrow(solver& s, bool is_positive, bool first) override;
|
||||
|
||||
inequality as_inequality(bool is_positive) const override { throw default_exception("is not an inequality"); }
|
||||
unsigned hash() const override;
|
||||
bool operator==(constraint const& other) const override;
|
||||
bool is_eq() const override { return false; }
|
||||
|
|
|
@ -215,13 +215,6 @@ namespace polysat {
|
|||
return eval(a.apply_to(lhs()), a.apply_to(rhs()));
|
||||
}
|
||||
|
||||
inequality ule_constraint::as_inequality(bool is_positive) const {
|
||||
if (is_positive)
|
||||
return inequality(lhs(), rhs(), false, this);
|
||||
else
|
||||
return inequality(rhs(), lhs(), true, this);
|
||||
}
|
||||
|
||||
unsigned ule_constraint::hash() const {
|
||||
return mk_mix(lhs().hash(), rhs().hash(), kind());
|
||||
}
|
||||
|
|
|
@ -41,7 +41,6 @@ namespace polysat {
|
|||
lbool eval() const override;
|
||||
lbool eval(assignment const& a) const override;
|
||||
void narrow(solver& s, bool is_positive, bool first) override;
|
||||
inequality as_inequality(bool is_positive) const override;
|
||||
unsigned hash() const override;
|
||||
bool operator==(constraint const& other) const override;
|
||||
bool is_eq() const override { return m_rhs.is_zero(); }
|
||||
|
|
|
@ -41,7 +41,6 @@ namespace polysat {
|
|||
lbool eval(assignment const& a) const override;
|
||||
void narrow(solver& s, bool is_positive, bool first) override;
|
||||
|
||||
inequality as_inequality(bool is_positive) const override { throw default_exception("is not an inequality"); }
|
||||
unsigned hash() const override;
|
||||
bool operator==(constraint const& other) const override;
|
||||
bool is_eq() const override { return false; }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue