3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-23 09:05:31 +00:00

Add initial value setting for variables in Z3 API, solver, and optimize modules

This commit is contained in:
Nikolaj Bjorner 2024-09-18 16:13:15 +03:00
parent 0ba306e7b3
commit 48712b4f60
31 changed files with 297 additions and 9 deletions

View file

@ -58,8 +58,9 @@ namespace opt {
}
void context::scoped_state::pop() {
m_hard.resize(m_hard_lim.back());
m_asms.resize(m_asms_lim.back());
m_hard.shrink(m_hard_lim.back());
m_asms.shrink(m_asms_lim.back());
m_values.shrink(m_values_lim.back());
unsigned k = m_objectives_term_trail_lim.back();
while (m_objectives_term_trail.size() > k) {
unsigned idx = m_objectives_term_trail.back();
@ -79,6 +80,7 @@ namespace opt {
m_objectives_lim.pop_back();
m_hard_lim.pop_back();
m_asms_lim.pop_back();
m_values_lim.pop_back();
}
void context::scoped_state::add(expr* hard) {
@ -306,13 +308,11 @@ namespace opt {
if (contains_quantifiers()) {
warning_msg("optimization with quantified constraints is not supported");
}
#if 0
if (is_qsat_opt()) {
return run_qsat_opt();
}
#endif
solver& s = get_solver();
s.assert_expr(m_hard_constraints);
for (auto const& [var, value] : m_scoped_state.m_values) {
s.user_propagate_initialize_value(var, value);
}
opt_params optp(m_params);
symbol pri = optp.priority();
@ -697,6 +697,11 @@ namespace opt {
}
}
void context::initialize_value(expr* var, expr* value) {
m_scoped_state.m_values.push_back({expr_ref(var, m), expr_ref(value, m)});
}
/**
* Set the solver to the SAT core.
* It requres:

View file

@ -140,12 +140,14 @@ namespace opt {
unsigned_vector m_objectives_lim;
unsigned_vector m_objectives_term_trail;
unsigned_vector m_objectives_term_trail_lim;
unsigned_vector m_values_lim;
map_id m_indices;
public:
expr_ref_vector m_hard;
expr_ref_vector m_asms;
vector<objective> m_objectives;
vector<std::pair<expr_ref, expr_ref>> m_values;
scoped_state(ast_manager& m):
m(m),
@ -275,6 +277,8 @@ namespace opt {
void add_offset(unsigned id, rational const& o) override;
void initialize_value(expr* var, expr* value);
void register_on_model(on_model_t& ctx, std::function<void(on_model_t&, model_ref&)>& on_model) {
m_on_model_ctx = ctx;
m_on_model_eh = on_model;

View file

@ -116,6 +116,7 @@ namespace opt {
phase* get_phase() override { return m_context.get_phase(); }
void set_phase(phase* p) override { m_context.set_phase(p); }
void move_to_front(expr* e) override { m_context.move_to_front(e); }
void user_propagate_initialize_value(expr* var, expr* value) override { m_context.user_propagate_initialize_value(var, value); }
void set_logic(symbol const& logic);