From 73224adc48b6468d8aa48b082919fab1b90d7139 Mon Sep 17 00:00:00 2001 From: Lev Nachmanson Date: Mon, 6 Mar 2023 09:51:10 -0800 Subject: [PATCH] cleanup --- src/math/lp/lar_core_solver_def.h | 5 +- src/math/lp/lp_core_solver_base.h | 12 ---- src/math/lp/lp_core_solver_base_def.h | 34 +---------- src/math/lp/lp_primal_core_solver.cpp | 1 - src/math/lp/lp_primal_core_solver.h | 4 -- src/math/lp/lp_primal_core_solver_def.h | 58 ++----------------- .../lp/lp_primal_core_solver_tableau_def.h | 6 +- src/math/lp/lp_settings.h | 1 - 8 files changed, 9 insertions(+), 112 deletions(-) diff --git a/src/math/lp/lar_core_solver_def.h b/src/math/lp/lar_core_solver_def.h index 22dc23bd5..fe99a202f 100644 --- a/src/math/lp/lar_core_solver_def.h +++ b/src/math/lp/lar_core_solver_def.h @@ -51,8 +51,6 @@ void lar_core_solver::prefix_r() { // m_r_solver.m_b.resize(m_r_solver.m_m()); if (m_r_solver.m_settings.simplex_strategy() != simplex_strategy_enum::tableau_rows) { - if(m_r_solver.m_settings.use_breakpoints_in_feasibility_search) - m_r_solver.m_breakpoint_indices_queue.resize(m_r_solver.m_n()); m_r_solver.m_costs.resize(m_r_solver.m_n()); m_r_solver.m_d.resize(m_r_solver.m_n()); m_r_solver.set_using_infeas_costs(true); @@ -61,7 +59,6 @@ void lar_core_solver::prefix_r() { void lar_core_solver::prefix_d() { // m_d_solver.m_b.resize(m_d_solver.m_m()); - m_d_solver.m_breakpoint_indices_queue.resize(m_d_solver.m_n()); m_d_solver.m_copy_of_xB.resize(m_d_solver.m_n()); m_d_solver.m_costs.resize(m_d_solver.m_n()); m_d_solver.m_d.resize(m_d_solver.m_n()); @@ -91,7 +88,7 @@ void lar_core_solver::fill_not_improvable_zero_sum() { return; } // reusing the existing mechanism for row_feasibility_loop - m_infeasible_sum_sign = m_r_solver.m_settings.use_breakpoints_in_feasibility_search? -1 : 1; + m_infeasible_sum_sign = 1; m_infeasible_linear_combination.clear(); for (auto j : m_r_solver.m_basis) { const mpq & cost_j = m_r_solver.m_costs[j]; diff --git a/src/math/lp/lp_core_solver_base.h b/src/math/lp/lp_core_solver_base.h index 0e8a2abdf..5f723c118 100644 --- a/src/math/lp/lp_core_solver_base.h +++ b/src/math/lp/lp_core_solver_base.h @@ -159,15 +159,8 @@ public: lp_status get_status() const{ return m_status; } - - void fill_cb(T * y) const; - - void fill_cb(vector & y) const; - void pretty_print(std::ostream & out); - - X get_cost() const { return dot_product(m_costs, m_x); } @@ -176,11 +169,6 @@ public: void restore_m_w(T * buffer); - // needed for debugging - void copy_m_ed(T * buffer); - - void restore_m_ed(T * buffer); - void add_delta_to_entering(unsigned entering, const X & delta); const X & get_var_value(unsigned j) const { diff --git a/src/math/lp/lp_core_solver_base_def.h b/src/math/lp/lp_core_solver_base_def.h index 01aa9802e..8b87728e0 100644 --- a/src/math/lp/lp_core_solver_base_def.h +++ b/src/math/lp/lp_core_solver_base_def.h @@ -101,21 +101,8 @@ pivot_to_reduced_costs_tableau(unsigned i, unsigned j) { } -template void lp_core_solver_base:: -fill_cb(T * y) const { - for (unsigned i = 0; i < m_m(); i++) { - y[i] = m_costs[m_basis[i]]; - } -} -template void lp_core_solver_base:: -fill_cb(vector & y) const { - for (unsigned i = 0; i < m_m(); i++) { - y[i] = m_costs[m_basis[i]]; - } -} - // template void lp_core_solver_base:: // update_index_of_ed() { @@ -155,25 +142,6 @@ restore_m_w(T * buffer) { } } -// needed for debugging -template void lp_core_solver_base:: -copy_m_ed(T * buffer) { - unsigned i = m_m(); - while (i --) { - buffer[i] = m_ed[i]; - } -} - -template void lp_core_solver_base:: -restore_m_ed(T * buffer) { - unsigned i = m_m(); - while (i --) { - m_ed[i] = buffer[i]; - } -} - - - template void lp_core_solver_base:: add_delta_to_entering(unsigned entering, const X& delta) { @@ -682,7 +650,7 @@ lp_core_solver_base::infeasibility_costs_are_correct() const { template bool lp_core_solver_base::infeasibility_cost_is_correct_for_column(unsigned j) const { - T r = (!this->m_settings.use_breakpoints_in_feasibility_search)? -one_of_type(): one_of_type(); + T r = -one_of_type(); switch (this->m_column_types[j]) { case column_type::fixed: diff --git a/src/math/lp/lp_primal_core_solver.cpp b/src/math/lp/lp_primal_core_solver.cpp index 8a4359806..f4597da76 100644 --- a/src/math/lp/lp_primal_core_solver.cpp +++ b/src/math/lp/lp_primal_core_solver.cpp @@ -34,7 +34,6 @@ template unsigned lp_primal_core_solver::solve(); template unsigned lp_primal_core_solver::solve_with_tableau(); template unsigned lp_primal_core_solver::solve(); template unsigned lp_primal_core_solver >::solve(); -template void lp::lp_primal_core_solver::clear_breakpoints(); template bool lp::lp_primal_core_solver::update_basis_and_x_tableau(int, int, lp::mpq const&); template bool lp::lp_primal_core_solver::update_basis_and_x_tableau(int, int, double const&); template bool lp::lp_primal_core_solver >::update_basis_and_x_tableau(int, int, lp::numeric_pair const&); diff --git a/src/math/lp/lp_primal_core_solver.h b/src/math/lp/lp_primal_core_solver.h index 38a2aa5f5..0a182ad91 100644 --- a/src/math/lp/lp_primal_core_solver.h +++ b/src/math/lp/lp_primal_core_solver.h @@ -47,8 +47,6 @@ public: unsigned m_column_norm_update_counter; T m_enter_price_eps; int m_sign_of_entering_delta; - vector> m_breakpoints; - binary_heap_priority_queue m_breakpoint_indices_queue; indexed_vector m_beta; // see Swietanowski working vector beta for column norms T m_epsilon_of_reduced_cost; vector m_costs_backup; @@ -545,8 +543,6 @@ public: void try_add_breakpoint_in_row(unsigned i); - void clear_breakpoints(); - void change_slope_on_breakpoint(unsigned entering, breakpoint * b, T & slope_at_entering); diff --git a/src/math/lp/lp_primal_core_solver_def.h b/src/math/lp/lp_primal_core_solver_def.h index 3967b6e66..5d4a662cf 100644 --- a/src/math/lp/lp_primal_core_solver_def.h +++ b/src/math/lp/lp_primal_core_solver_def.h @@ -112,8 +112,6 @@ template bool lp_primal_core_solver::column_is_benefitial_for_entering_basis(unsigned j) const { if (numeric_traits::precise()) return column_is_benefitial_for_entering_basis_precise(j); - if (this->using_infeas_costs() && this->m_settings.use_breakpoints_in_feasibility_search) - return column_is_benefitial_for_entering_on_breakpoints(j); const T& dj = this->m_d[j]; switch (this->m_column_types[j]) { case column_type::fixed: break; @@ -146,8 +144,6 @@ bool lp_primal_core_solver::column_is_benefitial_for_entering_basis(unsign template bool lp_primal_core_solver::column_is_benefitial_for_entering_basis_precise(unsigned j) const { lp_assert (numeric_traits::precise()); - if (this->using_infeas_costs() && this->m_settings.use_breakpoints_in_feasibility_search) - return column_is_benefitial_for_entering_on_breakpoints(j); const T& dj = this->m_d[j]; TRACE("lar_solver", tout << "dj=" << dj << "\n";); switch (this->m_column_types[j]) { @@ -219,8 +215,6 @@ int lp_primal_core_solver::choose_entering_column_presize(unsigned number_ return -1; unsigned entering = *entering_iter; m_sign_of_entering_delta = this->m_d[entering] > 0 ? 1 : -1; - if (this->using_infeas_costs() && this->m_settings.use_breakpoints_in_feasibility_search) - m_sign_of_entering_delta = -m_sign_of_entering_delta; m_non_basis_list.erase(entering_iter); m_non_basis_list.push_back(entering); return entering; @@ -259,8 +253,6 @@ int lp_primal_core_solver::choose_entering_column(unsigned number_of_benef if (entering_iter != m_non_basis_list.end()) { unsigned entering = *entering_iter; m_sign_of_entering_delta = this->m_d[entering] > 0? 1 : -1; - if (this->using_infeas_costs() && this->m_settings.use_breakpoints_in_feasibility_search) - m_sign_of_entering_delta = - m_sign_of_entering_delta; m_non_basis_list.erase(entering_iter); m_non_basis_list.push_back(entering); return entering; @@ -268,28 +260,6 @@ int lp_primal_core_solver::choose_entering_column(unsigned number_of_benef return -1; } -template int lp_primal_core_solver::advance_on_sorted_breakpoints(unsigned entering, X &t) { - T slope_at_entering = this->m_d[entering]; - breakpoint * last_bp = nullptr; - lp_assert(m_breakpoint_indices_queue.is_empty()==false); - while (m_breakpoint_indices_queue.is_empty() == false) { - unsigned bi = m_breakpoint_indices_queue.dequeue(); - breakpoint *b = &m_breakpoints[bi]; - change_slope_on_breakpoint(entering, b, slope_at_entering); - last_bp = b; - if (slope_at_entering * m_sign_of_entering_delta > - m_epsilon_of_reduced_cost) { // the slope started to increase infeasibility - break; - } else { - if ((numeric_traits::precise() == false) || ( numeric_traits::is_zero(slope_at_entering) && this->m_settings.random_next() % 2 == 0)) { - // it is not cost beneficial to advance the delta more, so just break to increase the randomness - break; - } - } - } - lp_assert (last_bp != nullptr); - t = last_bp->m_delta; - return last_bp->m_j; -} template int @@ -406,8 +376,6 @@ try_jump_to_another_bound_on_entering_unlimited(unsigned entering, X & t ) { } template int lp_primal_core_solver::find_leaving_and_t_precise(unsigned entering, X & t) { - if (this->m_settings.use_breakpoints_in_feasibility_search && !this->current_x_is_feasible()) - return find_leaving_and_t_with_breakpoints(entering, t); bool unlimited = true; unsigned steps = this->m_ed.m_index.size(); unsigned k = this->m_settings.random_next() % steps; @@ -472,8 +440,6 @@ template int lp_primal_core_solver::find_leaving_ template int lp_primal_core_solver::find_leaving_and_t(unsigned entering, X & t) { - if (this->m_settings.use_breakpoints_in_feasibility_search && !this->current_x_is_feasible()) - return find_leaving_and_t_with_breakpoints(entering, t); X theta = zero_of_type(); bool unlimited = get_harris_theta(theta); lp_assert(unlimited || theta >= zero_of_type()); @@ -584,7 +550,7 @@ void lp_primal_core_solver::update_reduced_costs_from_pivot_row(unsigned e this->m_d[j] -= dq * this->m_pivot_row[j]; } this->m_d[leaving] = -dq; - if (this->current_x_is_infeasible() && !this->m_settings.use_breakpoints_in_feasibility_search) { + if (this->current_x_is_infeasible()) { this->m_d[leaving] -= this->m_costs[leaving]; this->m_costs[leaving] = zero_of_type(); } @@ -833,14 +799,7 @@ template void lp_primal_core_solver::one_iteratio } - -template void lp_primal_core_solver::clear_breakpoints() { - m_breakpoints.clear(); - m_breakpoint_indices_queue.clear(); -} - template void lp_primal_core_solver::fill_breakpoints_array(unsigned entering) { - clear_breakpoints(); for (unsigned i : this->m_ed.m_index) try_add_breakpoint_in_row(i); @@ -924,9 +883,8 @@ lp_primal_core_solver::get_infeasibility_cost_for_column(unsigned j) const break; } - if (!this->m_settings.use_breakpoints_in_feasibility_search) { - ret = - ret; - } + ret = - ret; + return ret; } @@ -982,9 +940,8 @@ lp_primal_core_solver::init_infeasibility_cost_for_column(unsigned j) { } else { this->insert_column_into_inf_set(j); } - if (!this->m_settings.use_breakpoints_in_feasibility_search) { - this->m_costs[j] = - this->m_costs[j]; - } + this->m_costs[j] = - this->m_costs[j]; + } @@ -1009,10 +966,7 @@ template void lp_primal_core_solver::print_column } } -template void lp_primal_core_solver::add_breakpoint(unsigned j, X delta, breakpoint_type type) { - m_breakpoints.push_back(breakpoint(j, delta, type)); - m_breakpoint_indices_queue.enqueue(m_breakpoint_indices_queue.size(), abs(delta)); -} + // j is the basic column, x is the value at x[j] // d is the coefficient before m_entering in the row with j as the basis column 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 e742b0cd0..b63c54bfd 100644 --- a/src/math/lp/lp_primal_core_solver_tableau_def.h +++ b/src/math/lp/lp_primal_core_solver_tableau_def.h @@ -88,8 +88,6 @@ template int lp_primal_core_solver::choose_enteri return -1; unsigned entering = *entering_iter; m_sign_of_entering_delta = this->m_d[entering] > 0 ? 1 : -1; - if (this->using_infeas_costs() && this->m_settings.use_breakpoints_in_feasibility_search) - m_sign_of_entering_delta = -m_sign_of_entering_delta; m_non_basis_list.erase(entering_iter); m_non_basis_list.push_back(entering); return entering; @@ -188,7 +186,7 @@ template void lp_primal_core_solver::advance_on_en return; } if (!is_zero(t)) { - if (this->current_x_is_feasible() || !this->m_settings.use_breakpoints_in_feasibility_search ) { + if (this->current_x_is_feasible() ) { if (m_sign_of_entering_delta == -1) t = -t; } @@ -297,8 +295,6 @@ template void lp_primal_core_solver::init_run_tab if (this->m_settings.backup_costs) backup_and_normalize_costs(); m_epsilon_of_reduced_cost = numeric_traits::precise() ? zero_of_type() : T(1) / T(10000000); - if (this->m_settings.use_breakpoints_in_feasibility_search) - m_breakpoint_indices_queue.resize(this->m_n()); if (!numeric_traits::precise()) { this->m_column_norm_update_counter = 0; init_column_norms(); diff --git a/src/math/lp/lp_settings.h b/src/math/lp/lp_settings.h index cb60eebc9..38270230e 100644 --- a/src/math/lp/lp_settings.h +++ b/src/math/lp/lp_settings.h @@ -223,7 +223,6 @@ public: unsigned column_norms_update_frequency { 12000 }; bool scale_with_ratio { true }; double density_threshold { 0.7 }; - bool use_breakpoints_in_feasibility_search { false }; unsigned max_row_length_for_bound_propagation { 300 }; bool backup_costs { true }; unsigned column_number_threshold_for_using_lu_in_lar_solver { 4000 };