Skip to content

Commit 33f5e30

Browse files
committed
use entry_status for FRESH entries
1 parent 0e71adf commit 33f5e30

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/math/lp/dioph_eq.cpp

+20-6
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
lar_term is just a sum of monomials
1919
-- entry : has a dependency lar_term, keeping the history of the entry
2020
updates, the rational constant of the corresponding term_o, and the entry
21-
status that is in {F,S, NO_S_NO_F}. The entry status is used for efficiency
21+
status that is in {F,S, FRESH}. The entry status is used for efficiency
2222
reasons. It allows quickly check if an entry belongs to F, S, or neither.
2323
dioph_eq::imp main fields are
2424
-- lra: pointer to lar_solver.
@@ -204,7 +204,7 @@ namespace lp {
204204
//
205205
enum class entry_status { F,
206206
S,
207-
NO_S_NO_F
207+
FRESH
208208
};
209209
struct entry {
210210
//lar_term m_l; the term is taken from matrix m_l_matrix of the index entry
@@ -600,6 +600,7 @@ namespace lp {
600600
m_l_matrix.multiply_row(ei, denom);
601601
m_e_matrix.multiply_row(ei, denom);
602602
}
603+
move_entry_from_s_to_f(ei);
603604
SASSERT(entry_invariant(ei));
604605
}
605606

@@ -680,8 +681,7 @@ namespace lp {
680681
for(unsigned k : entries_to_recalculate) {
681682
if (k >= m_entries.size())
682683
continue;;
683-
recalculate_entry(k);
684-
move_entry_from_s_to_f(k);
684+
recalculate_entry(k);
685685
if (m_e_matrix.m_columns.back().size() == 0) {
686686
m_e_matrix.m_columns.pop_back();
687687
m_var_register.shrink(m_e_matrix.column_count());
@@ -747,18 +747,26 @@ namespace lp {
747747
}
748748
else it++;
749749
}
750+
750751
for (unsigned k = 0; k < m_k2s.size(); k++) {
751752
if (m_k2s[k] != UINT_MAX && contains(entries_to_recalculate, m_k2s[k])) {
752753
m_k2s[k] = -1;
753754
}
754755
}
756+
755757
for (unsigned ei: entries_to_recalculate) {
756758
SASSERT(std::find(m_f.begin(), m_f.end(), ei) == m_f.end());
759+
SASSERT(!is_substituted(ei));
757760
m_f.push_back(ei);
758761
m_entries[ei].m_entry_status = entry_status::F;
759762
}
760763
}
761764

765+
// returns true if a variable j is substituted
766+
bool is_substituted(unsigned j) const {
767+
return std::find(m_k2s.begin(), m_k2s.end(), j) != m_k2s.end();
768+
}
769+
762770
bool entries_are_ok() {
763771
for (unsigned ei = 0; ei < m_entries.size(); ei++) {
764772
if (entry_invariant(ei) == false) {
@@ -903,7 +911,7 @@ namespace lp {
903911
if (m_indexed_work_vector[k].is_zero())
904912
return;
905913
const entry& e = entry_for_subs(k);
906-
SASSERT(e.m_entry_status == entry_status::S);
914+
SASSERT(e.m_entry_status != entry_status::F);
907915
TRACE("dioph_eq", tout << "k:" << k << ", in ";
908916
print_term_o(create_term_from_ind_c(), tout) << std::endl;
909917
tout << "subs with e:";
@@ -1721,6 +1729,12 @@ namespace lp {
17211729
}
17221730

17231731
bool entry_invariant(unsigned ei) const {
1732+
const auto & e= m_entries[ei];
1733+
if ((e.m_entry_status == entry_status::F && is_substituted(ei)) ||
1734+
(e.m_entry_status != entry_status::F && !is_substituted(ei)))
1735+
return false;
1736+
1737+
17241738
for (const auto &p: m_e_matrix.m_rows[ei]) {
17251739
if (!p.coeff().is_int()) {
17261740
return false;
@@ -1842,7 +1856,7 @@ namespace lp {
18421856
e.m_c = r;
18431857
m_e_matrix.add_new_element(h, xt, ahk);
18441858

1845-
m_entries.push_back({q, entry_status::NO_S_NO_F});
1859+
m_entries.push_back({q, entry_status::FRESH});
18461860
m_e_matrix.add_new_element(fresh_row, xt, -mpq(1));
18471861
m_e_matrix.add_new_element(fresh_row, k, mpq(1));
18481862
for (unsigned i : m_indexed_work_vector.m_index) {

0 commit comments

Comments
 (0)