3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-13 20:38:43 +00:00

lcm normalization

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2022-05-11 09:03:57 -07:00
parent 5ca3bc3212
commit cbaa16df57
2 changed files with 18 additions and 2 deletions

View file

@ -485,6 +485,21 @@ namespace opt {
}
}
model_based_opt::row& model_based_opt::row::normalize() {
if (m_type == t_mod)
return *this;
rational D(abs(m_coeff));
for (auto const& [id, coeff] : m_vars)
D = lcm(D, coeff);
if (D == 1)
return *this;
SASSERT(D > 0);
for (auto & [id, coeff] : m_vars)
coeff *= D;
m_coeff *= D;
return *this;
}
//
// Let
// row1: t1 + a1*x <= 0
@ -923,9 +938,9 @@ namespace opt {
}
void model_based_opt::get_live_rows(vector<row>& rows) {
for (row const& r : m_rows) {
for (row & r : m_rows) {
if (r.m_alive) {
rows.push_back(r);
rows.push_back(r.normalize());
}
}
}

View file

@ -59,6 +59,7 @@ namespace opt {
bool m_alive; // rows can be marked dead if they have been processed.
void reset() { m_vars.reset(); m_coeff.reset(); m_value.reset(); }
row& normalize();
void neg() { for (var & v : m_vars) v.m_coeff.neg(); m_coeff.neg(); m_value.neg(); }
rational get_coefficient(unsigned x) const;
};