Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
levnach committed Mar 8, 2023
1 parent 377ceba commit 73224ad
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 112 deletions.
5 changes: 1 addition & 4 deletions src/math/lp/lar_core_solver_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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());
Expand Down Expand Up @@ -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];
Expand Down
12 changes: 0 additions & 12 deletions src/math/lp/lp_core_solver_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,8 @@ class lp_core_solver_base {
lp_status get_status() const{
return m_status;
}

void fill_cb(T * y) const;

void fill_cb(vector<T> & y) const;

void pretty_print(std::ostream & out);



X get_cost() const {
return dot_product(m_costs, m_x);
}
Expand All @@ -176,11 +169,6 @@ class lp_core_solver_base {

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 {
Expand Down
34 changes: 1 addition & 33 deletions src/math/lp/lp_core_solver_base_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,7 @@ pivot_to_reduced_costs_tableau(unsigned i, unsigned j) {
}


template <typename T, typename X> void lp_core_solver_base<T, X>::
fill_cb(T * y) const {
for (unsigned i = 0; i < m_m(); i++) {
y[i] = m_costs[m_basis[i]];
}
}


template <typename T, typename X> void lp_core_solver_base<T, X>::
fill_cb(vector<T> & y) const {
for (unsigned i = 0; i < m_m(); i++) {
y[i] = m_costs[m_basis[i]];
}
}


// template <typename T, typename X> void lp_core_solver_base<T, X>::
Expand Down Expand Up @@ -155,25 +142,6 @@ restore_m_w(T * buffer) {
}
}

// needed for debugging
template <typename T, typename X> void lp_core_solver_base<T, X>::
copy_m_ed(T * buffer) {
unsigned i = m_m();
while (i --) {
buffer[i] = m_ed[i];
}
}

template <typename T, typename X> void lp_core_solver_base<T, X>::
restore_m_ed(T * buffer) {
unsigned i = m_m();
while (i --) {
m_ed[i] = buffer[i];
}
}




template <typename T, typename X> void lp_core_solver_base<T, X>::
add_delta_to_entering(unsigned entering, const X& delta) {
Expand Down Expand Up @@ -682,7 +650,7 @@ lp_core_solver_base<T, X>::infeasibility_costs_are_correct() const {

template <typename T, typename X> bool
lp_core_solver_base<T, X>::infeasibility_cost_is_correct_for_column(unsigned j) const {
T r = (!this->m_settings.use_breakpoints_in_feasibility_search)? -one_of_type<T>(): one_of_type<T>();
T r = -one_of_type<T>();

switch (this->m_column_types[j]) {
case column_type::fixed:
Expand Down
1 change: 0 additions & 1 deletion src/math/lp/lp_primal_core_solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ template unsigned lp_primal_core_solver<double, double>::solve();
template unsigned lp_primal_core_solver<double, double>::solve_with_tableau();
template unsigned lp_primal_core_solver<mpq, mpq>::solve();
template unsigned lp_primal_core_solver<mpq, numeric_pair<mpq> >::solve();
template void lp::lp_primal_core_solver<double, double>::clear_breakpoints();
template bool lp::lp_primal_core_solver<lp::mpq, lp::mpq>::update_basis_and_x_tableau(int, int, lp::mpq const&);
template bool lp::lp_primal_core_solver<double, double>::update_basis_and_x_tableau(int, int, double const&);
template bool lp::lp_primal_core_solver<lp::mpq, lp::numeric_pair<lp::mpq> >::update_basis_and_x_tableau(int, int, lp::numeric_pair<lp::mpq> const&);
Expand Down
4 changes: 0 additions & 4 deletions src/math/lp/lp_primal_core_solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ class lp_primal_core_solver:public lp_core_solver_base<T, X> {
unsigned m_column_norm_update_counter;
T m_enter_price_eps;
int m_sign_of_entering_delta;
vector<breakpoint<X>> m_breakpoints;
binary_heap_priority_queue<X> m_breakpoint_indices_queue;
indexed_vector<T> m_beta; // see Swietanowski working vector beta for column norms
T m_epsilon_of_reduced_cost;
vector<T> m_costs_backup;
Expand Down Expand Up @@ -545,8 +543,6 @@ class lp_primal_core_solver:public lp_core_solver_base<T, X> {

void try_add_breakpoint_in_row(unsigned i);

void clear_breakpoints();

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


Expand Down
58 changes: 6 additions & 52 deletions src/math/lp/lp_primal_core_solver_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ template <typename T, typename X>
bool lp_primal_core_solver<T, X>::column_is_benefitial_for_entering_basis(unsigned j) const {
if (numeric_traits<T>::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;
Expand Down Expand Up @@ -146,8 +144,6 @@ bool lp_primal_core_solver<T, X>::column_is_benefitial_for_entering_basis(unsign
template <typename T, typename X>
bool lp_primal_core_solver<T, X>::column_is_benefitial_for_entering_basis_precise(unsigned j) const {
lp_assert (numeric_traits<T>::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]) {
Expand Down Expand Up @@ -219,8 +215,6 @@ int lp_primal_core_solver<T, X>::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;
Expand Down Expand Up @@ -259,37 +253,13 @@ int lp_primal_core_solver<T, X>::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;
}
return -1;
}

template <typename T, typename X> int lp_primal_core_solver<T, X>::advance_on_sorted_breakpoints(unsigned entering, X &t) {
T slope_at_entering = this->m_d[entering];
breakpoint<X> * 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<X> *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<T>::precise() == false) || ( numeric_traits<T>::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 <typename T, typename X> int
Expand Down Expand Up @@ -406,8 +376,6 @@ try_jump_to_another_bound_on_entering_unlimited(unsigned entering, X & t ) {
}

template <typename T, typename X> int lp_primal_core_solver<T, X>::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;
Expand Down Expand Up @@ -472,8 +440,6 @@ template <typename T, typename X> int lp_primal_core_solver<T, X>::find_leaving_


template <typename T, typename X> int lp_primal_core_solver<T, X>::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<X>();
bool unlimited = get_harris_theta(theta);
lp_assert(unlimited || theta >= zero_of_type<X>());
Expand Down Expand Up @@ -584,7 +550,7 @@ void lp_primal_core_solver<T, X>::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<T>();
}
Expand Down Expand Up @@ -833,14 +799,7 @@ 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>::clear_breakpoints() {
m_breakpoints.clear();
m_breakpoint_indices_queue.clear();
}

template <typename T, typename X> void lp_primal_core_solver<T, X>::fill_breakpoints_array(unsigned entering) {
clear_breakpoints();
for (unsigned i : this->m_ed.m_index)
try_add_breakpoint_in_row(i);

Expand Down Expand Up @@ -924,9 +883,8 @@ lp_primal_core_solver<T, X>::get_infeasibility_cost_for_column(unsigned j) const
break;
}

if (!this->m_settings.use_breakpoints_in_feasibility_search) {
ret = - ret;
}
ret = - ret;

return ret;
}

Expand Down Expand Up @@ -982,9 +940,8 @@ lp_primal_core_solver<T, X>::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];

}


Expand All @@ -1009,10 +966,7 @@ template <typename T, typename X> void lp_primal_core_solver<T, X>::print_column
}
}

template <typename T, typename X> void lp_primal_core_solver<T, X>::add_breakpoint(unsigned j, X delta, breakpoint_type type) {
m_breakpoints.push_back(breakpoint<X>(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
Expand Down
6 changes: 1 addition & 5 deletions src/math/lp/lp_primal_core_solver_tableau_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ template <typename T, typename X> int lp_primal_core_solver<T, X>::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;
Expand Down Expand Up @@ -188,7 +186,7 @@ template <typename T, typename X>void lp_primal_core_solver<T, X>::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;
}
Expand Down Expand Up @@ -297,8 +295,6 @@ template <typename T, typename X> void lp_primal_core_solver<T, X>::init_run_tab
if (this->m_settings.backup_costs)
backup_and_normalize_costs();
m_epsilon_of_reduced_cost = numeric_traits<X>::precise() ? zero_of_type<T>() : T(1) / T(10000000);
if (this->m_settings.use_breakpoints_in_feasibility_search)
m_breakpoint_indices_queue.resize(this->m_n());
if (!numeric_traits<X>::precise()) {
this->m_column_norm_update_counter = 0;
init_column_norms();
Expand Down
1 change: 0 additions & 1 deletion src/math/lp/lp_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ struct lp_settings {
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 };
Expand Down

0 comments on commit 73224ad

Please sign in to comment.