3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-24 01:25:31 +00:00

enable wcnf output for weighted maxsat problems

This commit is contained in:
Nikolaj Bjorner 2021-02-28 09:59:36 -08:00
parent b02cba6106
commit 13f05ae9dc
6 changed files with 115 additions and 60 deletions

View file

@ -4002,17 +4002,18 @@ namespace sat {
void solver::display_wcnf(std::ostream & out, unsigned sz, literal const* lits, unsigned const* weights) const {
unsigned max_weight = 0;
for (unsigned i = 0; i < sz; ++i) {
max_weight = std::max(max_weight, weights[i]);
}
for (unsigned i = 0; i < sz; ++i)
max_weight += weights[i];
++max_weight;
if (m_ext)
throw default_exception("wcnf is only supported for pure CNF problems");
out << "p wcnf " << num_vars() << " " << num_clauses() + sz << " " << max_weight << "\n";
out << "c soft " << sz << "\n";
for (literal lit : m_trail) {
for (literal lit : m_trail)
out << max_weight << " " << dimacs_lit(lit) << " 0\n";
}
unsigned l_idx = 0;
for (watch_list const& wlist : m_watches) {
literal l = ~to_literal(l_idx);