From 569f5be91f4101eaa5cce897f84501b165f9c2b4 Mon Sep 17 00:00:00 2001 From: Lev Nachmanson Date: Mon, 6 Mar 2023 15:35:54 -0800 Subject: [PATCH] rm dead code --- src/math/lp/lp_core_solver_base.h | 7 +- src/math/lp/lp_core_solver_base_def.h | 2 - src/math/lp/lp_primal_core_solver.h | 14 +-- src/math/lp/lp_primal_core_solver_def.h | 114 +----------------- .../lp/lp_primal_core_solver_tableau_def.h | 5 +- 5 files changed, 7 insertions(+), 135 deletions(-) diff --git a/src/math/lp/lp_core_solver_base.h b/src/math/lp/lp_core_solver_base.h index 5f723c1185f..cb275ebc908 100644 --- a/src/math/lp/lp_core_solver_base.h +++ b/src/math/lp/lp_core_solver_base.h @@ -86,21 +86,18 @@ class lp_core_solver_base { lp_settings & m_settings; vector m_y; // the buffer for yB = cb - // a device that is able to solve Bx=c, xB=d, and change the basis const column_namer & m_column_names; indexed_vector m_w; // the vector featuring in 24.3 of the Chvatal book vector m_d; // the vector of reduced costs indexed_vector m_ed; // the solution of B*m_ed = a const vector & m_column_types; const vector & m_lower_bounds; - const vector & m_upper_bounds; - vector m_column_norms; // the approximate squares of column norms that help choosing a profitable column + const vector & m_upper_bounds; vector m_copy_of_xB; unsigned m_basis_sort_counter; - vector m_steepest_edge_coefficients; vector m_trace_of_basis_change_vector; // the even positions are entering, the odd positions are leaving bool m_tracing_basis_changes; - u_set* m_pivoted_rows; + u_set* m_pivoted_rows; bool m_look_for_feasible_solution_only; void start_tracing_basis_changes() { diff --git a/src/math/lp/lp_core_solver_base_def.h b/src/math/lp/lp_core_solver_base_def.h index 8b87728e090..474d39b572b 100644 --- a/src/math/lp/lp_core_solver_base_def.h +++ b/src/math/lp/lp_core_solver_base_def.h @@ -62,10 +62,8 @@ lp_core_solver_base(static_matrix & A, m_column_types(column_types), m_lower_bounds(lower_bound_values), m_upper_bounds(upper_bound_values), - m_column_norms(m_n()), m_copy_of_xB(m_m()), m_basis_sort_counter(0), - m_steepest_edge_coefficients(A.column_count()), m_tracing_basis_changes(false), m_pivoted_rows(nullptr), m_look_for_feasible_solution_only(false) { diff --git a/src/math/lp/lp_primal_core_solver.h b/src/math/lp/lp_primal_core_solver.h index 10de624f55a..219cc2ad35d 100644 --- a/src/math/lp/lp_primal_core_solver.h +++ b/src/math/lp/lp_primal_core_solver.h @@ -369,24 +369,12 @@ class lp_primal_core_solver:public lp_core_solver_base { unsigned get_number_of_non_basic_column_to_try_for_enter(); - void print_column_norms(std::ostream & out); // returns the number of iterations unsigned solve(); - // according to Swietanowski, " A new steepest edge approximation for the simplex method for linear programming" - void init_column_norms(); - - T calculate_column_norm_exactly(unsigned j); - - void update_or_init_column_norms(unsigned entering, unsigned leaving); - - // following Swietanowski - A new steepest ... - void update_column_norms(unsigned entering, unsigned leaving); - - T calculate_norm_of_entering_exactly(); - + void find_feasible_solution(); // bool is_tiny() const {return this->m_m < 10 && this->m_n < 20;} diff --git a/src/math/lp/lp_primal_core_solver_def.h b/src/math/lp/lp_primal_core_solver_def.h index 7a027f8d38c..dac1c15face 100644 --- a/src/math/lp/lp_primal_core_solver_def.h +++ b/src/math/lp/lp_primal_core_solver_def.h @@ -58,14 +58,8 @@ void lp_primal_core_solver::sort_non_basis() { sort_non_basis_rational(); return; } - for (unsigned j : this->m_nbasis) { - T const & da = this->m_d[j]; - this->m_steepest_edge_coefficients[j] = da * da / this->m_column_norms[j]; - } - std::sort(this->m_nbasis.begin(), this->m_nbasis.end(), [this](unsigned a, unsigned b) { - return this->m_steepest_edge_coefficients[a] > this->m_steepest_edge_coefficients[b]; - }); - + + m_non_basis_list.clear(); // reinit m_basis_heading for (unsigned j = 0; j < this->m_nbasis.size(); j++) { @@ -190,41 +184,7 @@ int lp_primal_core_solver::choose_entering_column_presize(unsigned number_ template int lp_primal_core_solver::choose_entering_column(unsigned number_of_benefitial_columns_to_go_over) { // at this moment m_y = cB * B(-1) - if (numeric_traits::precise()) - return choose_entering_column_presize(number_of_benefitial_columns_to_go_over); - if (number_of_benefitial_columns_to_go_over == 0) - return -1; - if (this->m_basis_sort_counter == 0) { - sort_non_basis(); - this->m_basis_sort_counter = 20; - } else { - this->m_basis_sort_counter--; - } - T steepest_edge = zero_of_type(); - std::list::iterator entering_iter = m_non_basis_list.end(); - for (auto non_basis_iter= m_non_basis_list.begin(); number_of_benefitial_columns_to_go_over && non_basis_iter != m_non_basis_list.end(); ++non_basis_iter) { - unsigned j = *non_basis_iter; - if (!column_is_benefitial_for_entering_basis(j)) - continue; - - // if we are here then j is a candidate to enter the basis - T dj = this->m_d[j]; - T t = dj * dj / this->m_column_norms[j]; - if (t > steepest_edge) { - steepest_edge = t; - entering_iter = non_basis_iter; - if (number_of_benefitial_columns_to_go_over) - number_of_benefitial_columns_to_go_over--; - } - }// while (number_of_benefitial_columns_to_go_over && initial_offset_in_non_basis != offset_in_nb); - if (entering_iter != m_non_basis_list.end()) { - unsigned entering = *entering_iter; - m_sign_of_entering_delta = this->m_d[entering] > 0? 1 : -1; - m_non_basis_list.erase(entering_iter); - m_non_basis_list.push_back(entering); - return entering; - } - return -1; + return choose_entering_column_presize(number_of_benefitial_columns_to_go_over); } @@ -607,13 +567,6 @@ template unsigned lp_primal_core_solver::get_num return std::max(static_cast(this->m_settings.random_next() % ret), 1u); } -template void lp_primal_core_solver::print_column_norms(std::ostream & out) { - out << " column norms " << std::endl; - for (unsigned j = 0; j < this->m_n(); j++) { - out << this->m_column_norms[j] << " "; - } - out << std::endl; - } // returns the number of iterations template unsigned lp_primal_core_solver::solve() { @@ -677,67 +630,6 @@ template unsigned lp_primal_core_solver::solve() return this->total_iterations(); } -// according to Swietanowski, " A new steepest edge approximation for the simplex method for linear programming" -template void lp_primal_core_solver::init_column_norms() { - lp_assert(numeric_traits::precise() == false); - for (unsigned j = 0; j < this->m_n(); j++) { - this->m_column_norms[j] = T(static_cast(this->m_A.m_columns[j].size() + 1)) - - + T(static_cast(this->m_settings.random_next() % 10000)) / T(100000); - } -} - -// debug only -template T lp_primal_core_solver::calculate_column_norm_exactly(unsigned j) { - lp_assert(false); -} - -template void lp_primal_core_solver::update_or_init_column_norms(unsigned entering, unsigned leaving) { - lp_assert(numeric_traits::precise() == false); - lp_assert(m_column_norm_update_counter <= this->m_settings.column_norms_update_frequency); - if (m_column_norm_update_counter == this->m_settings.column_norms_update_frequency) { - m_column_norm_update_counter = 0; - init_column_norms(); - } else { - m_column_norm_update_counter++; - update_column_norms(entering, leaving); - } -} - -// following Swietanowski - A new steepest ... -template void lp_primal_core_solver::update_column_norms(unsigned entering, unsigned leaving) { - lp_assert(numeric_traits::precise() == false); - T pivot = this->m_pivot_row[entering]; - T g_ent = calculate_norm_of_entering_exactly() / pivot / pivot; - if (!numeric_traits::precise()) { - if (g_ent < T(0.000001)) - g_ent = T(0.000001); - } - this->m_column_norms[leaving] = g_ent; - - for (unsigned j : this->m_pivot_row.m_index) { - if (j == leaving) - continue; - const T & t = this->m_pivot_row[j]; - T s = this->m_A.dot_product_with_column(m_beta.m_data, j); - T k = -2 / pivot; - T tp = t/pivot; - if (this->m_column_types[j] != column_type::fixed) { // a fixed columns do not enter the basis, we don't use the norm of a fixed column - this->m_column_norms[j] = std::max(this->m_column_norms[j] + t * (t * g_ent + k * s), // see Istvan Maros, page 196 - 1 + tp * tp); - } - } -} - -template T lp_primal_core_solver::calculate_norm_of_entering_exactly() { - T r = numeric_traits::one(); - for (auto i : this->m_ed.m_index) { - T t = this->m_ed[i]; - r += t * t; - } - return r; -} - // calling it stage1 is too cryptic template void lp_primal_core_solver::find_feasible_solution() { this->m_look_for_feasible_solution_only = true; 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 b63c54bfd10..a63a6be17ad 100644 --- a/src/math/lp/lp_primal_core_solver_tableau_def.h +++ b/src/math/lp/lp_primal_core_solver_tableau_def.h @@ -295,10 +295,7 @@ 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 (!numeric_traits::precise()) { - this->m_column_norm_update_counter = 0; - init_column_norms(); - } + if (this->m_settings.simplex_strategy() == simplex_strategy_enum::tableau_rows) init_tableau_rows(); lp_assert(this->reduced_costs_are_correct_tableau());