3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-05-28 04:46:27 +00:00

Using only one solver

This commit is contained in:
CEisenhofer 2026-05-07 15:49:16 +02:00
parent 712cd68e8c
commit f7f2ee8f74
8 changed files with 154 additions and 108 deletions

View file

@ -414,13 +414,12 @@ namespace seq {
// nielsen_graph
// -----------------------------------------------
nielsen_graph::nielsen_graph(euf::sgraph &sg, simple_solver &solver, simple_solver &core_solver):
nielsen_graph::nielsen_graph(euf::sgraph &sg, simple_solver &solver):
m(sg.get_manager()),
a(sg.get_manager()),
m_seq(sg.get_seq_util()),
m_sg(sg),
m_solver(solver),
m_core_solver(core_solver),
m_parikh(alloc(seq_parikh, sg)),
m_seq_regex(alloc(seq::seq_regex, sg)) {}
@ -534,7 +533,6 @@ namespace seq {
m_length_info.reset();
m_dep_mgr.reset();
m_solver.reset();
m_core_solver.reset();
SASSERT(m_nodes.empty());
SASSERT(m_edges.empty());
SASSERT(m_root == nullptr);
@ -4438,7 +4436,7 @@ namespace seq {
SASSERT(m_literal_if_false);
for (unsigned i = node->m_parent_ic_count; i < node->constraints().size(); ++i) {
auto& c = node->constraints()[i];
m_solver.assert_expr(c.fml);
m_solver.assert_expr(c.fml, c.dep);
auto lit = m_literal_if_false(c.fml);
// std::cout << "Internalizing literal " << mk_pp(c.fml, m) << " [" << (lit == sat::null_literal) << "]" << std::endl;
if (lit != sat::null_literal)
@ -4505,32 +4503,10 @@ namespace seq {
return m_solver.check() != l_false;
}
dep_tracker nielsen_graph::get_subsolver_dependency(nielsen_node* n) {
u_map<dep_tracker> expr_to_dep;
expr_ref_vector assumptions(m);
assumptions.resize(n->constraints().size());
unsigned j = 0;
for (auto const &c : n->constraints()) {
if (expr_to_dep.contains(c.fml->get_id()))
continue;
expr_to_dep.insert_if_not_there(c.fml->get_id(), c.dep);
assumptions[j++] = c.fml;
}
assumptions.shrink(j);
expr_ref_vector core(m);
lbool res = m_core_solver.check_with_assumptions(assumptions, core);
CTRACE(seq, res != l_false,
tout << "Unexpected satisfiable/unknown result from core solver "
<< res << " " << core
<< "\nassumptions\n"
<< assumptions << "\n");
VERIFY(res == l_false);
dep_tracker dep = dep_mgr().mk_empty();
for (expr* e : core) {
dep = dep_mgr().mk_join(dep, expr_to_dep[e->get_id()]);
}
return dep;
dep_tracker nielsen_graph::get_subsolver_dependency(nielsen_node* /*n*/) {
// check_int_feasibility() already called m_solver.check() which computed
// the UNSAT core in terms of tracked assumption literals and their deps.
return m_solver.core();
}
bool nielsen_graph::check_lp_le(expr* lhs, expr* rhs, nielsen_node* n, dep_tracker& dep) {

View file

@ -264,32 +264,6 @@ namespace seq {
std::string snode_label_html(euf::snode const* n, ast_manager& m);
/**
* Abstract interface for an incremental solver used by nielsen_graph
* to check integer/arithmetic feasibility of path constraints.
*
* Users of nielsen_graph can wrap smt::kernel or any other solver
* to serve as the arithmetic back-end. When no solver is provided,
* integer feasibility checks are skipped (optimistically assumed feasible).
*/
class simple_solver {
public:
virtual ~simple_solver() {}
virtual lbool check() = 0;
virtual void assert_expr(expr* e) = 0;
virtual void push() = 0;
virtual void pop(unsigned num_scopes) = 0;
virtual void get_model(model_ref& mdl) { mdl = nullptr; }
virtual lbool check_with_assumptions(expr_ref_vector& assumptions, expr_ref_vector& core) { return l_undef; }
// Optional bound queries on arithmetic expressions (non-strict integer bounds).
// Default implementation reports "unsupported".
virtual bool lower_bound(expr* e, rational& lo) const { return false; }
virtual bool upper_bound(expr* e, rational& hi) const { return false; }
virtual bool current_value(expr *e, rational &v) const { return false; }
virtual void reset() = 0;
};
// simplification result for constraint processing
// mirrors ZIPT's SimplifyResult enum
enum class simplify_result {
@ -362,6 +336,31 @@ namespace seq {
// nullptr represents the empty dependency set.
using dep_tracker = dep_manager::dependency*;
/**
* Abstract interface for an incremental solver used by nielsen_graph
* to check integer/arithmetic feasibility of path constraints.
*
* Users of nielsen_graph can wrap smt::kernel or any other solver
* to serve as the arithmetic back-end. When no solver is provided,
* integer feasibility checks are skipped (optimistically assumed feasible).
*/
class simple_solver {
public:
virtual ~simple_solver() {}
virtual lbool check() = 0;
virtual void assert_expr(expr* e, dep_tracker dep = nullptr) = 0;
virtual void push() = 0;
virtual void pop(unsigned num_scopes) = 0;
virtual void get_model(model_ref& mdl) { mdl = nullptr; }
virtual dep_tracker core() { return nullptr; }
// Optional bound queries on arithmetic expressions (non-strict integer bounds).
// Default implementation reports "unsupported".
virtual bool lower_bound(expr* e, rational& lo) const { return false; }
virtual bool upper_bound(expr* e, rational& hi) const { return false; }
virtual bool current_value(expr* e, rational& v) const { return false; }
virtual void reset() = 0;
};
// partition dep_source leaves from deps into enode pairs, sat literals,
// and arithmetic <= dependencies.
void deps_to_lits(dep_tracker deps,
@ -852,7 +851,6 @@ namespace seq {
// and optimistically assumes feasibility.
// -----------------------------------------------
simple_solver& m_solver;
simple_solver& m_core_solver;
// Constraint.Shared: guards re-assertion of root-level constraints.
// Set to true after assert_root_constraints_to_solver() is first called.
@ -895,7 +893,7 @@ namespace seq {
public:
// Construct with a caller-supplied solver. Ownership is NOT transferred;
// the caller is responsible for keeping the solver alive.
nielsen_graph(euf::sgraph& sg, simple_solver& solver, simple_solver &core_solver);
nielsen_graph(euf::sgraph& sg, simple_solver& solver);
~nielsen_graph();
void set_literal_if_false(std::function<sat::literal(expr* e)> const& lif) {