diff --git a/src/opt/opt_context.cpp b/src/opt/opt_context.cpp index 55b2a33ec..9acd93a01 100644 --- a/src/opt/opt_context.cpp +++ b/src/opt/opt_context.cpp @@ -125,7 +125,7 @@ namespace opt { m_solver(nullptr), m_pareto1(false), m_box_index(UINT_MAX), - m_optsmt(m), + m_optsmt(m, *this), m_scoped_state(m), m_fm(alloc(generic_model_converter, m, "opt")), m_model_fixed(), @@ -357,6 +357,17 @@ namespace opt { } } + void context::set_model(model_ref& m) { + m_model = m; + opt_params optp(m_params); + if (optp.dump_models()) { + model_ref md = m->copy(); + fix_model(md); + std::cout << *md << "\n"; + } + } + + void context::get_model_core(model_ref& mdl) { mdl = m_model; fix_model(mdl); @@ -1062,6 +1073,9 @@ namespace opt { void context::model_updated(model* md) { + model_ref mdl = md; + set_model(mdl); +#if 0 opt_params optp(m_params); symbol prefix = optp.solution_prefix(); if (prefix == symbol::null || prefix == symbol("")) return; @@ -1074,6 +1088,7 @@ namespace opt { out << *mdl; out.close(); } +#endif } diff --git a/src/opt/opt_context.h b/src/opt/opt_context.h index fe0d4a13e..796e83535 100644 --- a/src/opt/opt_context.h +++ b/src/opt/opt_context.h @@ -189,7 +189,7 @@ namespace opt { bool empty() override { return m_scoped_state.m_objectives.empty(); } void set_hard_constraints(expr_ref_vector const& hard) override; lbool optimize(expr_ref_vector const& asms) override; - void set_model(model_ref& _m) override { m_model = _m; } + void set_model(model_ref& _m) override; void get_model_core(model_ref& _m) override; void get_box_model(model_ref& _m, unsigned index) override; void fix_model(model_ref& _m) override; diff --git a/src/opt/opt_params.pyg b/src/opt/opt_params.pyg index f72bafbd8..623eefea3 100644 --- a/src/opt/opt_params.pyg +++ b/src/opt/opt_params.pyg @@ -5,6 +5,7 @@ def_module_params('opt', ('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', 'box'"), ('dump_benchmarks', BOOL, False, 'dump benchmarks for profiling'), + ('dump_models', BOOL, False, 'display intermediary models to stdout'), ('solution_prefix', SYMBOL, '', "path prefix to dump intermediary, but non-optimal, solutions"), ('timeout', UINT, UINT_MAX, 'timeout (in milliseconds) (UINT_MAX and 0 mean no timeout)'), ('rlimit', UINT, 0, 'resource limit (0 means no limit)'), diff --git a/src/opt/optsmt.cpp b/src/opt/optsmt.cpp index 7feb8f615..4a35acd02 100644 --- a/src/opt/optsmt.cpp +++ b/src/opt/optsmt.cpp @@ -31,6 +31,7 @@ Notes: #include #include "opt/optsmt.h" #include "opt/opt_solver.h" +#include "opt/opt_context.h" #include "ast/arith_decl_plugin.h" #include "smt/theory_arith.h" #include "ast/ast_pp.h" @@ -362,12 +363,14 @@ namespace opt { verbose_stream() << "(optsmt lower bound: " << v << ")\n"; else verbose_stream() << "(optsmt upper bound: " << (-v) << ")\n"; - ); + ); expr_ref tmp(m); for (unsigned i = idx+1; i < m_vars.size(); ++i) { m_s->maximize_objective(i, tmp); m_lower[i] = m_s->saved_objective_value(i); } + + m_context.set_model(m_model); } } diff --git a/src/opt/optsmt.h b/src/opt/optsmt.h index 6db7eaadf..c9aa4f41d 100644 --- a/src/opt/optsmt.h +++ b/src/opt/optsmt.h @@ -27,8 +27,11 @@ namespace opt { Returns an optimal assignment to objective functions. */ + class context; + class optsmt { ast_manager& m; + context& m_context; opt_solver* m_s; vector m_lower; vector m_upper; @@ -40,8 +43,8 @@ namespace opt { svector m_labels; sref_vector m_models; public: - optsmt(ast_manager& m): - m(m), m_s(nullptr), m_objs(m), m_lower_fmls(m) {} + optsmt(ast_manager& m, context& ctx): + m(m), m_context(ctx), m_s(nullptr), m_objs(m), m_lower_fmls(m) {} void setup(opt_solver& solver);