3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-06-27 16:38:45 +00:00

bug fixes

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2013-11-08 22:40:43 -08:00
parent b573b94f84
commit ba05f79415
6 changed files with 16 additions and 12 deletions

View file

@ -28,6 +28,7 @@ namespace opt {
lbool is_sat; lbool is_sat;
m_answer.reset(); m_answer.reset();
m_msolver = 0; m_msolver = 0;
m_s = &s;
if (m_soft_constraints.empty()) { if (m_soft_constraints.empty()) {
m_msolver = 0; m_msolver = 0;
is_sat = s.check_sat(0, 0); is_sat = s.check_sat(0, 0);
@ -80,8 +81,9 @@ namespace opt {
} }
void maxsmt::commit_assignment() { void maxsmt::commit_assignment() {
SASSERT(m_s);
for (unsigned i = 0; i < m_answer.size(); ++i) { for (unsigned i = 0; i < m_answer.size(); ++i) {
s->assert_expr(m_answer[i].get()); m_s->assert_expr(m_answer[i].get());
} }
} }

View file

@ -41,14 +41,14 @@ namespace opt {
class maxsmt { class maxsmt {
ast_manager& m; ast_manager& m;
solver* s; solver* m_s;
volatile bool m_cancel; volatile bool m_cancel;
expr_ref_vector m_soft_constraints; expr_ref_vector m_soft_constraints;
expr_ref_vector m_answer; expr_ref_vector m_answer;
vector<rational> m_weights; vector<rational> m_weights;
scoped_ptr<maxsmt_solver> m_msolver; scoped_ptr<maxsmt_solver> m_msolver;
public: public:
maxsmt(ast_manager& m): m(m), s(0), m_cancel(false), m_soft_constraints(m), m_answer(m) {} maxsmt(ast_manager& m): m(m), m_s(0), m_cancel(false), m_soft_constraints(m), m_answer(m) {}
lbool operator()(solver& s); lbool operator()(solver& s);

View file

@ -51,9 +51,14 @@ namespace opt {
} }
lbool context::optimize() { lbool context::optimize() {
// TBD: add configuration parameter to select between box and pareto // TBD: does not work...
if (m_params.get_bool("pareto", false)) {
return optimize_pareto();
}
else {
return optimize_box(); return optimize_box();
} }
}
lbool context::optimize_box() { lbool context::optimize_box() {
opt_solver& s = *m_solver.get(); opt_solver& s = *m_solver.get();

View file

@ -3,6 +3,7 @@ def_module_params('opt',
export=True, export=True,
params=(('timeout', UINT, UINT_MAX, 'set timeout'), params=(('timeout', UINT, UINT_MAX, 'set timeout'),
('engine', SYMBOL, 'basic', "select optimization engine: 'basic', 'farkas', 'symba'"), ('engine', SYMBOL, 'basic', "select optimization engine: 'basic', 'farkas', 'symba'"),
('pareto', BOOL, False, 'return a Pareto front (as opposed to a bounding box)'),
)) ))

View file

@ -204,13 +204,7 @@ namespace opt {
lbool optsmt::operator()(opt_solver& solver) { lbool optsmt::operator()(opt_solver& solver) {
s = &solver; s = &solver;
s->reset_objectives(); s->reset_objectives();
m_lower.reset();
m_upper.reset();
m_vars.reset(); m_vars.reset();
for (unsigned i = 0; i < m_objs.size(); ++i) {
m_lower.push_back(inf_eps(rational(-1),inf_rational(0)));
m_upper.push_back(inf_eps(rational(1), inf_rational(0)));
}
// First check_sat call to initialize theories // First check_sat call to initialize theories
lbool is_sat = s->check_sat(0, 0); lbool is_sat = s->check_sat(0, 0);
@ -297,6 +291,8 @@ namespace opt {
SASSERT(is_app(t2)); SASSERT(is_app(t2));
m_objs.push_back(to_app(t2)); m_objs.push_back(to_app(t2));
m_is_max.push_back(is_max); m_is_max.push_back(is_max);
m_lower.push_back(inf_eps(rational(-1),inf_rational(0)));
m_upper.push_back(inf_eps(rational(1), inf_rational(0)));
} }
void optsmt::updt_params(params_ref& p) { void optsmt::updt_params(params_ref& p) {

View file

@ -51,7 +51,7 @@ namespace opt {
void display_assignment(std::ostream& out) const; void display_assignment(std::ostream& out) const;
void display_range_assignment(std::ostream& out) const; void display_range_assignment(std::ostream& out) const;
unsigned get_num_objectives() const { return m_vars.size(); } unsigned get_num_objectives() const { return m_objs.size(); }
void commit_assignment(unsigned index); void commit_assignment(unsigned index);
inf_eps get_value(unsigned index) const; inf_eps get_value(unsigned index) const;
inf_eps get_lower(unsigned index) const; inf_eps get_lower(unsigned index) const;