Skip to content

Commit 28fbc81

Browse files
committed
unifying vectors into eprime_entry
1 parent 42bdc89 commit 28fbc81

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

src/math/lp/dioph_eq.cpp

+23-23
Original file line numberDiff line numberDiff line change
@@ -113,23 +113,23 @@ namespace lp {
113113
e is an equation and ℓ is a linear combination of variables from L
114114
*/
115115
//
116+
enum class entry_status {
117+
F,
118+
S,
119+
NO_S_NO_F
120+
};
116121
struct eprime_entry {
117122
unsigned m_row_index; // the index of the row in the constraint matrix that m_e corresponds to
118123
term_o m_e; // it will be used for debugging only
119124
// we keep the dependency of the equation in m_l
120125
// a more expensive alternative is to keep the history term of m_e : originally m_l is i, the index of row m_e was constructed from
121126
u_dependency *m_l;
122-
};
123-
enum class row_status {
124-
F,
125-
S,
126-
NO_S_NO_F
127+
mpq m_c; // the constant of the term
128+
entry_status m_entry_status;
127129
};
128130
vector<eprime_entry> m_eprime;
129131
// the terms are stored in m_A and m_c
130132
static_matrix<mpq, numeric_pair<mpq>> m_e_matrix; // the rows of the matrix are the terms, without the constant part
131-
vector<row_status> m_row_status;
132-
vector<mpq> m_c; // to keep the constants of the terms
133133
int_solver& lia;
134134
lar_solver& lra;
135135
explanation m_infeas_explanation;
@@ -152,7 +152,7 @@ namespace lp {
152152
for (const auto & p: m_e_matrix.m_rows[i]) {
153153
t.add_monomial(p.coeff(), p.var());
154154
}
155-
t.c() = m_c[i];
155+
t.c() = m_eprime[i].m_c;
156156
return t;
157157
}
158158
private:
@@ -168,7 +168,7 @@ namespace lp {
168168
t.c() *= lcm;
169169
#endif
170170
// init m_e_matrix and m_c
171-
mpq & c = m_c[row_index];
171+
mpq & c = m_eprime[row_index].m_c;
172172
for (const auto & p: row)
173173
if (lia.is_fixed(p.var()))
174174
c += p.coeff()*lia.lower_bound(p.var()).x;
@@ -181,8 +181,6 @@ namespace lp {
181181

182182
void init() {
183183
m_e_matrix = static_matrix<mpq, impq>(lra.row_count(), lra.column_count());
184-
m_row_status.resize(lra.row_count(), row_status::NO_S_NO_F);
185-
m_c.resize(lra.row_count(), mpq(0));
186184
m_report_branch = false;
187185
unsigned n_of_rows = lra.A_r().row_count();
188186
m_k2s.clear();
@@ -209,7 +207,7 @@ namespace lp {
209207
continue;
210208
}
211209
term_o t = create_eprime_entry_from_row(row, i);
212-
m_row_status[i] = row_status::F;
210+
m_eprime[i].m_entry_status = entry_status::F;
213211
TRACE("dioph_eq", tout << "row = "; lra.print_row(row, tout) << std::endl;);
214212
if (t.size() == 0) {
215213
SASSERT(t.c().is_zero());
@@ -292,12 +290,12 @@ namespace lp {
292290
return true;
293291
}
294292
TRACE("dioph_eq", tout << "g:" << g << std::endl;);
295-
mpq c_g = m_c[row_index] / g;
293+
mpq c_g = m_eprime[row_index].m_c / g;
296294
if (c_g.is_int()) {
297295
for (auto& p: m_e_matrix.m_rows[row_index]) {
298296
p.coeff() /= g;
299297
}
300-
m_c[row_index] = c_g;
298+
m_eprime[row_index].m_c = c_g;
301299
// ep.m_l *= (1/g);
302300
TRACE("dioph_eq", tout << "ep_m_e:"; print_eprime_entry(ep, tout) << std::endl;);
303301
return true;
@@ -453,6 +451,7 @@ namespace lp {
453451
// }
454452

455453
// return tighten_bounds_for_term(t, g, j, dep);
454+
return false;
456455
}
457456
void handle_constant_term(term_o& t, unsigned j, u_dependency* dep) {
458457
if (t.c().is_zero()) {
@@ -514,6 +513,7 @@ namespace lp {
514513
// }
515514
// }
516515
// return change;
516+
return false;
517517
}
518518

519519
void tighten_bound_for_term_for_bound_kind(term_o& t,
@@ -666,20 +666,20 @@ namespace lp {
666666

667667
unsigned f_rows_in_column =0;
668668
for (const auto& c: column) {
669-
if (m_row_status[c.var()] == row_status::F)
669+
if (m_eprime[c.var()].m_entry_status == entry_status::F)
670670
f_rows_in_column ++;
671671
}
672672
TRACE("dioph_eq", tout << "f_rows_in_column:" << f_rows_in_column << std::endl;);
673673
while (column.size() > 1 && f_rows_in_column > 0 ) {
674674
auto & c = column.back();
675-
if (m_row_status[c.var()] != row_status::F)
675+
if (m_eprime[c.var()].m_entry_status != entry_status::F)
676676
continue;
677677
f_rows_in_column--;
678678
SASSERT(c.var() != piv_row_index);
679679
mpq coeff = m_e_matrix.get_val(c);
680680
TRACE("dioph_eq", tout << "c_row:" << c.var(); print_e_row(c.var(), tout) << std::endl;);
681681
m_e_matrix.pivot_row_to_row_given_cell_with_sign(piv_row_index, c, j, j_sign);
682-
m_c[c.var()] -= j_sign* coeff*m_c[piv_row_index];
682+
m_eprime[c.var()].m_c -= j_sign* coeff*m_eprime[piv_row_index].m_c;
683683
TRACE("dioph_eq", tout << "after pivoting c_row:"; print_e_row(c.var(), tout) << std::endl;);
684684
}
685685
}
@@ -705,17 +705,17 @@ namespace lp {
705705
unsigned fresh_row = m_e_matrix.row_count();
706706
m_e_matrix.add_row(); // for the fresh variable definition
707707
m_e_matrix.add_column(); // the fresh variable itself
708-
m_row_status.push_back(row_status::S); // adding a new row to S
708+
m_eprime.push_back({fresh_row, term_o(), nullptr, mpq(0), entry_status::S});
709709
// Add a new row for the fresh variable definition
710710
/* Let eh = sum(ai*xi) + c. For each i != k, let ai = qi*ahk + ri, and let c = c_q * ahk + c_r.
711711
eh = ahk*(x_k + sum{qi*xi|i != k} + c_q) + sum {ri*xi|i!= k} + c_r.
712712
Then -xt + x_k + sum {qi*x_i)| i != k} + c_q will be the fresh row
713713
eh = ahk*xt + sum {ri*x_i | i != k} + c_r is the row m_e_matrix[e.m_row_index]
714714
*/
715715
mpq q, r;
716-
q = machine_div_rem(m_c[h], ahk, r);
717-
m_c[h] = r;
718-
m_c.push_back(q);
716+
q = machine_div_rem(e.m_c, ahk, r);
717+
e.m_c = r;
718+
m_eprime.back().m_c = q;
719719
m_e_matrix.add_new_element(h, xt, ahk);
720720
m_e_matrix.add_new_element(fresh_row, xt, -mpq(1));
721721
m_e_matrix.add_new_element(fresh_row, k, mpq(1));
@@ -755,8 +755,8 @@ namespace lp {
755755

756756
// k is the index of the index of the variable with the coefficient +-1 that is being substituted
757757
void move_entry_from_f_to_s(unsigned k, std::list<unsigned>::iterator it) {
758-
SASSERT(m_row_status[*it] == row_status::F);
759-
m_row_status[*it] = row_status::S;
758+
SASSERT(m_eprime[*it].m_entry_status == entry_status::F);
759+
m_eprime[*it].m_entry_status = entry_status::S;
760760
if (k >= m_k2s.size()) { // k is a fresh variable
761761
m_k2s.resize(k+1, -1 );
762762
}

0 commit comments

Comments
 (0)