@@ -1602,8 +1602,30 @@ namespace lp {
1602
1602
return dep;
1603
1603
}
1604
1604
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
+
1605
1620
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)) {}
1607
1629
1608
1630
if (m_conflict_index != UINT_MAX) {
1609
1631
lra.stats ().m_dio_rewrite_conflicts ++;
@@ -1977,7 +1999,16 @@ namespace lp {
1977
1999
}
1978
2000
}
1979
2001
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) {
1981
2012
bool first = true ;
1982
2013
mpq ahk;
1983
2014
unsigned k;
@@ -1995,7 +2026,7 @@ namespace lp {
1995
2026
}
1996
2027
}
1997
2028
1998
- return std::make_tuple (ahk, k, k_sign);
2029
+ return std::make_tuple (ahk, k, k_sign, find_markovich_number (k) );
1999
2030
}
2000
2031
2001
2032
term_o get_term_to_subst (const term_o& eh, unsigned k, int k_sign) {
@@ -2322,14 +2353,19 @@ namespace lp {
2322
2353
2323
2354
// this is the step 6 or 7 of the algorithm
2324
2355
// 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 ;
2326
2359
unsigned h = -1 ;
2327
2360
unsigned n = 0 ; // number of choices for a fresh variable
2328
2361
mpq the_smallest_ahk;
2329
2362
unsigned kh;
2330
2363
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));
2333
2369
if (m_e_matrix.m_rows [ei].size () == 0 ) {
2334
2370
if (m_sum_of_fixed[ei].is_zero ()) {
2335
2371
continue ;
@@ -2339,45 +2375,45 @@ namespace lp {
2339
2375
}
2340
2376
}
2341
2377
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);
2349
2379
mpq gcd;
2350
2380
if (!normalize_e_by_gcd (ei, gcd)) {
2351
2381
m_conflict_index = ei;
2352
2382
return false ;
2353
2383
}
2354
- if (!gcd.is_one ()) {
2384
+ if (!gcd.is_one ())
2355
2385
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
- }
2363
2386
2364
2387
if (n == 0 || the_smallest_ahk > ahk) {
2388
+ ih = i;
2365
2389
n = 1 ;
2366
2390
the_smallest_ahk = ahk;
2367
2391
h = ei;
2368
2392
kh = k;
2369
2393
kh_sign = k_sign;
2394
+ h_markovich_number = markovich_number;
2370
2395
continue ;
2371
2396
}
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;
2373
2399
h = ei;
2374
2400
kh = k;
2375
2401
kh_sign = k_sign;
2402
+ h_markovich_number = markovich_number;
2376
2403
}
2377
2404
}
2378
2405
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));
2381
2417
return true ;
2382
2418
}
2383
2419
0 commit comments