mirror of
https://github.com/Z3Prover/z3
synced 2025-06-06 06:03:23 +00:00
add init_model, global m_delta, get_value, get_ivalue to push model maintainance into lar_solver #4740
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
ab199dedf9
commit
ee12e3fb52
5 changed files with 2269 additions and 2211 deletions
File diff suppressed because it is too large
Load diff
|
@ -137,10 +137,7 @@ class lar_solver : public column_namer {
|
||||||
|
|
||||||
inline void clear_columns_with_changed_bounds() { m_columns_with_changed_bounds.clear(); }
|
inline void clear_columns_with_changed_bounds() { m_columns_with_changed_bounds.clear(); }
|
||||||
inline void increase_by_one_columns_with_changed_bounds() { m_columns_with_changed_bounds.increase_size_by_one(); }
|
inline void increase_by_one_columns_with_changed_bounds() { m_columns_with_changed_bounds.increase_size_by_one(); }
|
||||||
inline void insert_to_columns_with_changed_bounds(unsigned j) {
|
inline void insert_to_columns_with_changed_bounds(unsigned j) { m_columns_with_changed_bounds.insert(j); }
|
||||||
m_columns_with_changed_bounds.insert(j);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void update_column_type_and_bound_check_on_equal(unsigned j, lconstraint_kind kind, const mpq & right_side, constraint_index constr_index, unsigned&);
|
void update_column_type_and_bound_check_on_equal(unsigned j, lconstraint_kind kind, const mpq & right_side, constraint_index constr_index, unsigned&);
|
||||||
void update_column_type_and_bound(unsigned j, lconstraint_kind kind, const mpq & right_side, constraint_index constr_index);
|
void update_column_type_and_bound(unsigned j, lconstraint_kind kind, const mpq & right_side, constraint_index constr_index);
|
||||||
|
@ -289,6 +286,11 @@ class lar_solver : public column_namer {
|
||||||
void collect_rounded_rows_to_fix();
|
void collect_rounded_rows_to_fix();
|
||||||
void register_normalized_term(const lar_term&, lpvar);
|
void register_normalized_term(const lar_term&, lpvar);
|
||||||
void deregister_normalized_term(const lar_term&);
|
void deregister_normalized_term(const lar_term&);
|
||||||
|
|
||||||
|
mutable std::unordered_set<impq> m_set_of_different_pairs;
|
||||||
|
mutable std::unordered_set<mpq> m_set_of_different_singles;
|
||||||
|
mutable mpq m_delta;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const map<mpq, unsigned, obj_hash<mpq>, default_eq<mpq>>& fixed_var_table_int() const {
|
const map<mpq, unsigned, obj_hash<mpq>, default_eq<mpq>>& fixed_var_table_int() const {
|
||||||
return m_fixed_var_table_int;
|
return m_fixed_var_table_int;
|
||||||
|
@ -520,6 +522,10 @@ public:
|
||||||
std::ostream& print_constraint_indices_only(const lar_base_constraint * c, std::ostream & out) const;
|
std::ostream& print_constraint_indices_only(const lar_base_constraint * c, std::ostream & out) const;
|
||||||
std::ostream& print_implied_bound(const implied_bound& be, std::ostream & out) const;
|
std::ostream& print_implied_bound(const implied_bound& be, std::ostream & out) const;
|
||||||
std::ostream& print_values(std::ostream& out) const;
|
std::ostream& print_values(std::ostream& out) const;
|
||||||
|
bool init_model() const;
|
||||||
|
mpq get_value(column_index const& j) const;
|
||||||
|
mpq get_value(tv const& t) const;
|
||||||
|
impq get_ivalue(tv const& t) const;
|
||||||
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_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;
|
||||||
|
@ -615,6 +621,7 @@ public:
|
||||||
inline const vector<unsigned> & r_nbasis() const { return m_mpq_lar_core_solver.r_nbasis(); }
|
inline const vector<unsigned> & r_nbasis() const { return m_mpq_lar_core_solver.r_nbasis(); }
|
||||||
inline bool column_is_real(unsigned j) const { return !column_is_int(j); }
|
inline bool column_is_real(unsigned j) const { return !column_is_int(j); }
|
||||||
lp_status get_status() const;
|
lp_status get_status() const;
|
||||||
|
bool has_changed_columns() const { return !m_columns_with_changed_bounds.empty(); }
|
||||||
void set_status(lp_status s);
|
void set_status(lp_status s);
|
||||||
lp_status solve();
|
lp_status solve();
|
||||||
void fill_explanation_from_crossed_bounds_column(explanation & evidence) const;
|
void fill_explanation_from_crossed_bounds_column(explanation & evidence) const;
|
||||||
|
@ -631,8 +638,8 @@ public:
|
||||||
inline const static_matrix<mpq, impq> & A_r() const { return m_mpq_lar_core_solver.m_r_A; }
|
inline const static_matrix<mpq, impq> & A_r() const { return m_mpq_lar_core_solver.m_r_A; }
|
||||||
// columns
|
// columns
|
||||||
bool column_is_int(column_index const& j) const { return column_is_int((unsigned)j); }
|
bool column_is_int(column_index const& j) const { return column_is_int((unsigned)j); }
|
||||||
const impq& get_value(column_index const& j) const { return get_column_value(j); }
|
const impq& get_ivalue(column_index const& j) const { return get_column_value(j); }
|
||||||
const impq& get_column_value(unsigned j) const { return m_mpq_lar_core_solver.m_r_x[j]; }
|
const impq& get_column_value(column_index const& j) const { return m_mpq_lar_core_solver.m_r_x[j]; }
|
||||||
inline
|
inline
|
||||||
var_index external_to_local(unsigned j) const {
|
var_index external_to_local(unsigned j) const {
|
||||||
var_index local_j;
|
var_index local_j;
|
||||||
|
|
|
@ -36,6 +36,20 @@ typedef unsigned lpvar;
|
||||||
const lpvar null_lpvar = UINT_MAX;
|
const lpvar null_lpvar = UINT_MAX;
|
||||||
const constraint_index null_ci = UINT_MAX;
|
const constraint_index null_ci = UINT_MAX;
|
||||||
|
|
||||||
|
class column_index {
|
||||||
|
unsigned m_index;
|
||||||
|
friend class lar_solver;
|
||||||
|
friend class lar_term;
|
||||||
|
friend nla::core;
|
||||||
|
|
||||||
|
operator unsigned() const { return m_index; }
|
||||||
|
|
||||||
|
public:
|
||||||
|
column_index(unsigned j): m_index(j) {}
|
||||||
|
unsigned index() const { return m_index; }
|
||||||
|
bool is_null() const { return m_index == null_lpvar; }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// index that comes from term or variable.
|
// index that comes from term or variable.
|
||||||
class tv {
|
class tv {
|
||||||
|
@ -49,6 +63,7 @@ public:
|
||||||
|
|
||||||
// retrieve the identifier associated with tv
|
// retrieve the identifier associated with tv
|
||||||
unsigned id() const { return unmask_term(m_index); }
|
unsigned id() const { return unmask_term(m_index); }
|
||||||
|
column_index column() const { SASSERT(is_var()); return column_index(id()); }
|
||||||
|
|
||||||
// retrieve the raw index.
|
// retrieve the raw index.
|
||||||
unsigned index() const { return m_index; }
|
unsigned index() const { return m_index; }
|
||||||
|
@ -74,20 +89,6 @@ public:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class column_index {
|
|
||||||
unsigned m_index;
|
|
||||||
friend class lar_solver;
|
|
||||||
friend class lar_term;
|
|
||||||
friend nla::core;
|
|
||||||
|
|
||||||
operator unsigned() const { return m_index; }
|
|
||||||
|
|
||||||
public:
|
|
||||||
column_index(unsigned j): m_index(j) {}
|
|
||||||
unsigned index() const { return m_index; }
|
|
||||||
bool is_null() const { return m_index == null_lpvar; }
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::ostream& operator<<(std::ostream& out, lp::tv const& t) {
|
inline std::ostream& operator<<(std::ostream& out, lp::tv const& t) {
|
||||||
|
|
|
@ -231,7 +231,6 @@ namespace euf {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void solver::get_antecedents(literal l, constraint& j, literal_vector& r, bool probing) {
|
void solver::get_antecedents(literal l, constraint& j, literal_vector& r, bool probing) {
|
||||||
expr* e = nullptr;
|
expr* e = nullptr;
|
||||||
euf::enode* n = nullptr;
|
euf::enode* n = nullptr;
|
||||||
|
|
|
@ -1474,6 +1474,7 @@ public:
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
auto I = m_variable_values.find(t2.index());
|
auto I = m_variable_values.find(t2.index());
|
||||||
|
std::cout << (I == E) << "\n";
|
||||||
if (I != E)
|
if (I != E)
|
||||||
result += I->second * coeff;
|
result += I->second * coeff;
|
||||||
}
|
}
|
||||||
|
@ -1619,7 +1620,7 @@ public:
|
||||||
IF_VERBOSE(12, verbose_stream() << "final-check " << lp().get_status() << "\n");
|
IF_VERBOSE(12, verbose_stream() << "final-check " << lp().get_status() << "\n");
|
||||||
lbool is_sat = l_true;
|
lbool is_sat = l_true;
|
||||||
SASSERT(lp().ax_is_correct());
|
SASSERT(lp().ax_is_correct());
|
||||||
if (lp().get_status() != lp::lp_status::OPTIMAL) {
|
if (lp().get_status() != lp::lp_status::OPTIMAL || lp().has_changed_columns()) {
|
||||||
is_sat = make_feasible();
|
is_sat = make_feasible();
|
||||||
}
|
}
|
||||||
final_check_status st = FC_DONE;
|
final_check_status st = FC_DONE;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue