3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-23 17:15:31 +00:00

add facility to solve for a linear term over API

This commit is contained in:
Nikolaj Bjorner 2024-11-30 09:34:27 -08:00
parent d2411567b5
commit 05e053247d
14 changed files with 109 additions and 6 deletions

View file

@ -617,6 +617,34 @@ namespace lp {
m_touched_rows.insert(rid);
}
bool lar_solver::solve_for(unsigned j, lar_term& t, mpq& coeff) {
t.clear();
if (column_is_fixed(j)) {
coeff = get_value(j);
return true;
}
if (!is_base(j)) {
for (const auto & c : A_r().m_columns[j]) {
lpvar basic_in_row = r_basis()[c.var()];
pivot(j, basic_in_row);
break;
}
}
if (!is_base(j))
return false;
auto const& r = basic2row(j);
for (auto const& c : r) {
if (c.var() == j)
continue;
if (column_is_fixed(c.var()))
coeff -= get_value(c.var());
else
t.add_monomial(-c.coeff(), c.var());
}
return true;
}
void lar_solver::remove_fixed_vars_from_base() {
// this will allow to disable and restore the tracking of the touched rows
flet<indexed_uint_set*> f(m_mpq_lar_core_solver.m_r_solver.m_touched_rows, nullptr);

View file

@ -346,6 +346,12 @@ public:
void set_value_for_nbasic_column(unsigned j, const impq& new_val);
void remove_fixed_vars_from_base();
/**
* \brief set j to basic (if not already basic)
* return the rest of the row as t comprising of non-fixed variables and coeff as sum of fixed variables.
* return false if j has no rows.
*/
bool solve_for(unsigned j, lar_term& t, mpq& coeff);
inline unsigned get_base_column_in_row(unsigned row_index) const {
return m_mpq_lar_core_solver.m_r_solver.get_base_column_in_row(row_index);