Skip to content

Commit

Permalink
remove more dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
levnach committed Mar 8, 2023
1 parent 748c752 commit c8c0a00
Show file tree
Hide file tree
Showing 8 changed files with 5 additions and 267 deletions.
128 changes: 1 addition & 127 deletions src/math/lp/lar_core_solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ Copyright (c) 2017 Microsoft Corporation
namespace lp {

class lar_core_solver {
// m_sign_of_entering is set to 1 if the entering variable needs
// to grow and is set to -1 otherwise
int m_sign_of_entering_delta;
vector<std::pair<mpq, unsigned>> m_infeasible_linear_combination;
int m_infeasible_sum_sign; // todo: get rid of this field
vector<numeric_pair<mpq>> m_right_sides_dummy;
Expand All @@ -40,8 +37,6 @@ class lar_core_solver {
vector<unsigned> m_r_basis;
vector<unsigned> m_r_nbasis;
vector<int> m_r_heading;
stacked_vector<unsigned> m_r_columns_nz;
stacked_vector<unsigned> m_r_rows_nz;


lp_primal_core_solver<mpq, numeric_pair<mpq>> m_r_solver; // solver in rational numbers
Expand Down Expand Up @@ -82,16 +77,9 @@ class lar_core_solver {
m_r_solver.print_column_bound_info(m_r_solver.m_basis[row_index], out);
}

bool row_is_infeasible(unsigned row);

bool row_is_evidence(unsigned row);

bool find_evidence_row();


void prefix_r();

void prefix_d();

unsigned m_m() const { return m_r_A.row_count(); }

unsigned m_n() const { return m_r_A.column_count(); }
Expand All @@ -103,8 +91,6 @@ class lar_core_solver {
template <typename L>
int get_sign(const L & v) { return v > zero_of_type<L>() ? 1 : (v < zero_of_type<L>() ? -1 : 0); }

void fill_evidence(unsigned row);

unsigned get_number_of_non_ints() const;

void solve();
Expand All @@ -131,31 +117,6 @@ class lar_core_solver {

}

template <typename K>
void push_vector(stacked_vector<K> & pushed_vector, const vector<K> & vector) {
lp_assert(pushed_vector.size() <= vector.size());
for (unsigned i = 0; i < vector.size();i++) {
if (i == pushed_vector.size()) {
pushed_vector.push_back(vector[i]);
} else {
pushed_vector[i] = vector[i];
}
}
pushed_vector.push();
}

void pop_markowitz_counts(unsigned k) {
m_r_columns_nz.pop(k);
m_r_rows_nz.pop(k);
m_r_solver.m_columns_nz.resize(m_r_columns_nz.size());
m_r_solver.m_rows_nz.resize(m_r_rows_nz.size());
for (unsigned i = 0; i < m_r_columns_nz.size(); i++)
m_r_solver.m_columns_nz[i] = m_r_columns_nz[i];
for (unsigned i = 0; i < m_r_rows_nz.size(); i++)
m_r_solver.m_rows_nz[i] = m_r_rows_nz[i];
}


void pop(unsigned k) {
// rationals
m_r_lower_bounds.pop(k);
Expand All @@ -172,72 +133,7 @@ class lar_core_solver {
}


template <typename L>
bool is_zero_vector(const vector<L> & b) {
for (const L & m: b)
if (!is_zero(m)) return false;
return true;
}


bool update_xj_and_get_delta(unsigned j, non_basic_column_value_position pos_type, numeric_pair<mpq> & delta) {
auto & x = m_r_x[j];
switch (pos_type) {
case at_lower_bound:
if (x == m_r_solver.m_lower_bounds[j])
return false;
delta = m_r_solver.m_lower_bounds[j] - x;
m_r_solver.m_x[j] = m_r_solver.m_lower_bounds[j];
break;
case at_fixed:
case at_upper_bound:
if (x == m_r_solver.m_upper_bounds[j])
return false;
delta = m_r_solver.m_upper_bounds[j] - x;
x = m_r_solver.m_upper_bounds[j];
break;
case free_of_bounds: {
return false;
}
case not_at_bound:
switch (m_column_types[j]) {
case column_type::free_column:
return false;
case column_type::upper_bound:
delta = m_r_solver.m_upper_bounds[j] - x;
x = m_r_solver.m_upper_bounds[j];
break;
case column_type::lower_bound:
delta = m_r_solver.m_lower_bounds[j] - x;
x = m_r_solver.m_lower_bounds[j];
break;
case column_type::boxed:
if (x > m_r_solver.m_upper_bounds[j]) {
delta = m_r_solver.m_upper_bounds[j] - x;
x += m_r_solver.m_upper_bounds[j];
} else {
delta = m_r_solver.m_lower_bounds[j] - x;
x = m_r_solver.m_lower_bounds[j];
}
break;
case column_type::fixed:
delta = m_r_solver.m_lower_bounds[j] - x;
x = m_r_solver.m_lower_bounds[j];
break;

default:
lp_assert(false);
}
break;
default:
lp_unreachable();
}
m_r_solver.remove_column_from_inf_set(j);
return true;
}



bool r_basis_is_OK() const {
#ifdef Z3DEBUG

Expand All @@ -255,28 +151,6 @@ class lar_core_solver {
}



void fill_basis_d(
vector<unsigned>& basis_d,
vector<int>& heading_d,
vector<unsigned>& nbasis_d){
basis_d = m_r_basis;
heading_d = m_r_heading;
nbasis_d = m_r_nbasis;
}

template <typename L, typename K>
void extract_signature_from_lp_core_solver(const lp_primal_core_solver<L, K> & solver, lar_solution_signature & signature) {
signature.clear();
lp_assert(signature.size() == 0);
for (unsigned j = 0; j < solver.m_basis_heading.size(); j++) {
if (solver.m_basis_heading[j] < 0) {
signature[j] = solver.get_non_basic_column_value_position(j);
}
}
}


bool lower_bound_is_set(unsigned j) const {
switch (m_column_types[j]) {
case column_type::free_column:
Expand Down
1 change: 0 additions & 1 deletion src/math/lp/lar_core_solver_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ void lar_core_solver::prefix_r() {
}



void lar_core_solver::fill_not_improvable_zero_sum_from_inf_row() {
unsigned bj = m_r_basis[m_r_solver.m_inf_row_index_for_tableau];
m_infeasible_sum_sign = m_r_solver.inf_sign_of_column(bj);
Expand Down
2 changes: 0 additions & 2 deletions src/math/lp/lp_core_solver_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ class lp_core_solver_base {
unsigned inf_set_size() const { return m_inf_set.size(); }
bool using_infeas_costs() const { return m_using_infeas_costs; }
void set_using_infeas_costs(bool val) { m_using_infeas_costs = val; }
vector<unsigned> m_columns_nz; // m_columns_nz[i] keeps an approximate value of non zeroes the i-th column
vector<unsigned> m_rows_nz; // m_rows_nz[i] keeps an approximate value of non zeroes in the i-th row
indexed_vector<T> m_pivot_row; // this is the real pivot row of the simplex tableu
static_matrix<T, X> & m_A; // the matrix A
// vector<X> const & m_b; // the right side
Expand Down
55 changes: 2 additions & 53 deletions src/math/lp/lp_primal_core_solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,54 +41,21 @@ namespace lp {
template <typename T, typename X>
class lp_primal_core_solver:public lp_core_solver_base<T, X> {
public:
// m_sign_of_entering is set to 1 if the entering variable needs
// to grow and is set to -1 otherwise
unsigned m_column_norm_update_counter;
T m_enter_price_eps;
int m_sign_of_entering_delta;
indexed_vector<T> m_beta; // see Swietanowski working vector beta for column norms
T m_epsilon_of_reduced_cost;
vector<T> m_costs_backup;
unsigned m_inf_row_index_for_tableau;
bool m_bland_mode_tableau;
u_set m_left_basis_tableau;
u_set m_left_basis_tableau;
unsigned m_bland_mode_threshold;
unsigned m_left_basis_repeated;
vector<unsigned> m_leaving_candidates;

std::list<unsigned> m_non_basis_list;
void sort_non_basis();
void sort_non_basis_rational();
int choose_entering_column(unsigned number_of_benefitial_columns_to_go_over);
int choose_entering_column_tableau();
int choose_entering_column_presize(unsigned number_of_benefitial_columns_to_go_over);

bool column_is_benefitial_for_entering_basis_on_sign_row_strategy(unsigned j, int sign) const {
// sign = 1 means the x of the basis column of the row has to grow to become feasible, when the coeff before j is neg, or x - has to diminish when the coeff is pos
// we have xbj = -aj * xj
lp_assert(this->m_basis_heading[j] < 0);
lp_assert(this->column_is_feasible(j));
switch (this->m_column_types[j]) {
case column_type::free_column: return true;
case column_type::fixed: return false;
case column_type::lower_bound:
if (sign < 0)
return true;
return !this->x_is_at_lower_bound(j);
case column_type::upper_bound:
if (sign > 0)
return true;
return !this->x_is_at_upper_bound(j);
case column_type::boxed:
if (sign < 0)
return !this->x_is_at_lower_bound(j);
return !this->x_is_at_upper_bound(j);
}

lp_assert(false); // cannot be here
return false;
}


bool needs_to_grow(unsigned bj) const {
lp_assert(!this->column_is_feasible(bj));
Expand Down Expand Up @@ -272,10 +239,7 @@ class lp_primal_core_solver:public lp_core_solver_base<T, X> {
a_ent = rc.coeff();
return rc.var();
}
static X positive_infinity() {
return convert_struct<X, unsigned>::convert(std::numeric_limits<unsigned>::max());
}


bool try_jump_to_another_bound_on_entering(unsigned entering, const X & theta, X & t, bool & unlimited);
bool try_jump_to_another_bound_on_entering_unlimited(unsigned entering, X & t);
int find_leaving_and_t_tableau(unsigned entering, X & t);
Expand Down Expand Up @@ -313,8 +277,6 @@ class lp_primal_core_solver:public lp_core_solver_base<T, X> {

void get_bound_on_variable_and_update_leaving_precisely(unsigned j, vector<unsigned> & leavings, T m, X & t, T & abs_of_d_of_leaving);

vector<T> m_lower_bounds_dummy; // needed for the base class only

X get_max_bound(vector<X> & b);

#ifdef Z3DEBUG
Expand All @@ -334,10 +296,6 @@ class lp_primal_core_solver:public lp_core_solver_base<T, X> {

void backup_and_normalize_costs();

void init_run();

void calc_working_vector_beta_for_column_norms();

void advance_on_entering_and_leaving(int entering, int leaving, X & t);
void advance_on_entering_and_leaving_tableau(int entering, int leaving, X & t);
void advance_on_entering_equal_leaving(int entering, X & t);
Expand Down Expand Up @@ -368,7 +326,6 @@ class lp_primal_core_solver:public lp_core_solver_base<T, X> {

// bool is_tiny() const {return this->m_m < 10 && this->m_n < 20;}

void one_iteration();
void one_iteration_tableau();

// this version assumes that the leaving already has the right value, and does not update it
Expand Down Expand Up @@ -658,12 +615,6 @@ class lp_primal_core_solver:public lp_core_solver_base<T, X> {
void init_infeasibility_costs_for_changed_basis_only();

void print_column(unsigned j, std::ostream & out);
// 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
template <typename L>
bool same_sign_with_entering_delta(const L & a) {
return (a > zero_of_type<L>() && m_sign_of_entering_delta > 0) || (a < zero_of_type<L>() && m_sign_of_entering_delta < 0);
}

void print_bound_info_and_x(unsigned j, std::ostream & out);

Expand Down Expand Up @@ -730,8 +681,6 @@ class lp_primal_core_solver:public lp_core_solver_base<T, X> {
column_type_array,
lower_bound_values,
upper_bound_values),
m_beta(A.row_count()),
m_epsilon_of_reduced_cost(T(1)/T(10000000)),
m_bland_mode_threshold(1000) {
this->set_status(lp_status::UNKNOWN);
}
Expand Down
Loading

0 comments on commit c8c0a00

Please sign in to comment.