Skip to content

Commit 2934618

Browse files
committed
remove simplify_inequality from gomory.cpp
1 parent 696b70f commit 2934618

File tree

4 files changed

+2
-112
lines changed

4 files changed

+2
-112
lines changed

src/math/lp/gomory.cpp

+2-109
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "math/lp/lar_solver.h"
2323
#include "math/lp/lp_utils.h"
2424

25-
#define SMALL_CUTS 1
2625
namespace lp {
2726

2827
struct create_cut {
@@ -36,9 +35,7 @@ struct create_cut {
3635
mpq m_one_minus_f;
3736
mpq m_fj;
3837
mpq m_one_minus_fj;
39-
#if SMALL_CUTS
4038
mpq m_abs_max, m_big_number;
41-
#endif
4239
int m_polarity;
4340
bool m_found_big;
4441
u_dependency* m_dep;
@@ -84,11 +81,8 @@ struct create_cut {
8481
}
8582
m_t.add_monomial(new_a, j);
8683
TRACE("gomory_cut_detail", tout << "new_a = " << new_a << ", k = " << m_k << "\n";);
87-
#if SMALL_CUTS
88-
// if (numerator(new_a).is_big()) throw found_big();
8984
if (numerator(new_a) > m_big_number)
9085
m_found_big = true;
91-
#endif
9286
}
9387

9488
void set_polarity(int p) {
@@ -134,11 +128,8 @@ struct create_cut {
134128
TRACE("gomory_cut_detail_real", tout << "add " << new_a << "*v" << j << ", k: " << m_k << "\n";
135129
tout << "m_t = "; lia.lra.print_term(m_t, tout) << "\nk: " << m_k << "\n";);
136130

137-
#if SMALL_CUTS
138-
// if (numerator(new_a).is_big()) throw found_big();
139131
if (numerator(new_a) > m_big_number)
140132
m_found_big = true;
141-
#endif
142133
}
143134

144135
lia_move report_conflict_from_gomory_cut() {
@@ -265,16 +256,14 @@ struct create_cut {
265256
tout << "1 - m_f: " << 1 - m_f << ", get_value(m_inf_col).x - m_f = " << get_value(m_inf_col).x - m_f << "\n";);
266257
lp_assert(m_f.is_pos() && (get_value(m_inf_col).x - m_f).is_int());
267258

268-
bool some_int_columns = false;
269-
#if SMALL_CUTS
270259
m_abs_max = 0;
271260
for (const auto & p : m_row) {
272261
mpq t = abs(ceil(p.coeff()));
273262
if (t > m_abs_max)
274263
m_abs_max = t;
275264
}
276265
m_big_number = m_abs_max.expt(2);
277-
#endif
266+
278267
for (const auto & p : m_row) {
279268
unsigned j = p.var();
280269
if (j == m_inf_col) continue;
@@ -288,7 +277,6 @@ struct create_cut {
288277
if (is_real(j))
289278
real_case_in_gomory_cut(- p.coeff(), j);
290279
else if (!p.coeff().is_int()) {
291-
some_int_columns = true;
292280
m_fj = fractional_part(-p.coeff());
293281
m_one_minus_fj = 1 - m_fj;
294282
int_case_in_gomory_cut(j);
@@ -315,8 +303,6 @@ struct create_cut {
315303
return report_conflict_from_gomory_cut();
316304
}
317305
TRACE("gomory_cut", print_linear_combination_of_column_indices_only(m_t.coeffs_as_vector(), tout << "gomory cut: "); tout << " >= " << m_k << std::endl;);
318-
if (lia.lra.settings().m_gomory_simplify && some_int_columns)
319-
simplify_inequality();
320306

321307
m_dep = nullptr;
322308
for (auto c : *m_ex)
@@ -330,99 +316,6 @@ struct create_cut {
330316
return lia_move::cut;
331317
}
332318

333-
// TODO: use this also for HNF cuts?
334-
mpq m_lcm_den = { mpq(1) };
335-
336-
void simplify_inequality() {
337-
338-
auto divd = [](mpq& r, mpq const& d) {
339-
r /= d;
340-
if (!r.is_int())
341-
r = ceil(r);
342-
};
343-
SASSERT(!lia.m_upper);
344-
lp_assert(!m_t.is_empty());
345-
// k = 1 + sum of m_t at bounds
346-
lar_term t = lia.lra.unfold_nested_subterms(m_t);
347-
auto pol = t.coeffs_as_vector();
348-
m_t.clear();
349-
if (pol.size() == 1 && is_int(pol[0].second)) {
350-
TRACE("gomory_cut_detail", tout << "pol.size() is 1" << std::endl;);
351-
auto const& [a, v] = pol[0];
352-
lp_assert(is_int(v));
353-
if (a.is_pos()) { // we have av >= k
354-
divd(m_k, a);
355-
m_t.add_monomial(mpq(1), v);
356-
}
357-
else {
358-
// av >= k
359-
// a/-a*v >= k / - a
360-
// -v >= k / - a
361-
// -v >= ceil(k / -a)
362-
divd(m_k, -a);
363-
m_t.add_monomial(-mpq(1), v);
364-
}
365-
}
366-
else {
367-
m_lcm_den = denominator(m_k);
368-
for (auto const& [c, v] : pol)
369-
m_lcm_den = lcm(m_lcm_den, denominator(c));
370-
lp_assert(m_lcm_den.is_pos());
371-
bool int_row = all_of(pol, [&](auto const& kv) { return is_int(kv.second); });
372-
TRACE("gomory_cut_detail", tout << "pol.size() > 1 den: " << m_lcm_den << std::endl;);
373-
374-
if (!m_lcm_den.is_one()) {
375-
// normalize coefficients of integer parameters to be integers.
376-
for (auto & [c,v]: pol) {
377-
c *= m_lcm_den;
378-
SASSERT(!is_int(v) || c.is_int());
379-
}
380-
m_k *= m_lcm_den;
381-
}
382-
// ax + by >= k
383-
// b > 0, c1 <= y <= c2
384-
// ax + b*c2 >= ax + by >= k
385-
// =>
386-
// ax >= k - by >= k - b*c1
387-
// b < 0
388-
// ax + b*c1 >= ax + by >= k
389-
//
390-
unsigned j = 0, i = 0;
391-
for (auto & [c, v] : pol) {
392-
if (lia.is_fixed(v)) {
393-
push_explanation(column_lower_bound_constraint(v));
394-
push_explanation(column_upper_bound_constraint(v));
395-
m_k -= c * lower_bound(v).x;
396-
}
397-
else
398-
pol[j++] = pol[i];
399-
++i;
400-
}
401-
pol.shrink(j);
402-
403-
// gcd reduction is loss-less:
404-
mpq g(1);
405-
for (const auto & [c, v] : pol)
406-
g = gcd(g, c);
407-
if (!int_row)
408-
g = gcd(g, m_k);
409-
410-
if (g != 1) {
411-
for (auto & [c, v] : pol)
412-
c /= g;
413-
divd(m_k, g);
414-
}
415-
416-
for (const auto & [c, v]: pol)
417-
m_t.add_monomial(c, v);
418-
VERIFY(m_t.size() > 0);
419-
}
420-
421-
TRACE("gomory_cut_detail", tout << "k = " << m_k << std::endl;);
422-
lp_assert(m_k.is_int());
423-
}
424-
425-
426319
create_cut(lar_term & t, mpq & k, explanation* ex, unsigned basic_inf_int_j, const row_strip<mpq>& row, int_solver& lia) :
427320
m_t(t),
428321
m_k(k),
@@ -570,7 +463,7 @@ struct create_cut {
570463

571464
}
572465

573-
// this way we create bounds for the variables in polar cases even where the terms had big numbers
466+
// this way we create bounds for the variables in polar cases even where the terms have big numbers
574467
for (auto const& p : polar_vars) {
575468
if (p.polarity == 1) {
576469
lra.update_column_type_and_bound(p.j, lp::lconstraint_kind::LE, floor(lra.get_column_value(p.j).x), p.dep);

src/math/lp/lp_settings.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,4 @@ void lp::lp_settings::updt_params(params_ref const& _p) {
3232
report_frequency = p.arith_rep_freq();
3333
m_simplex_strategy = static_cast<lp::simplex_strategy_enum>(p.arith_simplex_strategy());
3434
m_nlsat_delay = p.arith_nl_delay();
35-
m_gomory_simplify = p.arith_gomory_simplify();
3635
}

src/math/lp/lp_settings.h

-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ struct lp_settings {
187187
random_gen m_rand;
188188

189189
public:
190-
bool m_gomory_simplify = false;
191190
void updt_params(params_ref const& p);
192191
bool enable_hnf() const { return m_enable_hnf; }
193192
unsigned nlsat_delay() const { return m_nlsat_delay; }

src/smt/params/smt_params_helper.pyg

-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ def_module_params(module_name='smt',
8484
('arith.nl.optimize_bounds', BOOL, True, 'enable bounds optimization'),
8585
('arith.nl.cross_nested', BOOL, True, 'enable cross-nested consistency checking'),
8686
('arith.propagate_eqs', BOOL, True, 'propagate (cheap) equalities'),
87-
('arith.gomory_simplify', BOOL, False, 'simplify gomory term'),
8887
('arith.propagation_mode', UINT, 1, '0 - no propagation, 1 - propagate existing literals, 2 - refine finite bounds'),
8988
('arith.branch_cut_ratio', UINT, 2, 'branch/cut ratio for linear integer arithmetic'),
9089
('arith.int_eq_branch', BOOL, False, 'branching using derived integer equations'),

0 commit comments

Comments
 (0)