mirror of
https://github.com/Z3Prover/z3
synced 2025-08-12 06:00:53 +00:00
prepare the mixed case
Signed-off-by: Lev Nachmanson <levnach@hotmail.com>
This commit is contained in:
parent
8980aff7f3
commit
0e86c567cc
4 changed files with 37 additions and 22 deletions
|
@ -1289,44 +1289,53 @@ void lar_solver::get_infeasibility_explanation_for_inf_sign(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// (x, y) != (x', y') => (x + delty*y) != (x' + delty*y')
|
||||||
void lar_solver::get_model(std::unordered_map<var_index, mpq> & variable_values) const {
|
void lar_solver::get_model(std::unordered_map<var_index, mpq> & variable_values) const {
|
||||||
lp_assert(m_mpq_lar_core_solver.m_r_solver.calc_current_x_is_feasible_include_non_basis());
|
lp_assert(m_mpq_lar_core_solver.m_r_solver.calc_current_x_is_feasible_include_non_basis());
|
||||||
variable_values.clear();
|
variable_values.clear();
|
||||||
mpq delta = mpq(1, 2); // start from 0.5 to have less clashes
|
mpq delta = m_mpq_lar_core_solver.find_delta_for_strict_bounds(mpq(1, 2)); // start from 0.5 to have less clashes
|
||||||
unsigned j;
|
unsigned j;
|
||||||
unsigned n = m_mpq_lar_core_solver.m_r_x.size();
|
unsigned n = m_mpq_lar_core_solver.m_r_x.size();
|
||||||
do {
|
|
||||||
// different pairs have to produce different singleton values
|
|
||||||
std::unordered_set<impq> set_of_different_pairs;
|
std::unordered_set<impq> set_of_different_pairs;
|
||||||
std::unordered_set<mpq> set_of_different_singles;
|
std::unordered_set<mpq> set_of_different_singles;
|
||||||
delta = m_mpq_lar_core_solver.find_delta_for_strict_bounds(delta);
|
do {
|
||||||
|
set_of_different_pairs.clear();
|
||||||
|
set_of_different_singles.clear();
|
||||||
for (j = 0; j < n; j++ ) {
|
for (j = 0; j < n; j++ ) {
|
||||||
const numeric_pair<mpq> & rp = m_mpq_lar_core_solver.m_r_x[j];
|
const numeric_pair<mpq> & rp = m_mpq_lar_core_solver.m_r_x[j];
|
||||||
set_of_different_pairs.insert(rp);
|
set_of_different_pairs.insert(rp);
|
||||||
mpq x = rp.x + delta * rp.y;
|
mpq x = rp.x + delta * rp.y;
|
||||||
set_of_different_singles.insert(x);
|
set_of_different_singles.insert(x);
|
||||||
if (set_of_different_pairs.size()
|
if (set_of_different_pairs.size() != set_of_different_singles.size()) {
|
||||||
!= set_of_different_singles.size()) {
|
|
||||||
delta /= mpq(2);
|
delta /= mpq(2);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
TRACE("get_model", tout << this->get_variable_name(j) << " := " << x << "\n";);
|
|
||||||
if (!column_corresponds_to_term(j))
|
|
||||||
variable_values[j] = x;
|
variable_values[j] = x;
|
||||||
}
|
}
|
||||||
} while (j != n);
|
} while (j != n);
|
||||||
|
TRACE("lar_solver_model", tout << "delta = " << delta << "\nmodel:\n";
|
||||||
|
for (auto p : variable_values ) {
|
||||||
|
tout << this->get_variable_name(p.first) << " = " << p.second << "\n";
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void lar_solver::get_model_do_not_care_about_diff_vars(std::unordered_map<var_index, mpq> & variable_values) const {
|
void lar_solver::get_model_do_not_care_about_diff_vars(std::unordered_map<var_index, mpq> & variable_values) const {
|
||||||
mpq delta = mpq(1);
|
mpq delta = m_mpq_lar_core_solver.find_delta_for_strict_bounds(mpq(1));
|
||||||
delta = m_mpq_lar_core_solver.find_delta_for_strict_bounds(delta);
|
|
||||||
for (unsigned i = 0; i < m_mpq_lar_core_solver.m_r_x.size(); i++ ) {
|
for (unsigned i = 0; i < m_mpq_lar_core_solver.m_r_x.size(); i++ ) {
|
||||||
const impq & rp = m_mpq_lar_core_solver.m_r_x[i];
|
const impq & rp = m_mpq_lar_core_solver.m_r_x[i];
|
||||||
variable_values[i] = rp.x + delta * rp.y;
|
variable_values[i] = rp.x + delta * rp.y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void lar_solver::get_rid_of_inf_eps() {
|
||||||
|
mpq delta = m_mpq_lar_core_solver.find_delta_for_strict_bounds(mpq(1));
|
||||||
|
for (unsigned j = 0; j < number_of_vars(); j++) {
|
||||||
|
auto & r = m_mpq_lar_core_solver.m_r_x[j];
|
||||||
|
r = impq(r.x + delta * r.y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void lar_solver::set_variable_name(var_index vi, std::string name) {
|
void lar_solver::set_variable_name(var_index vi, std::string name) {
|
||||||
m_var_register.set_name(vi, name);
|
m_var_register.set_name(vi, name);
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,9 +45,10 @@ Revision History:
|
||||||
|
|
||||||
namespace lp {
|
namespace lp {
|
||||||
|
|
||||||
|
typedef unsigned lpvar;
|
||||||
|
const lpvar null_lpvar = UINT_MAX;
|
||||||
|
|
||||||
class lar_solver : public column_namer {
|
class lar_solver : public column_namer {
|
||||||
typedef unsigned lpvar;
|
|
||||||
struct term_hasher {
|
struct term_hasher {
|
||||||
std::size_t operator()(const lar_term &t) const
|
std::size_t operator()(const lar_term &t) const
|
||||||
{
|
{
|
||||||
|
@ -483,6 +484,8 @@ public:
|
||||||
|
|
||||||
void get_model(std::unordered_map<var_index, mpq> & variable_values) const;
|
void get_model(std::unordered_map<var_index, mpq> & variable_values) const;
|
||||||
|
|
||||||
|
void get_rid_of_inf_eps();
|
||||||
|
|
||||||
void get_model_do_not_care_about_diff_vars(std::unordered_map<var_index, mpq> & variable_values) const;
|
void get_model_do_not_care_about_diff_vars(std::unordered_map<var_index, mpq> & variable_values) const;
|
||||||
|
|
||||||
std::string get_variable_name(var_index vi) const;
|
std::string get_variable_name(var_index vi) const;
|
||||||
|
|
|
@ -165,6 +165,7 @@ rational core::product_value(const unsigned_vector & m) const {
|
||||||
// return true iff the monic value is equal to the product of the values of the factors
|
// return true iff the monic value is equal to the product of the values of the factors
|
||||||
bool core::check_monic(const monic& m) const {
|
bool core::check_monic(const monic& m) const {
|
||||||
SASSERT((!m_lar_solver.column_is_int(m.var())) || m_lar_solver.get_column_value(m.var()).is_int());
|
SASSERT((!m_lar_solver.column_is_int(m.var())) || m_lar_solver.get_column_value(m.var()).is_int());
|
||||||
|
TRACE("nla_solver", print_monic_with_vars(m, tout) << '\n';);
|
||||||
return product_value(m.vars()) == m_lar_solver.get_column_value_rational(m.var());
|
return product_value(m.vars()) == m_lar_solver.get_column_value_rational(m.var());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1122,14 +1123,10 @@ std::unordered_map<unsigned, unsigned_vector> core::get_rm_by_arity() {
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool core::rm_check(const monic& rm) const {
|
bool core::rm_check(const monic& rm) const {
|
||||||
return check_monic(m_emons[rm.var()]);
|
return check_monic(m_emons[rm.var()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Add |v| ~ |bound|
|
\brief Add |v| ~ |bound|
|
||||||
where ~ is <, <=, >, >=,
|
where ~ is <, <=, >, >=,
|
||||||
|
@ -1330,6 +1327,7 @@ bool core::elists_are_consistent(bool check_in_model) const {
|
||||||
lbool core::check(vector<lemma>& l_vec) {
|
lbool core::check(vector<lemma>& l_vec) {
|
||||||
lp_settings().stats().m_nla_calls++;
|
lp_settings().stats().m_nla_calls++;
|
||||||
TRACE("nla_solver", tout << "calls = " << lp_settings().stats().m_nla_calls << "\n";);
|
TRACE("nla_solver", tout << "calls = " << lp_settings().stats().m_nla_calls << "\n";);
|
||||||
|
m_lar_solver.get_rid_of_inf_eps();
|
||||||
m_lemma_vec = &l_vec;
|
m_lemma_vec = &l_vec;
|
||||||
if (!(m_lar_solver.get_status() == lp::lp_status::OPTIMAL || m_lar_solver.get_status() == lp::lp_status::FEASIBLE )) {
|
if (!(m_lar_solver.get_status() == lp::lp_status::OPTIMAL || m_lar_solver.get_status() == lp::lp_status::FEASIBLE )) {
|
||||||
TRACE("nla_solver", tout << "unknown because of the m_lar_solver.m_status = " << m_lar_solver.get_status() << "\n";);
|
TRACE("nla_solver", tout << "unknown because of the m_lar_solver.m_status = " << m_lar_solver.get_status() << "\n";);
|
||||||
|
|
|
@ -752,7 +752,7 @@ class theory_lra::imp {
|
||||||
|
|
||||||
lpvar register_theory_var_in_lar_solver(theory_var v) {
|
lpvar register_theory_var_in_lar_solver(theory_var v) {
|
||||||
lpvar lpv = lp().external_to_local(v);
|
lpvar lpv = lp().external_to_local(v);
|
||||||
if (lpv + 1)
|
if (lpv != lp::null_lpvar)
|
||||||
return lpv;
|
return lpv;
|
||||||
return lp().add_var(v, is_int(v));
|
return lp().add_var(v, is_int(v));
|
||||||
}
|
}
|
||||||
|
@ -3717,12 +3717,17 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void display(std::ostream & out) const {
|
void display(std::ostream & out) {
|
||||||
if (m_solver) {
|
if (m_solver) {
|
||||||
lp().print_constraints(out);
|
lp().print_constraints(out);
|
||||||
lp().print_terms(out);
|
lp().print_terms(out);
|
||||||
// auto pp = lp ::core_solver_pretty_printer<lp::mpq, lp::impq>(lp().m_mpq_lar_core_solver.m_r_solver, out);
|
// the tableau
|
||||||
// pp.print();
|
auto pp = lp ::core_solver_pretty_printer<lp::mpq, lp::impq>(
|
||||||
|
lp().m_mpq_lar_core_solver.m_r_solver, out);
|
||||||
|
pp.print();
|
||||||
|
for (unsigned j = 0; j < lp().number_of_vars(); j++) {
|
||||||
|
lp().m_mpq_lar_core_solver.m_r_solver.print_column_info(j, out);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
unsigned nv = th.get_num_vars();
|
unsigned nv = th.get_num_vars();
|
||||||
for (unsigned v = 0; v < nv; ++v) {
|
for (unsigned v = 0; v < nv; ++v) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue