Skip to content

Commit 1af2474

Browse files
NikolajBjornerlevnach
authored andcommitted
code review updates, tidy pretty printer for column info
Signed-off-by: Nikolaj Bjorner <[email protected]>
1 parent 3202808 commit 1af2474

File tree

3 files changed

+31
-28
lines changed

3 files changed

+31
-28
lines changed

src/math/lp/dioph_eq.cpp

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -541,10 +541,10 @@ namespace lp {
541541
TRACE("d_undo", tout << "t:" << t << ", t->j():" << t->j() << std::endl;);
542542
TRACE("dioph_eq", lra.print_term(*t, tout); tout << ", t->j() =" << t->j() << std::endl;);
543543
if (!contains(m_active_terms, t)) {
544-
for (int i = static_cast<int>(m_added_terms.size() - 1); i >= 0; --i) {
545-
if (m_added_terms[i] != t) continue;
546-
if ((unsigned)i != m_added_terms.size() - 1)
547-
m_added_terms[i] = m_added_terms.back();
544+
for (auto i = m_added_terms.size(); i-- > 0; ) {
545+
if (m_added_terms[i] != t)
546+
continue;
547+
m_added_terms[i] = m_added_terms.back();
548548
m_added_terms.pop_back();
549549
break; // all is done since the term has not made it to m_active_terms
550550
}
@@ -679,15 +679,13 @@ namespace lp {
679679
void make_sure_j_is_in_the_last_row_of_l_matrix() {
680680
unsigned j = m_l_matrix.column_count() - 1;
681681
const auto& last_e_row = m_l_matrix.m_rows.back();
682-
mpq alpha;
683-
for (const auto& p : last_e_row) {
684-
if (p.var() == j) {
685-
return;
686-
}
687-
}
688-
SASSERT(m_l_matrix.m_columns.back().size());
682+
if (any_of(last_e_row, [j](auto const& p) { return p.var() == j; }))
683+
return;
684+
SASSERT(m_l_matrix.m_columns.back().size() > 0);
689685
unsigned i = m_l_matrix.m_columns[j][0].var();
690686
m_l_matrix.add_rows(mpq(1), i, m_l_matrix.row_count() - 1);
687+
// what is the post-condition? Is 'j' used in the post-condition or is it 'i'?
688+
// SASSERT(any_of(m_l_matrix.m_rows.back(), [i](auto const& p) { return p.var() == i; }));
691689
}
692690

693691
void shrink_matrices() {
@@ -705,9 +703,8 @@ namespace lp {
705703

706704
remove_irrelevant_fresh_defs_for_row(i);
707705

708-
if (m_k2s.has_val(i)) {
706+
if (m_k2s.has_val(i))
709707
remove_from_S(i);
710-
}
711708

712709
m_sum_of_fixed.pop_back();
713710
}
@@ -760,7 +757,7 @@ namespace lp {
760757
TRACE("dio", tout << "marked term change j:" << j << std::endl;);
761758
m_changed_terms.insert(j);
762759
}
763-
760+
764761
void update_column_bound_callback(unsigned j) {
765762
if (!lra.column_is_int(j) || !lra.column_is_fixed(j))
766763
return;
@@ -1158,12 +1155,9 @@ namespace lp {
11581155

11591156
template <typename T>
11601157
bool has_fresh_var(const T& t) const {
1161-
for (const auto& p : t) {
1162-
if (var_is_fresh(p.var()))
1163-
return true;
1164-
}
1165-
return false;
1158+
return any_of(t, [&](auto const& p) { return var_is_fresh(p.var()); });
11661159
}
1160+
11671161
bool has_fresh_var(unsigned row_index) const {
11681162
return has_fresh_var(m_e_matrix[row_index]);
11691163
}
@@ -1417,6 +1411,7 @@ namespace lp {
14171411
TRACE("dio",
14181412
tout << "changed terms:"; for (auto j : sorted_changed_terms) tout << j << " "; tout << std::endl;
14191413
print_S(tout);
1414+
// lra.display(tout);
14201415
// print_bounds(tout);
14211416
);
14221417
for (unsigned j : sorted_changed_terms) {

src/math/lp/lar_solver.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -618,11 +618,12 @@ class lar_solver : public column_namer {
618618
inline bool column_has_term(lpvar j) const { return m_columns[j].term() != nullptr; }
619619

620620
std::ostream& print_column_info(unsigned j, std::ostream& out, bool print_expl = false) const {
621-
m_mpq_lar_core_solver.m_r_solver.print_column_info(j, out);
621+
m_mpq_lar_core_solver.m_r_solver.print_column_info(j, out, false);
622622
if (column_has_term(j))
623-
print_term_as_indices(get_term(j), out) << "\n";
623+
print_term_as_indices(get_term(j), out << " := ") << " ";
624+
out << "\n";
624625
if (print_expl)
625-
display_column_explanation(out, j);
626+
display_column_explanation(out, j);
626627
return out;
627628
}
628629

src/math/lp/lp_core_solver_base.h

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ class lp_core_solver_base {
436436
return out;
437437
}
438438

439-
std::ostream& print_column_info(unsigned j, std::ostream & out, const std::string& var_prefix = "x") const {
439+
std::ostream& print_column_info(unsigned j, std::ostream & out, bool print_nl = false, const std::string& var_prefix = "j") const {
440440
if (j >= m_lower_bounds.size()) {
441441
out << "[" << j << "] is not present\n";
442442
return out;
@@ -446,12 +446,15 @@ class lp_core_solver_base {
446446
strm << m_x[j];
447447
std::string j_val = strm.str();
448448
out << var_prefix << j << " = " << std::setw(6) << j_val;
449+
if (j < 10)
450+
out << " ";
451+
else if (j < 100)
452+
out << " ";
453+
449454
if (m_basis_heading[j] >= 0)
450-
out << " base ";
455+
out << " base ";
451456
else
452-
out << " ";
453-
for (auto k = j_val.size(); k < 15; ++k)
454-
out << " ";
457+
out << " ";
455458
switch (m_column_types[j]) {
456459
case column_type::fixed:
457460
case column_type::boxed:
@@ -469,7 +472,11 @@ class lp_core_solver_base {
469472
default:
470473
UNREACHABLE();
471474
}
472-
return out << "\n";
475+
if (print_nl)
476+
out << "\n";
477+
else
478+
out << "\t";
479+
return out;
473480
}
474481

475482
bool column_is_fixed(unsigned j) const { return this->m_column_types[j] == column_type::fixed; }

0 commit comments

Comments
 (0)