From c16d90307ba24ea69250e67860967a3a9ef4172c Mon Sep 17 00:00:00 2001 From: Lev Nachmanson Date: Mon, 23 Mar 2020 18:33:31 -0700 Subject: [PATCH] more careful resize in int_set Signed-off-by: Lev Nachmanson --- src/math/lp/int_set.h | 11 +++++++++++ src/math/lp/lar_solver.cpp | 1 - src/math/lp/lp_core_solver_base.h | 1 + src/math/lp/lp_core_solver_base_def.h | 2 ++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/math/lp/int_set.h b/src/math/lp/int_set.h index 992b5031c..d8db90d24 100644 --- a/src/math/lp/int_set.h +++ b/src/math/lp/int_set.h @@ -24,6 +24,7 @@ namespace lp { // serves at a set of non-negative integers smaller than the set size class int_set { vector m_data; + vector m_resize_buffer; public: vector m_index; int_set(unsigned size): m_data(size, -1) {} @@ -56,6 +57,16 @@ public: int operator[](unsigned j) const { return m_index[j]; } void resize(unsigned size) { + if (size < data_size()) { + for (unsigned j: m_index) { + if (j > size) + m_resize_buffer.push_back(j); + } + for (unsigned j : m_resize_buffer) + erase(j); + std::cout << m_resize_buffer.size() << "\n"; + m_resize_buffer.clear(); + } m_data.resize(size, -1); } diff --git a/src/math/lp/lar_solver.cpp b/src/math/lp/lar_solver.cpp index 72e88e97f..f7f6a6f1d 100644 --- a/src/math/lp/lar_solver.cpp +++ b/src/math/lp/lar_solver.cpp @@ -839,7 +839,6 @@ void lar_solver::solve_with_core_solver() { } m_mpq_lar_core_solver.prefix_r(); if (costs_are_used()) { - m_basic_columns_with_changed_cost.clear(); m_basic_columns_with_changed_cost.resize(m_mpq_lar_core_solver.m_r_x.size()); } if (use_tableau()) diff --git a/src/math/lp/lp_core_solver_base.h b/src/math/lp/lp_core_solver_base.h index 9eb55c32e..22cdae336 100644 --- a/src/math/lp/lp_core_solver_base.h +++ b/src/math/lp/lp_core_solver_base.h @@ -244,6 +244,7 @@ public: d -= this->m_costs[this->m_basis[cc.var()]] * this->m_A.get_val(cc); } if (m_d[j] != d) { + TRACE("lar_solver", tout << "reduced costs are incorrect for column j = " << j << " should be " << d << " but we have m_d[j] = " << m_d[j] << std::endl;); return false; } } diff --git a/src/math/lp/lp_core_solver_base_def.h b/src/math/lp/lp_core_solver_base_def.h index 728c3017f..365dbc229 100644 --- a/src/math/lp/lp_core_solver_base_def.h +++ b/src/math/lp/lp_core_solver_base_def.h @@ -996,9 +996,11 @@ lp_core_solver_base::infeasibility_costs_are_correct() const { lp_assert(costs_on_nbasis_are_zeros()); for (unsigned j :this->m_basis) { if (!infeasibility_cost_is_correct_for_column(j)) { + TRACE("lar_solver", tout << "incorrect cost for column " << j << std::endl;); return false; } if (!is_zero(m_d[j])) { + TRACE("lar_solver", tout << "non zero inf cost for basis j = " << j << std::endl;); return false; } }