3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-23 17:15:31 +00:00

fix wrong simplex backtracking

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2014-05-09 08:51:07 -07:00
parent d2db8007d8
commit 05a39cb2cf
11 changed files with 231 additions and 56 deletions

View file

@ -124,8 +124,6 @@ static void test4() {
feas(S);
}
void tst_simplex() {
Simplex S;

View file

@ -3,6 +3,7 @@
#include "model_v2_pp.h"
#include "reg_decl_plugins.h"
#include "theory_pb.h"
#include "th_rewriter.h"
unsigned populate_literals(unsigned k, smt::literal_vector& lits) {
SASSERT(k < (1u << lits.size()));
@ -19,7 +20,105 @@ unsigned populate_literals(unsigned k, smt::literal_vector& lits) {
return t;
}
class pb_fuzzer {
ast_manager& m;
random_gen rand;
smt_params params;
smt::context ctx;
expr_ref_vector vars;
public:
pb_fuzzer(ast_manager& m): m(m), rand(0), ctx(m, params), vars(m) {
params.m_model = true;
params.m_pb_enable_simplex = true;
unsigned N = 3;
for (unsigned i = 0; i < N; ++i) {
std::stringstream strm;
strm << "b" << i;
vars.push_back(m.mk_const(symbol(strm.str().c_str()), m.mk_bool_sort()));
std::cout << "(declare-const " << strm.str() << " Bool)\n";
}
}
void fuzz() {
enable_trace("pb");
enable_trace("simplex");
unsigned nr = 0;
for (unsigned i = 0; i < 100000; ++i) {
fuzz_round(nr, 2);
}
}
private:
void add_ineq() {
pb_util pb(m);
expr_ref fml(m), tmp(m);
th_rewriter rw(m);
vector<rational> coeffs(vars.size());
expr_ref_vector args(vars);
while (true) {
rational k(rand(6));
for (unsigned i = 0; i < coeffs.size(); ++i) {
int v = 3 - rand(5);
coeffs[i] = rational(v);
if (coeffs[i].is_neg()) {
args[i] = m.mk_not(args[i].get());
coeffs[i].neg();
k += coeffs[i];
}
}
fml = pb.mk_ge(args.size(), coeffs.c_ptr(), args.c_ptr(), k);
rw(fml, tmp);
rw(tmp, tmp);
if (pb.is_ge(tmp)) {
fml = tmp;
break;
}
}
std::cout << "(assert " << fml << ")\n";
ctx.assert_expr(fml);
}
void fuzz_round(unsigned& num_rounds, unsigned lvl) {
unsigned num_rounds2 = 0;
lbool is_sat = l_true;
std::cout << "(push)\n";
ctx.push();
unsigned r = 0;
while (is_sat == l_true && r <= num_rounds + 1) {
add_ineq();
std::cout << "(check-sat)\n";
is_sat = ctx.check();
if (lvl > 0 && is_sat == l_true) {
fuzz_round(num_rounds2, lvl-1);
}
++r;
}
num_rounds = r;
std::cout << "; number of rounds: " << num_rounds << " level: " << lvl << "\n";
ctx.pop(1);
std::cout << "(pop)\n";
}
};
static void fuzz_pb()
{
ast_manager m;
reg_decl_plugins(m);
pb_fuzzer fuzzer(m);
fuzzer.fuzz();
}
void tst_theory_pb() {
fuzz_pb();
ast_manager m;
smt_params params;
params.m_model = true;