3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-23 17:15:31 +00:00

adjust hnf

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

change in settings + random in adding terms to hnf

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

add terms in hnf from the beginning

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

adjusting settings

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

remove non used determinant()

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>
This commit is contained in:
Lev Nachmanson 2018-06-22 09:51:33 -07:00
parent eeaca949e0
commit e5eea467b7
9 changed files with 36 additions and 79 deletions

View file

@ -130,15 +130,13 @@ void pivot_column_non_fractional(M &m, unsigned r, bool & overflow, const mpq &
lp_assert(!is_zero(m[r][r]));
for (unsigned j = r + 1; j < m.column_count(); j++) {
for (unsigned i = r + 1; i < m.row_count(); i++) {
m[i][j] =
(r > 0) ?
(m[r][r]*m[i][j] - m[i][r]*m[r][j]) / m[r-1][r-1] :
(m[r][r]*m[i][j] - m[i][r]*m[r][j]);
if (m[i][j] >= big_number) {
if (
(m[i][j] = (r > 0) ? (m[r][r]*m[i][j] - m[i][r]*m[r][j]) / m[r-1][r-1] :
(m[r][r]*m[i][j] - m[i][r]*m[r][j]))
>= big_number) {
overflow = true;
return;
}
lp_assert(is_int(m[i][j]));
}
}
@ -201,16 +199,6 @@ mpq determinant_of_rectangular_matrix(const M& m, svector<unsigned> & basis_rows
TRACE("hnf_calc", tout << "basis_rows = "; print_vector(basis_rows, tout); m_copy.print(tout, "m_copy = "););
return gcd_of_row_starting_from_diagonal(m_copy, rank - 1);
}
template <typename M>
mpq determinant(const M& m) {
lp_assert(m.row_count() == m.column_count());
auto mc = m;
svector<unsigned> basis_rows;
mpq d = determinant_of_rectangular_matrix(mc, basis_rows);
return basis_rows.size() < m.row_count() ? zero_of_type<mpq>() : d;
}
} // end of namespace hnf_calc
template <typename M> // M is the matrix type

View file

@ -463,7 +463,7 @@ bool int_solver::tighten_terms_for_cube() {
}
lia_move int_solver::find_cube() {
if (m_branch_cut_counter % settings().m_int_find_cube_period != 0)
if (m_number_of_calls % settings().m_int_find_cube_period != 0)
return lia_move::undef;
settings().st().m_cube_calls++;
@ -510,7 +510,7 @@ lia_move int_solver::run_gcd_test() {
}
lia_move int_solver::gomory_cut() {
if ((m_branch_cut_counter) % settings().m_int_gomory_cut_period != 0)
if ((m_number_of_calls) % settings().m_int_gomory_cut_period != 0)
return lia_move::undef;
if (move_non_basic_columns_to_bounds()) {
@ -598,7 +598,7 @@ lia_move int_solver::make_hnf_cut() {
}
lia_move int_solver::hnf_cut() {
if ((m_branch_cut_counter) % settings().m_hnf_cut_period == 0) {
if ((m_number_of_calls) % settings().m_hnf_cut_period == 0) {
return make_hnf_cut();
}
return lia_move::undef;
@ -618,7 +618,7 @@ lia_move int_solver::check(lar_term& t, mpq& k, explanation& ex, bool & upper) {
r = patch_nbasic_columns();
if (r != lia_move::undef) return r;
++m_branch_cut_counter;
++m_number_of_calls;
r = find_cube();
if (r != lia_move::undef) return r;
@ -936,7 +936,7 @@ linear_combination_iterator<mpq> * int_solver::get_column_iterator(unsigned j) {
int_solver::int_solver(lar_solver* lar_slv) :
m_lar_solver(lar_slv),
m_branch_cut_counter(0),
m_number_of_calls(0),
m_hnf_cutter(settings()) {
m_lar_solver->set_int_solver(this);
}

View file

@ -38,7 +38,7 @@ class int_solver {
public:
// fields
lar_solver *m_lar_solver;
unsigned m_branch_cut_counter;
unsigned m_number_of_calls;
lar_term *m_t; // the term to return in the cut
mpq *m_k; // the right side of the cut
explanation *m_ex; // the conflict explanation

View file

@ -2240,6 +2240,22 @@ bool lar_solver::get_equality_and_right_side_for_term_on_current_x(unsigned term
return false;
}
void lar_solver::set_cut_strategy(unsigned cut_frequency) {
if (cut_frequency < 4) { // enable only gomory cut
settings().m_int_gomory_cut_period = 2;
settings().m_hnf_cut_period = 100000000;
settings().m_int_find_cube_period = 100000000;
} else if (cut_frequency == 4) { // enable all cuts and cube equally
settings().m_int_gomory_cut_period = 4;
settings().m_hnf_cut_period = 4;
settings().m_int_find_cube_period = 4;
} else {
// disable all heuristics
settings().m_int_gomory_cut_period = 10000000;
settings().m_hnf_cut_period = 100000000;
settings().m_int_find_cube_period = 100000000;
}
}
} // namespace lp

View file

@ -577,5 +577,6 @@ public:
bool get_equality_and_right_side_for_term_on_current_x(unsigned i, mpq &rs, constraint_index& ci) const;
bool remove_from_basis(unsigned);
lar_term get_term_to_maximize(unsigned ext_j) const;
void set_cut_strategy(unsigned cut_frequency);
};
}

View file

@ -102,10 +102,6 @@ struct stats {
unsigned m_need_to_solve_inf;
unsigned m_max_cols;
unsigned m_max_rows;
unsigned m_chase_cut_solver_calls;
unsigned m_chase_cut_solver_true;
unsigned m_chase_cut_solver_false;
unsigned m_chase_cut_solver_undef;
unsigned m_gcd_calls;
unsigned m_gcd_conflicts;
unsigned m_cube_calls;
@ -192,11 +188,9 @@ public:
bool backup_costs;
unsigned column_number_threshold_for_using_lu_in_lar_solver;
unsigned m_int_gomory_cut_period;
unsigned m_int_chase_cut_solver_period;
unsigned m_int_find_cube_period;
unsigned m_hnf_cut_period;
bool m_int_run_gcd_test;
unsigned m_chase_cut_solver_cycle_on_var;
bool m_int_pivot_fixed_vars_from_basis;
bool m_int_patch_only_integer_values;
unsigned limit_on_rows_for_hnf_cutter;
@ -258,11 +252,9 @@ public:
backup_costs(true),
column_number_threshold_for_using_lu_in_lar_solver(4000),
m_int_gomory_cut_period(4),
m_int_chase_cut_solver_period(8),
m_int_find_cube_period(4),
m_hnf_cut_period(4),
m_int_run_gcd_test(true),
m_chase_cut_solver_cycle_on_var(10),
m_int_pivot_fixed_vars_from_basis(false),
m_int_patch_only_integer_values(true),
limit_on_rows_for_hnf_cutter(75),