3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-08-12 22:20:54 +00:00

prepare bound_analyzer for using in dio

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>
This commit is contained in:
Lev Nachmanson 2025-02-21 16:59:24 -08:00
parent 67d77e26d2
commit c3461c60eb
3 changed files with 360 additions and 333 deletions

View file

@ -1,24 +1,24 @@
/*++
Copyright (c) 2017 Microsoft Corporation
Copyright (c) 2017 Microsoft Corporation
Module Name:
Module Name:
<name>
Abstract:
Abstract:
We have an equality : sum by j of row[j]*x[j] = rs
We try to pin a var by pushing the total by using the variable bounds
on a loop we drive the partial sum down, denoting the variables of this process by _u.
In the same loop trying to pin variables by pushing the partial sum up, denoting the variable related to it by _l
Author:
Author:
Lev Nachmanson (levnach)
Nikolaj Bjorner (nbjorner)
Revision History:
Revision History:
--*/
--*/
#pragma once
#include "util/vector.h"
@ -28,8 +28,8 @@ Revision History:
namespace lp {
template <typename C, typename B> // C plays a role of a container, B - lp_bound_propagator
class bound_analyzer_on_row {
template <typename C, typename B> // C plays a role of a container, B - lp_bound_propagator
class bound_analyzer_on_row {
const C& m_row;
B & m_bp;
int m_column_of_u; // index of an unlimited from above monoid
@ -37,7 +37,7 @@ class bound_analyzer_on_row {
int m_column_of_l; // index of an unlimited from below monoid
impq m_rs;
public :
public :
// constructor
bound_analyzer_on_row(
const C & it,
@ -59,7 +59,7 @@ public :
return a.analyze();
}
private:
private:
unsigned analyze() {
unsigned num_prop = 0;
@ -92,13 +92,13 @@ private:
}
const impq & ub(unsigned j) const {
lp_assert(m_bp.upper_bound_is_available(j));
return m_bp.get_upper_bound(j);
lp_assert(upper_bound_is_available(j));
return get_upper_bound(j);
}
const impq & lb(unsigned j) const {
lp_assert(m_bp.lower_bound_is_available(j));
return m_bp.get_lower_bound(j);
lp_assert(lower_bound_is_available(j));
return get_lower_bound(j);
}
const mpq & monoid_max_no_mult(bool a_is_pos, unsigned j, bool & strict) const {
@ -310,7 +310,7 @@ private:
}
void analyze_bound_on_var_on_coeff(int j, const mpq &a) {
switch (m_bp.get_column_type(j)) {
switch (get_column_type(j)) {
case column_type::lower_bound:
if (numeric_traits<mpq>::is_pos(a))
advance_u(j);
@ -332,8 +332,42 @@ private:
}
}
};
const impq& get_upper_bound(unsigned j) const {
return lp().get_upper_bound(j);
}
const impq& get_lower_bound(unsigned j) const {
return lp().get_lower_bound(j);
}
column_type get_column_type(unsigned j) const {
return (lp().get_column_types())[j];
}
const auto& lp() const { return m_bp.lp(); }
auto& lp() { return m_bp.lp(); }
bool upper_bound_is_available(unsigned j) const {
switch (get_column_type(j)) {
case column_type::fixed:
case column_type::boxed:
case column_type::upper_bound:
return true;
default:
return false;
}
}
bool lower_bound_is_available(unsigned j) const {
switch (get_column_type(j)) {
case column_type::fixed:
case column_type::boxed:
case column_type::lower_bound:
return true;
default:
return false;
}
}
};
}

View file

@ -1623,7 +1623,17 @@ namespace lp {
}
lia_move propagate_bounds_on_tightened_columns() {
for (unsigned j : m_tightened_columns) {
const auto& t = lra.get_term(j);
// SASSERT(get_term_value(t).x = lra.get_column_value(j).x);
bound_analyzer_on_row<lar_term, dioph_eq::imp>::analyze_row(t, lra.get_column_value(j), *this);
}
return lia_move::undef;
}
void add_bound(mpq const& v, unsigned j, bool is_low, bool strict, std::function<u_dependency* ()> explain_bound) {
NOT_IMPLEMENTED_YET();
}
// m_espace contains the coefficients of the term
// m_c contains the fixed part of the term
@ -1647,7 +1657,7 @@ namespace lp {
return lia_move::conflict;
}
}
std::cout << "new tbs:" << m_tightened_columns.size() << "\n";
return lia_move::undef;
}
@ -2559,6 +2569,10 @@ namespace lp {
SASSERT(!ret || m_var_register.local_to_external(j) == UINT_MAX);
return ret;
}
// needed for the template bound_analyzer_on_row.h
const lar_solver& lp() const { return lra; }
lar_solver& lp() {return lra;}
};
// Constructor definition
dioph_eq::dioph_eq(int_solver& lia) {

View file

@ -44,26 +44,6 @@ class lp_bound_propagator {
public:
const lar_solver& lp() const { return m_imp.lp(); }
lar_solver& lp() { return m_imp.lp(); }
bool upper_bound_is_available(unsigned j) const {
switch (get_column_type(j)) {
case column_type::fixed:
case column_type::boxed:
case column_type::upper_bound:
return true;
default:
return false;
}
}
bool lower_bound_is_available(unsigned j) const {
switch (get_column_type(j)) {
case column_type::fixed:
case column_type::boxed:
case column_type::lower_bound:
return true;
default:
return false;
}
}
private:
void try_add_equation_with_internal_fixed_tables(unsigned r1) {
unsigned v1, v2;
@ -145,7 +125,6 @@ public:
return (*m_column_types)[j] == column_type::fixed && get_lower_bound(j).y.is_zero();
}
void add_bound(mpq const& v, unsigned j, bool is_low, bool strict, std::function<u_dependency* ()> explain_bound) {
lconstraint_kind kind = is_low ? GE : LE;
if (strict)