Skip to content

Commit 52241b6

Browse files
committed
some refactoring of lar_solver.h
Signed-off-by: Lev Nachmanson <[email protected]>
1 parent fef954c commit 52241b6

File tree

2 files changed

+40
-43
lines changed

2 files changed

+40
-43
lines changed

src/math/lp/lar_solver.cpp

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,41 @@ namespace lp {
139139
return solver.get_status() == lp_status::INFEASIBLE;
140140
}
141141
}
142-
};
142+
void require_nbasis_sort() { m_mpq_lar_core_solver.m_r_solver.m_nbasis_sort_counter = 0; }
143+
void register_in_fixed_var_table(unsigned j, unsigned& equal_to_j) {
144+
SASSERT(lra.column_is_fixed(j));
145+
equal_to_j = null_lpvar;
146+
const impq& bound = lra.get_lower_bound(j);
147+
if (!bound.y.is_zero())
148+
return;
149+
150+
const mpq& key = bound.x;
151+
unsigned k;
152+
bool j_is_int = lra.column_is_int(j);
153+
if (j_is_int) {
154+
if (!m_fixed_var_table_int.find(key, k)) {
155+
m_fixed_var_table_int.insert(key, j);
156+
return;
157+
}
158+
}
159+
else { // j is not integral column
160+
if (!m_fixed_var_table_real.find(key, k)) {
161+
m_fixed_var_table_real.insert(key, j);
162+
return;
163+
}
164+
}
165+
166+
CTRACE("arith", !lra.column_is_fixed(k), lra.print_terms(tout););
167+
// SASSERT(column_is_fixed(k));
168+
if (j != k && lra.column_is_fixed(k)) {
169+
SASSERT(lra.column_is_int(j) == lra.column_is_int(k));
170+
equal_to_j = k;
171+
TRACE("lar_solver", tout << "found equal column k = " << k <<
172+
", external = " << equal_to_j << "\n";);
173+
}
174+
}
175+
176+
}; // imp
143177
unsigned_vector& lar_solver::row_bounds_to_replay() { return m_imp->m_row_bounds_to_replay; }
144178

