mirror of
https://github.com/Z3Prover/z3
synced 2025-04-23 09:05:31 +00:00
tune initialization for wmax and sortmax
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
ea601dd403
commit
df0e3a100c
5 changed files with 32 additions and 12 deletions
|
@ -58,15 +58,34 @@ namespace opt {
|
|||
ptr_vector<expr> out;
|
||||
obj_map<expr, rational>::iterator it = soft.begin(), end = soft.end();
|
||||
for (; it != end; ++it) {
|
||||
if (!it->m_value.is_unsigned()) {
|
||||
throw default_exception("sortmax can only handle unsigned weights. Use a different heuristic.");
|
||||
}
|
||||
unsigned n = it->m_value.get_unsigned();
|
||||
while (n > 0) {
|
||||
in.push_back(it->m_key);
|
||||
--n;
|
||||
}
|
||||
m_upper += it->m_value;
|
||||
}
|
||||
m_sort.sorting(in.size(), in.c_ptr(), out);
|
||||
|
||||
// initialize sorting network outputs using the initial assignment.
|
||||
unsigned first = 0;
|
||||
it = soft.begin();
|
||||
for (; it != end; ++it) {
|
||||
expr_ref tmp(m);
|
||||
if (m_model->eval(it->m_key, tmp) && m.is_true(tmp)) {
|
||||
unsigned n = it->m_value.get_unsigned();
|
||||
while (n > 0) {
|
||||
s().assert_expr(out[first]);
|
||||
++first;
|
||||
--n;
|
||||
}
|
||||
}
|
||||
else {
|
||||
m_upper += it->m_value;
|
||||
}
|
||||
}
|
||||
while (l_true == is_sat && first < out.size() && m_lower < m_upper) {
|
||||
trace_bounds("sortmax");
|
||||
s().assert_expr(out[first]);
|
||||
|
|
|
@ -48,14 +48,18 @@ namespace opt {
|
|||
rational offset = m_lower;
|
||||
m_upper = offset;
|
||||
bool was_sat = false;
|
||||
expr_ref_vector disj(m);
|
||||
obj_map<expr, rational>::iterator it = soft.begin(), end = soft.end();
|
||||
for (; it != end; ++it) {
|
||||
wth().assert_weighted(it->m_key, it->m_value);
|
||||
expr_ref tmp(m);
|
||||
if (!m_model->eval(it->m_key, tmp) || !m.is_true(tmp)) {
|
||||
bool is_true = m_model->eval(it->m_key, tmp) && m.is_true(tmp);
|
||||
expr* c = wth().assert_weighted(it->m_key, it->m_value, is_true);
|
||||
if (!is_true) {
|
||||
m_upper += it->m_value;
|
||||
disj.push_back(c);
|
||||
}
|
||||
}
|
||||
s().assert_expr(mk_or(disj));
|
||||
trace_bounds("wmax");
|
||||
while (l_true == is_sat && m_lower < m_upper) {
|
||||
is_sat = s().check_sat(0, 0);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue