Skip to content

Commit 134bed8

Browse files
committed
throttle the branching in dio
Signed-off-by: Lev Nachmanson <levnach@hotmail.com>
1 parent bd8cf29 commit 134bed8

File tree

5 files changed

+30
-31
lines changed

5 files changed

+30
-31
lines changed

src/math/lp/dioph_eq.cpp

+23-25
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,12 @@ namespace lp {
7777
unsigned size() const {return static_cast<unsigned>(m_map.size());}
7878

7979
void erase_val(unsigned b) {
80-
SASSERT(contains(m_rev_map, b) && contains(m_map, m_rev_map[b]));
81-
unsigned key = m_rev_map[b];
82-
m_rev_map.erase(b);
80+
VERIFY(contains(m_rev_map, b) && contains(m_map, m_rev_map[b]));
81+
auto it = m_rev_map.find(b);
82+
if (it == m_rev_map.end()) return;
83+
unsigned key = it->second;
84+
m_rev_map.erase(it);
85+
VERIFY(has_key(key));
8386
m_map.erase(key);
8487
}
8588
bool has_val(unsigned b) const {
@@ -123,7 +126,7 @@ namespace lp {
123126
}
124127
unsigned operator[](unsigned i) const {
125128
auto it = m_map.find(i);
126-
SASSERT(it != m_map.end());
129+
VERIFY(it != m_map.end());
127130
return it->second;
128131
}
129132
};
@@ -151,10 +154,10 @@ namespace lp {
151154
}
152155

153156
void erase_by_second_key(unsigned b) {
154-
SASSERT(m_bij.has_val(b));
157+
VERIFY(m_bij.has_val(b));
155158
m_bij.erase_val(b);
156159
auto it = m_data.find(b);
157-
SASSERT(it != m_data.end());
160+
VERIFY(it != m_data.end());
158161
m_data.erase(it);
159162
}
160163

@@ -169,7 +172,7 @@ namespace lp {
169172
// Get the data by 'b' directly
170173
const T& get_by_val(unsigned b) const {
171174
auto it = m_data.find(b);
172-
SASSERT(it != m_data.end());
175+
VERIFY(it != m_data.end());
173176
return it->second;
174177
}
175178
};
@@ -351,7 +354,7 @@ namespace lp {
351354

352355
const mpq& operator[](unsigned j) const {
353356
SASSERT(j >= 0 && j < m_index.size());
354-
SASSERT(m_index[j] >= 0 && m_index[j] < m_data.size());
357+
SASSERT(m_index[j] >= 0 && m_index[j] < (int)m_data.size());
355358
return m_data[m_index[j]].coeff();
356359
}
357360

@@ -470,8 +473,8 @@ namespace lp {
470473

471474

472475
unsigned m_conflict_index = -1; // the row index of the conflict
473-
unsigned m_max_number_of_iterations = 100;
474-
unsigned m_number_of_iterations;
476+
unsigned m_max_of_branching_iterations = 0;
477+
unsigned m_number_of_branching_calls;
475478
struct branch {
476479
unsigned m_j = UINT_MAX;
477480
mpq m_rs;
@@ -1084,7 +1087,7 @@ namespace lp {
10841087
m_conflict_index = -1;
10851088
m_infeas_explanation.clear();
10861089
lia.get_term().clear();
1087-
m_number_of_iterations = 0;
1090+
m_number_of_branching_calls = 0;
10881091
m_branch_stack.clear();
10891092
m_lra_level = 0;
10901093

@@ -1182,11 +1185,6 @@ namespace lp {
11821185
return true;
11831186
}
11841187
// c_g is not integral
1185-
if (lra.stats().m_dio_calls %
1186-
lra.settings().dio_branch_from_proof_period() ==
1187-
0 &&
1188-
!has_fresh_var(ei))
1189-
prepare_lia_branch_report(ei, e, g, c_g);
11901188
return false;
11911189
}
11921190

@@ -1738,8 +1736,8 @@ namespace lp {
17381736
lia_move branching_on_undef() {
17391737
m_explanation_of_branches.clear();
17401738
bool need_create_branch = true;
1741-
m_number_of_iterations = 0;
1742-
while (++m_number_of_iterations < m_max_number_of_iterations) {
1739+
m_number_of_branching_calls = 0;
1740+
while (++m_number_of_branching_calls < m_max_of_branching_iterations) {
17431741
lra.stats().m_dio_branch_iterations++;
17441742
if (need_create_branch) {
17451743
if (!push_branch()) {
@@ -1954,12 +1952,14 @@ namespace lp {
19541952
if (ret == lia_move::branch || ret == lia_move::conflict)
19551953
return ret;
19561954
SASSERT(ret == lia_move::undef);
1957-
ret = branching_on_undef();
1955+
if (lra.stats().m_dio_calls % lra.settings().dio_branching_period() == 0) {
1956+
ret = branching_on_undef();
1957+
}
19581958
if (ret == lia_move::sat || ret == lia_move::conflict) {
19591959
return ret;
19601960
}
19611961
SASSERT(ret == lia_move::undef);
1962-
m_max_number_of_iterations = (unsigned)m_max_number_of_iterations/2;
1962+
m_max_of_branching_iterations = (unsigned)m_max_of_branching_iterations/2;
19631963

19641964
return lia_move::undef;
19651965
}
@@ -1979,8 +1979,7 @@ namespace lp {
19791979
mpq t;
19801980
for (const auto& p : m_e_matrix.m_rows[ei]) {
19811981
t = abs(p.coeff());
1982-
if (first || t < ahk ||
1983-
(t == ahk && p.var() < k)) { // the last condition is for debug
1982+
if (first || t < ahk) {
19841983
ahk = t;
19851984
k_sign = p.coeff().is_pos() ? 1 : -1;
19861985
k = p.var();
@@ -2092,11 +2091,10 @@ namespace lp {
20922091

20932092
mpq coeff = m_e_matrix.get_val(c);
20942093
TRACE("dioph_eq", tout << "before pivot entry :"; print_entry(c.var(), tout) << std::endl;);
2095-
unsigned c_row = c.var();
20962094
m_e_matrix.pivot_term_to_row_given_cell(t, c, j, j_sign);
20972095
TRACE("dioph_eq", tout << "after pivoting c_row:";
2098-
print_entry(c_row, tout););
2099-
SASSERT(entry_invariant(c_row));
2096+
print_entry(c.var(), tout););
2097+
SASSERT(entry_invariant(c.var()));
21002098
cell_to_process--;
21012099
}
21022100
SASSERT(is_eliminated_from_f(j));

src/math/lp/lp_settings.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ void lp::lp_settings::updt_params(params_ref const& _p) {
3333
m_simplex_strategy = static_cast<lp::simplex_strategy_enum>(p.arith_simplex_strategy());
3434
m_nlsat_delay = p.arith_nl_delay();
3535
m_dio_eqs = p.arith_lp_dio_eqs();
36-
m_dio_branch_from_proof_period = p.arith_lp_dio_branch_from_proof_period();
36+
m_dio_branching_period = p.arith_lp_dio_branching_period();
3737
}

src/math/lp/lp_settings.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ struct lp_settings {
253253
bool m_dio_eqs = false;
254254
bool m_dio_enable_gomory_cuts = true;
255255
bool m_dio_enable_hnf_cuts = true;
256-
unsigned m_dio_branch_from_proof_period = 100; // report rarely
256+
unsigned m_dio_branching_period = 100; // do branching rarere
257257

258258
public:
259259
bool print_external_var_name() const { return m_print_external_var_name; }
@@ -263,9 +263,9 @@ struct lp_settings {
263263
unsigned random_next() { return m_rand(); }
264264
unsigned random_next(unsigned u ) { return m_rand(u); }
265265
bool dio_eqs() { return m_dio_eqs; }
266-
bool dio_enable_gomory_cuts() { return m_dio_eqs && m_dio_enable_gomory_cuts; }
267-
bool dio_enable_hnf_cuts() { return m_dio_eqs && m_dio_enable_hnf_cuts; }
268-
unsigned dio_branch_from_proof_period() { return m_dio_branch_from_proof_period; }
266+
bool dio_enable_gomory_cuts() const { return m_dio_eqs && m_dio_enable_gomory_cuts; }
267+
bool dio_enable_hnf_cuts() const { return m_dio_eqs && m_dio_enable_hnf_cuts; }
268+
unsigned dio_branching_period() const { return m_dio_branching_period; }
269269
void set_random_seed(unsigned s) { m_rand.set_seed(s); }
270270

271271
bool bound_progation() const {

src/math/lp/static_matrix_def.h

+1
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ namespace lp {
166166
SASSERT(!is_zero(iv.coeff()));
167167
int j_offs = m_work_vector_of_row_offsets[j];
168168
if (j_offs == -1) { // it is a new element
169+
add_columns_up_to(j);
169170
T alv = alpha * iv.coeff();
170171
add_new_element(ii, j, alv);
171172
}

src/smt/params/smt_params_helper.pyg

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def_module_params(module_name='smt',
5858
('arith.random_initial_value', BOOL, False, 'use random initial values in the simplex-based procedure for linear arithmetic'),
5959
('arith.solver', UINT, 6, 'arithmetic solver: 0 - no solver, 1 - bellman-ford based solver (diff. logic only), 2 - simplex based solver, 3 - floyd-warshall based solver (diff. logic only) and no theory combination 4 - utvpi, 5 - infinitary lra, 6 - lra solver'),
6060
('arith.lp.dio_eqs', BOOL, True, 'use Diophantine equalities'),
61-
('arith.lp.dio_branch_from_proof_period', UINT, 100, 'Period of creating a branch instead of a cut'),
61+
('arith.lp.dio_branching_period', UINT, 100, 'Period of calling branching on undef in Diophantine handler'),
6262
('arith.lp.dio_cuts_enable_gomory', BOOL, True, 'enable Gomory cuts together with Diophantine cuts, only relevant when dioph_eq is true'),
6363
('arith.lp.dio_cuts_enable_hnf', BOOL, True, 'enable hnf cuts together with Diophantine cuts, only relevant when dioph_eq is true'),
6464
('arith.nl', BOOL, True, '(incomplete) nonlinear arithmetic support based on Groebner basis and interval propagation, relevant only if smt.arith.solver=2'),

0 commit comments

Comments
 (0)