145179
trail_stack& lar_solver::trail() { return m_imp->m_trail; }
@@ -211,8 +245,6 @@ namespace lp {
211245

212246
indexed_uint_set& lar_solver::basic_columns_with_changed_cost() { return m_imp->m_basic_columns_with_changed_cost; }
213247

214-
void lar_solver::require_nbasis_sort() { m_imp->m_mpq_lar_core_solver.m_r_solver.m_nbasis_sort_counter = 0; }
215-
216248
mpq lar_solver::bound_span_x(lpvar j) const {
217249
SASSERT(column_has_upper_bound(j) && column_has_lower_bound(j));
218250
return get_upper_bound(j).x - get_lower_bound(j).x;
@@ -533,7 +565,7 @@ namespace lp {
533565
m_imp->m_usage_in_terms.pop(k);
534566
m_imp->m_dependencies.pop_scope(k);
535567
// init the nbasis sorting
536-
require_nbasis_sort();
568+
m_imp->require_nbasis_sort();
537569
set_status(lp_status::UNKNOWN);
538570
}
539571

@@ -759,7 +791,7 @@ namespace lp {
759791
TRACE("lar_solver", print_term(term, tout << "maximize: ") << "\n"
760792
<< constraints() << ", strategy = " << (int)settings().simplex_strategy() << "\n";);
761793
if (settings().simplex_strategy() != simplex_strategy_enum::tableau_costs)
762-
require_nbasis_sort();
794+
m_imp->require_nbasis_sort();
763795
flet f(settings().simplex_strategy(), simplex_strategy_enum::tableau_costs);
764796
prepare_costs_for_r_solver(term);
765797
ret = maximize_term_on_tableau(term, term_max);
@@ -1962,7 +1994,7 @@ namespace lp {
19621994
else {
19631995
get_core_solver().m_r_heading.push_back(-static_cast<int>(get_core_solver().m_r_nbasis.size()) - 1);
19641996
get_core_solver().m_r_nbasis.push_back(j);
1965-
require_nbasis_sort();
1997+
m_imp->require_nbasis_sort();
19661998
}
19671999
}
19682000

@@ -2099,38 +2131,6 @@ namespace lp {
20992131
remove_non_fixed_from_table(m_imp->m_fixed_var_table_real);
21002132
}
21012133

2102-
void lar_solver::register_in_fixed_var_table(unsigned j, unsigned& equal_to_j) {
2103-
SASSERT(column_is_fixed(j));
2104-
equal_to_j = null_lpvar;
2105-
const impq& bound = get_lower_bound(j);
2106-
if (!bound.y.is_zero())
2107-
return;
2108-
2109-
const mpq& key = bound.x;
2110-
unsigned k;
2111-
bool j_is_int = column_is_int(j);
2112-
if (j_is_int) {
2113-
if (!m_imp->m_fixed_var_table_int.find(key, k)) {
2114-
m_imp->m_fixed_var_table_int.insert(key, j);
2115-
return;
2116-
}
2117-
}
2118-
else { // j is not integral column
2119-
if (!m_imp->m_fixed_var_table_real.find(key, k)) {
2120-
m_imp->m_fixed_var_table_real.insert(key, j);
2121-
return;
2122-
}
2123-
}
2124-
2125-
CTRACE("arith", !column_is_fixed(k), print_terms(tout););
2126-
// SASSERT(column_is_fixed(k));
2127-
if (j != k && column_is_fixed(k)) {
2128-
SASSERT(column_is_int(j) == column_is_int(k));
2129-
equal_to_j = k;
2130-
TRACE("lar_solver", tout << "found equal column k = " << k <<
2131-
", external = " << equal_to_j << "\n";);
2132-
}
2133-
}
21342134

21352135
void lar_solver::activate_check_on_equal(constraint_index ci, unsigned& equal_column) {
21362136
auto const& c = m_imp->m_constraints[ci];
@@ -2318,7 +2318,7 @@ namespace lp {
23182318
update_column_type_and_bound(j, right_side, constr_index);
23192319
equal_to_j = null_lpvar;
23202320
if (column_is_fixed(j)) {
2321-
register_in_fixed_var_table(j, equal_to_j);
2321+
m_imp->register_in_fixed_var_table(j, equal_to_j);
23222322
}
23232323
}
23242324

src/math/lp/lar_solver.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ class lar_solver : public column_namer {
5454

5555
////////////////// methods ////////////////////////////////
5656

57-
static bool valid_index(unsigned j) { return static_cast<int>(j) >= 0; }
5857
bool row_has_a_big_num(unsigned i) const;
5958
// init region
6059
void register_new_external_var(unsigned ext_v, bool is_int);
@@ -95,16 +94,14 @@ class lar_solver : public column_namer {
9594
public:
9695
bool validate_blocker() const { return m_validate_blocker; }
9796
bool & validate_blocker() { return m_validate_blocker; }
98-
void update_column_type_and_bound(unsigned j, lconstraint_kind kind, const mpq& right_side, u_dependency* dep);
97+
void update_column_type_and_bound(unsigned j, lconstraint_kind kind, const mpq& right_side, u_dependency* dep);
9998
private:
100-
void require_nbasis_sort();
10199
void update_column_type_and_bound_with_ub(lpvar j, lconstraint_kind kind, const mpq& right_side, u_dependency* dep);
102100
void update_column_type_and_bound_with_no_ub(lpvar j, lconstraint_kind kind, const mpq& right_side, u_dependency* dep);
103101
void update_bound_with_ub_lb(lpvar j, lconstraint_kind kind, const mpq& right_side, u_dependency* dep);
104102
void update_bound_with_no_ub_lb(lpvar j, lconstraint_kind kind, const mpq& right_side, u_dependency* dep);
105103
void update_bound_with_ub_no_lb(lpvar j, lconstraint_kind kind, const mpq& right_side, u_dependency* dep);
106104
void update_bound_with_no_ub_no_lb(lpvar j, lconstraint_kind kind, const mpq& right_side, u_dependency* dep);
107-
void register_in_fixed_var_table(unsigned, unsigned&);
108105
void remove_non_fixed_from_fixed_var_table();
109106
constraint_index add_var_bound_on_constraint_for_term(lpvar j, lconstraint_kind kind, const mpq& right_side);
110107
void set_crossed_bounds_column_and_deps(unsigned j, bool lower_bound, u_dependency* dep);

0 commit comments

Comments
 (0)