Skip to content

Commit 36293ac

Browse files
committed
test that pivoting is correct in dioph_eq.cpp
1 parent 0db0efc commit 36293ac

10 files changed

+397
-221
lines changed

src/math/lp/dioph_eq.cpp

+350-213
Large diffs are not rendered by default.

src/math/lp/explanation.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ class explanation {
2626
typedef vector<std::pair<unsigned, mpq>> pair_vec;
2727
typedef hashtable<unsigned, u_hash, u_eq> ci_set;
2828
// Only one of the fields below is used. The first call adding an entry decides which one it is.
29+
public:
2930
vector<std::pair<constraint_index, mpq>> m_vector;
3031
ci_set m_set;
31-
public:
32-
explanation() = default;
32+
explanation() {}
3333

3434
template <typename T>
3535
explanation(const T& t) {

src/math/lp/indexed_vector.h

+2
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ class indexed_vector {
113113
if (was_zero)
114114
m_index.push_back(j);
115115
}
116+
SASSERT(v.is_zero() ==
117+
( std::find(m_index.begin(), m_index.end(), j) == m_index.end()));
116118
}
117119

118120
void erase(unsigned j);

src/math/lp/int_solver.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ namespace lp {
181181
return lia_move::branch;
182182
}
183183

184-
m_dioph_eq_period *= 2; // the overflow is fine, maybe to try again
184+
// m_dioph_eq_period *= 2;
185185
return lia_move::undef;
186186
}
187187

src/math/lp/lar_solver.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1950,7 +1950,8 @@ namespace lp {
19501950
// SASSERT(validate_bound(j, kind, right_side, dep));
19511951
TRACE(
19521952
"lar_solver_feas",
1953-
tout << "j" << j << " " << lconstraint_kind_string(kind) << " " << right_side << std::endl;
1953+
tout << "j" << j << " " << lconstraint_kind_string(kind) << " " << right_side << std::endl;
1954+
print_column_info(j, tout) << "\n";
19541955
if (dep) {
19551956
tout << "dep:\n";
19561957
auto cs = flatten(dep);

src/math/lp/lar_solver.h

+1
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,7 @@ class lar_solver : public column_namer {
653653
inline int_solver* get_int_solver() { return m_int_solver; }
654654
inline const int_solver* get_int_solver() const { return m_int_solver; }
655655
inline const lar_term& get_term(lpvar j) const {
656+
SASSERT(column_has_term(j));
656657
return *m_columns[j].term();
657658
}
658659
lp_status find_feasible_solution();

src/math/lp/lar_term.h

+26-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class lar_term {
5151
return;
5252
auto *e = m_coeffs.find_core(j);
5353
if (e == nullptr) {
54-
m_coeffs.insert(j, c);
54+
m_coeffs.insert(j, -c);
5555
} else {
5656
e->get_data().m_value -= c;
5757
if (e->get_data().m_value.is_zero())
@@ -90,6 +90,21 @@ class lar_term {
9090
}
9191
// constructors
9292
lar_term() = default;
93+
<<<<<<< HEAD
94+
=======
95+
lar_term(lar_term&& other) noexcept = default;
96+
// copy assignment operator
97+
lar_term& operator=(const lar_term& other) = default;
98+
// move assignment operator
99+
lar_term& operator=(lar_term&& other) noexcept = default;
100+
~lar_term() = default;
101+
lar_term(const lar_term& a) {
102+
for (auto const& p : a) {
103+
add_monomial(p.coeff(), p.var());
104+
}
105+
}
106+
107+
>>>>>>> 956229fb6 (test that pivoting is correct in dioph_eq.cpp)
93108
lar_term(const vector<std::pair<mpq, unsigned>>& coeffs) {
94109
for (auto const& p : coeffs) {
95110
add_monomial(p.first, p.second);
@@ -205,7 +220,16 @@ class lar_term {
205220
}
206221
return r;
207222
}
208-
223+
224+
friend lar_term operator-(const lar_term& a, const lar_term& b) {
225+
lar_term r(a);
226+
for (const auto& p : b) {
227+
r.sub_monomial(p.coeff(), p.j());
228+
}
229+
return r;
230+
}
231+
232+
209233
lar_term& operator+=(const lar_term& a) {
210234
for (const auto& p : a) {
211235
add_monomial(p.coeff(), p.j());

src/math/lp/lp_utils.h

+11-1
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,18 @@ std::ostream& print_linear_combination_customized(const vector<std::pair<T, unsi
9090
out << "0";
9191
return out;
9292
}
93+
// Copy term to a std_vector and sort by p.j()
94+
std_vector<std::pair<T, unsigned>> sorted_coeffs;
95+
sorted_coeffs.reserve(coeffs.size());
96+
for (const auto& p : coeffs) {
97+
sorted_coeffs.emplace_back(p.first, p.second);
98+
}
99+
std::sort(sorted_coeffs.begin(), sorted_coeffs.end(),
100+
[](const auto& a, const auto& b) { return a.second < b.second; });
101+
102+
// Print the sorted term
93103
bool first = true;
94-
for (const auto & it : coeffs) {
104+
for (const auto & it : sorted_coeffs) {
95105
T val = it.first;
96106
if (first) {
97107
first = false;

src/math/lp/static_matrix.h

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ typedef vector<column_cell> column_strip;
4646
template <typename T>
4747
using row_strip = vector<row_cell<T>>;
4848
template <typename K> mpq get_denominators_lcm(const K & row) {
49+
SASSERT(row.size() > 0);
4950
mpq r = mpq(1);
5051
for (const auto & c : row)
5152
r = lcm(r, denominator(c.coeff()));

src/math/lp/static_matrix_def.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ inline void static_matrix<T, X>::pivot_row_to_row_given_cell_with_sign(unsigned
9090
column_cell& c, unsigned pivot_col, int pivot_sign) {
9191
unsigned ii = c.var();
9292
SASSERT(ii != piv_row_index);
93-
T alpha = get_val(c) * pivot_sign;
93+
T alpha = - get_val(c) * pivot_sign;
9494
SASSERT(!is_zero(alpha));
9595
auto & rowii = m_rows[ii];
9696
remove_element(rowii, rowii[c.offset()]);

0 commit comments

Comments
 (0)