3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-24 01:25:31 +00:00

fix at-most-1 constraint compiler bug

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2016-10-22 18:50:16 -07:00
parent bb6d826908
commit 23b9d3ef55
17 changed files with 369 additions and 62 deletions

View file

@ -27,6 +27,7 @@ Revision History:
#include"cancel_eh.h"
#include"scoped_timer.h"
#include"smt2parser.h"
#include"api_ast_vector.h"
extern "C" {
@ -296,6 +297,36 @@ extern "C" {
}
Z3_ast_vector Z3_API Z3_optimize_get_assertions(Z3_context c, Z3_optimize o) {
Z3_TRY;
LOG_Z3_optimize_get_assertions(c, o);
RESET_ERROR_CODE();
Z3_ast_vector_ref * v = alloc(Z3_ast_vector_ref, *mk_c(c), mk_c(c)->m());
mk_c(c)->save_object(v);
expr_ref_vector hard(mk_c(c)->m());
to_optimize_ptr(o)->get_hard_constraints(hard);
for (unsigned i = 0; i < hard.size(); i++) {
v->m_ast_vector.push_back(hard[i].get());
}
RETURN_Z3(of_ast_vector(v));
Z3_CATCH_RETURN(0);
}
unsigned Z3_API Z3_optimize_get_num_objectives(Z3_context c, Z3_optimize o) {
RESET_ERROR_CODE();
return to_optimize_ptr(o)->num_objectives();
}
Z3_ast Z3_API Z3_optimize_get_objective(Z3_context c, Z3_optimize o, unsigned index) {
Z3_TRY;
LOG_Z3_optimize_get_objective(c, o, index);
RESET_ERROR_CODE();
expr_ref result = to_optimize_ptr(o)->get_objective(index);
mk_c(c)->save_ast_trail(result);
RETURN_Z3(of_expr(result));
Z3_CATCH_RETURN(0);
}
};

View file

@ -6796,6 +6796,15 @@ class Optimize(Z3PPObject):
"""Parse assertions and objectives from a string"""
Z3_optimize_from_string(self.ctx.ref(), self.optimize, s)
def assertions(self):
"""Return an AST vector containing all added constraints."""
return AstVector(Z3_optimize_get_assertions(self.ctx.ref(), self.optimize), self.ctx)
def objectives(self):
"""returns set of objective functions"""
num = Z3_optimize_get_num_objectives(self.ctx.ref(), self.optimize)
return [_to_expr_ref(Z3_optimize_get_objective(self.ctx.ref(), self.optimize, i), self.ctx) for i in range(num)]
def __repr__(self):
"""Return a formatted string with all added rules and constraints."""
return self.sexpr()

View file

@ -5832,7 +5832,7 @@ extern "C" {
void Z3_API Z3_solver_assert_and_track(Z3_context c, Z3_solver s, Z3_ast a, Z3_ast p);
/**
\brief Return the set of asserted formulas as a goal object.
\brief Return the set of asserted formulas on the solver.
def_API('Z3_solver_get_assertions', AST_VECTOR, (_in(CONTEXT), _in(SOLVER)))
*/

View file

@ -239,6 +239,33 @@ extern "C" {
def_API('Z3_optimize_get_statistics', STATS, (_in(CONTEXT), _in(OPTIMIZE)))
*/
Z3_stats Z3_API Z3_optimize_get_statistics(Z3_context c, Z3_optimize d);
/**
\brief Return the set of asserted formulas on the optimization context.
def_API('Z3_optimize_get_assertions', AST_VECTOR, (_in(CONTEXT), _in(OPTIMIZE)))
*/
Z3_ast_vector Z3_API Z3_optimize_get_assertions(Z3_context c, Z3_optimize o);
/**
\brief Return number of objectives on the optimization context.
def_API('Z3_optimize_get_num_objectives', UINT, (_in(CONTEXT), _in(OPTIMIZE)))
*/
unsigned Z3_API Z3_optimize_get_num_objectives(Z3_context c, Z3_optimize o);
/**
\brief Return i'th objective function. If the objective function is a max-sat objective it is returned
as a Pseudo-Boolean (minimization) sum of the form (+ (if f1 w1 0) (if f2 w2 0) ...)
If the objective function is entered as a maximization objective, then return the corresponding minimizaiton
objective. In this way the resulting objective function is always returned as a minimization objective.
def_API('Z3_optimize_get_objective', AST, (_in(CONTEXT), _in(OPTIMIZE), _in(UINT)))
*/
Z3_ast Z3_API Z3_optimize_get_objective(Z3_context c, Z3_optimize o, unsigned index);
/*@}*/
/*@}*/