Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolajBjorner committed Jul 11, 2021
1 parent 18a76ab commit cab1076
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 16 deletions.
37 changes: 25 additions & 12 deletions src/math/simplex/model_based_opt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,20 +134,29 @@ namespace opt {
}

void model_based_opt::def::normalize() {
if (m_div.is_one()) return;
SASSERT(m_div.is_int());
if (m_div.is_neg()) {
for (var& v : m_vars)
v.m_coeff.neg();
m_coeff.neg();
m_div.neg();
}
if (m_div.is_one())
return;
rational g(m_div);
if (!m_coeff.is_int())
return;
g = gcd(g, m_coeff);
for (var const& v : m_vars) {
if (!v.m_coeff.is_int())
return;
g = gcd(g, abs(v.m_coeff));
if (g.is_one()) break;
}
if (m_div.is_neg()) {
g.neg();
if (g.is_one())
break;
}
if (!g.is_one()) {
for (var& v : m_vars) {
v.m_coeff /= g;
}
for (var& v : m_vars)
v.m_coeff /= g;
m_coeff /= g;
m_div /= g;
}
Expand Down Expand Up @@ -1130,9 +1139,12 @@ namespace opt {
}
TRACE("opt1", display(tout << "tableau after replace x by y := v" << y << "\n"););
def result = project(y, compute_def);
if (compute_def)
result = (result * D) + u;
SASSERT(!compute_def || eval(result) == eval(x));
if (compute_def) {
result = (result * D) + u;
m_var2value[x] = eval(result);
}
TRACE("opt1", display(tout << "tableau after project y" << y << "\n"););

return result;
}

Expand Down Expand Up @@ -1181,7 +1193,7 @@ namespace opt {
// 3 | -t & 21 | (-ct + 3s) & a-t <= 3u

model_based_opt::def model_based_opt::solve_for(unsigned row_id1, unsigned x, bool compute_def) {
TRACE("opt", tout << "v" << x << "\n" << m_rows[row_id1] << "\n";);
TRACE("opt", tout << "v" << x << " := " << eval(x) << "\n" << m_rows[row_id1] << "\n";);
rational a = get_coefficient(row_id1, x), b;
ineq_type ty = m_rows[row_id1].m_type;
SASSERT(!a.is_zero());
Expand Down Expand Up @@ -1231,6 +1243,7 @@ namespace opt {
if (compute_def) {
result = def(m_rows[row_id1], x);
m_var2value[x] = eval(result);
TRACE("opt1", tout << "updated eval " << x << " := " << eval(x) << "\n";);
}
retire_row(row_id1);
return result;
Expand Down
4 changes: 3 additions & 1 deletion src/qe/mbp/mbp_arith.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,9 @@ namespace mbp {
}
}
fmls.shrink(j);
TRACE("qe", tout << "formulas\n" << fmls << "\n";);
TRACE("qe", tout << "formulas\n" << fmls << "\n";
for (auto [e, id] : tids)
tout << mk_pp(e, m) << " -> " << id << "\n";);

// fmls holds residue,
// mbo holds linear inequalities that are in scope
Expand Down
2 changes: 1 addition & 1 deletion src/qe/mbp/mbp_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ namespace mbp {
model_evaluator eval(model);
eval.set_expand_array_equalities(true);
TRACE("qe", tout << fmls << "\n";);
DEBUG_CODE(for (expr* fml : fmls) { CTRACE("qe", m.is_false(eval(fml)), tout << mk_pp(fml, m) << " is false\n";); SASSERT(!m.is_false(eval(fml))); });
DEBUG_CODE(for (expr* fml : fmls) { CTRACE("qe", m.is_false(eval(fml)), tout << mk_pp(fml, m) << " is false\n" << model;); SASSERT(!m.is_false(eval(fml))); });

for (unsigned i = 0; i < fmls.size(); ++i) {
expr* fml = fmls.get(i), * nfml, * f1, * f2, * f3;
Expand Down
8 changes: 6 additions & 2 deletions src/sat/smt/euf_solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,13 +302,17 @@ namespace euf {
size_t* c = to_ptr(l);
SASSERT(is_literal(c));
SASSERT(l == get_literal(c));
if (!sign && n->is_equality()) {
if (n->value_conflict()) {
euf::enode* nb = sign ? mk_false() : mk_true();
m_egraph.merge(n, nb, c);
}
else if (!sign && n->is_equality()) {
SASSERT(!m.is_iff(e));
euf::enode* na = n->get_arg(0);
euf::enode* nb = n->get_arg(1);
m_egraph.merge(na, nb, c);
}
else if (n->merge_tf() || n->value_conflict()) {
else if (n->merge_tf()) {
euf::enode* nb = sign ? mk_false() : mk_true();
m_egraph.merge(n, nb, c);
}
Expand Down

0 comments on commit cab1076

Please sign in to comment.