mirror of
https://github.com/Z3Prover/z3
synced 2025-06-20 21:03:39 +00:00
add has_value utility to retrieve value from solver state
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
593a6e5139
commit
b6054b8406
3 changed files with 25 additions and 2 deletions
|
@ -2606,8 +2606,11 @@ public:
|
||||||
|
|
||||||
bool get_value(enode* n, expr_ref& r) {
|
bool get_value(enode* n, expr_ref& r) {
|
||||||
theory_var v = n->get_th_var(get_id());
|
theory_var v = n->get_th_var(get_id());
|
||||||
if (can_get_value(v)) {
|
if (!can_get_bound(v)) return false;
|
||||||
r = a.mk_numeral(get_value(v), is_int(n));
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -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<mpq>::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<mpq>::is_zero(r.y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void lar_solver::get_infeasibility_explanation(vector<std::pair<mpq, constraint_index>> & explanation) const {
|
void lar_solver::get_infeasibility_explanation(vector<std::pair<mpq, constraint_index>> & explanation) const {
|
||||||
explanation.clear();
|
explanation.clear();
|
||||||
if (m_infeasible_column_index != -1) {
|
if (m_infeasible_column_index != -1) {
|
||||||
|
|
|
@ -426,6 +426,7 @@ public:
|
||||||
|
|
||||||
bool has_upper_bound(var_index var, constraint_index& ci, mpq& value, bool& is_strict) const;
|
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<std::pair<mpq, constraint_index>> & explanation) const;
|
void get_infeasibility_explanation(vector<std::pair<mpq, constraint_index>> & explanation) const;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue