Skip to content

Commit 058b9e4

Browse files
committed
optimise rewrite_eqs to avoid fresh variables
Signed-off-by: Lev Nachmanson <levnach@hotmail.com>
1 parent ed3df33 commit 058b9e4

File tree

1 file changed

+29
-16
lines changed

1 file changed

+29
-16
lines changed

src/math/lp/dioph_eq.cpp

+29-16
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,7 @@ namespace lp {
923923
const auto & row = m_e_matrix.m_rows[ei];
924924
for (const auto& p : row) {
925925
if (m_k2s.has_key(p.var())) {
926+
/*
926927
std::cout << "entry:" << ei << " belongs to f but depends on column " << p.var() << std::endl;
927928
std::cout << "m_var_register.local_to_external(p.var()):" << m_var_register.local_to_external(p.var()) << std::endl;
928929
print_entry(ei, std::cout);
@@ -933,7 +934,8 @@ namespace lp {
933934
934935
std::cout << std::endl;
935936
std::cout << "column " << p.var() << " is subst by entry:";
936-
print_entry(m_k2s[p.var()],std::cout) << std::endl;
937+
print_entry(m_k2s[p.var()],std::cout) << std::endl;
938+
*/
937939
return false;
938940
}
939941
}
@@ -2190,6 +2192,9 @@ namespace lp {
21902192
// returns true if an equlity was rewritten and false otherwise
21912193
bool rewrite_eqs() {
21922194
unsigned h = -1;
2195+
unsigned n = 0; // number of choices for a fresh variable
2196+
mpq the_smallest_ahk;
2197+
unsigned kh, kh_sign;
21932198
for (unsigned ei=0; ei < m_e_matrix.row_count(); ei++) {
21942199
if (belongs_to_s(ei)) continue;
21952200
if (m_e_matrix.m_rows[ei].size() == 0) {
@@ -2200,23 +2205,31 @@ namespace lp {
22002205
return false;
22012206
}
22022207
}
2203-
h = ei;
2204-
break;
2205-
}
2206-
if (h == UINT_MAX)
2207-
return false;
2208-
auto [ahk, k, k_sign] = find_minimal_abs_coeff(h);
2209-
TRACE("dioph_eq", tout << "eh:"; print_entry(h, tout);
2210-
tout << "ahk:" << ahk << ", k:" << k << ", k_sign:" << k_sign
2211-
<< std::endl;);
2208+
auto [ahk, k, k_sign] = find_minimal_abs_coeff(ei);
2209+
if (ahk.is_one()) {
2210+
TRACE("dioph_eq", tout << "push to S:\n"; print_entry(ei, tout););
2211+
move_entry_from_f_to_s(k, ei);
2212+
eliminate_var_in_f(ei, k, k_sign);
2213+
return true;
2214+
}
22122215

2213-
if (ahk.is_one()) {
2214-
TRACE("dioph_eq", tout << "push to S:\n"; print_entry(h, tout););
2215-
move_entry_from_f_to_s(k, h);
2216-
eliminate_var_in_f(h, k, k_sign);
2217-
} else {
2218-
fresh_var_step(h, k, ahk * mpq(k_sign));
2216+
if (n == 0 || the_smallest_ahk > ahk) {
2217+
n = 1;
2218+
the_smallest_ahk = ahk;
2219+
h = ei;
2220+
kh = k;
2221+
kh_sign = k_sign;
2222+
continue;
2223+
}
2224+
if (the_smallest_ahk == ahk && lra.settings().random_next() % (++n) == 0) {
2225+
h = ei;
2226+
kh = k;
2227+
kh_sign = k_sign;
2228+
}
22192229
}
2230+
if (h == UINT_MAX) return false;
2231+
SASSERT(!the_smallest_ahk.is_one());
2232+
fresh_var_step(h, kh, the_smallest_ahk * mpq(kh_sign));
22202233
return true;
22212234
}
22222235

0 commit comments

Comments
 (0)