@@ -487,7 +487,12 @@ namespace lp {
487
487
// m_changed_columns are the columns that just became fixed, or those that just stopped being fixed.
488
488
// If such a column appears in an entry it has to be recalculated.
489
489
indexed_uint_set m_changed_columns;
490
- indexed_uint_set m_changed_terms; // a term is defined by its column j, as in lar_solver.get_term(j)
490
+ enum class term_status {
491
+ no_change,
492
+ change, // need to find changed rows depending on the term
493
+ bound_change // need to tighten the term
494
+ };
495
+ std_vector<term_status> m_changed_terms;
491
496
indexed_uint_set m_tightened_columns; // the column that got tightened by the tigthening phase,
492
497
// m_column_to_terms[j] is the set of all k such lra.get_term(k) depends on j
493
498
std::unordered_map<unsigned , std::unordered_set<unsigned >> m_columns_to_terms;
@@ -732,30 +737,37 @@ namespace lp {
732
737
std_vector<constraint_index> m_explanation_of_branches;
733
738
void add_term_callback (const lar_term* t) {
734
739
unsigned j = t->j ();
735
- TRACE (" dioph_eq " , tout << " term column t->j():" << j << std::endl; lra.print_term (*t, tout) << std::endl;);
740
+ TRACE (" dio " , tout << " term column t->j():" << j << std::endl; lra.print_term (*t, tout) << std::endl;);
736
741
if (!lra.column_is_int (j)) {
737
- TRACE (" dioph_eq " , tout << " ignored a non-integral column" << std::endl;);
742
+ TRACE (" dio " , tout << " ignored a non-integral column" << std::endl;);
738
743
return ;
739
744
}
740
745
741
- CTRACE (" dioph_eq " , !lra.column_has_term (j), tout << " added term that is not associated with a column yet" << std::endl;);
746
+ CTRACE (" dio " , !lra.column_has_term (j), tout << " added term that is not associated with a column yet" << std::endl;);
742
747
743
748
if (!lia.column_is_int (t->j ())) {
744
- TRACE (" dioph_eq " , tout << " not all vars are integrall\n " ;);
749
+ TRACE (" dio " , tout << " not all vars are integrall\n " ;);
745
750
return ;
746
751
}
747
752
m_added_terms.push_back (t);
748
- m_changed_terms. insert (t->j ());
753
+ mark_term_change (t->j ());
749
754
auto undo = undo_add_term (*this , t);
750
755
lra.trail ().push (undo);
751
756
}
752
757
758
+ void mark_term_change (unsigned j) {
759
+ TRACE (" dio" , tout << " marked term change j:" << j << std::endl;);
760
+ if (j >= m_changed_terms.size ())
761
+ m_changed_terms.resize (j + 1 , term_status::no_change);
762
+ m_changed_terms[j] = term_status::change;
763
+ }
764
+
753
765
void update_column_bound_callback (unsigned j) {
754
766
if (!lra.column_is_int (j) || !lra.column_is_fixed (j))
755
767
return ;
768
+ TRACE (" dio" , tout << " j:" << j << " \n " ; lra.print_column_info (j, tout););
756
769
m_changed_columns.insert (j);
757
- auto undo = undo_fixed_column (*this , j);
758
- lra.trail ().push (undo);
770
+ lra.trail ().push (undo_fixed_column (*this , j));
759
771
}
760
772
761
773
public:
@@ -782,7 +794,7 @@ namespace lp {
782
794
}
783
795
784
796
void register_columns_to_term (const lar_term& t) {
785
- TRACE (" dioph_eq " , tout << " register term:" ; lra.print_term (t, tout); tout << " , t.j()=" << t.j () << std::endl;);
797
+ TRACE (" dio_reg " , tout << " register term:" ; lra.print_term (t, tout); tout << " , t.j()=" << t.j () << std::endl;);
786
798
for (const auto & p : t.ext_coeffs ()) {
787
799
auto it = m_columns_to_terms.find (p.var ());
788
800
TRACE (" dio_reg" , tout << " register p.var():" << p.var () << " ->" << t.j () << std::endl;);
@@ -799,11 +811,9 @@ namespace lp {
799
811
}
800
812
// the term has form sum(a_i*x_i) - t.j() = 0,
801
813
void fill_entry (const lar_term& t) {
802
- TRACE (" dioph_eq" , print_lar_term_L (t, tout) << std::endl;);
803
814
unsigned entry_index = (unsigned )m_e_matrix.row_count ();
804
815
m_sum_of_fixed.push_back (mpq (0 ));
805
- mpq& e = m_sum_of_fixed.back ();
806
- SASSERT (m_l_matrix.row_count () == m_e_matrix.row_count ());
816
+ mpq& fixed_sum = m_sum_of_fixed.back ();
807
817
// fill m_l_matrix row
808
818
m_l_matrix.add_row ();
809
819
// todo: consider to compress variables t.j() by using a devoted var_register for term columns
@@ -812,21 +822,21 @@ namespace lp {
812
822
// fill E-entry
813
823
m_e_matrix.add_row ();
814
824
815
- SASSERT (m_e_matrix.row_count () == m_e_matrix.row_count ());
825
+ SASSERT (m_sum_of_fixed. size () == m_l_matrix. row_count () && m_e_matrix.row_count () == m_e_matrix.row_count ());
816
826
817
827
for (const auto & p : t.ext_coeffs ()) {
818
828
SASSERT (p.coeff ().is_int ());
819
829
if (is_fixed (p.var ()))
820
- e += p.coeff () * lia.lower_bound (p.var ()).x ;
830
+ fixed_sum += p.coeff () * lia.lower_bound (p.var ()).x ;
821
831
else {
822
832
unsigned lj = add_var (p.var ());
823
833
m_e_matrix.add_columns_up_to (lj);
824
834
m_e_matrix.add_new_element (entry_index, lj, p.coeff ());
825
835
}
826
836
}
827
- TRACE (" dioph_eq" , print_entry (entry_index, tout) << std::endl;);
828
837
subs_entry (entry_index);
829
838
SASSERT (entry_invariant (entry_index));
839
+ TRACE (" dio" , print_entry (entry_index, tout) << std::endl;);
830
840
}
831
841
void subs_entry (unsigned ei) {
832
842
if (ei >= m_e_matrix.row_count ()) return ;
@@ -836,7 +846,10 @@ namespace lp {
836
846
if (can_substitute (p.var ()))
837
847
m_q.push (p.var ());
838
848
}
839
- if (m_q.size () == 0 ) return ;
849
+ if (m_q.size () == 0 ) {
850
+ TRACE (" dio" , tout << " nothing to subst on ei:" << ei << " \n " ;);
851
+ return ;
852
+ }
840
853
substitute_on_q (ei);
841
854
SASSERT (entry_invariant (ei));
842
855
}
@@ -908,10 +921,10 @@ namespace lp {
908
921
}
909
922
910
923
void recalculate_entry (unsigned ei) {
911
- TRACE (" dioph_eq " , print_entry (ei, tout) << std::endl;);
912
- mpq& c = m_sum_of_fixed[ei];
913
- c = mpq (0 );
914
- open_l_term_to_espace (ei, c );
924
+ TRACE (" dio " , print_entry (ei, tout) << std::endl;);
925
+ mpq& fixed_sum = m_sum_of_fixed[ei];
926
+ fixed_sum = mpq (0 );
927
+ open_l_term_to_espace (ei, fixed_sum );
915
928
clear_e_row (ei);
916
929
mpq denom (1 );
917
930
for (const auto & p : m_espace.m_data ) {
@@ -923,7 +936,7 @@ namespace lp {
923
936
}
924
937
}
925
938
if (!denom.is_one ()) {
926
- c *= denom;
939
+ fixed_sum *= denom;
927
940
m_l_matrix.multiply_row (ei, denom);
928
941
m_e_matrix.multiply_row (ei, denom);
929
942
}
@@ -938,12 +951,12 @@ namespace lp {
938
951
const auto it = m_columns_to_terms.find (j);
939
952
if (it != m_columns_to_terms.end ())
940
953
for (unsigned k : it->second ) {
941
- m_changed_terms. insert (k);
954
+ mark_term_change (k);
942
955
}
943
956
if (!m_var_register.external_is_used (j))
944
957
continue ;
945
958
for (const auto & p : m_e_matrix.column (this ->lar_solver_to_local (j))) {
946
- m_changed_rows.insert (p.var ()); // TODO: is it necessary?
959
+ m_changed_rows.insert (p.var ());
947
960
}
948
961
}
949
962
}
@@ -984,10 +997,17 @@ namespace lp {
984
997
985
998
void process_changed_columns (std_vector<unsigned > &f_vector) {
986
999
find_changed_terms_and_more_changed_rows ();
987
- for (unsigned j : m_changed_terms) {
988
- if (j >= m_l_matrix.column_count ()) continue ;
989
- for (const auto & cs : m_l_matrix.column (j)) {
990
- m_changed_rows.insert (cs.var ());
1000
+ for (unsigned j = 0 ; j < m_changed_terms.size (); j++) {
1001
+ term_status t = m_changed_terms[j];
1002
+ if (t != term_status::change) {
1003
+ TRACE (" dio" , tout << " went on continue\n " ;);
1004
+ continue ;
1005
+ }
1006
+ m_changed_terms[j] = term_status::bound_change; // prepare for tightening
1007
+ if (j < m_l_matrix.column_count ()) {
1008
+ for (const auto & cs : m_l_matrix.column (j)) {
1009
+ m_changed_rows.insert (cs.var ());
1010
+ }
991
1011
}
992
1012
}
993
1013
@@ -1366,14 +1386,14 @@ namespace lp {
1366
1386
lia_move tighten_terms_with_S () {
1367
1387
// Copy changed terms to another vector for sorting
1368
1388
std_vector<unsigned > sorted_changed_terms;
1369
- std_vector<unsigned > cleanup;
1370
1389
m_tightened_columns.reset ();
1371
- for (unsigned j : m_changed_terms) {
1390
+ for (unsigned j = 0 ; j < m_changed_terms.size (); j++) {
1391
+ if (m_changed_terms[j] == term_status::no_change) continue ;
1372
1392
if (j >= lra.column_count () ||
1373
1393
!lra.column_has_term (j) ||
1374
1394
lra.column_is_free (j) ||
1375
1395
!lia.column_is_int (j)) {
1376
- cleanup. push_back (j);
1396
+ unmark_changed_term (j);
1377
1397
continue ;
1378
1398
}
1379
1399
sorted_changed_terms.push_back (j);
@@ -1392,18 +1412,19 @@ namespace lp {
1392
1412
// print_bounds(tout);
1393
1413
);
1394
1414
for (unsigned j : sorted_changed_terms) {
1395
- m_changed_terms. remove (j);
1415
+ unmark_changed_term (j);
1396
1416
r = tighten_bounds_for_term_column (j);
1397
1417
if (r != lia_move::undef) {
1398
1418
break ;
1399
1419
}
1400
1420
}
1401
- for (unsigned j : cleanup) {
1402
- m_changed_terms.remove (j);
1403
- }
1404
1421
return r;
1405
1422
}
1406
1423
1424
+ void unmark_changed_term (unsigned j) {
1425
+ m_changed_terms[j] = term_status::no_change;
1426
+ }
1427
+
1407
1428
term_o create_term_from_espace () const {
1408
1429
term_o t;
1409
1430
for (const auto & p : m_espace.m_data ) {
@@ -1754,7 +1775,7 @@ namespace lp {
1754
1775
}
1755
1776
return lia_move::conflict;
1756
1777
}
1757
- TRACE (" dio " , print_S (tout));
1778
+ TRACE (" dio_s " , print_S (tout));
1758
1779
1759
1780
return lia_move::undef;
1760
1781
}
@@ -2286,6 +2307,20 @@ namespace lp {
2286
2307
mpq ls_val = get_term_value (ls);
2287
2308
if (!ls_val.is_zero ()) {
2288
2309
std::cout << " ls_val is not zero\n " ;
2310
+ enable_trace (" dio" );
2311
+ TRACE (" dio" , {
2312
+ tout << " get_term_from_entry(" << ei << " ):" ;
2313
+ print_term_o (get_term_from_entry (ei), tout) << std::endl;
2314
+ tout << " ls:" ;
2315
+ print_term_o (ls, tout) << std::endl;
2316
+ tout << " e.m_l:" ;
2317
+ print_lar_term_L (l_term_from_row (ei), tout) << std::endl;
2318
+ tout << " open_ml(e.m_l):" ;
2319
+ print_lar_term_L (open_ml (l_term_from_row (ei)), tout) << std::endl;
2320
+ tout << " rs:" ;
2321
+ print_term_o (fix_vars (open_ml (m_l_matrix.m_rows [ei])), tout) << std::endl;
2322
+ });
2323
+
2289
2324
return false ;
2290
2325
}
2291
2326
bool ret = ls == fix_vars (open_ml (m_l_matrix.m_rows [ei]));
@@ -2296,8 +2331,7 @@ namespace lp {
2296
2331
tout << " get_term_from_entry(" << ei << " ):" ;
2297
2332
print_term_o (get_term_from_entry (ei), tout) << std::endl;
2298
2333
tout << " ls:" ;
2299
- print_term_o (remove_fresh_vars (get_term_from_entry (ei)), tout)
2300
- << std::endl;
2334
+ print_term_o (ls, tout) << std::endl;
2301
2335
tout << " e.m_l:" ;
2302
2336
print_lar_term_L (l_term_from_row (ei), tout) << std::endl;
2303
2337
tout << " open_ml(e.m_l):" ;
0 commit comments