Skip to content

Commit

Permalink
rm lu
Browse files Browse the repository at this point in the history
Signed-off-by: Lev Nachmanson <levnach@hotmail.com>
  • Loading branch information
levnach committed Mar 8, 2023
1 parent 9a7c99d commit 5f03c93
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 100 deletions.
3 changes: 0 additions & 3 deletions src/math/lp/lp_core_solver_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ template void lp::lp_core_solver_base<double, double>::snap_xN_to_bounds_and_fre
template void lp::lp_core_solver_base<lp::mpq, lp::numeric_pair<lp::mpq> >::snap_xN_to_bounds_and_free_columns_to_zeroes();
template void lp::lp_core_solver_base<double, double>::solve_Ax_eq_b();
template void lp::lp_core_solver_base<double, double>::solve_yB(vector<double >&) const;
template bool lp::lp_core_solver_base<double, double>::update_basis_and_x(int, int, double const&);
template void lp::lp_core_solver_base<double, double>::add_delta_to_entering(unsigned int, const double&);
template bool lp::lp_core_solver_base<lp::mpq, lp::mpq>::A_mult_x_is_off() const;
template bool lp::lp_core_solver_base<lp::mpq, lp::mpq>::A_mult_x_is_off_on_index(const vector<unsigned> &) const;
Expand All @@ -67,7 +66,6 @@ template void lp::lp_core_solver_base<lp::mpq, lp::mpq>::restore_x(unsigned int,
template void lp::lp_core_solver_base<lp::mpq, lp::mpq>::set_non_basic_x_to_correct_bounds();
template void lp::lp_core_solver_base<lp::mpq, lp::mpq>::solve_Ax_eq_b();
template void lp::lp_core_solver_base<lp::mpq, lp::mpq>::solve_yB(vector<lp::mpq>&) const;
template bool lp::lp_core_solver_base<lp::mpq, lp::mpq>::update_basis_and_x(int, int, lp::mpq const&);
template void lp::lp_core_solver_base<lp::mpq, lp::mpq>::add_delta_to_entering(unsigned int, const lp::mpq&);
template void lp::lp_core_solver_base<lp::mpq, lp::numeric_pair<lp::mpq> >::calculate_pivot_row_when_pivot_row_of_B1_is_ready(unsigned);
template void lp::lp_core_solver_base<lp::mpq, lp::numeric_pair<lp::mpq> >::init();
Expand All @@ -82,7 +80,6 @@ template bool lp::lp_core_solver_base<lp::mpq, lp::numeric_pair<lp::mpq> >::prin
template void lp::lp_core_solver_base<lp::mpq, lp::numeric_pair<lp::mpq> >::snap_xN_to_bounds_and_fill_xB();
template void lp::lp_core_solver_base<lp::mpq, lp::numeric_pair<lp::mpq> >::solve_Ax_eq_b();

template bool lp::lp_core_solver_base<lp::mpq, lp::numeric_pair<lp::mpq> >::update_basis_and_x(int, int, lp::numeric_pair<lp::mpq> const&);
template void lp::lp_core_solver_base<lp::mpq, lp::numeric_pair<lp::mpq> >::add_delta_to_entering(unsigned int, const lp::numeric_pair<lp::mpq>&);
template lp::lp_core_solver_base<lp::mpq, lp::mpq>::lp_core_solver_base(
lp::static_matrix<lp::mpq, lp::mpq>&,
Expand Down
3 changes: 1 addition & 2 deletions src/math/lp/lp_core_solver_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,7 @@ class lp_core_solver_base {

bool find_x_by_solving();

bool update_basis_and_x(int entering, int leaving, X const & tt);


bool basis_has_no_doubles() const;

bool non_basis_has_no_doubles() const;
Expand Down
60 changes: 0 additions & 60 deletions src/math/lp/lp_core_solver_base_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -457,66 +457,6 @@ template <typename T, typename X> bool lp_core_solver_base<T, X>::inf_set_is_cor
return true;
}

template <typename T, typename X> bool lp_core_solver_base<T, X>::
update_basis_and_x(int entering, int leaving, X const & tt) {

if (!is_zero(tt)) {
add_delta_to_entering(entering, tt);
if ((!numeric_traits<T>::precise()) && A_mult_x_is_off_on_index(m_ed.m_index) && !find_x_by_solving()) {
init_factorization(m_factorization, m_A, m_basis, m_settings);
if (!find_x_by_solving()) {
restore_x(entering, tt);
if(A_mult_x_is_off()) {
m_status = lp_status::FLOATING_POINT_ERROR;
m_iters_with_no_cost_growing++;
return false;
}

init_factorization(m_factorization, m_A, m_basis, m_settings);
m_iters_with_no_cost_growing++;
if (m_factorization->get_status() != LU_status::OK) {
std::stringstream s;
// s << "failing refactor on off_result for entering = " << entering << ", leaving = " << leaving << " total_iterations = " << total_iterations();
m_status = lp_status::FLOATING_POINT_ERROR;
return false;
}
return false;
}
}
}

bool refactor = m_factorization->need_to_refactor();
if (!refactor) {
const T & pivot = this->m_pivot_row[entering]; // m_ed[m_factorization->basis_heading(leaving)] is the same but the one that we are using is more precise
m_factorization->replace_column(pivot, m_w, m_basis_heading[leaving]);
if (m_factorization->get_status() == LU_status::OK) {
change_basis(entering, leaving);
return true;
}
}
// need to refactor == true
change_basis(entering, leaving);
init_lu();
if (m_factorization->get_status() != LU_status::OK) {
if (m_look_for_feasible_solution_only && !precise()) {
m_status = lp_status::UNSTABLE;
delete m_factorization;
m_factorization = nullptr;
return false;
}
// LP_OUT(m_settings, "failing refactor for entering = " << entering << ", leaving = " << leaving << " total_iterations = " << total_iterations() << std::endl);
restore_x_and_refactor(entering, leaving, tt);
if (m_status == lp_status::FLOATING_POINT_ERROR)
return false;
CASSERT("A_off", !A_mult_x_is_off());
m_iters_with_no_cost_growing++;
// LP_OUT(m_settings, "rolled back after failing of init_factorization()" << std::endl);
m_status = lp_status::UNSTABLE;
return false;
}
return true;
}


template <typename T, typename X> bool lp_core_solver_base<T, X>::
divide_row_by_pivot(unsigned pivot_row, unsigned pivot_col) {
Expand Down
28 changes: 1 addition & 27 deletions src/math/lp/lp_dual_core_solver_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -411,33 +411,7 @@ template <typename T, typename X> void lp_dual_core_solver<T, X>::init_betas_pre

// step 7 of the algorithm from Progress
template <typename T, typename X> bool lp_dual_core_solver<T, X>::basis_change_and_update() {
update_betas();
update_d_and_xB();
// m_theta_P = m_delta / this->m_ed[m_r];
m_theta_P = m_delta / this->m_pivot_row[m_q];
// xb_minus_delta_p_pivot_column();
apply_flips();
if (!this->update_basis_and_x(m_q, m_p, m_theta_P)) {
init_betas_precisely();
return false;
}

if (snap_runaway_nonbasic_column(m_p)) {
if (!this->find_x_by_solving()) {
revert_to_previous_basis();
this->iters_with_no_cost_growing()++;
return false;
}
}

if (!problem_is_dual_feasible()) {
// todo : shift the costs!!!!
revert_to_previous_basis();
this->iters_with_no_cost_growing()++;
return false;
}

lp_assert(d_is_correct());

return true;
}

Expand Down
4 changes: 2 additions & 2 deletions src/math/lp/lp_primal_core_solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -552,9 +552,9 @@ class lp_primal_core_solver:public lp_core_solver_base<T, X> {
void clear_breakpoints();

void change_slope_on_breakpoint(unsigned entering, breakpoint<X> * b, T & slope_at_entering);
void advance_on_sorted_breakpoints(unsigned entering);


void update_basis_and_x_with_comparison(unsigned entering, unsigned leaving, X delta);


void decide_on_status_when_cannot_find_entering() {
lp_assert(!need_to_switch_costs());
Expand Down
6 changes: 0 additions & 6 deletions src/math/lp/lp_primal_core_solver_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -855,12 +855,6 @@ template <typename T, typename X> void lp_primal_core_solver<T, X>::one_iteratio
}
}

template <typename T, typename X> void lp_primal_core_solver<T, X>::update_basis_and_x_with_comparison(unsigned entering, unsigned leaving, X delta) {
if (entering != leaving)
this->update_basis_and_x(entering, leaving, delta);
else
this->update_x(entering, delta);
}


template <typename T, typename X> void lp_primal_core_solver<T, X>::clear_breakpoints() {
Expand Down

0 comments on commit 5f03c93

Please sign in to comment.