mirror of
https://github.com/Z3Prover/z3
synced 2025-04-23 17:15:31 +00:00
enable wcnf output for weighted maxsat problems
This commit is contained in:
parent
b02cba6106
commit
13f05ae9dc
6 changed files with 115 additions and 60 deletions
|
@ -24,6 +24,7 @@ Notes:
|
|||
#include "ast/pb_decl_plugin.h"
|
||||
#include "ast/ast_smt_pp.h"
|
||||
#include "ast/ast_pp_util.h"
|
||||
#include "ast/display_dimacs.h"
|
||||
#include "model/model_smt2_pp.h"
|
||||
#include "tactic/goal.h"
|
||||
#include "tactic/tactic.h"
|
||||
|
@ -1540,9 +1541,12 @@ namespace opt {
|
|||
m_enable_sls = _p.enable_sls();
|
||||
m_maxsat_engine = _p.maxsat_engine();
|
||||
m_pp_neat = _p.pp_neat();
|
||||
m_pp_wcnf = _p.pp_wcnf();
|
||||
}
|
||||
|
||||
std::string context::to_string() const {
|
||||
std::string context::to_string() {
|
||||
if (m_pp_wcnf)
|
||||
return to_wcnf();
|
||||
return to_string(false, m_scoped_state.m_hard, m_scoped_state.m_objectives);
|
||||
}
|
||||
|
||||
|
@ -1557,6 +1561,9 @@ namespace opt {
|
|||
auto const& objectives = m_objectives;
|
||||
if (objectives.size() > 1)
|
||||
throw default_exception("only single objective weighted MaxSAT wcnf output is supported");
|
||||
ptr_vector<expr> soft_f;
|
||||
vector<rational> soft_w;
|
||||
svector<std::pair<expr*, unsigned>> soft;
|
||||
if (objectives.size() == 1) {
|
||||
auto const& obj = objectives[0];
|
||||
if (obj.m_type != O_MAXSMT)
|
||||
|
@ -1565,10 +1572,15 @@ namespace opt {
|
|||
rational w = obj.m_weights[j];
|
||||
if (!w.is_unsigned())
|
||||
throw default_exception("only single objective weighted MaxSAT wcnf output is supported");
|
||||
soft_f.push_back(obj.m_terms[j]);
|
||||
soft_w.push_back(w);
|
||||
}
|
||||
}
|
||||
NOT_IMPLEMENTED_YET();
|
||||
return std::string("");
|
||||
std::ostringstream strm;
|
||||
m_sat_solver = mk_inc_sat_solver(m, m_params);
|
||||
m_sat_solver->assert_expr(m_hard_constraints);
|
||||
inc_sat_display(strm, *m_sat_solver.get(), soft_f.size(), soft_f.c_ptr(), soft_w.c_ptr());
|
||||
return strm.str();
|
||||
}
|
||||
|
||||
std::string context::to_string(bool is_internal, expr_ref_vector const& hard, vector<objective> const& objectives) const {
|
||||
|
|
|
@ -179,10 +179,11 @@ namespace opt {
|
|||
func_decl_ref_vector m_objective_refs;
|
||||
expr_ref_vector m_core;
|
||||
tactic_ref m_simplify;
|
||||
bool m_enable_sat;
|
||||
bool m_enable_sls;
|
||||
bool m_is_clausal;
|
||||
bool m_pp_neat;
|
||||
bool m_enable_sat { true } ;
|
||||
bool m_enable_sls { false };
|
||||
bool m_is_clausal { false };
|
||||
bool m_pp_neat { true };
|
||||
bool m_pp_wcnf { false };
|
||||
symbol m_maxsat_engine;
|
||||
symbol m_logic;
|
||||
svector<symbol> m_labels;
|
||||
|
@ -232,7 +233,7 @@ namespace opt {
|
|||
void get_lower(unsigned idx, expr_ref_vector& es) { to_exprs(get_lower_as_num(idx), es); }
|
||||
void get_upper(unsigned idx, expr_ref_vector& es) { to_exprs(get_upper_as_num(idx), es); }
|
||||
|
||||
std::string to_string() const;
|
||||
std::string to_string();
|
||||
|
||||
|
||||
unsigned num_objectives() override { return m_scoped_state.m_objectives.size(); }
|
||||
|
|
|
@ -16,6 +16,7 @@ def_module_params('opt',
|
|||
('elim_01', BOOL, True, 'eliminate 01 variables'),
|
||||
('pp.neat', BOOL, True, 'use neat (as opposed to less readable, but faster) pretty printer when displaying context'),
|
||||
('pb.compile_equality', BOOL, False, 'compile arithmetical equalities into pseudo-Boolean equality (instead of two inequalites)'),
|
||||
('pp.wcnf', BOOL, False, 'print maxsat benchmark into wcnf format'),
|
||||
('maxlex.enable', BOOL, True, 'enable maxlex heuristic for lexicographic MaxSAT problems'),
|
||||
('maxres.hill_climb', BOOL, True, 'give preference for large weight cores'),
|
||||
('maxres.add_upper_bound_block', BOOL, False, 'restict upper bound with constraint'),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue