mirror of
https://github.com/Z3Prover/z3
synced 2025-04-29 11:55:51 +00:00
misc fixes to grobner state (#109)
* fixes to use list bookkeeping Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * fix reset logic Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * fix non-termination bug in simplifier Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * missing reset of values Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * add configuration to throttle memory usage Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * fix misc. invariant violations Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * multiple linear constraints seem to be violated Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
a9a602c1aa
commit
7eac995824
4 changed files with 141 additions and 60 deletions
|
@ -19,7 +19,6 @@ Revision History:
|
|||
--*/
|
||||
#pragma once
|
||||
#include "util/vector.h"
|
||||
#include "math/lp/indexed_vector.h"
|
||||
#include <ostream>
|
||||
namespace lp {
|
||||
// serves at a set of non-negative integers smaller than the set size
|
||||
|
|
|
@ -22,6 +22,7 @@ Revision History:
|
|||
#include "math/lp/nex.h"
|
||||
#include "math/grobner/pdd_grobner.h"
|
||||
#include "math/dd/pdd_interval.h"
|
||||
#include "math/dd/pdd_eval.h"
|
||||
namespace nla {
|
||||
|
||||
core::core(lp::lar_solver& s, reslimit & lim) :
|
||||
|
@ -1419,7 +1420,18 @@ void core::run_pdd_grobner() {
|
|||
for (unsigned i : m_rows) {
|
||||
add_row_to_pdd_grobner(m_lar_solver.A_r().m_rows[i]);
|
||||
}
|
||||
|
||||
#if 0
|
||||
IF_VERBOSE(2, m_pdd_grobner.display(verbose_stream()));
|
||||
dd::pdd_eval eval(m_pdd_manager);
|
||||
eval.var2val() = [&](unsigned j){ return val(j); };
|
||||
for (auto* e : m_pdd_grobner.equations()) {
|
||||
dd::pdd p = e->poly();
|
||||
rational v = eval(p);
|
||||
if (p.is_linear() && !eval(p).is_zero()) {
|
||||
IF_VERBOSE(0, verbose_stream() << "violated linear constraint " << p << "\n");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// configure grobner
|
||||
// TBD: move this code somewhere self-contained, and tune it.
|
||||
|
@ -1449,9 +1461,36 @@ void core::run_pdd_grobner() {
|
|||
}
|
||||
else {
|
||||
IF_VERBOSE(2, verbose_stream() << "grobner miss\n");
|
||||
IF_VERBOSE(4, diagnose_pdd_miss(verbose_stream()));
|
||||
}
|
||||
}
|
||||
|
||||
std::ostream& core::diagnose_pdd_miss(std::ostream& out) {
|
||||
|
||||
// m_pdd_grobner.display(out);
|
||||
|
||||
dd::pdd_eval eval(m_pdd_manager);
|
||||
eval.var2val() = [&](unsigned j){ return val(j); };
|
||||
for (auto* e : m_pdd_grobner.equations()) {
|
||||
dd::pdd p = e->poly();
|
||||
rational v = eval(p);
|
||||
if (!v.is_zero()) {
|
||||
out << p << " := " << v << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
for (unsigned j = 0; j < m_lar_solver.column_count(); ++j) {
|
||||
if (m_lar_solver.column_has_lower_bound(j) || m_lar_solver.column_has_upper_bound(j)) {
|
||||
out << j << ": [";
|
||||
if (m_lar_solver.column_has_lower_bound(j)) out << m_lar_solver.get_lower_bound(j);
|
||||
out << "..";
|
||||
if (m_lar_solver.column_has_upper_bound(j)) out << m_lar_solver.get_upper_bound(j);
|
||||
out << "]\n";
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
bool core::check_pdd_eq(const dd::grobner::equation* e) {
|
||||
dd::pdd_interval eval(m_pdd_manager, m_reslim);
|
||||
eval.var2interval() =
|
||||
|
@ -1620,15 +1659,27 @@ void core::set_active_vars_weights(nex_creator& nc) {
|
|||
|
||||
void core::set_level2var_for_pdd_grobner() {
|
||||
unsigned n = m_lar_solver.column_count();
|
||||
unsigned_vector sorted_vars(n);
|
||||
for (unsigned j = 0; j < n; j++)
|
||||
unsigned_vector sorted_vars(n), weighted_vars(n);
|
||||
for (unsigned j = 0; j < n; j++) {
|
||||
sorted_vars[j] = j;
|
||||
// sort that the larger weights are in beginning
|
||||
std::sort(sorted_vars.begin(), sorted_vars.end(), [this](unsigned a, unsigned b) {
|
||||
unsigned wa = get_var_weight(a);
|
||||
unsigned wb = get_var_weight(b);
|
||||
weighted_vars[j] = get_var_weight(j);
|
||||
}
|
||||
#if 1
|
||||
// potential update to weights
|
||||
for (unsigned j = 0; j < n; j++) {
|
||||
if (is_monic_var(j) && m_to_refine.contains(j)) {
|
||||
for (lpvar k : m_emons[j].vars()) {
|
||||
weighted_vars[k] += 6;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
std::sort(sorted_vars.begin(), sorted_vars.end(), [&](unsigned a, unsigned b) {
|
||||
unsigned wa = weighted_vars[a];
|
||||
unsigned wb = weighted_vars[b];
|
||||
return wa < wb || (wa == wb && a < b); });
|
||||
|
||||
|
||||
unsigned_vector l2v(n);
|
||||
for (unsigned j = 0; j < n; j++)
|
||||
l2v[j] = sorted_vars[j];
|
||||
|
@ -1658,8 +1709,9 @@ unsigned core::get_var_weight(lpvar j) const {
|
|||
}
|
||||
if (is_monic_var(j)) {
|
||||
k++;
|
||||
if (m_to_refine.contains(j))
|
||||
if (m_to_refine.contains(j)) {
|
||||
k++;
|
||||
}
|
||||
}
|
||||
return k;
|
||||
}
|
||||
|
|
|
@ -220,6 +220,7 @@ public:
|
|||
std::ostream& print_product_with_vars(const T& m, std::ostream& out) const;
|
||||
std::ostream& print_monic_with_vars(const monic& m, std::ostream& out) const;
|
||||
std::ostream& print_explanation(const lp::explanation& exp, std::ostream& out) const;
|
||||
std::ostream& diagnose_pdd_miss(std::ostream& out);
|
||||
template <typename T>
|
||||
void trace_print_rms(const T& p, std::ostream& out);
|
||||
void trace_print_monic_and_factorization(const monic& rm, const factorization& f, std::ostream& out) const;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue