3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-12 12:08:18 +00:00

add solution_prefix per #1463, have parto with single objective behave similar to multipe-objectives #1439

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2018-01-28 11:45:39 -08:00
parent 57406d6cc4
commit e4198c38e2
6 changed files with 31 additions and 3 deletions

View file

@ -727,6 +727,7 @@ public:
} }
m_model = mdl; m_model = mdl;
m_c.model_updated(mdl);
for (unsigned i = 0; i < m_soft.size(); ++i) { for (unsigned i = 0; i < m_soft.size(); ++i) {
m_assignment[i] = is_true(m_soft[i]); m_assignment[i] = is_true(m_soft[i]);

View file

@ -155,7 +155,7 @@ namespace opt {
rational l = m_adjust_value(m_lower); rational l = m_adjust_value(m_lower);
rational u = m_adjust_value(m_upper); rational u = m_adjust_value(m_upper);
if (l > u) std::swap(l, u); if (l > u) std::swap(l, u);
verbose_stream() << "(opt." << solver << " [" << l << ":" << u << "])\n";); verbose_stream() << "(opt." << solver << " [" << l << ":" << u << "])\n";);
} }
lbool maxsmt_solver_base::find_mutexes(obj_map<expr, rational>& new_soft) { lbool maxsmt_solver_base::find_mutexes(obj_map<expr, rational>& new_soft) {
@ -391,6 +391,10 @@ namespace opt {
return m_c.get_solver(); return m_c.get_solver();
} }
void maxsmt::model_updated(model* mdl) {
m_c.model_updated(mdl);
}
}; };

View file

@ -147,6 +147,7 @@ namespace opt {
bool get_assignment(unsigned index) const; bool get_assignment(unsigned index) const;
void display_answer(std::ostream& out) const; void display_answer(std::ostream& out) const;
void collect_statistics(statistics& st) const; void collect_statistics(statistics& st) const;
void model_updated(model* mdl);
private: private:
bool is_maxsat_problem(weights_t& ws) const; bool is_maxsat_problem(weights_t& ws) const;
void verify_assignment(); void verify_assignment();

View file

@ -138,6 +138,7 @@ namespace opt {
p.set_bool("unsat_core", true); p.set_bool("unsat_core", true);
p.set_bool("elim_to_real", true); p.set_bool("elim_to_real", true);
updt_params(p); updt_params(p);
m_model_counter = 0;
} }
context::~context() { context::~context() {
@ -1007,6 +1008,22 @@ namespace opt {
} }
} }
void context::model_updated(model* md) {
opt_params optp(m_params);
symbol prefix = optp.solution_prefix();
if (prefix == symbol::null) return;
model_ref mdl = md->copy();
fix_model(mdl);
std::ostringstream buffer;
buffer << prefix << (m_model_counter++) << ".smt2";
std::ofstream out(buffer.str());
if (out) {
model_smt2_pp(out, m, *mdl, 0);
out.close();
}
}
bool context::verify_model(unsigned index, model* md, rational const& _v) { bool context::verify_model(unsigned index, model* md, rational const& _v) {
rational r; rational r;
app_ref term = m_objectives[index].m_term; app_ref term = m_objectives[index].m_term;
@ -1015,7 +1032,7 @@ namespace opt {
} }
rational v = m_objectives[index].m_adjust_value(_v); rational v = m_objectives[index].m_adjust_value(_v);
expr_ref val(m); expr_ref val(m);
model_ref mdl = md; model_ref mdl = md->copy();
fix_model(mdl); fix_model(mdl);
if (!mdl->eval(term, val)) { if (!mdl->eval(term, val)) {

View file

@ -57,6 +57,7 @@ namespace opt {
virtual unsigned num_objectives() = 0; virtual unsigned num_objectives() = 0;
virtual bool verify_model(unsigned id, model* mdl, rational const& v) = 0; virtual bool verify_model(unsigned id, model* mdl, rational const& v) = 0;
virtual void set_model(model_ref& _m) = 0; virtual void set_model(model_ref& _m) = 0;
virtual void model_updated(model* mdl) = 0;
}; };
/** /**
@ -154,9 +155,10 @@ namespace opt {
map_t m_maxsmts; map_t m_maxsmts;
scoped_state m_scoped_state; scoped_state m_scoped_state;
vector<objective> m_objectives; vector<objective> m_objectives;
model_ref m_model; model_ref m_model;
model_converter_ref m_model_converter; model_converter_ref m_model_converter;
filter_model_converter m_fm; filter_model_converter m_fm;
unsigned m_model_counter;
obj_map<func_decl, unsigned> m_objective_fns; obj_map<func_decl, unsigned> m_objective_fns;
obj_map<func_decl, expr*> m_objective_orig; obj_map<func_decl, expr*> m_objective_orig;
func_decl_ref_vector m_objective_refs; func_decl_ref_vector m_objective_refs;
@ -231,6 +233,8 @@ namespace opt {
virtual bool verify_model(unsigned id, model* mdl, rational const& v); virtual bool verify_model(unsigned id, model* mdl, rational const& v);
virtual void model_updated(model* mdl);
private: private:
lbool execute(objective const& obj, bool committed, bool scoped); lbool execute(objective const& obj, bool committed, bool scoped);

View file

@ -5,6 +5,7 @@ def_module_params('opt',
('maxsat_engine', SYMBOL, 'maxres', "select engine for maxsat: 'core_maxsat', 'wmax', 'maxres', 'pd-maxres'"), ('maxsat_engine', SYMBOL, 'maxres', "select engine for maxsat: 'core_maxsat', 'wmax', 'maxres', 'pd-maxres'"),
('priority', SYMBOL, 'lex', "select how to priortize objectives: 'lex' (lexicographic), 'pareto', or 'box'"), ('priority', SYMBOL, 'lex', "select how to priortize objectives: 'lex' (lexicographic), 'pareto', or 'box'"),
('dump_benchmarks', BOOL, False, 'dump benchmarks for profiling'), ('dump_benchmarks', BOOL, False, 'dump benchmarks for profiling'),
('solution_prefix', SYMBOL, None, "path prefix to dump intermediary, but non-optimal, solutions"),
('timeout', UINT, UINT_MAX, 'timeout (in milliseconds) (UINT_MAX and 0 mean no timeout)'), ('timeout', UINT, UINT_MAX, 'timeout (in milliseconds) (UINT_MAX and 0 mean no timeout)'),
('rlimit', UINT, 0, 'resource limit (0 means no limit)'), ('rlimit', UINT, 0, 'resource limit (0 means no limit)'),
('enable_sls', BOOL, False, 'enable SLS tuning during weighted maxsast'), ('enable_sls', BOOL, False, 'enable SLS tuning during weighted maxsast'),