3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-02-20 23:44:41 +00:00
* rename ul_pair to column

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

* t

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

* simple test passed

* remove an assert

* relax an assertion

* remove an obsolete function

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

* access a term by the term column

* remove the column index from colunm.h

* remove an unused method

* remove debug code

* fix the build of lp_tst

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

---------

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>
Co-authored-by: Lev Nachmanson <levnach@hotmail.com>
This commit is contained in:
Nikolaj Bjorner 2024-01-24 16:05:18 -08:00 committed by GitHub
parent 133546625c
commit bdb9106f99
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
45 changed files with 587 additions and 973 deletions

View file

@ -370,7 +370,7 @@ namespace arith {
void solver::refine_bound(theory_var v, const lp::implied_bound& be) {
lpvar vi = be.m_j;
if (lp::tv::is_term(vi))
if (lp().column_has_term(vi))
return;
expr_ref w(var2expr(v), m);
if (a.is_add(w) || a.is_numeral(w) || m.is_ite(w))
@ -418,7 +418,7 @@ namespace arith {
++m_stats.m_assert_upper;
inf_rational value = b.get_value(is_true);
if (propagate_eqs() && value.is_rational())
propagate_eqs(b.tv(), ci, k, b, value.get_rational());
propagate_eqs(b.column_index(), ci, k, b, value.get_rational());
#if 0
if (propagation_mode() != BP_NONE)
lp().add_column_rows_to_touched_rows(b.tv().id());
@ -426,30 +426,29 @@ namespace arith {
}
void solver::propagate_eqs(lp::tv t, lp::constraint_index ci1, lp::lconstraint_kind k, api_bound& b, rational const& value) {
void solver::propagate_eqs(lp::lpvar t, lp::constraint_index ci1, lp::lconstraint_kind k, api_bound& b, rational const& value) {
u_dependency* dep;
auto& dm = lp().dep_manager();
if (k == lp::GE && set_lower_bound(t, ci1, value) && has_upper_bound(t.index(), dep, value)) {
if (k == lp::GE && set_lower_bound(t, ci1, value) && has_upper_bound(t, dep, value)) {
fixed_var_eh(b.get_var(), dm.mk_join(dm.mk_leaf(ci1), dep), value);
}
else if (k == lp::LE && set_upper_bound(t, ci1, value) && has_lower_bound(t.index(), dep, value)) {
else if (k == lp::LE && set_upper_bound(t, ci1, value) && has_lower_bound(t, dep, value)) {
fixed_var_eh(b.get_var(), dm.mk_join(dm.mk_leaf(ci1), dep), value);
}
}
bool solver::set_bound(lp::tv tv, lp::constraint_index ci, rational const& v, bool is_lower) {
if (tv.is_term()) {
lpvar ti = tv.id();
bool solver::set_bound(lp::lpvar tv, lp::constraint_index ci, rational const& v, bool is_lower) {
if (lp().column_has_term(tv)) {
auto& vec = is_lower ? m_lower_terms : m_upper_terms;
if (vec.size() <= ti) {
vec.resize(ti + 1, constraint_bound(UINT_MAX, rational()));
if (vec.size() <= tv) {
vec.resize(tv + 1, constraint_bound(UINT_MAX, rational()));
}
constraint_bound& b = vec[ti];
constraint_bound& b = vec[tv];
if (b.first == UINT_MAX || (is_lower ? b.second < v : b.second > v)) {
TRACE("arith", tout << "tighter bound " << tv.to_string() << "\n";);
m_history.push_back(vec[ti]);
ctx.push(history_trail<constraint_bound>(vec, ti, m_history));
TRACE("arith", tout << "tighter bound " << tv << "\n";);
m_history.push_back(vec[tv]);
ctx.push(history_trail<constraint_bound>(vec, tv, m_history));
b.first = ci;
b.second = v;
}
@ -461,10 +460,10 @@ namespace arith {
rational b;
u_dependency* dep = nullptr;
if (is_lower) {
return lp().has_lower_bound(tv.id(), dep, b, is_strict) && !is_strict && b == v;
return lp().has_lower_bound(tv, dep, b, is_strict) && !is_strict && b == v;
}
else {
return lp().has_upper_bound(tv.id(), dep, b, is_strict) && !is_strict && b == v;
return lp().has_upper_bound(tv, dep, b, is_strict) && !is_strict && b == v;
}
}
}
@ -772,7 +771,7 @@ namespace arith {
bool solver::has_lower_bound(lpvar vi, u_dependency*& ci, rational const& bound) { return has_bound(vi, ci, bound, true); }
bool solver::has_bound(lpvar vi, u_dependency*& dep, rational const& bound, bool is_lower) {
if (lp::tv::is_term(vi)) {
if (lp().column_has_term(vi)) {
theory_var v = lp().local_to_external(vi);
rational val;
TRACE("arith", tout << lp().get_variable_name(vi) << " " << v << "\n";);
@ -782,9 +781,8 @@ namespace arith {
}
auto& vec = is_lower ? m_lower_terms : m_upper_terms;
lpvar ti = lp::tv::unmask_term(vi);
if (vec.size() > ti) {
auto& [ci, coeff] = vec[ti];
if (vec.size() > vi) {
auto& [ci, coeff] = vec[vi];
if (ci == UINT_MAX)
return false;
dep = lp().dep_manager().mk_leaf(ci);
@ -876,11 +874,16 @@ namespace arith {
lp::impq solver::get_ivalue(theory_var v) const {
SASSERT(is_registered_var(v));
return m_solver->get_tv_ivalue(get_tv(v));
return m_solver->get_column_value(get_column(v));
}
lp::lpvar solver::get_column(theory_var v) const {
SASSERT(is_registered_var(v));
return m_solver->external_to_local(v);
}
rational solver::get_value(theory_var v) const {
return is_registered_var(v) ? m_solver->get_tv_value(get_tv(v)) : rational::zero();
return is_registered_var(v) ? m_solver->get_value(get_column(v)) : rational::zero();
}
void solver::random_update() {
@ -895,18 +898,18 @@ namespace arith {
if (is_bool(v))
continue;
ensure_column(v);
lp::column_index vj = lp().to_column_index(v);
SASSERT(!vj.is_null());
lp::lpvar vj = lp().external_to_local(v);
SASSERT(vj != lp::null_lpvar);
theory_var other = m_model_eqs.insert_if_not_there(v);
if (is_equal(v, other))
continue;
if (!lp().is_fixed(vj))
vars.push_back(vj.index());
if (!lp().column_is_fixed(vj))
vars.push_back(vj);
else if (!m_tmp_var_set.contains(other)) {
lp::column_index other_j = lp().to_column_index(other);
if (!lp().is_fixed(other_j)) {
lp::lpvar other_j = lp().external_to_local(other);
if (!lp().column_is_fixed(other_j)) {
m_tmp_var_set.insert(other);
vars.push_back(other_j.index());
vars.push_back(other_j);
}
}
}
@ -1068,14 +1071,14 @@ namespace arith {
nlsat::anum const& solver::nl_value(theory_var v, scoped_anum& r) const {
SASSERT(m_nla);
SASSERT(m_nla->use_nra_model());
auto t = get_tv(v);
if (!t.is_term()) {
m_nla->am().set(r, m_nla->am_value(t.id()));
auto t = get_column(v);
if (!lp().column_has_term(t)) {
m_nla->am().set(r, m_nla->am_value(t));
}
else {
m_todo_terms.push_back(std::make_pair(t, rational::one()));
TRACE("nl_value", tout << "v" << v << " " << t.to_string() << "\n";);
TRACE("nl_value", tout << "v" << v << " := w" << t.to_string() << "\n";
TRACE("nl_value", tout << "v" << v << " " << t << "\n";);
TRACE("nl_value", tout << "v" << v << " := w" << t << "\n";
lp().print_term(lp().get_term(t), tout) << "\n";);
m_nla->am().set(r, 0);
@ -1090,14 +1093,14 @@ namespace arith {
m_nla->am().set(r1, c1.to_mpq());
m_nla->am().add(r, r1, r);
for (lp::lar_term::ival arg : term) {
auto wi = lp().column2tv(arg.column());
auto wi = arg.j();
c1 = arg.coeff() * wcoeff;
if (wi.is_term()) {
if (lp().column_has_term(wi)) {
m_todo_terms.push_back(std::make_pair(wi, c1));
}
else {
m_nla->am().set(r1, c1.to_mpq());
m_nla->am().mul(m_nla->am_value(wi.id()), r1, r1);
m_nla->am().mul(m_nla->am_value(wi), r1, r1);
m_nla->am().add(r1, r, r);
}
}
@ -1393,17 +1396,17 @@ namespace arith {
TRACE("arith", lp().print_term(term, tout) << "\n";);
for (lp::lar_term::ival ti : term) {
theory_var w;
auto tv = lp().column2tv(ti.column());
if (tv.is_term()) {
auto tv = ti.j();
if (lp().column_has_term(tv)) {
lp::lar_term const& term1 = lp().get_term(tv);
rational coeff2 = coeff * ti.coeff();
term2coeffs(term1, coeffs, coeff2);
continue;
}
else {
w = lp().local_to_external(tv.id());
w = lp().local_to_external(tv);
SASSERT(w >= 0);
TRACE("arith", tout << (tv.id()) << ": " << w << "\n";);
TRACE("arith", tout << tv << ": " << w << "\n";);
}
rational c0(0);
coeffs.find(w, c0);