mirror of
https://github.com/Z3Prover/z3
synced 2025-04-23 17:15:31 +00:00
add branch / cut selection heuristic from solver=2
disabled for testing.
This commit is contained in:
parent
bb44b91e45
commit
368d60f553
6 changed files with 114 additions and 12 deletions
|
@ -377,10 +377,20 @@ bool gomory::is_gomory_cut_target(const row_strip<mpq>& row) {
|
|||
}
|
||||
|
||||
int gomory::find_basic_var() {
|
||||
int result = -1;
|
||||
unsigned n = 0;
|
||||
int result = -1;
|
||||
unsigned min_row_size = UINT_MAX;
|
||||
// Prefer smaller row size
|
||||
|
||||
#if 0
|
||||
result = lia.select_int_infeasible_var();
|
||||
|
||||
if (result == -1)
|
||||
return result;
|
||||
|
||||
const row_strip<mpq>& row = lra.get_row(lia.row_of_basic_column(result));
|
||||
if (is_gomory_cut_target(row))
|
||||
return result;
|
||||
#endif
|
||||
|
||||
for (unsigned j : lra.r_basis()) {
|
||||
if (!lia.column_is_int_inf(j))
|
||||
|
@ -389,6 +399,7 @@ int gomory::find_basic_var() {
|
|||
if (!is_gomory_cut_target(row))
|
||||
continue;
|
||||
IF_VERBOSE(20, lia.display_row_info(verbose_stream(), lia.row_of_basic_column(j)));
|
||||
// Prefer smaller row size
|
||||
if (min_row_size == UINT_MAX ||
|
||||
2*row.size() < min_row_size ||
|
||||
(4*row.size() < 5*min_row_size && lia.random() % (++n) == 0)) {
|
||||
|
|
|
@ -52,16 +52,22 @@ lia_move int_branch::create_branch_on_column(int j) {
|
|||
|
||||
|
||||
int int_branch::find_inf_int_base_column() {
|
||||
|
||||
#if 0
|
||||
return lia.select_int_infeasible_var();
|
||||
#endif
|
||||
|
||||
int result = -1;
|
||||
mpq range;
|
||||
mpq new_range;
|
||||
mpq small_range_thresold(1024);
|
||||
mpq small_value(1024);
|
||||
unsigned n = 0;
|
||||
lar_core_solver & lcs = lra.m_mpq_lar_core_solver;
|
||||
unsigned prev_usage = 0; // to quiet down the compile
|
||||
unsigned k = 0;
|
||||
unsigned usage;
|
||||
unsigned j;
|
||||
|
||||
// this loop looks for a column with the most usages, but breaks when
|
||||
// a column with a small span of bounds is found
|
||||
for (; k < lra.r_basis().size(); k++) {
|
||||
|
@ -69,12 +75,13 @@ int int_branch::find_inf_int_base_column() {
|
|||
if (!lia.column_is_int_inf(j))
|
||||
continue;
|
||||
usage = lra.usage_in_terms(j);
|
||||
if (lia.is_boxed(j) && (range = lcs.m_r_upper_bounds()[j].x - lcs.m_r_lower_bounds()[j].x - rational(2*usage)) <= small_range_thresold) {
|
||||
if (lia.is_boxed(j) && (range = lcs.m_r_upper_bounds()[j].x - lcs.m_r_lower_bounds()[j].x - rational(2*usage)) <= small_value) {
|
||||
result = j;
|
||||
k++;
|
||||
n = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
if (n == 0 || usage > prev_usage) {
|
||||
result = j;
|
||||
prev_usage = usage;
|
||||
|
|
|
@ -632,4 +632,73 @@ bool int_solver::non_basic_columns_are_at_bounds() const {
|
|||
return true;
|
||||
}
|
||||
|
||||
int int_solver::select_int_infeasible_var() {
|
||||
int result = -1;
|
||||
mpq range;
|
||||
mpq new_range;
|
||||
mpq small_value(1024);
|
||||
unsigned n = 0;
|
||||
lar_core_solver & lcs = lra.m_mpq_lar_core_solver;
|
||||
unsigned prev_usage = 0; // to quiet down the compile
|
||||
unsigned k = 0;
|
||||
unsigned usage;
|
||||
unsigned j;
|
||||
|
||||
enum state { small_box, is_small_value, any_value, not_found };
|
||||
state st = not_found;
|
||||
|
||||
// 1. small box
|
||||
// 2. small value
|
||||
// 3. any value
|
||||
for (; k < lra.r_basis().size(); k++) {
|
||||
j = lra.r_basis()[k];
|
||||
if (!column_is_int_inf(j))
|
||||
continue;
|
||||
usage = lra.usage_in_terms(j);
|
||||
if (is_boxed(j) && (new_range = lcs.m_r_upper_bounds()[j].x - lcs.m_r_lower_bounds()[j].x - rational(2*usage)) <= small_value) {
|
||||
SASSERT(!is_fixed(j));
|
||||
if (st != small_box) {
|
||||
n = 0;
|
||||
st = small_box;
|
||||
}
|
||||
if (n == 0 || new_range < range) {
|
||||
result = j;
|
||||
range = new_range;
|
||||
n = 1;
|
||||
}
|
||||
else if (new_range == range && (random() % (++n) == 0)) {
|
||||
result = j;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (st == small_box)
|
||||
continue;
|
||||
impq const& value = get_value(j);
|
||||
if (abs(value.x) < small_value ||
|
||||
(has_upper(j) && small_value > upper_bound(j).x - value.x) ||
|
||||
(has_lower(j) && small_value > value.x - lower_bound(j).x)) {
|
||||
if (st != is_small_value) {
|
||||
n = 0;
|
||||
st = is_small_value;
|
||||
}
|
||||
if (random() % (++n) == 0)
|
||||
result = j;
|
||||
}
|
||||
if (st == is_small_value)
|
||||
continue;
|
||||
SASSERT(st == not_found || st == any_value);
|
||||
st = any_value;
|
||||
if (n == 0 /*|| usage > prev_usage*/) {
|
||||
result = j;
|
||||
prev_usage = usage;
|
||||
n = 1;
|
||||
}
|
||||
else if (usage > 0 && /*usage == prev_usage && */ (random() % (++n) == 0))
|
||||
result = j;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -129,5 +129,8 @@ public:
|
|||
void find_feasible_solution();
|
||||
lia_move hnf_cut();
|
||||
void patch_nbasic_column(unsigned j) { m_patcher.patch_nbasic_column(j); }
|
||||
|
||||
int select_int_infeasible_var();
|
||||
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue