Skip to content

Commit cec8dc2

Browse files
committedFeb 11, 2025
try markovich number
Signed-off-by: Lev Nachmanson <[email protected]>
1 parent 3f2d2e8 commit cec8dc2

File tree

1 file changed

+60
-24
lines changed

1 file changed

+60
-24
lines changed
 

Diff for: ‎src/math/lp/dioph_eq.cpp

+60-24
Original file line numberDiff line numberDiff line change
@@ -1602,8 +1602,30 @@ namespace lp {
16021602
return dep;
16031603
}
16041604

1605+
void fill_f_vector(std_vector<unsigned> & f_vector) {
1606+
for (unsigned ei = 0; ei < m_e_matrix.row_count(); ei++) {
1607+
if (belongs_to_s(ei)) continue;
1608+
if (m_e_matrix.m_rows[ei].size() == 0) {
1609+
if (m_sum_of_fixed[ei].is_zero()) {
1610+
continue;
1611+
} else {
1612+
m_conflict_index = ei;
1613+
return;
1614+
}
1615+
}
1616+
f_vector.push_back(ei);
1617+
}
1618+
}
1619+
16051620
lia_move process_f() {
1606-
while (rewrite_eqs()) {}
1621+
std_vector<unsigned> f_vector;
1622+
fill_f_vector(f_vector);
1623+
if (m_conflict_index != UINT_MAX) {
1624+
lra.stats().m_dio_rewrite_conflicts++;
1625+
return lia_move::conflict;
1626+
}
1627+
1628+
while (rewrite_eqs(f_vector)) {}
16071629

16081630
if (m_conflict_index != UINT_MAX) {
16091631
lra.stats().m_dio_rewrite_conflicts++;
@@ -1977,7 +1999,16 @@ namespace lp {
19771999
}
19782000
}
19792001

1980-
std::tuple<mpq, unsigned, int> find_minimal_abs_coeff(unsigned ei) const {
2002+
2003+
unsigned find_markovich_number(unsigned k) {
2004+
unsigned r = 0;
2005+
for (const auto & p: m_e_matrix.m_columns[k]) {
2006+
r += m_e_matrix.m_rows[p.var()].size();
2007+
}
2008+
return r;
2009+
}
2010+
2011+
std::tuple<mpq, unsigned, int, unsigned> find_minimal_abs_coeff(unsigned ei) {
19812012
bool first = true;
19822013
mpq ahk;
19832014
unsigned k;
@@ -1995,7 +2026,7 @@ namespace lp {
19952026
}
19962027
}
19972028

1998-
return std::make_tuple(ahk, k, k_sign);
2029+
return std::make_tuple(ahk, k, k_sign, find_markovich_number(k));
19992030
}
20002031

20012032
term_o get_term_to_subst(const term_o& eh, unsigned k, int k_sign) {
@@ -2322,14 +2353,19 @@ namespace lp {
23222353

23232354
// this is the step 6 or 7 of the algorithm
23242355
// returns true if an equlity was rewritten and false otherwise
2325-
bool rewrite_eqs() {
2356+
bool rewrite_eqs(std_vector<unsigned>& f_vector) {
2357+
if (f_vector.size() == 0)
2358+
return false;
23262359
unsigned h = -1;
23272360
unsigned n = 0; // number of choices for a fresh variable
23282361
mpq the_smallest_ahk;
23292362
unsigned kh;
23302363
int kh_sign;
2331-
for (unsigned ei = 0; ei < m_e_matrix.row_count(); ei++) {
2332-
if (belongs_to_s(ei)) continue;
2364+
unsigned h_markovich_number;
2365+
unsigned ih; // f_vector[ih] = h
2366+
for (unsigned i = 0; i < f_vector.size(); i++) {
2367+
unsigned ei = f_vector[i];
2368+
SASSERT (belongs_to_f(ei));
23332369
if (m_e_matrix.m_rows[ei].size() == 0) {
23342370
if (m_sum_of_fixed[ei].is_zero()) {
23352371
continue;
@@ -2339,45 +2375,45 @@ namespace lp {
23392375
}
23402376
}
23412377

2342-
auto [ahk, k, k_sign] = find_minimal_abs_coeff(ei);
2343-
if (ahk.is_one()) {
2344-
TRACE("dioph_eq", tout << "push to S:\n"; print_entry(ei, tout););
2345-
move_entry_from_f_to_s(k, ei);
2346-
eliminate_var_in_f(ei, k, k_sign);
2347-
return true;
2348-
}
2378+
auto [ahk, k, k_sign, markovich_number] = find_minimal_abs_coeff(ei);
23492379
mpq gcd;
23502380
if (!normalize_e_by_gcd(ei, gcd)) {
23512381
m_conflict_index = ei;
23522382
return false;
23532383
}
2354-
if (!gcd.is_one()) {
2384+
if (!gcd.is_one())
23552385
ahk /= gcd;
2356-
if (ahk.is_one()) {
2357-
TRACE("dioph_eq", tout << "push to S:\n"; print_entry(ei, tout););
2358-
move_entry_from_f_to_s(k, ei);
2359-
eliminate_var_in_f(ei, k, k_sign);
2360-
return true;
2361-
}
2362-
}
23632386

23642387
if (n == 0 || the_smallest_ahk > ahk) {
2388+
ih = i;
23652389
n = 1;
23662390
the_smallest_ahk = ahk;
23672391
h = ei;
23682392
kh = k;
23692393
kh_sign = k_sign;
2394+
h_markovich_number = markovich_number;
23702395
continue;
23712396
}
2372-
if (the_smallest_ahk == ahk && lra.settings().random_next() % (++n) == 0) {
2397+
if (the_smallest_ahk == ahk && h_markovich_number > markovich_number) {
2398+
ih = i;
23732399
h = ei;
23742400
kh = k;
23752401
kh_sign = k_sign;
2402+
h_markovich_number = markovich_number;
23762403
}
23772404
}
23782405
if (h == UINT_MAX) return false;
2379-
SASSERT(!the_smallest_ahk.is_one());
2380-
fresh_var_step(h, kh, the_smallest_ahk * mpq(kh_sign));
2406+
SASSERT(h == f_vector[ih]);
2407+
if (the_smallest_ahk.is_one()) {
2408+
TRACE("dioph_eq", tout << "push to S:\n"; print_entry(h, tout););
2409+
move_entry_from_f_to_s(kh, h);
2410+
eliminate_var_in_f(h, kh, kh_sign);
2411+
if (ih != f_vector.size() - 1) {
2412+
f_vector[ih] = f_vector.back();
2413+
}
2414+
f_vector.pop_back();
2415+
} else
2416+
fresh_var_step(h, kh, the_smallest_ahk * mpq(kh_sign));
23812417
return true;
23822418
}
23832419

0 commit comments

Comments
 (0)