mirror of
https://github.com/Z3Prover/z3
synced 2025-08-24 03:57:51 +00:00
viable
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
0520180846
commit
0fc9d7ad0d
4 changed files with 256 additions and 183 deletions
|
@ -14,12 +14,11 @@ Author:
|
|||
Notes:
|
||||
|
||||
NEW_VIABLE uses cheaper book-keeping, but is partial.
|
||||
The implementation of NEW_VIABLE is atm incomplete and ad-hoc.
|
||||
|
||||
--*/
|
||||
#pragma once
|
||||
|
||||
#define NEW_VIABLE 0
|
||||
#define NEW_VIABLE 1
|
||||
|
||||
#include <limits>
|
||||
|
||||
|
@ -44,52 +43,57 @@ namespace polysat {
|
|||
class viable_set : public mod_interval<rational> {
|
||||
unsigned m_num_bits;
|
||||
rational p2() const { return rational::power_of_two(m_num_bits); }
|
||||
bool is_max(rational const& a) const;
|
||||
bool is_max(rational const& a) const override;
|
||||
void intersect_eq(rational const& a, bool is_positive);
|
||||
void narrow(std::function<bool(rational const&)>& eval, unsigned& budget);
|
||||
bool narrow(std::function<bool(rational const&)>& eval);
|
||||
public:
|
||||
viable_set(unsigned num_bits): m_num_bits(num_bits) {}
|
||||
bool is_singleton() const;
|
||||
dd::find_t find_hint(rational const& c, rational& val) const;
|
||||
void set_ne(rational const& a) { intersect_eq(a, false); }
|
||||
void set_lo(rational const& lo);
|
||||
void set_hi(rational const& hi);
|
||||
bool intersect_eq(rational const& a, rational const& b, bool is_positive);
|
||||
void intersect_eq(rational const& a, rational const& b, bool is_positive, unsigned& budget);
|
||||
bool intersect_ule(rational const& a, rational const& b, rational const& c, rational const& d, bool is_positive);
|
||||
void intersect_ule(rational const& a, rational const& b, rational const& c, rational const& d, bool is_positive, unsigned& budget);
|
||||
bool intersect_le(rational const& a, rational const& b, rational const& c, rational const& d, bool is_positive);
|
||||
rational prev(rational const& p) const;
|
||||
};
|
||||
#endif
|
||||
|
||||
class viable {
|
||||
solver& s;
|
||||
typedef dd::bdd bdd;
|
||||
typedef dd::fdd fdd;
|
||||
solver& s;
|
||||
dd::bdd_manager m_bdd;
|
||||
scoped_ptr_vector<dd::fdd> m_bits;
|
||||
#if NEW_VIABLE
|
||||
struct ineq_entry {
|
||||
struct cached_constraint {
|
||||
enum op_code { is_ule, is_eq };
|
||||
op_code m_op;
|
||||
unsigned m_num_bits;
|
||||
rational a, b, c, d;
|
||||
bdd repr;
|
||||
unsigned m_activity = 0;
|
||||
ineq_entry(unsigned n, rational const& a, rational const& b, rational const& c, rational const& d, bdd& f) :
|
||||
m_num_bits(n), a(a), b(b), c(c), d(d), repr(f) {}
|
||||
cached_constraint(unsigned n, rational const& a, rational const& b, rational const& c, rational const& d, bdd& f) :
|
||||
m_op(op_code::is_ule), m_num_bits(n), a(a), b(b), c(c), d(d), repr(f) {}
|
||||
cached_constraint(unsigned n, rational const& a, rational const& b, bdd& f) :
|
||||
m_op(op_code::is_eq), m_num_bits(n), a(a), b(b), repr(f) {}
|
||||
|
||||
struct hash {
|
||||
unsigned operator()(ineq_entry const* e) const {
|
||||
return mk_mix(e->a.hash(), e->b.hash(), mk_mix(e->c.hash(), e->d.hash(), e->m_num_bits));
|
||||
unsigned operator()(cached_constraint const* e) const {
|
||||
return mk_mix(e->a.hash(), e->b.hash(), mk_mix(e->c.hash(), e->d.hash(), e->m_num_bits)) + e->m_op;
|
||||
}
|
||||
};
|
||||
struct eq {
|
||||
bool operator()(ineq_entry const* x, ineq_entry const* y) const {
|
||||
return x->a == y->a && x->b == y->b && x->c == y->c && x->d == y->d && x->m_num_bits == y->m_num_bits;
|
||||
bool operator()(cached_constraint const* x, cached_constraint const* y) const {
|
||||
return x->m_op == y->m_op && x->a == y->a && x->b == y->b && x->c == y->c && x->d == y->d && x->m_num_bits == y->m_num_bits;
|
||||
}
|
||||
};
|
||||
};
|
||||
vector<viable_set> m_viable;
|
||||
vector<std::pair<pvar, viable_set>> m_viable_trail;
|
||||
hashtable<ineq_entry*, ineq_entry::hash, ineq_entry::eq> m_ineq_cache;
|
||||
hashtable<cached_constraint*, cached_constraint::hash, cached_constraint::eq> m_constraint_cache;
|
||||
|
||||
void intersect_ule_bdd(pvar v, rational const& a, rational const& b, rational const& c, rational const& d, bool is_positive);
|
||||
void intersect_eq_bdd(pvar v, rational const& a, rational const& b, bool is_positive);
|
||||
cached_constraint& cache_constraint(pvar v, cached_constraint& entry0, std::function<bdd(void)>& mk_constraint);
|
||||
void gc_cached_constraints();
|
||||
void narrow(pvar v, bdd const& is_false);
|
||||
#else
|
||||
|
||||
|
||||
|
@ -110,6 +114,8 @@ namespace polysat {
|
|||
public:
|
||||
viable(solver& s);
|
||||
|
||||
~viable();
|
||||
|
||||
void push(unsigned num_bits) {
|
||||
#if NEW_VIABLE
|
||||
m_viable.push_back(viable_set(num_bits));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue