Skip to content

Commit 7577f6f

Browse files
NikolajBjornerlevnach
authored andcommitted
neatify loops
Signed-off-by: Nikolaj Bjorner <[email protected]>
1 parent f091b6f commit 7577f6f

File tree

1 file changed

+16
-26
lines changed

1 file changed

+16
-26
lines changed

src/math/lp/dioph_eq.cpp

+16-26
Original file line numberDiff line numberDiff line change
@@ -1878,12 +1878,10 @@ namespace lp {
18781878
}
18791879

18801880
lia_move add_var_bound_for_branch(const branch& b) {
1881-
if (b.m_left) {
1881+
if (b.m_left)
18821882
lra.add_var_bound(b.m_j, lconstraint_kind::LE, b.m_rs);
1883-
}
1884-
else {
1883+
else
18851884
lra.add_var_bound(b.m_j, lconstraint_kind::GE, b.m_rs + mpq(1));
1886-
}
18871885
TRACE("dio_br", lra.print_column_info(b.m_j, tout) << "add bound" << std::endl;);
18881886
if (lra.column_is_fixed(b.m_j)) {
18891887
unsigned local_bj;
@@ -1951,7 +1949,9 @@ namespace lp {
19511949
}
19521950
auto st = lra.find_feasible_solution();
19531951
TRACE("dio_br", tout << "st:" << lp_status_to_string(st) << std::endl;);
1954-
if ((int)st >= (int)(lp_status::FEASIBLE)) {
1952+
if (st == lp_status::CANCELLED)
1953+
return lia_move::undef;
1954+
else if ((int)st >= (int)(lp_status::FEASIBLE)) {
19551955
// have a feasible solution
19561956
unsigned n_of_ii = get_number_of_int_inf();
19571957
TRACE("dio_br", tout << "n_of_ii:" << n_of_ii << "\n";);
@@ -1965,7 +1965,6 @@ namespace lp {
19651965
need_create_branch = true;
19661966
}
19671967
else {
1968-
if (st == lp_status::CANCELLED) return lia_move::undef;
19691968
collect_evidence();
19701969
undo_explored_branches();
19711970
if (m_branch_stack.size() == 0) {
@@ -2002,16 +2001,13 @@ namespace lp {
20022001

20032002
void update_branch_stats(const branch& b, unsigned n_of_ii) {
20042003
// Ensure the branch stats vector is large enough
2005-
if (b.m_j >= m_branch_stats.size()) {
2004+
if (b.m_j >= m_branch_stats.size())
20062005
m_branch_stats.resize(b.m_j + 1);
2007-
}
20082006

2009-
if (b.m_left) {
2007+
if (b.m_left)
20102008
m_branch_stats[b.m_j].m_ii_after_left.push_back(n_of_ii);
2011-
}
2012-
else {
2009+
else
20132010
m_branch_stats[b.m_j].m_ii_after_right.push_back(n_of_ii);
2014-
}
20152011
}
20162012

20172013
branch create_branch() {
@@ -2208,13 +2204,10 @@ namespace lp {
22082204
pivot_col_cell_index;
22092205
}
22102206

2211-
unsigned cell_to_process = static_cast<unsigned>(column.size() - 1);
2212-
while (cell_to_process > 0) {
2207+
for (auto cell_to_process = column.size(); cell_to_process-- > 0; ) {
22132208
auto& c = column[cell_to_process];
2214-
if (belongs_to_s(c.var())) {
2215-
cell_to_process--;
2209+
if (belongs_to_s(c.var()))
22162210
continue;
2217-
}
22182211

22192212
SASSERT(c.var() != ei && entry_invariant(c.var()));
22202213
mpq coeff = m_e_matrix.get_val(c);
@@ -2235,7 +2228,6 @@ namespace lp {
22352228
<< std::endl;
22362229
});
22372230
SASSERT(entry_invariant(i));
2238-
cell_to_process--;
22392231
}
22402232
SASSERT(is_eliminated_from_f(j));
22412233
}
@@ -2248,31 +2240,29 @@ namespace lp {
22482240
print_lar_term_L(t, tout) << std::endl;);
22492241
auto& column = m_e_matrix.m_columns[j];
22502242

2251-
int cell_to_process = static_cast<int>(column.size() - 1);
2252-
while (cell_to_process >= 0) {
2243+
for (auto cell_to_process = column.size(); cell_to_process-- > 0; ) {
22532244
auto& c = column[cell_to_process];
2254-
if (belongs_to_s(c.var())) {
2255-
cell_to_process--;
2245+
if (belongs_to_s(c.var()))
22562246
continue;
2257-
}
22582247

22592248
mpq coeff = m_e_matrix.get_val(c);
22602249
TRACE("dio", tout << "before pivot entry :"; print_entry(c.var(), tout) << std::endl;);
22612250
m_e_matrix.pivot_term_to_row_given_cell(t, c, j, j_sign);
22622251
TRACE("dio", tout << "after pivoting c_row:";
22632252
print_entry(c.var(), tout););
22642253
SASSERT(entry_invariant(c.var()));
2265-
cell_to_process--;
22662254
}
22672255
SASSERT(is_eliminated_from_f(j));
22682256
}
22692257

22702258
bool is_eliminated_from_f(unsigned j) const {
22712259
for (unsigned ei = 0; ei < m_e_matrix.row_count(); ei++) {
2272-
if (!belongs_to_f(ei)) continue;
2260+
if (!belongs_to_f(ei))
2261+
continue;
22732262
const auto& row = m_e_matrix.m_rows[ei];
22742263
bool eliminated_in_row = all_of(row, [j](auto & p) { return p.var() != j; });
2275-
if (!eliminated_in_row) return false;
2264+
if (!eliminated_in_row)
2265+
return false;
22762266
}
22772267
return true;
22782268
}

0 commit comments

Comments
 (0)