Skip to content

Commit 294dcf7

Browse files
Merge pull request #2455 from levnach/fix
fix a bug in lar_solver in querying if a column is int
2 parents 9d6728a + e9e9500 commit 294dcf7

10 files changed

+29
-27
lines changed

src/test/lp/gomory_test.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ struct gomory_test {
8686
}
8787

8888
void int_case_in_gomory_cut(const mpq & a, unsigned x_j, mpq & k, lar_term & t, explanation& expl, mpq & lcm_den, const mpq& f_0, const mpq& one_minus_f_0) {
89-
lp_assert(is_int(x_j));
89+
lp_assert(is_integer(x_j));
9090
lp_assert(!a.is_int());
9191
lp_assert(f_0 > zero_of_type<mpq>() && f_0 < one_of_type<mpq>());
9292
mpq f_j = fractional_part(a);
@@ -138,7 +138,7 @@ struct gomory_test {
138138
if (pol.size() == 1) {
139139
TRACE("gomory_cut_detail", tout << "pol.size() is 1" << std::endl;);
140140
unsigned v = pol[0].second;
141-
lp_assert(is_int(v));
141+
lp_assert(is_integer(v));
142142
const mpq& a = pol[0].first;
143143
k /= a;
144144
if (a.is_pos()) { // we have av >= k
@@ -165,7 +165,7 @@ struct gomory_test {
165165
// normalize coefficients of integer parameters to be integers.
166166
for (auto & pi: pol) {
167167
pi.first *= lcm_den;
168-
SASSERT(!is_int(pi.second) || pi.first.is_int());
168+
SASSERT(!is_integer(pi.second) || pi.first.is_int());
169169
}
170170
k *= lcm_den;
171171
}

src/util/lp/gomory.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class gomory::imp {
4747
bool column_is_fixed(unsigned j) const { return m_int_solver.m_lar_solver->column_is_fixed(j); }
4848

4949
void int_case_in_gomory_cut(unsigned j) {
50-
lp_assert(is_int(j) && m_fj.is_pos());
50+
lp_assert(m_int_solver.column_is_int(j) && m_fj.is_pos());
5151
TRACE("gomory_cut_detail",
5252
tout << " k = " << m_k;
5353
tout << ", fj: " << m_fj << ", ";
@@ -117,7 +117,7 @@ class gomory::imp {
117117
if (pol.size() == 1) {
118118
TRACE("gomory_cut_detail", tout << "pol.size() is 1" << std::endl;);
119119
unsigned v = pol[0].second;
120-
lp_assert(is_int(v));
120+
lp_assert(m_int_solver.column_is_int(v));
121121
const mpq& a = pol[0].first;
122122
m_k /= a;
123123
if (a.is_pos()) { // we have av >= k
@@ -139,7 +139,7 @@ class gomory::imp {
139139
// normalize coefficients of integer parameters to be integers.
140140
for (auto & pi: pol) {
141141
pi.first *= m_lcm_den;
142-
SASSERT(!is_int(pi.second) || pi.first.is_int());
142+
SASSERT(!m_int_solver.column_is_int(pi.second) || pi.first.is_int());
143143
}
144144
m_k *= m_lcm_den;
145145
}
@@ -195,7 +195,7 @@ class gomory::imp {
195195
}
196196

197197
void dump_declaration(std::ostream& out, unsigned v) const {
198-
out << "(declare-const " << var_name(v) << (is_int(v) ? " Int" : " Real") << ")\n";
198+
out << "(declare-const " << var_name(v) << (m_int_solver.column_is_int(v) ? " Int" : " Real") << ")\n";
199199
}
200200

201201
void dump_declarations(std::ostream& out) const {

src/util/lp/hnf.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ void pivot_column_non_fractional(M &m, unsigned r, bool & overflow, const mpq &
137137
overflow = true;
138138
return;
139139
}
140-
lp_assert(is_int(m[i][j]));
140+
lp_assert(is_integer(m[i][j]));
141141
}
142142
}
143143
}
@@ -577,7 +577,7 @@ class hnf {
577577
process_row_modulo();
578578
lp_assert(is_pos(m_W[m_i][m_i]));
579579
m_R /= m_W[m_i][m_i];
580-
lp_assert(is_int(m_R));
580+
lp_assert(is_integer(m_R));
581581
m_half_R = floor(m_R / 2);
582582
}
583583
}

src/util/lp/hnf_cutter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class hnf_cutter {
120120
int ret = -1;
121121
int n = 0;
122122
for (int i = 0; i < static_cast<int>(b.size()); i++) {
123-
if (is_int(b[i])) continue;
123+
if (is_integer(b[i])) continue;
124124
if (n == 0 ) {
125125
lp_assert(ret == -1);
126126
n = 1;

src/util/lp/int_solver.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ void int_solver::trace_inf_rows() const {
1616
TRACE("arith_int_rows",
1717
unsigned num = m_lar_solver->A_r().column_count();
1818
for (unsigned v = 0; v < num; v++) {
19-
if (is_int(v) && !get_value(v).is_int()) {
19+
if (column_is_int(v) && !get_value(v).is_int()) {
2020
display_column(tout, v);
2121
}
2222
}
@@ -197,7 +197,7 @@ impq int_solver::get_cube_delta_for_term(const lar_term& t) const {
197197
bool seen_minus = false;
198198
bool seen_plus = false;
199199
for(const auto & p : t) {
200-
if (!is_int(p.var()))
200+
if (!column_is_int(p.var()))
201201
goto usual_delta;
202202
const mpq & c = p.coeff();
203203
if (c == one_of_type<mpq>()) {
@@ -215,7 +215,7 @@ impq int_solver::get_cube_delta_for_term(const lar_term& t) const {
215215
usual_delta:
216216
mpq delta = zero_of_type<mpq>();
217217
for (const auto & p : t)
218-
if (is_int(p.var()))
218+
if (column_is_int(p.var()))
219219
delta += abs(p.coeff());
220220

221221
delta *= mpq(1, 2);
@@ -759,7 +759,7 @@ bool int_solver::get_freedom_interval_for_column(unsigned j, bool & inf_l, impq
759759

760760
unsigned i = lcs.m_r_basis[row_index];
761761
impq const & xi = get_value(i);
762-
if (is_int(i) && is_int(j) && !a.is_int())
762+
if (column_is_int(i) && column_is_int(j) && !a.is_int())
763763
m = lcm(m, denominator(a));
764764
if (a.is_neg()) {
765765
if (has_low(i))
@@ -791,12 +791,12 @@ bool int_solver::get_freedom_interval_for_column(unsigned j, bool & inf_l, impq
791791
return (inf_l || inf_u || l <= u);
792792
}
793793

794-
bool int_solver::is_int(unsigned j) const {
794+
bool int_solver::column_is_int(unsigned j) const {
795795
return m_lar_solver->column_is_int(j);
796796
}
797797

798798
bool int_solver::is_real(unsigned j) const {
799-
return !is_int(j);
799+
return !column_is_int(j);
800800
}
801801

802802
bool int_solver::value_is_int(unsigned j) const {
@@ -821,7 +821,7 @@ void int_solver::display_column(std::ostream & out, unsigned j) const {
821821
}
822822

823823
bool int_solver::column_is_int_inf(unsigned j) const {
824-
return is_int(j) && (!value_is_int(j));
824+
return column_is_int(j) && (!value_is_int(j));
825825
}
826826

827827
bool int_solver::is_base(unsigned j) const {
@@ -912,7 +912,7 @@ bool int_solver::shift_var(unsigned j, unsigned range) {
912912
set_value_for_nbasic_column_ignore_old_values(j, new_val);
913913
return true;
914914
}
915-
if (is_int(j)) {
915+
if (column_is_int(j)) {
916916
if (!inf_l) {
917917
l = ceil(l);
918918
if (!m.is_one())
@@ -940,7 +940,7 @@ bool int_solver::shift_var(unsigned j, unsigned range) {
940940
set_value_for_nbasic_column_ignore_old_values(j, new_val);
941941
return true;
942942
}
943-
if (!is_int(j)) {
943+
if (!column_is_int(j)) {
944944
SASSERT(!inf_l && !inf_u);
945945
mpq delta = mpq(random() % (range + 1));
946946
impq new_val = l + ((delta * (u - l)) / mpq(range));
@@ -975,7 +975,7 @@ bool int_solver::non_basic_columns_are_at_bounds() const {
975975
return false;
976976
break;
977977
default:
978-
if (is_int(j) && !val.is_int()) {
978+
if (column_is_int(j) && !val.is_int()) {
979979
return false;
980980
}
981981
}

src/util/lp/int_solver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class int_solver {
5959
bool is_real(unsigned j) const;
6060
const impq & lower_bound(unsigned j) const;
6161
const impq & upper_bound(unsigned j) const;
62-
bool is_int(unsigned j) const;
62+
bool column_is_int(unsigned j) const;
6363
const impq & get_value(unsigned j) const;
6464
bool at_lower(unsigned j) const;
6565
bool at_upper(unsigned j) const;

src/util/lp/lar_solver.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ bool lar_solver::move_non_basic_column_to_bounds(unsigned j) {
512512
}
513513
break;
514514
default:
515-
if (is_int(j) && !val.is_int()) {
515+
if (column_is_int(j) && !val.is_int()) {
516516
set_value_for_nbasic_column(j, impq(floor(val)));
517517
return true;
518518
}
@@ -526,6 +526,7 @@ void lar_solver::set_value_for_nbasic_column(unsigned j, const impq & new_val) {
526526
auto & x = m_mpq_lar_core_solver.m_r_x[j];
527527
auto delta = new_val - x;
528528
x = new_val;
529+
m_mpq_lar_core_solver.m_r_solver.track_column_feasibility(j);
529530
change_basic_columns_dependend_on_a_given_nb_column(j, delta);
530531
}
531532

src/util/lp/lp_core_solver_base.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,7 @@ class lp_core_solver_base {
550550
bool non_basic_columns_are_set_correctly() const {
551551
for (unsigned j : this->m_nbasis)
552552
if (!column_is_feasible(j)) {
553+
TRACE("lp_core", tout << "inf col "; print_column_info(j, tout) << "\n";);
553554
return false;
554555
}
555556
return true;
@@ -573,7 +574,7 @@ class lp_core_solver_base {
573574
}
574575
}
575576

576-
void print_column_info(unsigned j, std::ostream & out) const {
577+
std::ostream& print_column_info(unsigned j, std::ostream & out) const {
577578
out << "j = " << j << ",\tname = "<< column_name(j) << "\t";
578579
switch (m_column_types[j]) {
579580
case column_type::fixed:
@@ -598,6 +599,7 @@ class lp_core_solver_base {
598599
out << " base\n";
599600
else
600601
out << " \n";
602+
return out;
601603
}
602604

603605
bool column_is_free(unsigned j) const { return this->m_column_type[j] == free; }

src/util/lp/lp_core_solver_base_def.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -511,12 +511,11 @@ template <typename T, typename X> bool lp_core_solver_base<T, X>::calc_current_x
511511
}
512512

513513
template <typename T, typename X> bool lp_core_solver_base<T, X>::inf_set_is_correct() const {
514-
unsigned j = this->m_n();
515-
while (j--) {
514+
for (unsigned j = 0; j < this->m_n(); j++) {
516515
bool belongs_to_set = m_inf_set.contains(j);
517516
bool is_feas = column_is_feasible(j);
518-
519517
if (is_feas == belongs_to_set) {
518+
TRACE("lp_core", tout << "incorrectly set column in inf set "; print_column_info(j, tout) << "\n";);
520519
return false;
521520
}
522521
}

src/util/lp/lp_utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ template <typename X> inline X one_of_type() { return numeric_traits<X>::one();
8686
template <typename X> inline bool is_zero(const X & v) { return numeric_traits<X>::is_zero(v); }
8787
template <typename X> inline bool is_pos(const X & v) { return numeric_traits<X>::is_pos(v); }
8888
template <typename X> inline bool is_neg(const X & v) { return numeric_traits<X>::is_neg(v); }
89-
template <typename X> inline bool is_int(const X & v) { return numeric_traits<X>::is_int(v); }
89+
template <typename X> inline bool is_integer(const X & v) { return numeric_traits<X>::is_int(v); }
9090

9191
template <typename X> inline X ceil_ratio(const X & a, const X & b) { return numeric_traits<X>::ceil_ratio(a, b); }
9292
template <typename X> inline X floor_ratio(const X & a, const X & b) { return numeric_traits<X>::floor_ratio(a, b); }

0 commit comments

Comments
 (0)