3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-23 17:15:31 +00:00
This commit is contained in:
Nikolaj Bjorner 2021-07-11 21:00:58 +02:00
parent 18a76ab82c
commit cab1076514
4 changed files with 35 additions and 16 deletions

View file

@ -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;
}
@ -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;
}
@ -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());
@ -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;