@@ -1339,26 +1339,56 @@ namespace lp {
1339
1339
subs_front_in_indexed_vector (q);
1340
1340
}
1341
1341
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
+
1342
1356
lia_move tighten_terms_with_S () {
1357
+ // Copy changed terms to another vector for sorting
1358
+ std_vector<unsigned > sorted_changed_terms;
1343
1359
std_vector<unsigned > cleanup;
1344
- lia_move ret = lia_move::undef;
1345
1360
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) ||
1349
1365
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
+
1352
1382
1353
1383
if (tighten_bounds_for_term_column (j)) {
1354
- ret = lia_move::conflict;
1384
+ r = lia_move::conflict;
1355
1385
break ;
1356
1386
}
1357
1387
}
1358
1388
for (unsigned j : cleanup) {
1359
1389
m_changed_terms.remove (j);
1360
1390
}
1361
- return ret ;
1391
+ return r ;
1362
1392
}
1363
1393
1364
1394
std::ostream& print_queue (std::queue<unsigned > q, std::ostream& out) {
0 commit comments