mirror of
https://github.com/Z3Prover/z3
synced 2025-04-23 17:15:31 +00:00
add fd solver for finite domain queries
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
948a1e600e
commit
d060359f01
16 changed files with 676 additions and 204 deletions
|
@ -11,7 +11,7 @@ Copyright (c) 2016 Microsoft Corporation
|
|||
#include "dt2bv_tactic.h"
|
||||
#include "tactic.h"
|
||||
#include "model_smt2_pp.h"
|
||||
//include
|
||||
#include "fd_solver.h"
|
||||
|
||||
static expr_ref mk_const(ast_manager& m, char const* name, sort* s) {
|
||||
return expr_ref(m.mk_const(symbol(name), s), m);
|
||||
|
@ -81,8 +81,8 @@ static void test2() {
|
|||
gl->assert_expr(m.mk_not(m.mk_eq(x, r)));
|
||||
gl->assert_expr(m.mk_not(m.mk_eq(x, b)));
|
||||
gl->display(std::cout);
|
||||
obj_map<func_decl, expr*> tr;
|
||||
obj_map<expr, func_decl*> rev_tr;
|
||||
obj_map<func_decl, func_decl*> tr;
|
||||
obj_map<func_decl, func_decl*> rev_tr;
|
||||
ref<tactic> dt2bv = mk_dt2bv_tactic(m, p, &tr);
|
||||
goal_ref_buffer result;
|
||||
model_converter_ref mc;
|
||||
|
@ -91,13 +91,13 @@ static void test2() {
|
|||
(*dt2bv)(gl, result, mc, pc, core);
|
||||
|
||||
// Collect translations from enumerations to bit-vectors
|
||||
obj_map<func_decl, expr*>::iterator it = tr.begin(), end = tr.end();
|
||||
obj_map<func_decl, func_decl*>::iterator it = tr.begin(), end = tr.end();
|
||||
for (; it != end; ++it) {
|
||||
rev_tr.insert(it->m_value, it->m_key);
|
||||
}
|
||||
|
||||
// Create bit-vector implication problem
|
||||
val = tr.find(to_app(x)->get_decl());
|
||||
val = m.mk_const(tr.find(to_app(x)->get_decl()));
|
||||
std::cout << val << "\n";
|
||||
ptr_vector<expr> fmls;
|
||||
result[0]->get_formulas(fmls);
|
||||
|
@ -119,7 +119,7 @@ static void test2() {
|
|||
rational num;
|
||||
unsigned bvsize;
|
||||
VERIFY(m.is_implies(conseq[i].get(), a, b));
|
||||
if (m.is_eq(b, u, v) && rev_tr.find(u, f) && bv.is_numeral(v, num, bvsize)) {
|
||||
if (m.is_eq(b, u, v) && rev_tr.find(to_app(u)->get_decl(), f) && bv.is_numeral(v, num, bvsize)) {
|
||||
SASSERT(num.is_unsigned());
|
||||
expr_ref head(m);
|
||||
head = m.mk_eq(m.mk_const(f), m.mk_const(enums[num.get_unsigned()]));
|
||||
|
@ -129,9 +129,66 @@ static void test2() {
|
|||
std::cout << conseq << "\n";
|
||||
}
|
||||
|
||||
void test3() {
|
||||
ast_manager m;
|
||||
reg_decl_plugins(m);
|
||||
bv_util bv(m);
|
||||
datatype_util dtutil(m);
|
||||
params_ref p;
|
||||
|
||||
datatype_decl_plugin & dt = *(static_cast<datatype_decl_plugin*>(m.get_plugin(m.get_family_id("datatype"))));
|
||||
sort_ref_vector new_sorts(m);
|
||||
constructor_decl* R = mk_constructor_decl(symbol("R"), symbol("is-R"), 0, 0);
|
||||
constructor_decl* G = mk_constructor_decl(symbol("G"), symbol("is-G"), 0, 0);
|
||||
constructor_decl* B = mk_constructor_decl(symbol("B"), symbol("is-B"), 0, 0);
|
||||
constructor_decl* constrs[3] = { R, G, B };
|
||||
datatype_decl * enum_sort = mk_datatype_decl(symbol("RGB"), 3, constrs);
|
||||
VERIFY(dt.mk_datatypes(1, &enum_sort, new_sorts));
|
||||
del_constructor_decls(3, constrs);
|
||||
sort* rgb = new_sorts[0].get();
|
||||
|
||||
expr_ref x = mk_const(m, "x", rgb), y = mk_const(m, "y", rgb), z = mk_const(m, "z", rgb);
|
||||
ptr_vector<func_decl> const& enums = *dtutil.get_datatype_constructors(rgb);
|
||||
expr_ref r = expr_ref(m.mk_const(enums[0]), m);
|
||||
expr_ref g = expr_ref(m.mk_const(enums[1]), m);
|
||||
expr_ref b = expr_ref(m.mk_const(enums[2]), m);
|
||||
|
||||
ref<solver> fd_solver = mk_fd_solver(m, p);
|
||||
fd_solver->assert_expr(m.mk_not(m.mk_eq(x, r)));
|
||||
fd_solver->assert_expr(m.mk_not(m.mk_eq(x, b)));
|
||||
|
||||
expr_ref_vector asms(m), vars(m), conseq(m);
|
||||
vars.push_back(x);
|
||||
vars.push_back(y);
|
||||
|
||||
VERIFY(l_true == fd_solver->get_consequences(asms, vars, conseq));
|
||||
std::cout << conseq << "\n";
|
||||
conseq.reset();
|
||||
|
||||
fd_solver->push();
|
||||
fd_solver->assert_expr(m.mk_not(m.mk_eq(x, g)));
|
||||
VERIFY(l_false == fd_solver->check_sat(0,0));
|
||||
fd_solver->pop(1);
|
||||
|
||||
VERIFY(l_true == fd_solver->get_consequences(asms, vars, conseq));
|
||||
|
||||
std::cout << conseq << "\n";
|
||||
conseq.reset();
|
||||
|
||||
model_ref mr;
|
||||
fd_solver->get_model(mr);
|
||||
model_smt2_pp(std::cout << "model:\n", m, *mr.get(), 0);
|
||||
|
||||
VERIFY(l_true == fd_solver->check_sat(0,0));
|
||||
fd_solver->get_model(mr);
|
||||
SASSERT(mr.get());
|
||||
model_smt2_pp(std::cout, m, *mr.get(), 0);
|
||||
|
||||
}
|
||||
|
||||
void tst_get_consequences() {
|
||||
test1();
|
||||
test2();
|
||||
|
||||
test3();
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue