mirror of
https://github.com/Z3Prover/z3
synced 2025-04-23 09:05:31 +00:00
add circuit and unate encoding besides sorting option
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
0b30ddb769
commit
3ae0ea8246
8 changed files with 488 additions and 184 deletions
|
@ -2591,22 +2591,54 @@ namespace sat {
|
|||
return literal(v, false);
|
||||
}
|
||||
|
||||
literal ba_solver::ba_sort::mk_max(literal l1, literal l2) {
|
||||
VERIFY(l1 != null_literal);
|
||||
VERIFY(l2 != null_literal);
|
||||
if (l1 == m_true) return l1;
|
||||
if (l2 == m_true) return l2;
|
||||
if (l1 == ~m_true) return l2;
|
||||
if (l2 == ~m_true) return l1;
|
||||
literal max = fresh("max");
|
||||
s.s().mk_clause(~l1, max);
|
||||
s.s().mk_clause(~l2, max);
|
||||
s.s().mk_clause(~max, l1, l2);
|
||||
return max;
|
||||
|
||||
literal ba_solver::ba_sort::mk_max(unsigned n, literal const* lits) {
|
||||
m_lits.reset();
|
||||
for (unsigned i = 0; i < n; ++i) {
|
||||
if (lits[i] == m_true) return m_true;
|
||||
if (lits[i] == ~m_true) continue;
|
||||
m_lits.push_back(lits[i]);
|
||||
}
|
||||
switch (m_lits.size()) {
|
||||
case 0:
|
||||
return ~m_true;
|
||||
case 1:
|
||||
return m_lits[0];
|
||||
default: {
|
||||
literal max = fresh("max");
|
||||
for (unsigned i = 0; i < n; ++i) {
|
||||
s.s().mk_clause(~m_lits[i], max);
|
||||
}
|
||||
m_lits.push_back(~max);
|
||||
s.s().mk_clause(m_lits.size(), m_lits.c_ptr());
|
||||
return max;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
literal ba_solver::ba_sort::mk_min(literal l1, literal l2) {
|
||||
return ~mk_max(~l1, ~l2);
|
||||
literal ba_solver::ba_sort::mk_min(unsigned n, literal const* lits) {
|
||||
m_lits.reset();
|
||||
for (unsigned i = 0; i < n; ++i) {
|
||||
if (lits[i] == ~m_true) return ~m_true;
|
||||
if (lits[i] == m_true) continue;
|
||||
m_lits.push_back(lits[i]);
|
||||
}
|
||||
switch (m_lits.size()) {
|
||||
case 0:
|
||||
return m_true;
|
||||
case 1:
|
||||
return m_lits[0];
|
||||
default: {
|
||||
literal min = fresh("min");
|
||||
for (unsigned i = 0; i < n; ++i) {
|
||||
s.s().mk_clause(~min, m_lits[i]);
|
||||
m_lits[i] = ~m_lits[i];
|
||||
}
|
||||
m_lits.push_back(min);
|
||||
s.s().mk_clause(m_lits.size(), m_lits.c_ptr());
|
||||
return min;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ba_solver::ba_sort::mk_clause(unsigned n, literal const* lits) {
|
||||
|
|
|
@ -255,8 +255,8 @@ namespace sat {
|
|||
pliteral mk_true();
|
||||
pliteral mk_not(pliteral l);
|
||||
pliteral fresh(char const*);
|
||||
pliteral mk_max(pliteral l1, pliteral l2);
|
||||
pliteral mk_min(pliteral l1, pliteral l2);
|
||||
pliteral mk_min(unsigned, pliteral const* lits);
|
||||
pliteral mk_max(unsigned, pliteral const* lits);
|
||||
void mk_clause(unsigned n, literal const* lits);
|
||||
std::ostream& pp(std::ostream& out, pliteral l) const;
|
||||
};
|
||||
|
|
|
@ -43,7 +43,7 @@ def_module_params('sat',
|
|||
('cardinality.solver', BOOL, True, 'use cardinality solver'),
|
||||
('pb.solver', SYMBOL, 'solver', 'method for handling Pseudo-Boolean constraints: circuit (arithmetical circuit), sorting (sorting circuit), totalizer (use totalizer encoding), solver (use native solver)'),
|
||||
('xor.solver', BOOL, False, 'use xor solver'),
|
||||
('atmost1_encoding', SYMBOL, 'grouped', 'encoding used for at-most-1 constraints grouped, bimander, ordered'),
|
||||
('cardinality.encoding', SYMBOL, 'grouped', 'encoding used for at-most-1 constraints grouped, bimander, ordered, unate, circuit'),
|
||||
('local_search', BOOL, False, 'use local search instead of CDCL'),
|
||||
('local_search_threads', UINT, 0, 'number of local search threads to find satisfiable solution'),
|
||||
('local_search_mode', SYMBOL, 'wsat', 'local search algorithm, either default wsat or qsat'),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue