Skip to content

Commit eed02b6

Browse files
improved logging, use C++11 for loops instead of iterators
1 parent 14312ef commit eed02b6

File tree

1 file changed

+36
-44
lines changed

1 file changed

+36
-44
lines changed

src/smt/theory_arith_int.h

+36-44
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,10 @@ namespace smt {
146146
*/
147147
template<typename Ext>
148148
theory_var theory_arith<Ext>::find_infeasible_int_base_var() {
149-
theory_var v = find_bounded_infeasible_int_base_var();
150-
if (v != null_theory_var) {
151-
TRACE("find_infeasible_int_base_var", display_var(tout, v););
152-
return v;
153-
}
149+
theory_var r = find_bounded_infeasible_int_base_var();
150+
CTRACE("find_infeasible_int_base_var", r != null_theory_var, display_var(tout << "bounded infeasible", r););
151+
154152
unsigned n = 0;
155-
theory_var r = null_theory_var;
156153

157154
#define SELECT_VAR(VAR) if (r == null_theory_var) { n = 1; r = VAR; } else { n++; SASSERT(n >= 2); if (m_random() % n == 0) r = VAR; }
158155

@@ -172,6 +169,7 @@ namespace smt {
172169
}
173170
}
174171
}
172+
CTRACE("find_infeasible_int_base_var", r != null_theory_var, tout << "found small value v" << r << "\n");
175173
}
176174

177175
if (r == null_theory_var) {
@@ -181,6 +179,8 @@ namespace smt {
181179
SELECT_VAR(v);
182180
}
183181
}
182+
CTRACE("find_infeasible_int_base_var", r != null_theory_var, tout << "found base v" << r << "\n");
183+
184184
}
185185

