mirror of
https://github.com/Z3Prover/z3
synced 2025-04-12 12:08:18 +00:00
fix push/pop bugs in optimize context, add example to c++, fix bug in arithemtic bounds axiom addition
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
31f16d7aa4
commit
3f8083dfa6
|
@ -972,7 +972,29 @@ void substitute_example() {
|
||||||
std::cout << new_f << std::endl;
|
std::cout << new_f << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void opt_example() {
|
||||||
|
context c;
|
||||||
|
optimize opt(c);
|
||||||
|
params p(c);
|
||||||
|
p.set("priority",c.str_symbol("pareto"));
|
||||||
|
opt.set(p);
|
||||||
|
expr x = c.int_const("x");
|
||||||
|
expr y = c.int_const("y");
|
||||||
|
opt.add(10 >= x && x >= 0);
|
||||||
|
opt.add(10 >= y && y >= 0);
|
||||||
|
opt.add(x + y <= 11);
|
||||||
|
optimize::handle h1 = opt.maximize(x);
|
||||||
|
optimize::handle h2 = opt.maximize(y);
|
||||||
|
check_result r = sat;
|
||||||
|
while (true) {
|
||||||
|
if (sat == opt.check()) {
|
||||||
|
std::cout << x << ": " << opt.lower(h1) << " " << y << ": " << opt.lower(h2) << "\n";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
try {
|
try {
|
||||||
|
@ -1012,6 +1034,7 @@ int main() {
|
||||||
expr_vector_example(); std::cout << "\n";
|
expr_vector_example(); std::cout << "\n";
|
||||||
exists_expr_vector_example(); std::cout << "\n";
|
exists_expr_vector_example(); std::cout << "\n";
|
||||||
substitute_example(); std::cout << "\n";
|
substitute_example(); std::cout << "\n";
|
||||||
|
opt_example(); std::cout << "\n";
|
||||||
std::cout << "done\n";
|
std::cout << "done\n";
|
||||||
}
|
}
|
||||||
catch (exception & ex) {
|
catch (exception & ex) {
|
||||||
|
|
|
@ -139,6 +139,7 @@ namespace opt {
|
||||||
for (; it != end; ++it) {
|
for (; it != end; ++it) {
|
||||||
dealloc(it->m_value);
|
dealloc(it->m_value);
|
||||||
}
|
}
|
||||||
|
m_maxsmts.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void context::push() {
|
void context::push() {
|
||||||
|
@ -149,21 +150,29 @@ namespace opt {
|
||||||
for (unsigned i = 0; i < n; ++i) {
|
for (unsigned i = 0; i < n; ++i) {
|
||||||
m_scoped_state.pop();
|
m_scoped_state.pop();
|
||||||
}
|
}
|
||||||
|
m_model.reset();
|
||||||
|
reset_maxsmts();
|
||||||
|
m_optsmt.reset();
|
||||||
|
m_hard_constraints.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void context::set_hard_constraints(ptr_vector<expr>& fmls) {
|
void context::set_hard_constraints(ptr_vector<expr>& fmls) {
|
||||||
m_scoped_state.set(fmls);
|
m_scoped_state.set(fmls);
|
||||||
|
m_model.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void context::add_hard_constraint(expr* f) {
|
void context::add_hard_constraint(expr* f) {
|
||||||
m_scoped_state.add(f);
|
m_scoped_state.add(f);
|
||||||
|
m_model.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned context::add_soft_constraint(expr* f, rational const& w, symbol const& id) {
|
unsigned context::add_soft_constraint(expr* f, rational const& w, symbol const& id) {
|
||||||
|
m_model.reset();
|
||||||
return m_scoped_state.add(f, w, id);
|
return m_scoped_state.add(f, w, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned context::add_objective(app* t, bool is_max) {
|
unsigned context::add_objective(app* t, bool is_max) {
|
||||||
|
m_model.reset();
|
||||||
return m_scoped_state.add(t, is_max);
|
return m_scoped_state.add(t, is_max);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3090,6 +3090,7 @@ namespace smt {
|
||||||
SASSERT(m_to_patch.empty());
|
SASSERT(m_to_patch.empty());
|
||||||
m_to_check.reset();
|
m_to_check.reset();
|
||||||
m_in_to_check.reset();
|
m_in_to_check.reset();
|
||||||
|
m_new_atoms.reset();
|
||||||
CASSERT("arith", wf_rows());
|
CASSERT("arith", wf_rows());
|
||||||
CASSERT("arith", wf_columns());
|
CASSERT("arith", wf_columns());
|
||||||
CASSERT("arith", valid_row_assignment());
|
CASSERT("arith", valid_row_assignment());
|
||||||
|
|
Loading…
Reference in a new issue