Skip to content

Commit 530f772

Browse files
committed
fixes in branching
Signed-off-by: Lev Nachmanson <[email protected]>
1 parent 236edad commit 530f772

9 files changed

+20
-40
lines changed

src/math/lp/gomory.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -442,12 +442,7 @@ int gomory::find_basic_var() {
442442
}
443443

444444
lia_move gomory::operator()() {
445-
if (lra.move_non_basic_columns_to_bounds()) {
446-
lp_status st = lra.find_feasible_solution();
447-
(void)st;
448-
lp_assert(st == lp_status::FEASIBLE || st == lp_status::OPTIMAL);
449-
}
450-
445+
lra.move_non_basic_columns_to_bounds();
451446
int j = find_basic_var();
452447
if (j == -1) return lia_move::undef;
453448
unsigned r = lia.row_of_basic_column(j);

src/math/lp/int_branch.cpp

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ namespace lp {
4545
lia.m_k = mpq(0);
4646
}
4747
else {
48-
lia.m_upper = lra.settings().branch_flip()? lia.random() % 2 : left_branch_is_more_narrow_than_right(j);
48+
lia.m_upper = lia.random() % 2;
4949
lia.m_k = lia.m_upper? floor(lia.get_value(j)) : ceil(lia.get_value(j));
5050
}
5151

@@ -55,23 +55,6 @@ namespace lp {
5555
return lia_move::branch;
5656
}
5757

58-
bool int_branch::left_branch_is_more_narrow_than_right(unsigned j) {
59-
switch (lra.get_column_type(j)) {
60-
case column_type::fixed:
61-
return false;
62-
case column_type::boxed: {
63-
auto k = floor(lia.get_value(j));
64-
return k - lia.lower_bound(j).x < lia.upper_bound(j).x - (k + mpq(1));
65-
}
66-
case column_type::lower_bound:
67-
return true;
68-
case column_type::upper_bound:
69-
return false;
70-
default:
71-
return false;
72-
}
73-
}
74-
7558
int int_branch::find_inf_int_base_column() {
7659
unsigned inf_int_count = 0;
7760
int j = find_inf_int_boxed_base_column_with_smallest_range(inf_int_count);
@@ -93,8 +76,9 @@ namespace lp {
9376
}
9477

9578
int int_branch::find_inf_int_nbasis_column() const {
79+
9680
for (unsigned j : lra.r_nbasis())
97-
if (!lia.column_is_int_inf(j)) {
81+
if (lia.column_is_int_inf(j)) {
9882
return j;
9983
}
10084
return -1;

src/math/lp/int_branch.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ namespace lp {
2828
class int_solver& lia;
2929
class lar_solver& lra;
3030
lia_move create_branch_on_column(int j);
31-
bool left_branch_is_more_narrow_than_right(unsigned j);
3231
int find_inf_int_base_column();
3332
int get_kth_inf_int(unsigned k) const;
3433
int find_inf_int_nbasis_column() const;

src/math/lp/int_cube.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ namespace lp {
4242
if (st != lp_status::FEASIBLE && st != lp_status::OPTIMAL) {
4343
TRACE("cube", tout << "cannot find a feasiblie solution";);
4444
lra.pop();
45+
lra.set_status(lp_status::OPTIMAL);
4546
lra.move_non_basic_columns_to_bounds();
46-
find_feasible_solution();
4747
// it can happen that we found an integer solution here
4848
return !lra.r_basis_has_inf_int()? lia_move::sat: lia_move::undef;
4949
}

src/math/lp/lar_solver.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -445,8 +445,7 @@ void lar_solver::set_costs_to_zero(const lar_term& term) {
445445
void lar_solver::prepare_costs_for_r_solver(const lar_term & term) {
446446
TRACE("lar_solver", print_term(term, tout << "prepare: ") << "\n";);
447447
m_basic_columns_with_changed_cost.resize(m_mpq_lar_core_solver.m_r_x.size());
448-
if (move_non_basic_columns_to_bounds())
449-
find_feasible_solution();
448+
move_non_basic_columns_to_bounds();
450449
auto & rslv = m_mpq_lar_core_solver.m_r_solver;
451450
rslv.set_using_infeas_costs(false);
452451
lp_assert(costs_are_zeros_for_r_solver());
@@ -464,17 +463,26 @@ void lar_solver::prepare_costs_for_r_solver(const lar_term & term) {
464463
lp_assert(rslv.reduced_costs_are_correct_tableau());
465464
}
466465

467-
bool lar_solver::move_non_basic_columns_to_bounds() {
466+
bool feasible(lp_status st) {
467+
return st == lp_status::FEASIBLE || st == lp_status::OPTIMAL;
468+
}
469+
470+
void lar_solver::move_non_basic_columns_to_bounds() {
468471
auto & lcs = m_mpq_lar_core_solver;
469472
bool change = false;
473+
bool feas = feasible(get_status());
470474
for (unsigned j : lcs.m_r_nbasis) {
471475
if (move_non_basic_column_to_bounds(j))
472476
change = true;
473477
}
474478

475-
if (settings().simplex_strategy() == simplex_strategy_enum::tableau_costs)
479+
if (settings().simplex_strategy() == simplex_strategy_enum::tableau_costs && change)
476480
update_x_and_inf_costs_for_columns_with_changed_bounds_tableau();
477-
return change;
481+
482+
if (feas && change) {
483+
find_feasible_solution();
484+
SASSERT(feasible(get_status()));
485+
}
478486
}
479487

480488
bool lar_solver::move_non_basic_column_to_bounds(unsigned j) {

src/math/lp/lar_solver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ class lar_solver : public column_namer {
421421
inline int_solver * get_int_solver() { return m_int_solver; }
422422
inline const lar_term & get_term(tv const& t) const { lp_assert(t.is_term()); return *m_terms[t.id()]; }
423423
lp_status find_feasible_solution();
424-
bool move_non_basic_columns_to_bounds();
424+
void move_non_basic_columns_to_bounds();
425425
bool move_non_basic_column_to_bounds(unsigned j);
426426
inline bool r_basis_has_inf_int() const {
427427
for (unsigned j : r_basis()) {

src/math/lp/lp_settings.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,6 @@ struct lp_settings {
200200
unsigned limit_on_columns_for_hnf_cutter;
201201
bool m_enable_hnf;
202202
bool m_print_external_var_name;
203-
bool m_branch_flip;
204203
#ifdef Z3DEBUG
205204
unsigned m_counter_for_debug;
206205
#endif
@@ -271,15 +270,12 @@ struct lp_settings {
271270
limit_on_rows_for_hnf_cutter(75),
272271
limit_on_columns_for_hnf_cutter(150),
273272
m_enable_hnf(true),
274-
m_print_external_var_name(false),
275-
m_branch_flip(false)
273+
m_print_external_var_name(false)
276274
#ifdef Z3DEBUG
277275
, m_counter_for_debug(0)
278276
#endif
279277
{}
280278

281-
bool branch_flip() const { return m_branch_flip; }
282-
void set_branch_flip(bool f) { m_branch_flip = f; }
283279
void set_resource_limit(lp_resource_limit& lim) { m_resource_limit = &lim; }
284280
bool get_cancel_flag() const { return m_resource_limit->get_cancel_flag(); }
285281

src/smt/params/smt_params_helper.pyg

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ def_module_params(module_name='smt',
6262
('arith.propagate_eqs', BOOL, True, 'propagate (cheap) equalities'),
6363
('arith.propagation_mode', UINT, 2, '0 - no propagation, 1 - propagate existing literals, 2 - refine bounds'),
6464
('arith.reflect', BOOL, True, 'reflect arithmetical operators to the congruence closure'),
65-
('arith.branch_flip', BOOL, False, 'flip branches randomly'),
6665
('arith.branch_cut_ratio', UINT, 2, 'branch/cut ratio for linear integer arithmetic'),
6766
('arith.int_eq_branch', BOOL, False, 'branching using derived integer equations'),
6867
('arith.ignore_int', BOOL, False, 'treat integer variables as real'),

src/smt/theory_lra.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,6 @@ class theory_lra::imp {
396396
lp().settings().print_statistics = lpar.arith_print_stats();
397397

398398
// todo : do not use m_arith_branch_cut_ratio for deciding on cheap cuts
399-
lp().settings().set_branch_flip(lpar.arith_branch_flip());
400399
unsigned branch_cut_ratio = ctx().get_fparams().m_arith_branch_cut_ratio;
401400
lp().set_cut_strategy(branch_cut_ratio);
402401

0 commit comments

Comments
 (0)