3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-29 20:05:51 +00:00

Split constraint_manager into separate file

This commit is contained in:
Jakob Rath 2022-11-07 13:33:48 +01:00
parent e33f728128
commit 7662427d92
8 changed files with 419 additions and 349 deletions

View file

@ -8,12 +8,11 @@ Module Name:
Author:
Nikolaj Bjorner (nbjorner) 2021-03-19
Jakob Rath 2021-04-6
Jakob Rath 2021-04-06
--*/
#pragma once
#include "math/polysat/boolean.h"
#include "math/polysat/clause.h"
#include "math/polysat/types.h"
#include "math/polysat/interval.h"
#include "math/polysat/search_state.h"
@ -24,6 +23,7 @@ namespace polysat {
enum ckind_t { ule_t, umul_ovfl_t, smul_fl_t, op_t };
class constraint_manager;
class constraint;
class ule_constraint;
class umul_ovfl_constraint;
@ -31,99 +31,6 @@ namespace polysat {
class op_constraint;
class signed_constraint;
using constraint_hash = obj_ptr_hash<constraint>;
using constraint_eq = deref_eq<constraint>;
using constraint_table = ptr_hashtable<constraint, constraint_hash, constraint_eq>;
using constraints = ptr_vector<constraint>;
using signed_constraints = vector<signed_constraint>;
// Manage constraint lifetime, deduplication, and connection to boolean variables/literals.
class constraint_manager {
friend class constraint;
bool_var_manager& m_bvars;
// Constraints indexed by their boolean variable
ptr_vector<constraint> m_bv2constraint;
// Constraints that have a boolean variable, for deduplication
constraint_table m_constraint_table;
scoped_ptr_vector<constraint> m_constraints;
// Clause storage per level
vector<vector<clause_ref>> m_clauses;
// Association to external dependency values (i.e., external names for constraints)
u_map<constraint*> m_external_constraints;
unsigned m_num_external = 0;
// Manage association of constraints to boolean variables
void assign_bv2c(sat::bool_var bv, constraint* c);
void erase_bv2c(constraint* c);
constraint* get_bv2c(sat::bool_var bv) const;
void store(constraint* c);
void erase(constraint* c);
constraint* dedup(constraint* c);
void gc_constraints(solver& s);
void gc_clauses(solver& s);
void watch(clause& cl, solver& s, bool value_propagate);
void unwatch(clause& cl);
void register_clause(clause* cl, solver& s);
void ensure_bvar(constraint* c);
void erase_bvar(constraint* c);
public:
constraint_manager(bool_var_manager& bvars): m_bvars(bvars) {}
~constraint_manager();
void store(clause* cl, solver& s, bool value_propagate);
/// Release clauses at the given level and above.
void release_level(unsigned lvl);
/// Garbage-collect temporary constraints (i.e., those that do not have a boolean variable).
void gc(solver& s);
bool should_gc();
constraint* lookup(sat::bool_var var) const;
signed_constraint lookup(sat::literal lit) const;
signed_constraint eq(pdd const& p);
signed_constraint ule(pdd const& a, pdd const& b);
signed_constraint ult(pdd const& a, pdd const& b);
signed_constraint sle(pdd const& a, pdd const& b);
signed_constraint slt(pdd const& a, pdd const& b);
signed_constraint umul_ovfl(pdd const& p, pdd const& q);
signed_constraint smul_ovfl(pdd const& p, pdd const& q);
signed_constraint smul_udfl(pdd const& p, pdd const& q);
signed_constraint bit(pdd const& p, unsigned i);
signed_constraint lshr(pdd const& p, pdd const& q, pdd const& r);
signed_constraint band(pdd const& p, pdd const& q, pdd const& r);
constraint* const* begin() const { return m_constraints.data(); }
constraint* const* end() const { return m_constraints.data() + m_constraints.size(); }
using clause_iterator = decltype(m_clauses)::const_iterator;
clause_iterator clauses_begin() const { return m_clauses.begin(); }
clause_iterator clauses_end() const { return m_clauses.end(); }
class clauses_t {
constraint_manager const* m_cm;
public:
clauses_t(constraint_manager const& cm): m_cm(&cm) {}
auto begin() const { return m_cm->clauses_begin(); }
auto end() const { return m_cm->clauses_end(); }
};
clauses_t clauses() const { return {*this}; }
};
/// Normalized inequality:
/// lhs <= rhs, if !is_strict
/// lhs < rhs, otherwise
@ -246,7 +153,7 @@ namespace polysat {
bool is_negative() const { return !is_positive(); }
bool is_always_false() const { return get()->is_always_false(is_positive()); }
bool is_always_true() const { return get()->is_always_false(is_negative()); }
bool is_always_true() const { return get()->is_always_false(is_negative()); }
bool is_currently_false(solver& s) const { return get()->is_currently_false(s, is_positive()); }
bool is_currently_true(solver& s) const { return get()->is_currently_false(s, is_negative()); }
bool is_currently_false(solver& s, assignment_t const& sub) const { return get()->is_currently_false(s, sub, is_positive()); }