mirror of
https://github.com/Z3Prover/z3
synced 2025-06-29 01:18:45 +00:00
cheap_eqs - work on fixed_phase
Signed-off-by: Lev Nachmanson <levnach@hotmail.com>
This commit is contained in:
parent
cb3ebac3dd
commit
29b3f438bc
1 changed files with 161 additions and 118 deletions
|
@ -25,24 +25,19 @@ class lp_bound_propagator {
|
||||||
vertex* m_parent;
|
vertex* m_parent;
|
||||||
unsigned m_level; // the distance in hops to the root;
|
unsigned m_level; // the distance in hops to the root;
|
||||||
// it is handy to find the common ancestor
|
// it is handy to find the common ancestor
|
||||||
bool m_neg; // false if grows with the root, true if grows with -root
|
|
||||||
public:
|
public:
|
||||||
vertex() {}
|
vertex() {}
|
||||||
vertex(unsigned row,
|
vertex(unsigned row,
|
||||||
unsigned column,
|
unsigned column) :
|
||||||
bool neg) :
|
|
||||||
m_row(row),
|
m_row(row),
|
||||||
m_column(column),
|
m_column(column),
|
||||||
m_parent(nullptr),
|
m_parent(nullptr),
|
||||||
m_level(0),
|
m_level(0)
|
||||||
m_neg(neg)
|
|
||||||
{}
|
{}
|
||||||
unsigned column() const { return m_column; }
|
unsigned column() const { return m_column; }
|
||||||
unsigned row() const { return m_row; }
|
unsigned row() const { return m_row; }
|
||||||
vertex* parent() const { return m_parent; }
|
vertex* parent() const { return m_parent; }
|
||||||
unsigned level() const { return m_level; }
|
unsigned level() const { return m_level; }
|
||||||
bool neg() const { return m_neg; }
|
|
||||||
bool& neg() { return m_neg; }
|
|
||||||
void add_child(vertex* child) {
|
void add_child(vertex* child) {
|
||||||
SASSERT(!(*this == *child));
|
SASSERT(!(*this == *child));
|
||||||
child->m_parent = this;
|
child->m_parent = this;
|
||||||
|
@ -50,17 +45,24 @@ class lp_bound_propagator {
|
||||||
child->m_level = m_level + 1;
|
child->m_level = m_level + 1;
|
||||||
}
|
}
|
||||||
const ptr_vector<vertex> & children() const { return m_children; }
|
const ptr_vector<vertex> & children() const { return m_children; }
|
||||||
std::ostream& print(std::ostream & out) const {
|
|
||||||
out << "r = " << m_row << ", c = " << m_column << ", P = {";
|
|
||||||
if (m_parent) { out << "(" << m_parent->row() << ", " << m_parent->column() << ")";}
|
|
||||||
else { out << "null"; }
|
|
||||||
out << "} , lvl = " << m_level << (neg()? " -":" +");
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
bool operator==(const vertex& o) const {
|
bool operator==(const vertex& o) const {
|
||||||
return m_row == o.m_row && m_column == o.m_column;
|
return m_row == o.m_row && m_column == o.m_column;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
std::ostream& print(std::ostream & out, const vertex* v) const {
|
||||||
|
out << "r = " << v->row() << ", c = " << v->column() << ", P = {";
|
||||||
|
if (v->parent()) { out << "(" << v->parent()->row() << ", " << v->parent()->column() << ")";}
|
||||||
|
else { out << "null"; }
|
||||||
|
out << "} , lvl = " << v->level();
|
||||||
|
if (m_pol.contains(v->column())) {
|
||||||
|
tout << (pol(v) == -1? " -":" +");
|
||||||
|
} else {
|
||||||
|
tout << " not in m_pol";
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
hashtable<unsigned, u_hash, u_eq> m_visited_rows;
|
hashtable<unsigned, u_hash, u_eq> m_visited_rows;
|
||||||
hashtable<unsigned, u_hash, u_eq> m_visited_columns;
|
hashtable<unsigned, u_hash, u_eq> m_visited_columns;
|
||||||
vertex* m_root;
|
vertex* m_root;
|
||||||
|
@ -69,26 +71,20 @@ class lp_bound_propagator {
|
||||||
// by adjusting the vertices offsets, so they become absolute.
|
// by adjusting the vertices offsets, so they become absolute.
|
||||||
// If the tree is fixed then in addition to checking with the m_vals_to_verts
|
// If the tree is fixed then in addition to checking with the m_vals_to_verts
|
||||||
// we are going to check with the m_fixed_var_tables.
|
// we are going to check with the m_fixed_var_tables.
|
||||||
vertex* m_fixed_vertex;
|
const vertex* m_fixed_vertex;
|
||||||
|
explanation m_fixed_vertex_explanation;
|
||||||
// a pair (o, j) belongs to m_vals_to_verts iff x[j] = x[m_root->column()] + o
|
// a pair (o, j) belongs to m_vals_to_verts iff x[j] = x[m_root->column()] + o
|
||||||
map<mpq, vertex*, obj_hash<mpq>, default_eq<mpq>> m_vals_to_verts;
|
map<mpq, vertex*, obj_hash<mpq>, default_eq<mpq>> m_vals_to_verts;
|
||||||
// a pair (o, j) belongs to m_vals_to_verts_neg iff -x[j] = x[m_root->column()] + o
|
// a pair (o, j) belongs to m_vals_to_verts_neg iff -x[j] = x[m_root->column()] + o
|
||||||
map<mpq, vertex*, obj_hash<mpq>, default_eq<mpq>> m_vals_to_verts_neg;
|
map<mpq, vertex*, obj_hash<mpq>, default_eq<mpq>> m_vals_to_verts_neg;
|
||||||
|
// x[m_root->column()] - m_pol[j]*x[j] == const;
|
||||||
|
u_map<int> m_pol;
|
||||||
|
// if m_pos.contains(j) then x[j] = x[m_root->column()] + o
|
||||||
|
uint_set m_pos;
|
||||||
|
|
||||||
// these maps map a column index to the corresponding index in ibounds
|
// these maps map a column index to the corresponding index in ibounds
|
||||||
std::unordered_map<unsigned, unsigned> m_improved_lower_bounds;
|
std::unordered_map<unsigned, unsigned> m_improved_lower_bounds;
|
||||||
std::unordered_map<unsigned, unsigned> m_improved_upper_bounds;
|
std::unordered_map<unsigned, unsigned> m_improved_upper_bounds;
|
||||||
class signed_column {
|
|
||||||
bool m_sign;
|
|
||||||
unsigned m_column;
|
|
||||||
public:
|
|
||||||
signed_column() : m_column(UINT_MAX) {}
|
|
||||||
bool not_set() const { return m_column == UINT_MAX; }
|
|
||||||
bool is_set() const { return m_column != UINT_MAX; }
|
|
||||||
bool sign() const { return m_sign; }
|
|
||||||
bool& sign() { return m_sign; }
|
|
||||||
unsigned column() const { return m_column; }
|
|
||||||
unsigned& column() { return m_column; }
|
|
||||||
};
|
|
||||||
|
|
||||||
T& m_imp;
|
T& m_imp;
|
||||||
vector<implied_bound> m_ibounds;
|
vector<implied_bound> m_ibounds;
|
||||||
|
@ -172,19 +168,6 @@ public:
|
||||||
m_imp.consume(a, ci);
|
m_imp.consume(a, ci);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool set_sign_and_column(signed_column& i, const row_cell<mpq> & c) const {
|
|
||||||
if (c.coeff().is_one()) {
|
|
||||||
i.sign() = false;
|
|
||||||
i.column() = c.var();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if (c.coeff().is_minus_one()){
|
|
||||||
i.sign() = true;
|
|
||||||
i.column() = c.var();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
const mpq& val(unsigned j) const {
|
const mpq& val(unsigned j) const {
|
||||||
return lp().get_column_value(j).x;
|
return lp().get_column_value(j).x;
|
||||||
}
|
}
|
||||||
|
@ -200,11 +183,11 @@ public:
|
||||||
if (!lp().find_in_fixed_tables(val(v_j), is_int(v_j), j))
|
if (!lp().find_in_fixed_tables(val(v_j), is_int(v_j), j))
|
||||||
return;
|
return;
|
||||||
TRACE("cheap_eq", tout << "found j=" << j << " for v=";
|
TRACE("cheap_eq", tout << "found j=" << j << " for v=";
|
||||||
v->print(tout) << "\n in lp.fixed tables\n";);
|
print(tout, v) << "\n in lp.fixed tables\n";);
|
||||||
ptr_vector<vertex> path;
|
ptr_vector<const vertex> path;
|
||||||
find_path_on_tree(path, v, m_fixed_vertex);
|
find_path_on_tree(path, v, m_fixed_vertex);
|
||||||
explanation ex = get_explanation_from_path(path);
|
explanation ex = get_explanation_from_path(path);
|
||||||
explain_fixed_column(ex, j);
|
ex.add_expl(m_fixed_vertex_explanation);
|
||||||
add_eq_on_columns(ex, j, v->column());
|
add_eq_on_columns(ex, j, v->column());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,34 +201,81 @@ public:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// pol for polarity
|
||||||
|
int pol(const vertex* v) const { return pol(v->column()); }
|
||||||
|
int pol(unsigned j) const { return m_pol[j]; }
|
||||||
|
void set_polarity(unsigned j, int p) {
|
||||||
|
SASSERT(p == 1 || p == -1);
|
||||||
|
SASSERT(!m_pol.contains(j));
|
||||||
|
m_pol.insert(j, p);
|
||||||
|
}
|
||||||
|
|
||||||
|
void check_polarity(vertex* v, int polarity) {
|
||||||
|
int prev_pol;
|
||||||
|
if (!m_pol.find(v->column(), prev_pol)) {
|
||||||
|
m_pol.insert(v->column(), polarity);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (prev_pol == polarity)
|
||||||
|
return;
|
||||||
|
TRACE("cheap_eq", tout << "polarity switch:"; print(tout , v) << "\n";);
|
||||||
|
const vertex *u = find_other_vertex_with_same_column(v);
|
||||||
|
ptr_vector<const vertex> path;
|
||||||
|
find_path_on_tree(path, u, v);
|
||||||
|
m_fixed_vertex_explanation = get_explanation_from_path(path);
|
||||||
|
set_fixed_vertex(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
const vertex* find_other_vertex_with_same_column(const vertex* t) const {
|
||||||
|
return find_other_vertex_with_same_column_under(m_root, t);
|
||||||
|
}
|
||||||
|
|
||||||
|
const vertex * find_other_vertex_with_same_column_under(const vertex* v, const vertex* t) const {
|
||||||
|
if (v != t && v->column() == t->column())
|
||||||
|
return v;
|
||||||
|
for (const vertex* c : v->children()) {
|
||||||
|
auto u = find_other_vertex_with_same_column_under(c, t);
|
||||||
|
if (u)
|
||||||
|
return u;
|
||||||
|
}
|
||||||
|
UNREACHABLE();
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
bool tree_contains(vertex *v) const {
|
bool tree_contains(vertex *v) const {
|
||||||
if (!m_root)
|
if (!m_root)
|
||||||
return false;
|
return false;
|
||||||
return tree_contains_r(m_root, v);
|
return tree_contains_r(m_root, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
vertex * alloc_v(unsigned row_index, unsigned column, bool neg) {
|
vertex * alloc_v(unsigned row_index, unsigned column) {
|
||||||
vertex * v = alloc(vertex, row_index, column, neg);
|
vertex * v = alloc(vertex, row_index, column);
|
||||||
SASSERT(!tree_contains(v));
|
SASSERT(!tree_contains(v));
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool not_set(unsigned j) { return j == UINT_MAX; }
|
||||||
|
static bool is_set(unsigned j) { return j != UINT_MAX; }
|
||||||
|
|
||||||
void create_root(unsigned row_index) {
|
void create_root(unsigned row_index) {
|
||||||
SASSERT(!m_root && !m_fixed_vertex);
|
SASSERT(!m_root && !m_fixed_vertex);
|
||||||
signed_column x, y;
|
unsigned x, y;
|
||||||
|
int polarity;
|
||||||
TRACE("cheap_eq", print_row(tout, row_index););
|
TRACE("cheap_eq", print_row(tout, row_index););
|
||||||
if (!is_tree_offset_row(row_index, x, y)) {
|
if (!is_tree_offset_row(row_index, x, y, polarity)) {
|
||||||
TRACE("cheap_eq", tout << "not an offset row\n";);
|
TRACE("cheap_eq", tout << "not an offset row\n";);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const mpq& r = val(x.column());
|
const mpq& r = val(x);
|
||||||
m_root = alloc_v(row_index, x.column(), false);
|
m_root = alloc_v(row_index, x);
|
||||||
if (y.not_set()) {
|
set_polarity(x, 1);
|
||||||
|
if (not_set(y)) {
|
||||||
set_fixed_vertex(m_root);
|
set_fixed_vertex(m_root);
|
||||||
|
explain_fixed_in_row(row_index, m_fixed_vertex_explanation);
|
||||||
} else {
|
} else {
|
||||||
bool neg = x.sign() == y.sign();
|
vertex *v = alloc_v(row_index, y);
|
||||||
vertex *v = alloc_v(row_index, y.column(), neg);
|
|
||||||
m_root->add_child(v);
|
m_root->add_child(v);
|
||||||
|
set_polarity(y, polarity);
|
||||||
}
|
}
|
||||||
// keep root in the positive table
|
// keep root in the positive table
|
||||||
m_vals_to_verts.insert(r, m_root);
|
m_vals_to_verts.insert(r, m_root);
|
||||||
|
@ -261,29 +291,33 @@ public:
|
||||||
// It is assumed that parent->column() is present in the row
|
// It is assumed that parent->column() is present in the row
|
||||||
vertex* add_child_from_row(unsigned row_index, vertex* parent) {
|
vertex* add_child_from_row(unsigned row_index, vertex* parent) {
|
||||||
TRACE("cheap_eq", print_row(tout, row_index););
|
TRACE("cheap_eq", print_row(tout, row_index););
|
||||||
signed_column x, y;
|
unsigned x, y; int polarity;
|
||||||
if (!is_tree_offset_row(row_index, x, y)) {
|
if (!is_tree_offset_row(row_index, x, y, polarity)) {
|
||||||
TRACE("cheap_eq", tout << "not an offset row\n"; );
|
TRACE("cheap_eq", tout << "not an offset row\n"; );
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
if (y.not_set()) {
|
if (not_set(y)) {
|
||||||
SASSERT(parent->column() == x.column());
|
SASSERT(parent->column() == x);
|
||||||
vertex *v = alloc_v( row_index, x.column(), parent->neg());
|
vertex *v = alloc_v(row_index, x);
|
||||||
parent->add_child(v);
|
parent->add_child(v);
|
||||||
|
if (!fixed_phase()) {
|
||||||
set_fixed_vertex(v);
|
set_fixed_vertex(v);
|
||||||
|
explain_fixed_in_row(row_index, m_fixed_vertex_explanation);
|
||||||
|
}
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
SASSERT(x.is_set() && y.is_set());
|
SASSERT(is_set(x) && is_set(y));
|
||||||
|
|
||||||
// v is exactly like parent, but the row is different
|
// v has the column of the parent, but the row is different
|
||||||
vertex *v = alloc_v(row_index, parent->column(), parent->neg());
|
vertex *v = alloc_v(row_index, parent->column());
|
||||||
parent->add_child(v);
|
parent->add_child(v);
|
||||||
SASSERT(x.column() == v->column() || y.column() == v->column());
|
SASSERT(x == v->column() || y == v->column());
|
||||||
unsigned col = v->column() == y.column()? x.column(): y.column();
|
unsigned col = v->column() == y? x : y;
|
||||||
bool neg = x.sign() == y.sign() ? !v->neg(): v->neg();
|
vertex *vy = alloc_v(v->row(), col);
|
||||||
vertex *vy = alloc_v(v->row(), col, neg);
|
|
||||||
v->add_child(vy);
|
v->add_child(vy);
|
||||||
|
if (!fixed_phase())
|
||||||
|
check_polarity(vy, polarity * pol(v));
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -292,26 +326,32 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
void check_for_eq_and_add_to_val_table(vertex* v, map<mpq, vertex*, obj_hash<mpq>, default_eq<mpq>>& table) {
|
void check_for_eq_and_add_to_val_table(vertex* v, map<mpq, vertex*, obj_hash<mpq>, default_eq<mpq>>& table) {
|
||||||
|
TRACE("cheap_eq", tout << "v="; print(tout, v) << "\n";);
|
||||||
vertex *k; // the other vertex
|
vertex *k; // the other vertex
|
||||||
if (table.find(val(v), k)) {
|
if (table.find(val(v), k)) {
|
||||||
TRACE("cheap_eq", tout << "found k " ; k->print(tout) << "\n";);
|
TRACE("cheap_eq", tout << "found k " ; print(tout, k) << "\n";);
|
||||||
if (k->column() != v->column() &&
|
if (k->column() != v->column() &&
|
||||||
is_int(k->column()) == is_int(v->column()) &&
|
is_int(k->column()) == is_int(v->column()) &&
|
||||||
!is_equal(k->column(), v->column()))
|
!is_equal(k->column(), v->column())) {
|
||||||
report_eq(k, v);
|
report_eq(k, v);
|
||||||
} else {
|
} else {
|
||||||
TRACE("cheap_eq", tout << "registered: " << val(v) << " -> { "; v->print(tout) << "} \n";);
|
TRACE("cheap_eq", tout << "no report\n";);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
TRACE("cheap_eq", tout << "registered: " << val(v) << " -> { "; print(tout, v) << "} \n";);
|
||||||
table.insert(val(v), v);
|
table.insert(val(v), v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void check_for_eq_and_add_to_val_tables(vertex* v) {
|
void check_for_eq_and_add_to_val_tables(vertex* v) {
|
||||||
TRACE("cheap_eq_det", v->print(tout) << "\n";);
|
TRACE("cheap_eq_det", print(tout, v) << "\n";);
|
||||||
if (v->neg())
|
if (!fixed_phase()) {
|
||||||
|
if (pol(v->column()) == -1)
|
||||||
check_for_eq_and_add_to_val_table(v, m_vals_to_verts_neg);
|
check_for_eq_and_add_to_val_table(v, m_vals_to_verts_neg);
|
||||||
else
|
else
|
||||||
check_for_eq_and_add_to_val_table(v, m_vals_to_verts);
|
check_for_eq_and_add_to_val_table(v, m_vals_to_verts);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void clear_for_eq() {
|
void clear_for_eq() {
|
||||||
m_visited_rows.reset();
|
m_visited_rows.reset();
|
||||||
|
@ -319,11 +359,11 @@ public:
|
||||||
m_root = nullptr;
|
m_root = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream& print_path(const ptr_vector<vertex>& path, std::ostream& out) const {
|
std::ostream& print_path(const ptr_vector<const vertex>& path, std::ostream& out) const {
|
||||||
unsigned pr = UINT_MAX;
|
unsigned pr = UINT_MAX;
|
||||||
out << "path = \n";
|
out << "path = \n";
|
||||||
for (vertex* k : path) {
|
for (const vertex* k : path) {
|
||||||
k->print(out) << "\n";
|
print(out, k) << "\n";
|
||||||
if (k->row() != pr) {
|
if (k->row() != pr) {
|
||||||
print_row(out, pr = k->row());
|
print_row(out, pr = k->row());
|
||||||
}
|
}
|
||||||
|
@ -336,13 +376,13 @@ public:
|
||||||
SASSERT(v_i != v_j);
|
SASSERT(v_i != v_j);
|
||||||
SASSERT(lp().get_column_value(v_i->column()) == lp().get_column_value(v_j->column()));
|
SASSERT(lp().get_column_value(v_i->column()) == lp().get_column_value(v_j->column()));
|
||||||
TRACE("cheap_eq", tout << v_i->column() << " = " << v_j->column() << "\nu = ";
|
TRACE("cheap_eq", tout << v_i->column() << " = " << v_j->column() << "\nu = ";
|
||||||
v_i->print(tout) << "\nv = "; v_j->print(tout) <<"\n";
|
print(tout, v_i) << "\nv = "; print(tout, v_j) <<"\n";
|
||||||
display_row_of_vertex(v_i, tout);
|
display_row_of_vertex(v_i, tout);
|
||||||
if (v_j->row() != v_i->row())
|
if (v_j->row() != v_i->row())
|
||||||
display_row_of_vertex(v_j, tout);
|
display_row_of_vertex(v_j, tout);
|
||||||
);
|
);
|
||||||
|
|
||||||
ptr_vector<vertex> path;
|
ptr_vector<const vertex> path;
|
||||||
find_path_on_tree(path, v_i, v_j);
|
find_path_on_tree(path, v_i, v_j);
|
||||||
lp::explanation exp = get_explanation_from_path(path);
|
lp::explanation exp = get_explanation_from_path(path);
|
||||||
add_eq_on_columns(exp, v_i->column(), v_j->column());
|
add_eq_on_columns(exp, v_i->column(), v_j->column());
|
||||||
|
@ -364,19 +404,6 @@ public:
|
||||||
lp().settings().stats().m_cheap_eqs++;
|
lp().settings().stats().m_cheap_eqs++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
The table functionality:
|
|
||||||
Cheap propagation of equalities x_i = x_j, when
|
|
||||||
x_i = y + k
|
|
||||||
x_j = y + k
|
|
||||||
|
|
||||||
This equalities are detected by maintaining a map:
|
|
||||||
(y, k) -> row_id when a row is of the form x = y + k
|
|
||||||
If x = k, then y is null_lpvar
|
|
||||||
This methods checks whether the given row is an offset row (is_offset_row())
|
|
||||||
and uses the map to find new equalities if that is the case.
|
|
||||||
Some equalities, those spreading more than two rows, can be missed
|
|
||||||
*/
|
|
||||||
// column to theory_var
|
// column to theory_var
|
||||||
unsigned col_to_imp(unsigned j) const {
|
unsigned col_to_imp(unsigned j) const {
|
||||||
return lp().local_to_external(lp().column_to_reported_index(j));
|
return lp().local_to_external(lp().column_to_reported_index(j));
|
||||||
|
@ -391,10 +418,10 @@ public:
|
||||||
return lp().column_is_int(j);
|
return lp().column_is_int(j);
|
||||||
}
|
}
|
||||||
|
|
||||||
explanation get_explanation_from_path(const ptr_vector<vertex>& path) const {
|
explanation get_explanation_from_path(const ptr_vector<const vertex>& path) const {
|
||||||
explanation ex;
|
explanation ex;
|
||||||
unsigned prev_row = UINT_MAX;
|
unsigned prev_row = UINT_MAX;
|
||||||
for (vertex* k : path) {
|
for (const vertex* k : path) {
|
||||||
unsigned row = k->row();
|
unsigned row = k->row();
|
||||||
if (row == prev_row)
|
if (row == prev_row)
|
||||||
continue;
|
continue;
|
||||||
|
@ -423,11 +450,11 @@ public:
|
||||||
return print_row(out, k->row());
|
return print_row(out, k->row());
|
||||||
}
|
}
|
||||||
|
|
||||||
void find_path_on_tree(ptr_vector<vertex> & path, vertex* u, vertex* v) const {
|
void find_path_on_tree(ptr_vector<const vertex> & path, const vertex* u, const vertex* v) const {
|
||||||
TRACE("cheap_eq_details", tout << "u = " ;u->print(tout); tout << "\nv = ";v->print(tout) << "\n";);
|
TRACE("cheap_eq_details", tout << "u = " ; print(tout, u); tout << "\nv = ";print(tout, v) << "\n";);
|
||||||
vertex* up; // u parent
|
vertex* up; // u parent
|
||||||
vertex* vp; // v parent
|
vertex* vp; // v parent
|
||||||
ptr_vector<vertex> v_branch;
|
vector<const vertex*> v_branch;
|
||||||
path.push_back(u);
|
path.push_back(u);
|
||||||
v_branch.push_back(v);
|
v_branch.push_back(v);
|
||||||
// equalize the levels
|
// equalize the levels
|
||||||
|
@ -445,7 +472,7 @@ public:
|
||||||
v = vp;
|
v = vp;
|
||||||
}
|
}
|
||||||
SASSERT(u->level() == v->level());
|
SASSERT(u->level() == v->level());
|
||||||
TRACE("cheap_eq_details", tout << "u = " ;u->print(tout); tout << "\nv = ";v->print(tout) << "\n";);
|
TRACE("cheap_eq_details", tout << "u = " ; print(tout, u); tout << "\nv = "; print(tout, v) << "\n";);
|
||||||
while (u != v) {
|
while (u != v) {
|
||||||
up = u->parent();
|
up = u->parent();
|
||||||
vp = v->parent();
|
vp = v->parent();
|
||||||
|
@ -457,7 +484,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
for (unsigned i = v_branch.size(); i--; ) {
|
for (unsigned i = v_branch.size(); i--; ) {
|
||||||
vertex * bv = v_branch[i];
|
const vertex * bv = v_branch[i];
|
||||||
if (path.back() != bv)
|
if (path.back() != bv)
|
||||||
path.push_back(bv);
|
path.push_back(bv);
|
||||||
}
|
}
|
||||||
|
@ -477,8 +504,8 @@ public:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool tree_is_correct(vertex* v, ptr_vector<vertex>& vs) const {
|
bool tree_is_correct(vertex* v, ptr_vector<vertex>& vs) const {
|
||||||
if (fixed_phase() && v->neg())
|
if (fixed_phase())
|
||||||
return false;
|
return true;
|
||||||
for (vertex * u : v->children()) {
|
for (vertex * u : v->children()) {
|
||||||
if (contains_vertex(u, vs))
|
if (contains_vertex(u, vs))
|
||||||
return false;
|
return false;
|
||||||
|
@ -495,7 +522,7 @@ public:
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
std::ostream& print_tree(std::ostream & out, vertex* v) const {
|
std::ostream& print_tree(std::ostream & out, vertex* v) const {
|
||||||
v->print(out);
|
print(out, v);
|
||||||
out << "\nchildren :\n";
|
out << "\nchildren :\n";
|
||||||
for (auto * c : v->children()) {
|
for (auto * c : v->children()) {
|
||||||
print_tree(out, c);
|
print_tree(out, c);
|
||||||
|
@ -514,16 +541,15 @@ public:
|
||||||
TRACE("cheap_eq", tout << "tree = "; print_tree(tout, m_root) << "\n";);
|
TRACE("cheap_eq", tout << "tree = "; print_tree(tout, m_root) << "\n";);
|
||||||
SASSERT(tree_is_correct());
|
SASSERT(tree_is_correct());
|
||||||
explore_under(m_root);
|
explore_under(m_root);
|
||||||
if (fixed_phase()) {
|
|
||||||
create_fixed_eqs(m_root);
|
|
||||||
}
|
|
||||||
TRACE("cheap_eq", tout << "done for row_index " << row_index << "\n";);
|
TRACE("cheap_eq", tout << "done for row_index " << row_index << "\n";);
|
||||||
TRACE("cheap_eq", tout << "tree size = " << verts_size(););
|
TRACE("cheap_eq", tout << "tree size = " << verts_size(););
|
||||||
delete_tree(m_root);
|
delete_tree(m_root);
|
||||||
m_root = nullptr;
|
m_root = nullptr;
|
||||||
set_fixed_vertex(nullptr);
|
set_fixed_vertex(nullptr);
|
||||||
|
m_fixed_vertex_explanation.clear();
|
||||||
m_vals_to_verts.reset();
|
m_vals_to_verts.reset();
|
||||||
m_vals_to_verts_neg.reset();
|
m_vals_to_verts_neg.reset();
|
||||||
|
m_pol.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void create_fixed_eqs(vertex* v) {
|
void create_fixed_eqs(vertex* v) {
|
||||||
|
@ -533,8 +559,8 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream& print_row(std::ostream & out, unsigned row_index) const {
|
std::ostream& print_row(std::ostream & out, unsigned row_index) const {
|
||||||
signed_column x, y;
|
unsigned x, y; int polarity;
|
||||||
if (true || !is_tree_offset_row(row_index, x, y))
|
if (true || !is_tree_offset_row(row_index, x, y, polarity))
|
||||||
return lp().get_int_solver()->display_row_info(out, row_index);
|
return lp().get_int_solver()->display_row_info(out, row_index);
|
||||||
|
|
||||||
bool first = true;
|
bool first = true;
|
||||||
|
@ -554,11 +580,12 @@ public:
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void set_fixed_vertex(vertex *v) {
|
void set_fixed_vertex(vertex *v) {
|
||||||
TRACE("cheap_eq", if (v) v->print(tout); else tout << "set m_fixed_vertex to nullptr"; tout << "\n";);
|
TRACE("cheap_eq", if (v) print(tout, v); else tout << "set m_fixed_vertex to nullptr"; tout << "\n";);
|
||||||
|
SASSERT(!m_fixed_vertex || v == nullptr);
|
||||||
m_fixed_vertex = v;
|
m_fixed_vertex = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned verts_size() const {
|
unsigned verts_size() const {
|
||||||
return subtree_size(m_root);
|
return subtree_size(m_root);
|
||||||
}
|
}
|
||||||
|
@ -612,23 +639,39 @@ public:
|
||||||
// In case of only one non fixed column, and the function returns true,
|
// In case of only one non fixed column, and the function returns true,
|
||||||
// this column would be represened by x.
|
// this column would be represened by x.
|
||||||
bool is_tree_offset_row( unsigned row_index,
|
bool is_tree_offset_row( unsigned row_index,
|
||||||
signed_column & x,
|
unsigned & x, unsigned & y, int & polarity ) const {
|
||||||
signed_column & y) const {
|
x = y = UINT_MAX;
|
||||||
|
const row_cell<mpq>* x_cell = nullptr;
|
||||||
|
const row_cell<mpq>* y_cell = nullptr;
|
||||||
const auto & row = lp().get_row(row_index);
|
const auto & row = lp().get_row(row_index);
|
||||||
for (unsigned k = 0; k < row.size(); k++) {
|
for (unsigned k = 0; k < row.size(); k++) {
|
||||||
const auto& c = row[k];
|
const auto& c = row[k];
|
||||||
if (column_is_fixed(c.var()))
|
if (column_is_fixed(c.var()))
|
||||||
continue;
|
continue;
|
||||||
if (x.not_set()) {
|
if (not_set(x)) {
|
||||||
if (!set_sign_and_column(x, c))
|
if (c.coeff().is_one() || c.coeff().is_minus_one()) {
|
||||||
|
x = c.var();
|
||||||
|
x_cell = & c;
|
||||||
|
} else {
|
||||||
return false;
|
return false;
|
||||||
} else if (y.not_set()) {
|
}
|
||||||
if (!set_sign_and_column(y, c))
|
} else if (not_set(y)) {
|
||||||
|
if (c.coeff().is_one() || c.coeff().is_minus_one()) {
|
||||||
|
y = c.var();
|
||||||
|
y_cell = & c;
|
||||||
|
} else
|
||||||
return false;
|
return false;
|
||||||
} else
|
} else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return x.is_set() || y.is_set();
|
if (is_set(x)) {
|
||||||
|
if (is_set(y))
|
||||||
|
polarity = x_cell->coeff().is_pos() == y_cell->coeff().is_pos()? -1 : 1;
|
||||||
|
else
|
||||||
|
polarity = 1;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue