mirror of
https://github.com/Z3Prover/z3
synced 2026-02-17 14:21:45 +00:00
Implement Z3_optimize_translate for context translation (#8072)
* Initial plan * Implement Z3_optimize_translate functionality Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com> * Fix compilation errors and add tests for optimize translate Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com> * Revert changes to opt_solver.cpp as requested Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>
This commit is contained in:
parent
f917005ee1
commit
313be1ca1b
6 changed files with 155 additions and 0 deletions
|
|
@ -20,6 +20,7 @@ Notes:
|
|||
#include "util/gparams.h"
|
||||
#include "ast/for_each_expr.h"
|
||||
#include "ast/ast_pp.h"
|
||||
#include "ast/ast_translation.h"
|
||||
#include "ast/bv_decl_plugin.h"
|
||||
#include "ast/pb_decl_plugin.h"
|
||||
#include "ast/ast_smt_pp.h"
|
||||
|
|
@ -155,6 +156,57 @@ namespace opt {
|
|||
reset_maxsmts();
|
||||
}
|
||||
|
||||
context* context::translate(ast_manager& target_m) {
|
||||
// Create AST translator
|
||||
ast_translation translator(m, target_m);
|
||||
|
||||
// Create new context in target manager
|
||||
context* result = alloc(context, target_m);
|
||||
|
||||
// Copy parameters
|
||||
result->updt_params(m_params);
|
||||
|
||||
// Set logic
|
||||
if (m_logic != symbol::null) {
|
||||
result->set_logic(m_logic);
|
||||
}
|
||||
|
||||
// Translate hard constraints from scoped state
|
||||
for (expr* e : m_scoped_state.m_hard) {
|
||||
result->add_hard_constraint(translator(e));
|
||||
}
|
||||
|
||||
// Translate objectives
|
||||
for (auto const& obj : m_scoped_state.m_objectives) {
|
||||
if (obj.m_type == O_MAXIMIZE || obj.m_type == O_MINIMIZE) {
|
||||
// Translate maximize/minimize objectives
|
||||
app_ref translated_term(to_app(translator(obj.m_term.get())), target_m);
|
||||
result->add_objective(translated_term, obj.m_type == O_MAXIMIZE);
|
||||
}
|
||||
else if (obj.m_type == O_MAXSMT) {
|
||||
// Translate soft constraints for MaxSMT objectives
|
||||
for (unsigned i = 0; i < obj.m_terms.size(); ++i) {
|
||||
result->add_soft_constraint(
|
||||
translator(obj.m_terms.get(i)),
|
||||
obj.m_weights[i],
|
||||
obj.m_id
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Copy configuration flags
|
||||
result->m_enable_sat = m_enable_sat;
|
||||
result->m_enable_sls = m_enable_sls;
|
||||
result->m_is_clausal = m_is_clausal;
|
||||
result->m_pp_neat = m_pp_neat;
|
||||
result->m_pp_wcnf = m_pp_wcnf;
|
||||
result->m_incremental = m_incremental;
|
||||
result->m_maxsat_engine = m_maxsat_engine;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void context::reset_maxsmts() {
|
||||
for (auto& kv : m_maxsmts) {
|
||||
dealloc(kv.m_value);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue