Skip to content

Commit bdb8f54

Browse files
committed
Revert "revert the term sorting"
This reverts commit c79d470.
1 parent 5ebee24 commit bdb8f54

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

src/math/lp/dioph_eq.cpp

+30-14
Original file line numberDiff line numberDiff line change
@@ -1354,25 +1354,41 @@ namespace lp {
13541354
}
13551355

13561356
lia_move tighten_terms_with_S() {
1357+
// Copy changed terms to another vector for sorting
1358+
std_vector<unsigned> sorted_changed_terms;
13571359
std_vector<unsigned> cleanup;
1358-
lia_move ret = lia_move::undef;
13591360
for (unsigned j : m_changed_terms) {
1360-
cleanup.push_back(j);
1361-
if (j >= lra.column_count()) continue;
1362-
if (!lra.column_has_term(j) || lra.column_is_free(j) ||
1361+
if (
1362+
j >= lra.column_count() ||
1363+
!lra.column_has_term(j) ||
1364+
lra.column_is_free(j) ||
13631365
is_fixed(j) || !lia.column_is_int(j)) {
1364-
continue;
1365-
}
1366-
1367-
if (tighten_bounds_for_term_column(j)) {
1368-
ret = lia_move::conflict;
1366+
cleanup.push_back(j);
1367+
continue;
1368+
}
1369+
sorted_changed_terms.push_back(j);
1370+
}
1371+
// Sort by term_weight descending
1372+
std::sort(sorted_changed_terms.begin(), sorted_changed_terms.end(),
1373+
[this](unsigned j1, unsigned j2) {
1374+
return term_weight(lra.get_term(j1)) > term_weight(lra.get_term(j2) );
1375+
});
1376+
1377+
lia_move r = lia_move::undef;
1378+
// Process sorted terms
1379+
for (unsigned j : sorted_changed_terms) {
1380+
m_changed_terms.remove(j);
1381+
1382+
1383+
if (tighten_bounds_for_term_column(j)) {
1384+
r = lia_move::conflict;
13691385
break;
13701386
}
13711387
}
1372-
for (unsigned j: cleanup) {
1388+
for (unsigned j : cleanup) {
13731389
m_changed_terms.remove(j);
13741390
}
1375-
return ret;
1391+
return r;
13761392
}
13771393

13781394
std::ostream& print_queue(std::queue<unsigned> q, std::ostream& out) {
@@ -1983,8 +1999,8 @@ namespace lp {
19831999
}
19842000
}
19852001

1986-
unsigned markovich_number(unsigned k, unsigned h) {
1987-
return (unsigned) m_e_matrix.m_columns[k].size() * m_e_matrix.m_rows[h].size();
2002+
unsigned find_markovich_number(unsigned k, unsigned h) {
2003+
return m_e_matrix.m_columns[k].size() * m_e_matrix.m_rows[h].size();
19882004
}
19892005

19902006
std::tuple<mpq, unsigned, int, unsigned> find_minimal_abs_coeff(unsigned ei) {
@@ -2005,7 +2021,7 @@ namespace lp {
20052021
}
20062022
}
20072023

2008-
return std::make_tuple(ahk, k, k_sign, markovich_number(k, ei));
2024+
return std::make_tuple(ahk, k, k_sign, find_markovich_number(k, ei));
20092025
}
20102026

20112027

0 commit comments

Comments
 (0)