From b6054b8406dabe5d2a60171939cc2c928418532b Mon Sep 17 00:00:00 2001 From: Nikolaj Bjorner Date: Sun, 1 Jul 2018 17:03:58 -0700 Subject: [PATCH] add has_value utility to retrieve value from solver state Signed-off-by: Nikolaj Bjorner --- src/smt/theory_lra.cpp | 7 +++++-- src/util/lp/lar_solver.cpp | 19 +++++++++++++++++++ src/util/lp/lar_solver.h | 1 + 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/smt/theory_lra.cpp b/src/smt/theory_lra.cpp index 88e73c10b..dc393676e 100644 --- a/src/smt/theory_lra.cpp +++ b/src/smt/theory_lra.cpp @@ -2606,8 +2606,11 @@ public: bool get_value(enode* n, expr_ref& r) { theory_var v = n->get_th_var(get_id()); - if (can_get_value(v)) { - r = a.mk_numeral(get_value(v), is_int(n)); + if (!can_get_bound(v)) return false; + lp::var_index vi = m_theory_var2var_index[v]; + rational val; + if (m_solver->has_value(vi, val)) { + r = a.mk_numeral(val, is_int(n)); return true; } else { diff --git a/src/util/lp/lar_solver.cpp b/src/util/lp/lar_solver.cpp index 8925a151a..122d01c8d 100644 --- a/src/util/lp/lar_solver.cpp +++ b/src/util/lp/lar_solver.cpp @@ -1104,6 +1104,25 @@ bool lar_solver::has_upper_bound(var_index var, constraint_index& ci, mpq& value } } +bool lar_solver::has_value(var_index var, mpq& value) const { + if (is_term(var)) { + lar_term const& t = get_term(var); + value = t.m_v; + for (auto const& cv : t) { + impq const& r = get_column_value(cv.var()); + if (!numeric_traits::is_zero(r.y)) return false; + value += r.x * cv.coeff(); + } + return true; + } + else { + impq const& r = get_column_value(var); + value = r.x; + return numeric_traits::is_zero(r.y); + } +} + + void lar_solver::get_infeasibility_explanation(vector> & explanation) const { explanation.clear(); if (m_infeasible_column_index != -1) { diff --git a/src/util/lp/lar_solver.h b/src/util/lp/lar_solver.h index 7209efced..9f79ff835 100644 --- a/src/util/lp/lar_solver.h +++ b/src/util/lp/lar_solver.h @@ -426,6 +426,7 @@ public: bool has_upper_bound(var_index var, constraint_index& ci, mpq& value, bool& is_strict) const; + bool has_value(var_index var, mpq& value) const; void get_infeasibility_explanation(vector> & explanation) const;