Skip to content

Commit 5b0b224

Browse files
committed
try sorting terms before tightening
Signed-off-by: Lev Nachmanson <levnach@hotmail.com>
1 parent dcd5783 commit 5b0b224

File tree

1 file changed

+38
-8
lines changed

1 file changed

+38
-8
lines changed

src/math/lp/dioph_eq.cpp

+38-8
Original file line numberDiff line numberDiff line change
@@ -1339,26 +1339,56 @@ namespace lp {
13391339
subs_front_in_indexed_vector(q);
13401340
}
13411341

1342+
unsigned term_weight(const lar_term& t) const {
1343+
unsigned weight = 0;
1344+
for (const auto& p : t) {
1345+
// Get index j from coefficient
1346+
unsigned j = p.var();
1347+
1348+
// Look up j in columns_to_terms map
1349+
auto it = m_columns_to_terms.find(j);
1350+
if (it != m_columns_to_terms.end())
1351+
weight += static_cast<unsigned>(it->second.size());
1352+
}
1353+
return weight;
1354+
}
1355+
13421356
lia_move tighten_terms_with_S() {
1357+
// Copy changed terms to another vector for sorting
1358+
std_vector<unsigned> sorted_changed_terms;
13431359
std_vector<unsigned> cleanup;
1344-
lia_move ret = lia_move::undef;
13451360
for (unsigned j : m_changed_terms) {
1346-
cleanup.push_back(j);
1347-
if (j >= lra.column_count()) continue;
1348-
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) ||
13491365
is_fixed(j) || !lia.column_is_int(j)) {
1350-
continue;
1351-
}
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+
13521382

13531383
if (tighten_bounds_for_term_column(j)) {
1354-
ret = lia_move::conflict;
1384+
r = lia_move::conflict;
13551385
break;
13561386
}
13571387
}
13581388
for (unsigned j : cleanup) {
13591389
m_changed_terms.remove(j);
13601390
}
1361-
return ret;
1391+
return r;
13621392
}
13631393

13641394
std::ostream& print_queue(std::queue<unsigned> q, std::ostream& out) {

0 commit comments

Comments
 (0)