Skip to content

Commit 5f5f1d4

Browse files
committed
init m_e_matrix on terms instead of the tableau
Signed-off-by: Lev Nachmanson <[email protected]>
1 parent 392c24a commit 5f5f1d4

File tree

4 files changed

+36
-25
lines changed

4 files changed

+36
-25
lines changed

src/math/lp/dioph_eq.cpp

+27-18
Original file line numberDiff line numberDiff line change
@@ -176,29 +176,37 @@ namespace lp {
176176
}
177177
private:
178178
// the row comes from lar_solver
179-
void fill_eprime_entry(const row_strip<mpq>& row, unsigned row_index) {
180-
m_f.push_back(row_index);
181-
eprime_entry& e = m_eprime[row_index];
182-
e.m_row_index = row_index;
183-
const auto lcm = get_denominators_lcm(row);
179+
void fill_eprime_entry(const lar_term& t, unsigned term_index) {
180+
m_f.push_back(term_index);
181+
eprime_entry& e = m_eprime[term_index];
182+
e.m_row_index = term_index;
183+
const auto lcm = get_denominators_lcm(t);
184184
mpq & c = e.m_c;
185185
SASSERT(c.is_zero());
186186

187-
for (const auto & p: row) {
187+
for (const auto & p: t) {
188188
if (lia.is_fixed(p.var())) {
189189
c += p.coeff()*lia.lower_bound(p.var()).x;
190190
e.m_l = lra.mk_join(e.m_l, lra.get_bound_constraint_witnesses_for_column(p.var()));
191191
}
192192
else {
193-
m_e_matrix.add_new_element(row_index, p.var(), lcm * p.coeff());
193+
m_e_matrix.add_new_element(term_index, p.var(), lcm * p.coeff());
194194
}
195195
}
196+
unsigned j = t.j();
197+
if (lia.is_fixed(j)) {
198+
c -= lia.lower_bound(j).x;
199+
e.m_l = lra.mk_join(e.m_l, lra.get_bound_constraint_witnesses_for_column(j));
200+
}
201+
else {
202+
m_e_matrix.add_new_element(term_index, j, - lcm);
203+
}
196204
c *= lcm;
197205
e.m_entry_status = entry_status::F;
198206
}
199207

200-
bool all_vars_are_int_and_small(const row_strip<mpq>& row) const {
201-
for (const auto& p : row) {
208+
bool all_vars_are_int_and_small(const lar_term& term) const {
209+
for (const auto& p : term) {
202210
if (!lia.column_is_int(p.var()))
203211
return false;
204212
if (p.coeff().is_big())
@@ -218,19 +226,20 @@ namespace lp {
218226
m_infeas_explanation.clear();
219227
lia.get_term().clear();
220228
m_eprime.clear();
221-
m_eprime.resize(n_of_rows);
222-
for (unsigned i = 0; i < n_of_rows; i++) {
223-
auto & row = lra.get_row(i);
224-
TRACE("dioph_eq", tout << "row "<< i <<":"; lra.print_row(row, tout) << "\n";
225-
for(auto & p: row) {
226-
lra.print_column_info(p.var(), tout);
227-
});
228-
if (!all_vars_are_int_and_small(row)) {
229+
m_eprime.resize(lra.terms().size());
230+
for (unsigned i = 0; i < lra.terms().size(); i++) {
231+
const lar_term* t = lra.terms()[i];
232+
TRACE("dioph_eq", tout << "term "<< i <<":"; lra.print_term(*t, tout) << "\n";
233+
for(auto & p: *t) {
234+
lra.print_column_info(p.var(), tout);
235+
}
236+
);
237+
if (t->j() == UINT_MAX || !all_vars_are_int_and_small(*t)) {
229238
TRACE("dioph_eq", tout << "not all vars are int and small\n";);
230239
m_eprime[i].m_entry_status = entry_status::NO_S_NO_F;
231240
continue;
232241
}
233-
fill_eprime_entry(row, i);
242+
fill_eprime_entry(*t, i);
234243
TRACE("dioph_eq", print_eprime_entry(static_cast<unsigned>(i), tout););
235244
}
236245

src/math/lp/lar_term.h

+1
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ class lar_term {
237237
public:
238238
ival(lpvar var, const mpq & val) : m_var(var), m_coeff(val) { }
239239
lpvar j() const { return m_var; }
240+
lpvar var() const { return m_var; }
240241
const mpq & coeff() const { return m_coeff; }
241242
};
242243

src/math/lp/static_matrix.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,6 @@ Revision History:
2626
#include "math/lp/lp_primal_core_solver.h"
2727
#include "math/lp/lar_solver.h"
2828
namespace lp {
29-
mpq get_denominators_lcm(const row_strip<mpq> & row) {
30-
mpq r(1);
31-
for (auto & c : row)
32-
r = lcm(r, denominator(c.coeff()));
33-
return r;
34-
}
3529

3630
template std::set<std::pair<unsigned, unsigned>> lp::static_matrix<lp::mpq, lp::mpq>::get_domain();
3731
template std::set<std::pair<unsigned, unsigned>> lp::static_matrix<lp::mpq, lp::numeric_pair<lp::mpq> >::get_domain();

src/math/lp/static_matrix.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,14 @@ typedef vector<column_cell> column_strip;
4545

4646
template <typename T>
4747
using row_strip = vector<row_cell<T>>;
48-
mpq get_denominators_lcm(const row_strip<mpq> & row);
48+
template <typename K> mpq get_denominators_lcm(const K & row) {
49+
mpq r = mpq(1);
50+
for (auto & c : row)
51+
r = lcm(r, denominator(c.coeff()));
52+
return r;
53+
}
54+
55+
4956

5057
template <typename T>
5158
std::ostream& operator<<(std::ostream& out, const row_strip<T>& r) {

0 commit comments

Comments
 (0)