From 99dcad0ddac8940c5fa7ff7361fbd7e2234216da Mon Sep 17 00:00:00 2001 From: Lev Nachmanson Date: Mon, 11 Jan 2016 11:07:02 -0800 Subject: [PATCH] dev(lp): performance tuning in find_leaving_on_harris_theta Signed-off-by: Lev Nachmanson --- src/util/lp/core_solver_pretty_printer.h | 1 + src/util/lp/eta_matrix.h | 1 + src/util/lp/lp_primal_core_solver.h | 21 ++------------- src/util/lp/lp_primal_simplex.h | 34 +++--------------------- 4 files changed, 8 insertions(+), 49 deletions(-) diff --git a/src/util/lp/core_solver_pretty_printer.h b/src/util/lp/core_solver_pretty_printer.h index 616a6a1959..27dc279855 100644 --- a/src/util/lp/core_solver_pretty_printer.h +++ b/src/util/lp/core_solver_pretty_printer.h @@ -8,6 +8,7 @@ #pragma once #include #include +#include namespace lean { template class lp_core_solver_base; // forward definition diff --git a/src/util/lp/eta_matrix.h b/src/util/lp/eta_matrix.h index 034bdb1a4b..b6ce28ac3b 100644 --- a/src/util/lp/eta_matrix.h +++ b/src/util/lp/eta_matrix.h @@ -6,6 +6,7 @@ */ #pragma once +#include namespace lean { // This is the sum of a unit matrix and a one-column matrix diff --git a/src/util/lp/lp_primal_core_solver.h b/src/util/lp/lp_primal_core_solver.h index 9a4c29ca51..57e1323e1e 100644 --- a/src/util/lp/lp_primal_core_solver.h +++ b/src/util/lp/lp_primal_core_solver.h @@ -148,7 +148,6 @@ public: // todo : move public lower ; it is for debug only int find_leaving_on_harris_theta(X const & harris_theta, X & t) { int leaving = -1; - int leaving_fixed = -1; // we would like to get rid of fixed columns in the basis first because they might bring t to zero T pivot_abs_max; T pivot_abs_max_fixed; // we know already that there is no bound flip on entering @@ -167,7 +166,7 @@ public: // todo : move public lower ; it is for debug only unsigned j = this->m_basis[i]; limit_theta_on_basis_column(j, - this->m_ed[i] * m_sign_of_entering_delta, ratio); if (ratio <= harris_theta) { - if (get_current_x_is_infeasible() && !m_recalc_reduced_costs) { // when we have made several basic variables feasible then we need to recalculate the costs and the reduced costs: here we are catching this case + if (!m_recalc_reduced_costs && get_current_x_is_infeasible()) { // when we have made several basic variables feasible we need to recalculate the costs and the reduced costs: here we are catching this case if (!is_zero(this->m_costs[j])) { if (column_with_non_zero_cost != -1) m_recalc_reduced_costs = true; @@ -179,28 +178,12 @@ public: // todo : move public lower ; it is for debug only t = ratio; leaving = j; pivot_abs_max = abs(this->m_ed[i]); - if (this->m_column_type[j] == fixed) { - leaving_fixed = j; - pivot_abs_max_fixed = pivot_abs_max; - } - } else if (this->m_column_type[j] == fixed) { - if (leaving_fixed == -1 || abs(this->m_ed[i]) > pivot_abs_max_fixed) { - pivot_abs_max_fixed = abs(this->m_ed[i]); - leaving_fixed = j; - } } } if (++i == this->m_m) i = 0; } while ( i != initial_i); restore_harris_eps(); - // if (m_j_uht.size() > 1) { - // cout << "under set " << std::endl; - // for(auto j : m_j_uht) - // print_column(j); - // // } - // cout << "done with under set" << std::endl; - return leaving; // debug - // return leaving_fixed != -1 ? leaving_fixed : leaving; + return leaving; } diff --git a/src/util/lp/lp_primal_simplex.h b/src/util/lp/lp_primal_simplex.h index fe16910c88..5b983f2740 100644 --- a/src/util/lp/lp_primal_simplex.h +++ b/src/util/lp/lp_primal_simplex.h @@ -230,12 +230,12 @@ public: solve_with_total_inf(); } - void fill_A_x_and_basis_for_stage_on_total_inf() { + void fill_A_x_and_basis_for_stage_one_total_inf() { for (unsigned row = 0; row < this->row_count(); row++) - fill_A_x_and_basis_for_stage_on_total_inf_for_row(row); + fill_A_x_and_basis_for_stage_one_total_inf_for_row(row); } - void fill_A_x_and_basis_for_stage_on_total_inf_for_row(unsigned row) { + void fill_A_x_and_basis_for_stage_one_total_inf_for_row(unsigned row) { lean_assert(row < this->row_count()); auto ext_row_it = this->m_core_solver_rows_to_external_rows.find(row); lean_assert(ext_row_it != this->m_core_solver_rows_to_external_rows.end()); @@ -279,7 +279,7 @@ public: this->m_basis.resize(this->row_count()); this->m_costs.clear(); this->m_costs.resize(total_vars, zero_of_type()); - fill_A_x_and_basis_for_stage_on_total_inf(); + fill_A_x_and_basis_for_stage_one_total_inf(); this->print_statistics_on_A(); this->fill_column_names_for_core_solver(); int j = this->m_A->column_count() - 1; @@ -304,32 +304,6 @@ public: } - // void stage_one_of_total_inf() { - // std::cout << "starting stage_one_of_total_inf()" << std::endl; - // int total_vars = this->m_A->column_count() + this->row_count(); - // m_low_bounds.clear(); - // m_low_bounds.resize(total_vars, zero_of_type()); // low bounds are shifted ot zero - // this->m_x.resize(total_vars, numeric_traits::zero()); - // this->m_basis.resize(this->row_count()); - // this->m_costs.clear(); - // this->m_costs.resize(total_vars, zero_of_type()); - // fill_A_x_and_basis_for_stage_on_total_inf(); - // this->print_statistics_on_A(); - // this->fill_column_names_for_core_solver(); - // m_core_solver = new lp_primal_core_solver(*this->m_A, - // this->m_b, - // this->m_x, - // this->m_basis, - // this->m_costs, - // this->m_column_types, - // m_low_bounds, - // this->m_upper_bounds, - // this->m_settings, this->m_name_map); - // m_core_solver->find_feasible_solution(); - // this->m_first_stage_iterations = m_core_solver->m_total_iterations; - // this->m_status = m_core_solver->m_status == lp_status::OPTIMAL? lp_status::FEASIBLE: m_core_solver->m_status; // just map FEASIBLE to OPTIMAL and do not change the rest - // } - ~lp_primal_simplex() { if (m_core_solver != nullptr) { delete m_core_solver;