From 08d3a82ce01bfd594d375354f318ee2a354deea1 Mon Sep 17 00:00:00 2001 From: Lev Nachmanson Date: Thu, 2 Nov 2023 11:09:01 -0700 Subject: [PATCH] simplify the jump on entering --- src/math/lp/lp_primal_core_solver.h | 2 +- src/math/lp/lp_primal_core_solver_def.h | 47 ++++--------------- .../lp/lp_primal_core_solver_tableau_def.h | 5 +- 3 files changed, 10 insertions(+), 44 deletions(-) diff --git a/src/math/lp/lp_primal_core_solver.h b/src/math/lp/lp_primal_core_solver.h index a239f1472..d34569032 100644 --- a/src/math/lp/lp_primal_core_solver.h +++ b/src/math/lp/lp_primal_core_solver.h @@ -231,7 +231,7 @@ namespace lp { return rc.var(); } - bool try_jump_to_another_bound_on_entering(unsigned entering, const X &theta, X &t, bool &unlimited); + bool try_jump_to_another_bound_on_entering(unsigned entering, X &t); bool try_jump_to_another_bound_on_entering_unlimited(unsigned entering, X &t); diff --git a/src/math/lp/lp_primal_core_solver_def.h b/src/math/lp/lp_primal_core_solver_def.h index 6ee265e39..f14d268a3 100644 --- a/src/math/lp/lp_primal_core_solver_def.h +++ b/src/math/lp/lp_primal_core_solver_def.h @@ -98,48 +98,17 @@ bool lp_primal_core_solver::column_is_benefitial_for_entering_basis(unsign } return false; } - -template bool lp_primal_core_solver::try_jump_to_another_bound_on_entering(unsigned entering, - const X & theta, - X & t, - bool & unlimited) { - switch(this->m_column_types[entering]){ - case column_type::boxed: - if (m_sign_of_entering_delta > 0) { - t = this->m_upper_bounds[entering] - this->m_x[entering]; - if (unlimited || t <= theta){ - lp_assert(t >= zero_of_type()); - return true; - } - } else { // m_sign_of_entering_delta == -1 - t = this->m_x[entering] - this->m_lower_bounds[entering]; - if (unlimited || t <= theta) { - lp_assert(t >= zero_of_type()); - return true; - } - } +// we assume that the columns are at their bounds +template bool lp_primal_core_solver::try_jump_to_another_bound_on_entering(unsigned entering, X & theta) { + if (this->m_column_types[entering] != column_type::boxed) return false; - case column_type::upper_bound: - if (m_sign_of_entering_delta > 0) { - t = this->m_upper_bounds[entering] - this->m_x[entering]; - if (unlimited || t <= theta){ - lp_assert(t >= zero_of_type()); - return true; - } - } - return false; - case column_type::lower_bound: - if (m_sign_of_entering_delta < 0) { - t = this->m_x[entering] - this->m_lower_bounds[entering]; - if (unlimited || t <= theta) { - lp_assert(t >= zero_of_type()); - return true; - } - } - return false; - default:return false; + X t = this->m_upper_bounds[entering] - this->m_lower_bounds[entering]; + if (t <= theta) { + theta = t; + return true; } return false; + } template bool lp_primal_core_solver:: diff --git a/src/math/lp/lp_primal_core_solver_tableau_def.h b/src/math/lp/lp_primal_core_solver_tableau_def.h index a700dbd29..437d27ae8 100644 --- a/src/math/lp/lp_primal_core_solver_tableau_def.h +++ b/src/math/lp/lp_primal_core_solver_tableau_def.h @@ -246,10 +246,7 @@ template int lp_primal_core_solver::find_leaving_ } } - ratio = t; - unlimited = false; - if (try_jump_to_another_bound_on_entering(entering, t, ratio, unlimited)) { - t = ratio; + if (try_jump_to_another_bound_on_entering(entering, t)) { return entering; } if (m_leaving_candidates.size() == 1)