186186
if (r == null_theory_var) {
@@ -191,6 +191,7 @@ namespace smt {
191191
SELECT_VAR(v);
192192
}
193193
}
194+
CTRACE("find_infeasible_int_base_var", r != null_theory_var, tout << "found quasi base v" << r << "\n");
194195
}
195196
CASSERT("arith", wf_rows());
196197
CASSERT("arith", wf_columns());
@@ -438,15 +439,13 @@ namespace smt {
438439
bool theory_arith<Ext>::is_gomory_cut_target(row const & r) {
439440
TRACE("gomory_cut", r.display(tout););
440441
theory_var b = r.get_base_var();
441-
typename vector<row_entry>::const_iterator it = r.begin_entries();
442-
typename vector<row_entry>::const_iterator end = r.end_entries();
443-
for (; it != end; ++it) {
442+
for (auto& e : r) {
444443
// All non base variables must be at their bounds and assigned to rationals (that is, infinitesimals are not allowed).
445-
if (!it->is_dead() && it->m_var != b && (!at_bound(it->m_var) || !get_value(it->m_var).is_rational())) {
444+
if (!e.is_dead() && e.m_var != b && (!at_bound(e.m_var) || !get_value(e.m_var).is_rational())) {
446445
TRACE("gomory_cut", tout << "row is not gomory cut target:\n";
447-
display_var(tout, it->m_var);
448-
tout << "at_bound: " << at_bound(it->m_var) << "\n";
449-
tout << "infinitesimal: " << !get_value(it->m_var).is_rational() << "\n";);
446+
display_var(tout, e.m_var);
447+
tout << "at_bound: " << at_bound(e.m_var) << "\n";
448+
tout << "infinitesimal: " << !get_value(e.m_var).is_rational() << "\n";);
450449
return false;
451450
}
452451
}
@@ -541,12 +540,10 @@ namespace smt {
541540
numeral lcm_den(1);
542541
unsigned num_ints = 0;
543542

544-
typename vector<row_entry>::const_iterator it = r.begin_entries();
545-
typename vector<row_entry>::const_iterator end = r.end_entries();
546-
for (; it != end; ++it) {
547-
if (!it->is_dead() && it->m_var != x_i) {
548-
theory_var x_j = it->m_var;
549-
numeral a_ij = it->m_coeff;
543+
for (row_entry const& e : r) {
544+
if (!e.is_dead() && e.m_var != x_i) {
545+
theory_var x_j = e.m_var;
546+
numeral a_ij = e.m_coeff;
550547
a_ij.neg(); // make the used format compatible with the format used in: Integrating Simplex with DPLL(T)
551548
if (is_real(x_j)) {
552549
numeral new_a_ij;
@@ -709,38 +706,36 @@ namespace smt {
709706
numeral gcds(0);
710707
numeral least_coeff(0);
711708
bool least_coeff_is_bounded = false;
712-
typename vector<row_entry>::const_iterator it = r.begin_entries();
713-
typename vector<row_entry>::const_iterator end = r.end_entries();
714-
for (; it != end; ++it) {
715-
if (!it->is_dead()) {
716-
if (is_fixed(it->m_var)) {
717-
// WARNING: it is not safe to use get_value(it->m_var) here, since
718-
// get_value(it->m_var) may not satisfy it->m_var bounds at this point.
719-
numeral aux = lcm_den * it->m_coeff;
720-
consts += aux * lower_bound(it->m_var).get_rational();
709+
for (row_entry const& e : r) {
710+
if (!e.is_dead()) {
711+
if (is_fixed(e.m_var)) {
712+
// WARNING: it is not safe to use get_value(e.m_var) here, since
713+
// get_value(e.m_var) may not satisfy e.m_var bounds at this point.
714+
numeral aux = lcm_den * e.m_coeff;
715+
consts += aux * lower_bound(e.m_var).get_rational();
721716
}
722-
else if (is_real(it->m_var)) {
717+
else if (is_real(e.m_var)) {
723718
return true;
724719
}
725720
else if (gcds.is_zero()) {
726-
gcds = abs(lcm_den * it->m_coeff);
721+
gcds = abs(lcm_den * e.m_coeff);
727722
least_coeff = gcds;
728-
least_coeff_is_bounded = is_bounded(it->m_var);
723+
least_coeff_is_bounded = is_bounded(e.m_var);
729724
}
730725
else {
731-
numeral aux = abs(lcm_den * it->m_coeff);
726+
numeral aux = abs(lcm_den * e.m_coeff);
732727
gcds = gcd(gcds, aux);
733728
if (aux < least_coeff) {
734729
least_coeff = aux;
735-
least_coeff_is_bounded = is_bounded(it->m_var);
730+
least_coeff_is_bounded = is_bounded(e.m_var);
736731
}
737732
else if (least_coeff_is_bounded && aux == least_coeff) {
738-
least_coeff_is_bounded = is_bounded(it->m_var);
733+
least_coeff_is_bounded = is_bounded(e.m_var);
739734
}
740735
}
741736
SASSERT(gcds.is_int());
742737
SASSERT(least_coeff.is_int());
743-
TRACE("gcd_test_bug", tout << "coeff: " << it->m_coeff << ", gcds: " << gcds
738+
TRACE("gcd_test_bug", tout << "coeff: " << e.m_coeff << ", gcds: " << gcds
744739
<< " least_coeff: " << least_coeff << " consts: " << consts << "\n";);
745740
}
746741
}
@@ -790,14 +785,11 @@ namespace smt {
790785

791786
antecedents ante(*this);
792787

793-
794-
typename vector<row_entry>::const_iterator it = r.begin_entries();
795-
typename vector<row_entry>::const_iterator end = r.end_entries();
796-
for (; it != end; ++it) {
797-
if (!it->is_dead() && !is_fixed(it->m_var)) {
798-
theory_var v = it->m_var;
788+
for (auto const& e : r) {
789+
if (!e.is_dead() && !is_fixed(e.m_var)) {
790+
theory_var v = e.m_var;
799791
SASSERT(!is_real(v));
800-
numeral ncoeff = lcm_den * it->m_coeff;
792+
numeral ncoeff = lcm_den * e.m_coeff;
801793
SASSERT(ncoeff.is_int());
802794
numeral abs_ncoeff = abs(ncoeff);
803795
if (abs_ncoeff == least_coeff) {
@@ -814,8 +806,8 @@ namespace smt {
814806
// u += ncoeff * lower_bound(v).get_rational();
815807
u.addmul(ncoeff, lower_bound(v).get_rational());
816808
}
817-
lower(v)->push_justification(ante, it->m_coeff, coeffs_enabled());
818-
upper(v)->push_justification(ante, it->m_coeff, coeffs_enabled());
809+
lower(v)->push_justification(ante, e.m_coeff, coeffs_enabled());
810+
upper(v)->push_justification(ante, e.m_coeff, coeffs_enabled());
819811
}
820812
else if (gcds.is_zero()) {
821813
gcds = abs_ncoeff;

0 commit comments

Comments
 (0)